Changeset - r18858:db5888e8ffaa
[Not reviewed]
master
0 1 0
rubidium - 13 years ago 2012-01-02 20:39:18
rubidium@openttd.org
(svn r23717) -Fix [FS#4927]: ships going to wrong dock location when moving the dock while the game is paused
1 file changed with 15 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file station_cmd.cpp Handling of station tiles. */
 

	
 
#include "stdafx.h"
 
#include "aircraft.h"
 
#include "bridge_map.h"
 
#include "cmd_helper.h"
 
#include "viewport_func.h"
 
#include "command_func.h"
 
#include "town.h"
 
#include "news_func.h"
 
#include "train.h"
 
#include "ship.h"
 
#include "roadveh.h"
 
#include "industry.h"
 
#include "newgrf_cargo.h"
 
#include "newgrf_debug.h"
 
#include "newgrf_station.h"
 
#include "newgrf_canal.h" /* For the buoy */
 
#include "pathfinder/yapf/yapf_cache.h"
 
#include "road_internal.h" /* For drawing catenary/checking road removal */
 
#include "autoslope.h"
 
#include "water.h"
 
#include "station_gui.h"
 
#include "strings_func.h"
 
#include "clear_func.h"
 
#include "window_func.h"
 
#include "date_func.h"
 
#include "vehicle_func.h"
 
#include "string_func.h"
 
#include "animated_tile_func.h"
 
#include "elrail_func.h"
 
#include "station_base.h"
 
#include "roadstop_base.h"
 
#include "newgrf_railtype.h"
 
#include "waypoint_base.h"
 
#include "waypoint_func.h"
 
#include "pbs.h"
 
#include "debug.h"
 
#include "core/random_func.hpp"
 
#include "company_base.h"
 
#include "table/airporttile_ids.h"
 
#include "newgrf_airporttiles.h"
 
#include "order_backup.h"
 
#include "newgrf_house.h"
 
#include "company_gui.h"
 

	
 
#include "table/strings.h"
 

	
 
/**
 
 * Check whether the given tile is a hangar.
 
 * @param t the tile to of whether it is a hangar.
 
 * @pre IsTileType(t, MP_STATION)
 
 * @return true if and only if the tile is a hangar.
 
 */
 
bool IsHangar(TileIndex t)
 
{
 
	assert(IsTileType(t, MP_STATION));
 

	
 
	/* If the tile isn't an airport there's no chance it's a hangar. */
 
	if (!IsAirport(t)) return false;
 
@@ -2476,121 +2477,135 @@ CommandCost CmdBuildDock(TileIndex tile,
 

	
 
			if (Company::IsValidID(_current_company)) {
 
				SetBit(st->town->have_ratings, _current_company);
 
			}
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		st->dock_tile = tile;
 
		st->AddFacility(FACIL_DOCK, tile);
 

	
 
		st->rect.BeforeAddRect(
 
				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
 
				_dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
 

	
 
		/* If the water part of the dock is on a canal, update infrastructure counts.
 
		 * This is needed as we've unconditionally cleared that tile before. */
 
		if (wc == WATER_CLASS_CANAL) {
 
			Company::Get(st->owner)->infrastructure.water++;
 
		}
 
		Company::Get(st->owner)->infrastructure.station += 2;
 
		DirtyCompanyInfrastructureWindows(st->owner);
 

	
 
		MakeDock(tile, st->owner, st->index, direction, wc);
 

	
 
		st->UpdateVirtCoord();
 
		UpdateStationAcceptance(st, false);
 
		st->RecomputeIndustriesNear();
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
 
		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_SHIPS);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]);
 
}
 

	
 
/**
 
 * Remove a dock
 
 * @param tile TileIndex been queried
 
 * @param flags operation to perform
 
 * @return cost or failure of operation
 
 */
 
static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
 
{
 
	Station *st = Station::GetByTile(tile);
 
	CommandCost ret = CheckOwnership(st->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	TileIndex docking_location = TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
 

	
 
	TileIndex tile1 = st->dock_tile;
 
	TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
 

	
 
	ret = EnsureNoVehicleOnGround(tile1);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile1);
 
		MarkTileDirtyByTile(tile1);
 
		MakeWaterKeepingClass(tile2, st->owner);
 

	
 
		st->rect.AfterRemoveTile(st, tile1);
 
		st->rect.AfterRemoveTile(st, tile2);
 

	
 
		st->dock_tile = INVALID_TILE;
 
		st->facilities &= ~FACIL_DOCK;
 

	
 
		Company::Get(st->owner)->infrastructure.station -= 2;
 
		DirtyCompanyInfrastructureWindows(st->owner);
 

	
 
		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_SHIPS);
 
		st->UpdateVirtCoord();
 
		st->RecomputeIndustriesNear();
 
		DeleteStationIfEmpty(st);
 

	
 
		/* All ships that were going to our station, can't go to it anymore.
 
		 * Just clear the order, then automatically the next appropriate order
 
		 * will be selected and in case of no appropriate order it will just
 
		 * wander around the world. */
 
		Ship *s;
 
		FOR_ALL_SHIPS(s) {
 
			if (s->dest_tile == docking_location) {
 
				s->dest_tile = 0;
 
				s->current_order.Free();
 
			}
 
		}
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_STATION_DOCK]);
 
}
 

	
 
#include "table/station_land.h"
 

	
 
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx)
 
{
 
	return &_station_display_datas[st][gfx];
 
}
 

	
 
static void DrawTile_Station(TileInfo *ti)
 
{
 
	const NewGRFSpriteLayout *layout = NULL;
 
	DrawTileSprites tmp_rail_layout;
 
	const DrawTileSprites *t = NULL;
 
	RoadTypes roadtypes;
 
	int32 total_offset;
 
	const RailtypeInfo *rti = NULL;
 
	uint32 relocation = 0;
 
	uint32 ground_relocation = 0;
 
	BaseStation *st = NULL;
 
	const StationSpec *statspec = NULL;
 
	uint tile_layout = 0;
 

	
 
	if (HasStationRail(ti->tile)) {
 
		rti = GetRailTypeInfo(GetRailType(ti->tile));
 
		roadtypes = ROADTYPES_NONE;
 
		total_offset = rti->GetRailtypeSpriteOffset();
 

	
 
		if (IsCustomStationSpecIndex(ti->tile)) {
 
			/* look for customization */
 
			st = BaseStation::GetByTile(ti->tile);
 
			statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
 

	
 
			if (statspec != NULL) {
 
				tile_layout = GetStationGfx(ti->tile);
 

	
 
				if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
 
					uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
 
					if (callback != CALLBACK_FAILED) tile_layout = (callback & ~1) + GetRailStationAxis(ti->tile);
 
				}
 

	
 
				/* Ensure the chosen tile layout is valid for this custom station */
 
				if (statspec->renderdata != NULL) {
 
					layout = &statspec->renderdata[tile_layout < statspec->tiles ? tile_layout : (uint)GetRailStationAxis(ti->tile)];
 
					if (!layout->NeedsPreprocessing()) {
0 comments (0 inline, 0 general)