src/station.cpp
author frosch
Sat, 25 Oct 2008 14:19:09 +0000
changeset 10290 56925f09d693
parent 10260 c6ec6b3c1b18
child 10347 6da2d30f2fe8
permissions -rw-r--r--
(svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
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;
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
    54
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
    55
	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
    56
	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
    57
}
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
/**
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
    60
 * 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
    61
 * 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
    62
 * 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
    63
 * 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
    64
 */
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
    65
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
    66
{
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
	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
    68
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
    69
	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
    70
	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
    71
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
	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
    73
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
    74
	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
    75
		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
    76
	}
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
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
    78
	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
    79
	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
    80
		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
    81
			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
    82
		}
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
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
    85
	MarkDirty();
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9111
diff changeset
    86
	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
    87
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
	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
    89
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
	/* 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
    91
	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
    92
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
    93
	/* 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
    94
	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
    95
10123
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 9413
diff changeset
    96
	/* Remove all news items */
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 9413
diff changeset
    97
	DeleteStationNews(this->index);
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 9413
diff changeset
    98
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
    99
	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
   100
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
	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
   102
		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
   103
	}
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
   104
}
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
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
   106
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
 * 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
   109
 * @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
   110
 * @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
   111
 */
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
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
   113
{
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8784
diff changeset
   114
	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
   115
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
	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
   117
		/* 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
   118
		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
   119
		/* 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
   120
		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
   121
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
		/* 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
   123
		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
   124
	}
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
	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
   127
}
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
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
   129
/** 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
   130
 * 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
   131
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
   132
{
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
	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
   134
		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
   135
		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
   136
	}
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
	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
   138
	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
   139
	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
   140
}
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
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
   142
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
   143
{
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
	if (sign.width_1 != 0) {
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 7931
diff changeset
   145
		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
   146
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
   147
		/* 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
   148
		 *  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
   149
		 *  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
   150
		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
   151
			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
   152
			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
   153
			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
   154
			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
   155
	}
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
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
   158
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
   159
{
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
	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
   161
	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
   162
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   163
	/* 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
   164
	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
   165
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
   166
	/* 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
   167
	 * 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
   168
	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
   169
		/* 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
   170
		 * 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
   171
		 * 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
   172
		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
   173
	}
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
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
   175
	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
   176
		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
   177
			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
   178
				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
   179
			}
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
			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
   181
		}
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
		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
   183
	}
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
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
   187
{
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
	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
   189
}
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
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
   191
/** 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
   192
 * @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
   193
 * @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
   194
 * @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
   195
 */
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
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
   197
{
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
	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
   199
	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
   200
	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
   201
	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
   202
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
	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
   204
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
	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
   206
	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
   207
		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
   208
		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
   209
	} 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
   210
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
	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
   212
	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
   213
		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
   214
		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
   215
	} 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
   216
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
	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
   218
}
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
/** 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
   221
 * 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
   222
 * @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
   223
 * @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
   224
 * @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
   225
 */
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
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
   227
{
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
	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
   229
	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
   230
	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
   231
	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
   232
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
	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
   234
		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
   235
		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
   236
	} 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
   237
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
	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
   239
}
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
5896
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   241
/** Determines whether a station is a buoy only.
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   242
 * @todo Ditch this encoding of buoys
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   243
 */
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   244
bool Station::IsBuoy() const
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   245
{
5997
e6d057d90fce (svn r8708) -Codechange(r8514): No need to use "this->" in methods
celestar
parents: 5996
diff changeset
   246
	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
   247
}
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   248
10290
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   249
/** Determines the catchment radius of the station
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   250
 * @return The radius
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   251
 */
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   252
uint Station::GetCatchmentRadius() const
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   253
{
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   254
	uint ret = CA_NONE;
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   255
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   256
	if (_settings_game.station.modified_catchment) {
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   257
		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
   258
		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
   259
		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
   260
		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
   261
		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
   262
	} else {
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   263
		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
   264
			ret = CA_UNMODIFIED;
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   265
		}
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
	return ret;
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   269
}
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   270
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   271
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
/*                     StationRect implementation                       */
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   274
/************************************************************************/
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
StationRect::StationRect()
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   277
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   278
	MakeEmpty();
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   279
}
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
void StationRect::MakeEmpty()
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   282
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   283
	left = top = right = bottom = 0;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   284
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   285
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
   286
/**
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
 * 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
   288
 * 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
   289
 * @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
   290
 * @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
   291
 * @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
   292
 * @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
   293
 * @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
   294
 */
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
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
   296
{
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
   297
	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
   298
}
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
bool StationRect::IsEmpty() const
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   301
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   302
	return (left == 0 || left > right || top > bottom);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   303
}
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
bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   306
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   307
	int x = TileX(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   308
	int y = TileY(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   309
	if (IsEmpty()) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   310
		/* 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
   311
		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
   312
			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
   313
			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
   314
		}
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
   315
	} else if (!PtInExtendedRect(x, y)) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   316
		/* current rect is not empty and new point is outside this rect */
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   317
		/* make new spread-out rectangle */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   318
		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
   319
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   320
		/* 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
   321
		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
   322
		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
   323
		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
   324
			assert(mode != ADD_TRY);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   325
			_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
   326
			return false;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   327
		}
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   328
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   329
		/* spread-out ok, return true */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   330
		if (mode != ADD_TEST) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   331
			/* we should update the station rect */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   332
			*this = new_rect;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   333
		}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   334
	} else {
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   335
		; // 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
   336
	}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   337
	return true;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   338
}
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
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
   341
{
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
   342
	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
   343
			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
   344
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   345
10260
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   346
/**
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   347
 * 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
   348
 * @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
   349
 * @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
   350
 * @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
   351
 * @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
   352
 * @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
   353
 * @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
   354
 */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   355
/*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
   356
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   357
	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
   358
	int width = right_a - left_a + 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   359
	int height = bottom_a - top_a + 1;
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   360
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   361
	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
   362
		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
   363
	END_TILE_LOOP(tile, width, height, top_left);
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   364
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   365
	return false;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   366
}
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
bool StationRect::AfterRemoveTile(Station *st, TileIndex tile)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   369
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   370
	int x = TileX(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   371
	int y = TileY(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   372
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   373
	/* look if removed tile was on the bounding rect edge
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   374
	 * and try to reduce the rect by this edge
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   375
	 * 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
   376
	for (;;) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   377
		/* 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
   378
		bool left_edge = (x == left);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   379
		bool right_edge = (x == right);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   380
		bool top_edge = (y == top);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   381
		bool bottom_edge = (y == bottom);
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   382
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   383
		/* can we reduce the rect in either direction? */
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   384
		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
   385
		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
   386
		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
   387
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   388
		if (reduce_x) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   389
			/* reduce horizontally */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   390
			if (left_edge) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   391
				/* move left edge right */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   392
				left = x = x + 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   393
			} else {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   394
				/* move right edge left */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   395
				right = x = x - 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   396
			}
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
		if (reduce_y) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   399
			/* reduce vertically */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   400
			if (top_edge) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   401
				/* move top edge down */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   402
				top = y = y + 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   403
			} else {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   404
				/* move bottom edge up */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   405
				bottom = y = y - 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   406
			}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   407
		}
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   408
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   409
		if (left > right || top > bottom) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   410
			/* 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
   411
			MakeEmpty();
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   412
			return true; // empty remaining rect
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   413
		}
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
	return false; // non-empty remaining rect
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   416
}
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
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
   419
{
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
   420
	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
   421
	assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1));
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   422
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   423
	bool empty = AfterRemoveTile(st, tile);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   424
	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
   425
	return empty;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   426
}
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
StationRect& StationRect::operator = (Rect src)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   429
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   430
	left = src.left;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   431
	top = src.top;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   432
	right = src.right;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   433
	bottom = src.bottom;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   434
	return *this;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   435
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   436
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
   437
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
/*                     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
   440
/************************************************************************/
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
/** Initializes a RoadStop */
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5713
diff changeset
   443
RoadStop::RoadStop(TileIndex tile) :
5713
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   444
	xy(tile),
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   445
	status(3), // stop is free
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   446
	num_vehicles(0),
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5835
diff changeset
   447
	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
   448
{
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5713
diff changeset
   449
	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
   450
}
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
/** 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
   453
  * 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
   454
  */
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
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
   456
{
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
   457
	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
   458
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
   459
	/* 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
   460
	if (num_vehicles != 0) {
5713
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   461
		Vehicle *v;
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   462
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
   463
		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
   464
			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
   465
		}
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
	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
   468
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5713
diff changeset
   469
	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
   470
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
   471
	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
   472
}
5835
7ef65a4a70ef (svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents: 5721
diff changeset
   473
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   474
/** 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
   475
bool RoadStop::HasFreeBay() const
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   476
{
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   477
	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
   478
}
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   479
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   480
/** 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
   481
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
   482
{
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   483
	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
   484
	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
   485
}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   486
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   487
/**
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   488
 * Allocates a bay
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   489
 * @return the allocated bay number
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   490
 * @pre this->HasFreeBay()
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   491
 */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   492
uint RoadStop::AllocateBay()
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   493
{
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
   494
	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
   495
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   496
	/* 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
   497
	uint bay_nr = 0;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7496
diff changeset
   498
	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
   499
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
   500
	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
   501
	return bay_nr;
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   502
}
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
/**
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   505
 * 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
   506
 * @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
   507
 */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   508
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
   509
{
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   510
	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
   511
	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
   512
}
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
/**
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   515
 * Frees the given bay
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   516
 * @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
   517
 */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   518
void RoadStop::FreeBay(uint nr)
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   519
{
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   520
	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
   521
	SetBit(status, nr);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   522
}
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
/** 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
   526
bool RoadStop::IsEntranceBusy() const
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   527
{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7496
diff changeset
   528
	return HasBit(status, 7);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   529
}
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
/** Makes an entrance occupied or free */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   532
void RoadStop::SetEntranceBusy(bool busy)
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   533
{
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
   534
	SB(status, 7, 1, busy);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   535
}
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
   536
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
 * 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
   539
 * @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
   540
 * @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
   541
 */
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
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
   543
{
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
	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
   545
		/* 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
   546
		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
   547
		/* 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
   548
		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
   549
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
		/* 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
   551
		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
   552
	}
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
	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
   555
}