Changeset - r8109:4be46a88003b
[Not reviewed]
master
0 3 0
smatz - 17 years ago 2007-12-19 23:35:14
smatz@openttd.org
(svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
3 files changed with 20 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/station.h
Show inline comments
 
@@ -291,9 +291,11 @@ void StationPickerDrawSprite(int x, int 
 

	
 
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type);
 
uint GetNumRoadStops(const Station* st, RoadStop::Type type);
 
RoadStop * AllocateRoadStop();
 
void ClearSlot(Vehicle *v);
 

	
 
bool HasStationInUse(StationID station, PlayerID player);
 

	
 
void DeleteOilRig(TileIndex t);
 

	
 
#endif /* STATION_H */
src/station_cmd.cpp
Show inline comments
 
@@ -1865,21 +1865,26 @@ CommandCost CmdBuildBuoy(TileIndex tile,
 
		st_auto_delete.Detach();
 
	}
 

	
 
	return CommandCost(_price.build_dock);
 
}
 

	
 
/* Checks if any ship is servicing the buoy specified. Returns yes or no */
 
static bool CheckShipsOnBuoy(Station *st)
 
/**
 
 * Tests whether the player's vehicles have this station in orders
 
 * When player == INVALID_PLAYER, then check all vehicles
 
 * @param station station ID
 
 * @param player player ID, INVALID_PLAYER to disable the check
 
 */
 
bool HasStationInUse(StationID station, PlayerID player)
 
{
 
	const Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_SHIP) {
 
		if (player == INVALID_PLAYER || v->owner == player) {
 
			const Order *order;
 
			FOR_VEHICLE_ORDERS(v, order) {
 
				if (order->type == OT_GOTO_STATION && order->dest == st->index) {
 
				if (order->type == OT_GOTO_STATION && order->dest == station) {
 
					return true;
 
				}
 
			}
 
		}
 
	}
 
	return false;
 
@@ -1889,13 +1894,13 @@ static CommandCost RemoveBuoy(Station *s
 
{
 
	/* XXX: strange stuff */
 
	if (!IsValidPlayer(_current_player))  return_cmd_error(INVALID_STRING_ID);
 

	
 
	TileIndex tile = st->dock_tile;
 

	
 
	if (CheckShipsOnBuoy(st))   return_cmd_error(STR_BUOY_IS_IN_USE);
 
	if (HasStationInUse(st->index, INVALID_PLAYER)) return_cmd_error(STR_BUOY_IS_IN_USE);
 
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		st->dock_tile = 0;
 
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
 
		 * braindead.. */
src/station_gui.cpp
Show inline comments
 
@@ -22,12 +22,13 @@
 
#include "date.h"
 
#include "vehicle.h"
 
#include "table/sprites.h"
 
#include "helpers.hpp"
 
#include "cargotype.h"
 
#include "station_gui.h"
 
#include "station.h"
 

	
 
typedef int CDECL StationSortListingTypeFunction(const void*, const void*);
 

	
 
static StationSortListingTypeFunction StationNameSorter;
 
static StationSortListingTypeFunction StationTypeSorter;
 
static StationSortListingTypeFunction StationWaitingSorter;
 
@@ -230,13 +231,13 @@ static void BuildStationsList(plstations
 
	/* Create array for sorting */
 
	const Station** station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
 

	
 
	DEBUG(misc, 3, "Building station list for player %d", owner);
 

	
 
	FOR_ALL_STATIONS(st) {
 
		if (st->owner == owner) {
 
		if (st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy() && HasStationInUse(st->index, owner))) {
 
			if (facilities & st->facilities) { //only stations with selected facilities
 
				int num_waiting_cargo = 0;
 
				for (CargoID j = 0; j < NUM_CARGO; j++) {
 
					if (!st->goods[j].cargo.Empty()) {
 
						num_waiting_cargo++; //count number of waiting cargo
 
						if (HasBit(cargo_filter, j)) {
 
@@ -377,13 +378,16 @@ static void PlayerStationsWndProc(Window
 

	
 
			for (int i = w->vscroll.pos; i < max; ++i) { // do until max number of stations of owner
 
				const Station *st = sl->sort_list[i];
 
				int x;
 

	
 
				assert(st->xy != 0);
 
				assert(st->owner == owner);
 

	
 
 				/* Do not do the complex check HasStationInUse here, it may be even false
 
				 * when the order had been removed and the station list hasn't been removed yet */
 
				assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
 

	
 
				SetDParam(0, st->index);
 
				SetDParam(1, st->facilities);
 
				x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5;
 

	
 
				/* show cargo waiting and station ratings */
 
@@ -407,13 +411,14 @@ static void PlayerStationsWndProc(Window
 

	
 
					id_v += w->vscroll.pos;
 

	
 
					if (id_v >= sl->list_length) return; // click out of list bound
 

	
 
					const Station *st = sl->sort_list[id_v];
 
					assert(st->owner == owner);
 
					/* do not check HasStationInUse - it is slow and may be invalid */
 
					assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
 
					ScrollMainWindowToTile(st->xy);
 
					break;
 
				}
 

	
 
				case SLW_TRAIN:
 
				case SLW_TRUCK:
0 comments (0 inline, 0 general)