2005-11-12 00:19:34 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2007-02-23 01:48:53 +00:00
|
|
|
/** @file newgrf_station.cpp Functions for dealing with station classes and custom stations. */
|
2005-11-12 00:19:34 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "debug.h"
|
2009-06-24 17:39:54 +00:00
|
|
|
#include "station_base.h"
|
2009-07-22 10:18:19 +00:00
|
|
|
#include "waypoint_base.h"
|
2009-06-23 21:44:48 +00:00
|
|
|
#include "roadstop_base.h"
|
2009-11-05 19:46:17 +00:00
|
|
|
#include "newgrf_cargo.h"
|
2006-02-03 15:51:00 +00:00
|
|
|
#include "newgrf_station.h"
|
2006-05-03 21:35:33 +00:00
|
|
|
#include "newgrf_spritegroup.h"
|
2008-04-21 11:29:01 +00:00
|
|
|
#include "newgrf_sound.h"
|
2010-02-07 22:22:54 +00:00
|
|
|
#include "newgrf_railtype.h"
|
2008-07-27 18:36:11 +00:00
|
|
|
#include "town.h"
|
2007-03-21 20:58:01 +00:00
|
|
|
#include "newgrf_town.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2008-07-19 10:10:21 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2010-08-26 17:01:17 +00:00
|
|
|
#include "newgrf_animation_base.h"
|
2010-08-07 22:07:07 +00:00
|
|
|
#include "newgrf_class_func.h"
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
|
2010-08-07 22:07:07 +00:00
|
|
|
template <typename Tspec, typename Tid, Tid Tmax>
|
|
|
|
/* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
|
|
|
|
{
|
|
|
|
/* Set up initial data */
|
|
|
|
classes[0].global_id = 'DFLT';
|
|
|
|
classes[0].name = STR_STATION_CLASS_DFLT;
|
2012-04-22 16:28:23 +00:00
|
|
|
classes[0].Insert(NULL);
|
2010-08-07 22:07:07 +00:00
|
|
|
|
|
|
|
classes[1].global_id = 'WAYP';
|
|
|
|
classes[1].name = STR_STATION_CLASS_WAYP;
|
2012-04-22 16:28:23 +00:00
|
|
|
classes[1].Insert(NULL);
|
2010-08-07 22:07:07 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 16:28:27 +00:00
|
|
|
template <typename Tspec, typename Tid, Tid Tmax>
|
|
|
|
bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint index) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:07:07 +00:00
|
|
|
INSTANTIATE_NEWGRF_CLASS_METHODS(StationClass, StationSpec, StationClassID, STAT_CLASS_MAX)
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2010-05-13 10:14:29 +00:00
|
|
|
static const uint MAX_SPECLIST = 255;
|
2006-05-08 13:35:25 +00:00
|
|
|
|
2009-07-21 11:11:05 +00:00
|
|
|
enum TriggerArea {
|
|
|
|
TA_TILE,
|
|
|
|
TA_PLATFORM,
|
|
|
|
TA_WHOLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ETileArea : TileArea {
|
|
|
|
ETileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
|
|
|
|
{
|
|
|
|
switch (ta) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
|
|
|
|
case TA_TILE:
|
|
|
|
this->tile = tile;
|
|
|
|
this->w = 1;
|
|
|
|
this->h = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TA_PLATFORM: {
|
|
|
|
TileIndex start, end;
|
|
|
|
Axis axis = GetRailStationAxis(tile);
|
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(AxisToDiagDir(axis));
|
|
|
|
|
2009-07-24 11:47:12 +00:00
|
|
|
for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(tile, end + delta); end += delta) { /* Nothing */ }
|
|
|
|
for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(tile, start - delta); start -= delta) { /* Nothing */ }
|
2009-07-21 11:11:05 +00:00
|
|
|
|
|
|
|
this->tile = start;
|
|
|
|
this->w = TileX(end) - TileX(start) + 1;
|
|
|
|
this->h = TileY(end) - TileY(start) + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TA_WHOLE:
|
|
|
|
st->GetTileArea(this, Station::IsExpected(st) ? STATION_RAIL : STATION_WAYPOINT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-20 14:15:02 +00:00
|
|
|
/**
|
|
|
|
* Evaluate a tile's position within a station, and return the result in a bit-stuffed format.
|
2010-07-31 21:02:56 +00:00
|
|
|
* if not centered: .TNLcCpP, if centered: .TNL..CP
|
2010-11-20 14:15:02 +00:00
|
|
|
* - T = Tile layout number (#GetStationGfx)
|
|
|
|
* - N = Number of platforms
|
|
|
|
* - L = Length of platforms
|
|
|
|
* - C = Current platform number from start, c = from end
|
|
|
|
* - P = Position along platform from start, p = from end
|
|
|
|
* .
|
2010-07-31 21:02:56 +00:00
|
|
|
* if centered, C/P start from the centre and c/p are not available.
|
2010-11-20 14:15:02 +00:00
|
|
|
* @return Platform information in bit-stuffed format.
|
2006-05-06 09:31:06 +00:00
|
|
|
*/
|
|
|
|
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
|
|
|
|
{
|
|
|
|
uint32 retval = 0;
|
|
|
|
|
|
|
|
if (axis == AXIS_X) {
|
2007-02-22 08:43:02 +00:00
|
|
|
Swap(platforms, length);
|
|
|
|
Swap(x, y);
|
2006-05-06 09:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (centred) {
|
|
|
|
x -= platforms / 2;
|
|
|
|
y -= length / 2;
|
2011-04-01 19:55:56 +00:00
|
|
|
x = Clamp(x, -8, 7);
|
2011-05-14 16:01:40 +00:00
|
|
|
y = Clamp(y, -8, 7);
|
2006-05-09 06:52:28 +00:00
|
|
|
SB(retval, 0, 4, y & 0xF);
|
|
|
|
SB(retval, 4, 4, x & 0xF);
|
2006-05-06 09:31:06 +00:00
|
|
|
} else {
|
2011-04-01 19:55:56 +00:00
|
|
|
SB(retval, 0, 4, min(15, y));
|
|
|
|
SB(retval, 4, 4, min(15, length - y - 1));
|
|
|
|
SB(retval, 8, 4, min(15, x));
|
|
|
|
SB(retval, 12, 4, min(15, platforms - x - 1));
|
2006-05-06 09:31:06 +00:00
|
|
|
}
|
2011-04-01 19:55:56 +00:00
|
|
|
SB(retval, 16, 4, min(15, length));
|
|
|
|
SB(retval, 20, 4, min(15, platforms));
|
2006-05-06 09:31:06 +00:00
|
|
|
SB(retval, 24, 4, tile);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 14:15:02 +00:00
|
|
|
/**
|
|
|
|
* Find the end of a railway station, from the \a tile, in the direction of \a delta.
|
|
|
|
* @param tile Start tile.
|
|
|
|
* @param delta Movement direction.
|
|
|
|
* @param check_type Stop when the custom station type changes.
|
|
|
|
* @param check_axis Stop when the station direction changes.
|
|
|
|
* @return Found end of the railway station.
|
2006-05-06 09:31:06 +00:00
|
|
|
*/
|
|
|
|
static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
|
|
|
|
{
|
|
|
|
byte orig_type = 0;
|
|
|
|
Axis orig_axis = AXIS_X;
|
2009-07-22 08:59:57 +00:00
|
|
|
StationID sid = GetStationIndex(tile);
|
2006-05-06 09:31:06 +00:00
|
|
|
|
2009-07-22 08:59:57 +00:00
|
|
|
if (check_type) orig_type = GetCustomStationSpecIndex(tile);
|
|
|
|
if (check_axis) orig_axis = GetRailStationAxis(tile);
|
2006-05-06 09:31:06 +00:00
|
|
|
|
2011-02-25 21:53:43 +00:00
|
|
|
for (;;) {
|
2006-05-06 09:31:06 +00:00
|
|
|
TileIndex new_tile = TILE_ADD(tile, delta);
|
|
|
|
|
2009-07-22 08:59:57 +00:00
|
|
|
if (!IsTileType(new_tile, MP_STATION) || GetStationIndex(new_tile) != sid) break;
|
2009-07-24 11:15:11 +00:00
|
|
|
if (!HasStationRail(new_tile)) break;
|
2009-07-22 08:59:57 +00:00
|
|
|
if (check_type && GetCustomStationSpecIndex(new_tile) != orig_type) break;
|
|
|
|
if (check_axis && GetRailStationAxis(new_tile) != orig_axis) break;
|
2006-05-06 09:31:06 +00:00
|
|
|
|
|
|
|
tile = new_tile;
|
|
|
|
}
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32 GetPlatformInfoHelper(TileIndex tile, bool check_type, bool check_axis, bool centred)
|
|
|
|
{
|
|
|
|
int tx = TileX(tile);
|
|
|
|
int ty = TileY(tile);
|
|
|
|
int sx = TileX(FindRailStationEnd(tile, TileDiffXY(-1, 0), check_type, check_axis));
|
|
|
|
int sy = TileY(FindRailStationEnd(tile, TileDiffXY( 0, -1), check_type, check_axis));
|
|
|
|
int ex = TileX(FindRailStationEnd(tile, TileDiffXY( 1, 0), check_type, check_axis)) + 1;
|
|
|
|
int ey = TileY(FindRailStationEnd(tile, TileDiffXY( 0, 1), check_type, check_axis)) + 1;
|
|
|
|
|
|
|
|
tx -= sx; ex -= sx;
|
|
|
|
ty -= sy; ey -= sy;
|
|
|
|
|
2009-07-22 08:59:57 +00:00
|
|
|
return GetPlatformInfo(GetRailStationAxis(tile), GetStationGfx(tile), ex, ey, tx, ty, centred);
|
2006-05-06 09:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-29 07:49:51 +00:00
|
|
|
static uint32 GetRailContinuationInfo(TileIndex tile)
|
|
|
|
{
|
|
|
|
/* Tile offsets and exit dirs for X axis */
|
2007-07-04 09:41:35 +00:00
|
|
|
static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N };
|
|
|
|
static const DiagDirection x_exits[8] = { DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SW, DIAGDIR_NE };
|
2006-12-29 07:49:51 +00:00
|
|
|
|
|
|
|
/* Tile offsets and exit dirs for Y axis */
|
2007-07-04 09:41:35 +00:00
|
|
|
static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N };
|
|
|
|
static const DiagDirection y_exits[8] = { DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_NW };
|
2006-12-29 07:49:51 +00:00
|
|
|
|
2009-07-22 08:59:57 +00:00
|
|
|
Axis axis = GetRailStationAxis(tile);
|
2006-12-29 07:49:51 +00:00
|
|
|
|
|
|
|
/* Choose appropriate lookup table to use */
|
2007-07-04 09:41:35 +00:00
|
|
|
const Direction *dir = axis == AXIS_X ? x_dir : y_dir;
|
|
|
|
const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits;
|
2006-12-29 07:49:51 +00:00
|
|
|
|
|
|
|
uint32 res = 0;
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
|
2008-07-19 10:10:21 +00:00
|
|
|
TileIndex neighbour_tile = tile + TileOffsByDir(*dir);
|
|
|
|
TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(neighbour_tile, TRANSPORT_RAIL, 0));
|
2008-02-20 17:49:50 +00:00
|
|
|
if (trackbits != TRACK_BIT_NONE) {
|
2006-12-29 07:49:51 +00:00
|
|
|
/* If there is any track on the tile, set the bit in the second byte */
|
2007-11-20 13:35:54 +00:00
|
|
|
SetBit(res, i + 8);
|
2006-12-29 07:49:51 +00:00
|
|
|
|
2008-07-19 10:10:21 +00:00
|
|
|
/* With tunnels and bridges the tile has tracks, but they are not necessarily connected
|
|
|
|
* with the next tile because the ramp is not going in the right direction. */
|
|
|
|
if (IsTileType(neighbour_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(neighbour_tile) != *diagdir) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-12-29 07:49:51 +00:00
|
|
|
/* If any track reaches our exit direction, set the bit in the lower byte */
|
2008-02-20 17:49:50 +00:00
|
|
|
if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i);
|
2006-12-29 07:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-03 21:35:33 +00:00
|
|
|
/* Station Resolver Functions */
|
2012-11-10 20:41:08 +00:00
|
|
|
/* virtual */ uint32 StationScopeResolver::GetRandomBits() const
|
2006-05-03 21:35:33 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
return (this->st == NULL ? 0 : this->st->random_bits) | (this->tile == INVALID_TILE ? 0 : GetStationTileRandomBits(this->tile) << 16);
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
/* virtual */ uint32 StationScopeResolver::GetTriggers() const
|
2006-05-03 21:35:33 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
return this->st == NULL ? 0 : this->st->waiting_triggers;
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
/* virtual */ void StationScopeResolver::SetTriggers(int triggers) const
|
2006-05-03 21:35:33 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
BaseStation *st = const_cast<BaseStation *>(this->st);
|
2006-05-03 21:35:33 +00:00
|
|
|
assert(st != NULL);
|
|
|
|
st->waiting_triggers = triggers;
|
|
|
|
}
|
|
|
|
|
2007-07-11 16:37:20 +00:00
|
|
|
/**
|
|
|
|
* Station variable cache
|
|
|
|
* This caches 'expensive' station variable lookups which iterate over
|
|
|
|
* several tiles that may be called multiple times per Resolve().
|
|
|
|
*/
|
|
|
|
static struct {
|
|
|
|
uint32 v40;
|
|
|
|
uint32 v41;
|
|
|
|
uint32 v45;
|
|
|
|
uint32 v46;
|
|
|
|
uint32 v47;
|
|
|
|
uint32 v49;
|
2010-08-02 20:32:39 +00:00
|
|
|
uint8 valid; ///< Bits indicating what variable is valid (for each bit, \c 0 is invalid, \c 1 is valid).
|
2007-07-11 16:37:20 +00:00
|
|
|
} _svc;
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
/**
|
|
|
|
* Get the town scope associated with a station, if it exists.
|
|
|
|
* On the first call, the town scope is created (if possible).
|
|
|
|
* @return Town scope, if available.
|
|
|
|
*/
|
|
|
|
TownScopeResolver *StationResolverObject::GetTown()
|
|
|
|
{
|
|
|
|
if (this->town_scope == NULL) {
|
|
|
|
Town *t = NULL;
|
|
|
|
if (this->station_scope.st != NULL) {
|
|
|
|
t = this->station_scope.st->town;
|
|
|
|
} else if (this->station_scope.tile != INVALID_TILE) {
|
|
|
|
t = ClosestTownFromTile(this->station_scope.tile, UINT_MAX);
|
2007-03-21 20:58:01 +00:00
|
|
|
}
|
2012-11-10 20:41:08 +00:00
|
|
|
if (t == NULL) return NULL;
|
|
|
|
this->town_scope = new TownScopeResolver(this, t, this->station_scope.st == NULL);
|
2007-03-21 20:58:01 +00:00
|
|
|
}
|
2012-11-10 20:41:08 +00:00
|
|
|
return this->town_scope;
|
|
|
|
}
|
2007-03-21 20:58:01 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
/* virtual */ uint32 StationScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
|
|
|
|
{
|
|
|
|
if (this->st == NULL) {
|
2011-07-11 16:32:35 +00:00
|
|
|
/* Station does not exist, so we're in a purchase list or the land slope check callback. */
|
2006-05-03 21:35:33 +00:00
|
|
|
switch (variable) {
|
|
|
|
case 0x40:
|
|
|
|
case 0x41:
|
|
|
|
case 0x46:
|
|
|
|
case 0x47:
|
2008-09-30 20:39:50 +00:00
|
|
|
case 0x49: return 0x2110000; // Platforms, tracks & position
|
|
|
|
case 0x42: return 0; // Rail type (XXX Get current type from GUI?)
|
2011-08-27 08:42:24 +00:00
|
|
|
case 0x43: return GetCompanyInfo(_current_company); // Station owner
|
2008-09-30 20:39:50 +00:00
|
|
|
case 0x44: return 2; // PBS status
|
2011-07-11 16:32:35 +00:00
|
|
|
case 0x67: // Land info of nearby tile
|
2012-11-10 20:41:08 +00:00
|
|
|
if (this->axis != INVALID_AXIS && this->tile != INVALID_TILE) {
|
|
|
|
TileIndex tile = this->tile;
|
|
|
|
if (parameter != 0) tile = GetNearbyTile(parameter, tile, true, this->axis); // only perform if it is required
|
2011-07-11 16:32:35 +00:00
|
|
|
|
2011-11-04 10:22:27 +00:00
|
|
|
Slope tileh = GetTileSlope(tile);
|
2012-11-10 20:41:08 +00:00
|
|
|
bool swap = (this->axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
|
2011-07-11 16:32:35 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
return GetNearbyTileInformation(tile, this->ro->grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
|
2011-07-11 16:32:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-11-19 18:38:10 +00:00
|
|
|
case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
2006-05-23 19:36:50 +00:00
|
|
|
|
|
|
|
*available = false;
|
2007-01-10 18:56:51 +00:00
|
|
|
return UINT_MAX;
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (variable) {
|
|
|
|
/* Calculated station variables */
|
2007-07-11 16:37:20 +00:00
|
|
|
case 0x40:
|
2012-11-10 20:41:08 +00:00
|
|
|
if (!HasBit(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(this->tile, false, false, false); SetBit(_svc.valid, 0); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v40;
|
|
|
|
|
|
|
|
case 0x41:
|
2012-11-10 20:41:08 +00:00
|
|
|
if (!HasBit(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(this->tile, true, false, false); SetBit(_svc.valid, 1); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v41;
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
case 0x42: return GetTerrainType(this->tile) | (GetReverseRailTypeTranslation(GetRailType(this->tile), this->statspec->grf_prop.grffile) << 8);
|
|
|
|
case 0x43: return GetCompanyInfo(this->st->owner); // Station owner
|
|
|
|
case 0x44: return HasStationReservation(this->tile) ? 7 : 4; // PBS status
|
2007-07-11 16:37:20 +00:00
|
|
|
case 0x45:
|
2012-11-10 20:41:08 +00:00
|
|
|
if (!HasBit(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(this->tile); SetBit(_svc.valid, 2); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v45;
|
|
|
|
|
|
|
|
case 0x46:
|
2012-11-10 20:41:08 +00:00
|
|
|
if (!HasBit(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(this->tile, false, false, true); SetBit(_svc.valid, 3); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v46;
|
|
|
|
|
|
|
|
case 0x47:
|
2012-11-10 20:41:08 +00:00
|
|
|
if (!HasBit(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(this->tile, true, false, true); SetBit(_svc.valid, 4); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v47;
|
|
|
|
|
|
|
|
case 0x49:
|
2012-11-10 20:41:08 +00:00
|
|
|
if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(this->tile, false, true, false); SetBit(_svc.valid, 5); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v49;
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2008-04-17 06:53:52 +00:00
|
|
|
case 0x4A: // Animation frame of tile
|
2012-11-10 20:41:08 +00:00
|
|
|
return GetAnimationFrame(this->tile);
|
2008-04-17 06:53:52 +00:00
|
|
|
|
2006-05-03 21:35:33 +00:00
|
|
|
/* Variables which use the parameter */
|
2011-06-04 21:24:23 +00:00
|
|
|
/* Variables 0x60 to 0x65 and 0x69 are handled separately below */
|
2012-11-10 20:41:08 +00:00
|
|
|
case 0x66: { // Animation frame of nearby tile
|
|
|
|
TileIndex tile = this->tile;
|
2008-04-17 06:53:52 +00:00
|
|
|
if (parameter != 0) tile = GetNearbyTile(parameter, tile);
|
2012-11-10 20:41:08 +00:00
|
|
|
return this->st->TileBelongsToRailStation(tile) ? GetAnimationFrame(tile) : UINT_MAX;
|
|
|
|
}
|
2008-04-17 06:53:52 +00:00
|
|
|
|
|
|
|
case 0x67: { // Land info of nearby tile
|
2012-11-10 20:41:08 +00:00
|
|
|
Axis axis = GetRailStationAxis(this->tile);
|
|
|
|
TileIndex tile = this->tile;
|
2007-12-21 22:11:55 +00:00
|
|
|
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
|
|
|
|
|
2011-11-04 10:22:27 +00:00
|
|
|
Slope tileh = GetTileSlope(tile);
|
2010-01-05 22:18:04 +00:00
|
|
|
bool swap = (axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
|
2008-01-31 17:46:08 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
return GetNearbyTileInformation(tile, this->ro->grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
|
2007-12-21 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case 0x68: { // Station info of nearby tiles
|
2012-11-10 20:41:08 +00:00
|
|
|
TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
|
2007-12-21 22:11:55 +00:00
|
|
|
|
2009-07-24 11:15:11 +00:00
|
|
|
if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
|
2007-12-21 22:11:55 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
uint32 grfid = this->st->speclist[GetCustomStationSpecIndex(this->tile)].grfid;
|
|
|
|
bool perpendicular = GetRailStationAxis(this->tile) != GetRailStationAxis(nearby_tile);
|
|
|
|
bool same_station = this->st->TileBelongsToRailStation(nearby_tile);
|
2007-12-21 22:11:55 +00:00
|
|
|
uint32 res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10;
|
|
|
|
|
|
|
|
if (IsCustomStationSpecIndex(nearby_tile)) {
|
2009-07-17 19:44:13 +00:00
|
|
|
const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
|
2007-12-21 22:11:55 +00:00
|
|
|
res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2009-07-17 21:06:06 +00:00
|
|
|
/* General station variables */
|
2006-05-03 21:35:33 +00:00
|
|
|
case 0x82: return 50;
|
2012-11-10 20:41:08 +00:00
|
|
|
case 0x84: return this->st->string_id;
|
2006-05-03 21:35:33 +00:00
|
|
|
case 0x86: return 0;
|
2012-11-10 20:41:08 +00:00
|
|
|
case 0xF0: return this->st->facilities;
|
|
|
|
case 0xFA: return Clamp(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
return this->st->GetNewGRFVariable(this->ro, variable, parameter, available);
|
2009-07-17 19:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const
|
|
|
|
{
|
|
|
|
switch (variable) {
|
|
|
|
case 0x48: { // Accepted cargo types
|
|
|
|
CargoID cargo_type;
|
|
|
|
uint32 value = 0;
|
|
|
|
|
|
|
|
for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
|
2012-11-12 18:10:42 +00:00
|
|
|
if (HasBit(this->goods[cargo_type].acceptance_pickup, GoodsEntry::GES_ACCEPTANCE)) SetBit(value, cargo_type);
|
2009-07-17 19:44:13 +00:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x8A: return this->had_vehicle_of_type;
|
2010-03-18 21:02:20 +00:00
|
|
|
case 0xF1: return (this->airport.tile != INVALID_TILE) ? this->airport.GetSpec()->ttd_airport_type : ATP_TTDP_LARGE;
|
2010-03-01 19:53:28 +00:00
|
|
|
case 0xF2: return (this->truck_stops != NULL) ? this->truck_stops->status : 0;
|
|
|
|
case 0xF3: return (this->bus_stops != NULL) ? this->bus_stops->status : 0;
|
2010-03-18 21:02:20 +00:00
|
|
|
case 0xF6: return this->airport.flags;
|
|
|
|
case 0xF7: return GB(this->airport.flags, 8, 8);
|
2009-07-17 19:44:13 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 21:24:23 +00:00
|
|
|
/* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */
|
|
|
|
if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) {
|
2012-09-01 19:36:15 +00:00
|
|
|
CargoID c = GetCargoTranslation(parameter, object->grffile);
|
2007-04-13 19:32:18 +00:00
|
|
|
|
2012-11-12 20:12:45 +00:00
|
|
|
if (c == CT_INVALID) {
|
|
|
|
switch (variable) {
|
|
|
|
case 0x62: return 0xFFFFFFFF;
|
|
|
|
case 0x64: return 0xFF00;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 19:44:13 +00:00
|
|
|
const GoodsEntry *ge = &this->goods[c];
|
2007-04-13 19:32:18 +00:00
|
|
|
|
|
|
|
switch (variable) {
|
2007-06-22 11:58:59 +00:00
|
|
|
case 0x60: return min(ge->cargo.Count(), 4095);
|
2012-11-12 21:59:02 +00:00
|
|
|
case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0;
|
2012-11-12 20:12:45 +00:00
|
|
|
case 0x62: return HasBit(ge->acceptance_pickup, GoodsEntry::GES_PICKUP) ? ge->rating : 0xFFFFFFFF;
|
2007-06-22 11:58:59 +00:00
|
|
|
case 0x63: return ge->cargo.DaysInTransit();
|
2012-11-12 20:12:45 +00:00
|
|
|
case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00;
|
2011-06-04 21:17:07 +00:00
|
|
|
case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::GES_ACCEPTANCE, 1) << 3;
|
2012-11-12 20:12:45 +00:00
|
|
|
case 0x69: {
|
|
|
|
assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 1 == (int)GoodsEntry::GES_LAST_MONTH);
|
|
|
|
assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 2 == (int)GoodsEntry::GES_CURRENT_MONTH);
|
|
|
|
assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 3 == (int)GoodsEntry::GES_ACCEPTED_BIGTICK);
|
|
|
|
return GB(ge->acceptance_pickup, GoodsEntry::GES_EVER_ACCEPTED, 4);
|
|
|
|
}
|
2007-04-13 19:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-04 07:26:30 +00:00
|
|
|
/* Handle cargo variables (deprecated) */
|
|
|
|
if (variable >= 0x8C && variable <= 0xEC) {
|
2009-07-17 19:44:13 +00:00
|
|
|
const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
|
2006-05-04 07:26:30 +00:00
|
|
|
switch (GB(variable - 0x8C, 0, 3)) {
|
2007-06-22 11:58:59 +00:00
|
|
|
case 0: return g->cargo.Count();
|
2011-06-04 21:17:07 +00:00
|
|
|
case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
|
2012-11-12 21:59:02 +00:00
|
|
|
case 2: return g->time_since_pickup;
|
2006-05-04 07:26:30 +00:00
|
|
|
case 3: return g->rating;
|
2007-06-22 11:58:59 +00:00
|
|
|
case 4: return g->cargo.Source();
|
|
|
|
case 5: return g->cargo.DaysInTransit();
|
2006-05-04 07:26:30 +00:00
|
|
|
case 6: return g->last_speed;
|
|
|
|
case 7: return g->last_age;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 21:06:06 +00:00
|
|
|
DEBUG(grf, 1, "Unhandled station variable 0x%X", variable);
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2006-05-23 19:36:50 +00:00
|
|
|
*available = false;
|
2007-01-10 18:56:51 +00:00
|
|
|
return UINT_MAX;
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 21:06:06 +00:00
|
|
|
uint32 Waypoint::GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const
|
|
|
|
{
|
|
|
|
switch (variable) {
|
|
|
|
case 0x48: return 0; // Accepted cargo types
|
2009-07-22 08:59:57 +00:00
|
|
|
case 0x8A: return HVOT_WAYPOINT;
|
2009-07-17 21:06:06 +00:00
|
|
|
case 0xF1: return 0; // airport type
|
|
|
|
case 0xF2: return 0; // truck stop status
|
|
|
|
case 0xF3: return 0; // bus stop status
|
|
|
|
case 0xF6: return 0; // airport flags
|
|
|
|
case 0xF7: return 0; // airport flags cont.
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle cargo variables with parameter, 0x60 to 0x65 */
|
|
|
|
if (variable >= 0x60 && variable <= 0x65) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle cargo variables (deprecated) */
|
|
|
|
if (variable >= 0x8C && variable <= 0xEC) {
|
|
|
|
switch (GB(variable - 0x8C, 0, 3)) {
|
|
|
|
case 3: return INITIAL_STATION_RATING;
|
|
|
|
case 4: return INVALID_STATION;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG(grf, 1, "Unhandled station variable 0x%X", variable);
|
|
|
|
|
|
|
|
*available = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
/* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
2006-05-03 21:35:33 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
if (this->station_scope.st == NULL || this->station_scope.statspec->cls_id == STAT_CLASS_WAYP) {
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->loading[0];
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
uint cargo = 0;
|
|
|
|
const Station *st = Station::From(this->station_scope.st);
|
2009-07-17 19:44:13 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
switch (this->station_scope.cargo_type) {
|
2007-02-24 23:36:40 +00:00
|
|
|
case CT_INVALID:
|
|
|
|
case CT_DEFAULT_NA:
|
|
|
|
case CT_PURCHASE:
|
2006-10-11 22:05:59 +00:00
|
|
|
cargo = 0;
|
|
|
|
break;
|
|
|
|
|
2007-02-24 23:36:40 +00:00
|
|
|
case CT_DEFAULT:
|
2012-11-10 20:41:08 +00:00
|
|
|
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
|
2007-06-22 11:58:59 +00:00
|
|
|
cargo += st->goods[cargo_type].cargo.Count();
|
2006-10-11 22:05:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-11-10 20:41:08 +00:00
|
|
|
cargo = st->goods[this->station_scope.cargo_type].cargo.Count();
|
2006-10-11 22:05:59 +00:00
|
|
|
break;
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
if (HasBit(this->station_scope.statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->train_station.w + st->train_station.h);
|
2006-05-03 21:35:33 +00:00
|
|
|
cargo = min(0xfff, cargo);
|
2006-02-03 23:02:01 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
if (cargo > this->station_scope.statspec->cargo_threshold) {
|
2009-05-23 12:13:42 +00:00
|
|
|
if (group->num_loading > 0) {
|
2012-11-10 20:41:08 +00:00
|
|
|
uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * group->num_loading) / (4096 - this->station_scope.statspec->cargo_threshold);
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->loading[set];
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
2006-05-04 18:10:17 +00:00
|
|
|
} else {
|
2009-05-23 12:13:42 +00:00
|
|
|
if (group->num_loaded > 0) {
|
2012-11-10 20:41:08 +00:00
|
|
|
uint set = (cargo * group->num_loaded) / (this->station_scope.statspec->cargo_threshold + 1);
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->loaded[set];
|
2006-05-04 18:10:17 +00:00
|
|
|
}
|
2006-02-03 23:02:01 +00:00
|
|
|
}
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->loading[0];
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/**
|
|
|
|
* Resolver for stations.
|
|
|
|
* @param statspec Station (type) specification.
|
|
|
|
* @param st Instance of the station.
|
|
|
|
* @param tile %Tile of the station.
|
|
|
|
* @param callback Callback ID.
|
|
|
|
* @param callback_param1 First parameter (var 10) of the callback.
|
|
|
|
* @param callback_param2 Second parameter (var 18) of the callback.
|
|
|
|
*/
|
2012-11-10 20:41:08 +00:00
|
|
|
StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
|
|
|
|
CallbackID callback, uint32 callback_param1, uint32 callback_param2)
|
|
|
|
: ResolverObject((statspec != NULL ? statspec->grf_prop.grffile : NULL), callback, callback_param1, callback_param2),
|
|
|
|
station_scope(this, statspec, st, tile), town_scope(NULL)
|
2011-06-12 20:50:03 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
/* Invalidate all cached vars */
|
|
|
|
_svc.valid = 0;
|
2011-06-12 20:50:03 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
StationResolverObject::~StationResolverObject()
|
2006-05-03 21:35:33 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
delete this->town_scope;
|
|
|
|
}
|
2011-03-30 21:39:44 +00:00
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/**
|
|
|
|
* Constructor for station scopes.
|
|
|
|
* @param ro Surrounding resolver.
|
|
|
|
* @param statspec Station (type) specification.
|
|
|
|
* @param st Instance of the station.
|
|
|
|
* @param tile %Tile of the station.
|
|
|
|
*/
|
2012-11-10 20:41:08 +00:00
|
|
|
StationScopeResolver::StationScopeResolver(ResolverObject *ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
|
|
|
|
: ScopeResolver(ro)
|
|
|
|
{
|
|
|
|
this->tile = tile;
|
|
|
|
this->st = st;
|
|
|
|
this->statspec = statspec;
|
|
|
|
this->cargo_type = CT_INVALID;
|
|
|
|
this->axis = INVALID_AXIS;
|
2006-02-03 23:02:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
static const SpriteGroup *ResolveStation(StationResolverObject *object)
|
2006-10-11 22:05:59 +00:00
|
|
|
{
|
2007-02-24 23:36:40 +00:00
|
|
|
CargoID ctype = CT_DEFAULT_NA;
|
2006-10-11 22:05:59 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
if (object->station_scope.st == NULL) {
|
2006-10-11 22:05:59 +00:00
|
|
|
/* No station, so we are in a purchase list */
|
2007-02-24 23:36:40 +00:00
|
|
|
ctype = CT_PURCHASE;
|
2012-11-10 20:41:08 +00:00
|
|
|
} else if (Station::IsExpected(object->station_scope.st)) {
|
|
|
|
const Station *st = Station::From(object->station_scope.st);
|
2006-10-11 22:05:59 +00:00
|
|
|
/* Pick the first cargo that we have waiting */
|
2009-07-16 20:40:06 +00:00
|
|
|
const CargoSpec *cs;
|
|
|
|
FOR_ALL_CARGOSPECS(cs) {
|
2012-11-10 20:41:08 +00:00
|
|
|
if (object->station_scope.statspec->grf_prop.spritegroup[cs->Index()] != NULL &&
|
2009-07-17 19:44:13 +00:00
|
|
|
!st->goods[cs->Index()].cargo.Empty()) {
|
2009-07-16 20:40:06 +00:00
|
|
|
ctype = cs->Index();
|
2006-10-11 22:05:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
const SpriteGroup *group = object->station_scope.statspec->grf_prop.spritegroup[ctype];
|
2006-10-11 22:05:59 +00:00
|
|
|
if (group == NULL) {
|
2007-02-24 23:36:40 +00:00
|
|
|
ctype = CT_DEFAULT;
|
2012-11-10 20:41:08 +00:00
|
|
|
group = object->station_scope.statspec->grf_prop.spritegroup[ctype];
|
|
|
|
if (group == NULL) return NULL;
|
2006-10-11 22:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remember the cargo type we've picked */
|
2012-11-10 20:41:08 +00:00
|
|
|
object->station_scope.cargo_type = ctype;
|
2006-10-11 22:05:59 +00:00
|
|
|
|
2009-05-23 15:25:52 +00:00
|
|
|
return SpriteGroup::Resolve(group, object);
|
2006-10-11 22:05:59 +00:00
|
|
|
}
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2011-05-14 13:12:47 +00:00
|
|
|
/**
|
|
|
|
* Resolve sprites for drawing a station tile.
|
|
|
|
* @param statspec Station spec
|
|
|
|
* @param st Station (NULL in GUI)
|
|
|
|
* @param tile Station tile being drawn (INVALID_TILE in GUI)
|
|
|
|
* @param var10 Value to put in variable 10; normally 0; 1 when resolving the groundsprite and SSF_SEPARATE_GROUND is set.
|
2013-01-08 22:46:42 +00:00
|
|
|
* @return First sprite of the Action 1 spriteset to use, minus an offset of 0x42D to accommodate for weird NewGRF specs.
|
2011-05-14 13:12:47 +00:00
|
|
|
*/
|
2011-06-12 20:34:03 +00:00
|
|
|
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10)
|
2006-05-07 10:58:53 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, var10);
|
|
|
|
const SpriteGroup *group = ResolveStation(&object);
|
2006-05-07 10:58:53 +00:00
|
|
|
if (group == NULL || group->type != SGT_RESULT) return 0;
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->GetResult() - 0x42D;
|
2006-02-03 23:02:01 +00:00
|
|
|
}
|
2006-04-19 07:17:00 +00:00
|
|
|
|
2011-05-14 12:38:10 +00:00
|
|
|
/**
|
|
|
|
* Resolve the sprites for custom station foundations.
|
|
|
|
* @param statspec Station spec
|
|
|
|
* @param st Station
|
|
|
|
* @param tile Station tile being drawn
|
|
|
|
* @param layout Spritelayout as returned by previous callback
|
|
|
|
* @param edge_info Information about northern tile edges; whether they need foundations or merge into adjacent tile's foundations.
|
2012-11-12 20:13:17 +00:00
|
|
|
* @return First sprite of a set of foundation sprites for various slopes, or 0 if default foundations shall be drawn.
|
2011-05-14 12:38:10 +00:00
|
|
|
*/
|
2011-06-12 20:34:03 +00:00
|
|
|
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
|
2010-01-03 22:44:57 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
/* callback_param1 == 2 means we are resolving the foundation sprites. */
|
|
|
|
StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16));
|
2010-01-03 22:44:57 +00:00
|
|
|
|
2011-05-14 12:36:31 +00:00
|
|
|
ClearRegister(0x100);
|
2012-11-10 20:41:08 +00:00
|
|
|
const SpriteGroup *group = ResolveStation(&object);
|
2010-01-03 22:44:57 +00:00
|
|
|
if (group == NULL || group->type != SGT_RESULT) return 0;
|
|
|
|
return group->GetResult() + GetRegister(0x100);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-12 20:32:52 +00:00
|
|
|
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile)
|
2006-05-04 19:27:41 +00:00
|
|
|
{
|
2012-11-10 20:41:08 +00:00
|
|
|
StationResolverObject object(statspec, st, tile, callback, param1, param2);
|
|
|
|
const SpriteGroup *group = ResolveStation(&object);
|
2009-05-23 12:13:42 +00:00
|
|
|
if (group == NULL) return CALLBACK_FAILED;
|
|
|
|
return group->GetCallbackResult();
|
2006-05-04 19:27:41 +00:00
|
|
|
}
|
|
|
|
|
2011-07-11 16:32:35 +00:00
|
|
|
/**
|
|
|
|
* Check the slope of a tile of a new station.
|
|
|
|
* @param north_tile Norther tile of the station rect.
|
|
|
|
* @param cur_tile Tile to check.
|
|
|
|
* @param statspec Station spec.
|
|
|
|
* @param axis Axis of the new station.
|
|
|
|
* @param plat_len Platform length.
|
|
|
|
* @param numtracks Number of platforms.
|
|
|
|
* @return Succeeded or failed command.
|
|
|
|
*/
|
|
|
|
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
|
|
|
|
{
|
|
|
|
TileIndexDiff diff = cur_tile - north_tile;
|
2011-11-04 10:22:27 +00:00
|
|
|
Slope slope = GetTileSlope(cur_tile);
|
2011-07-11 16:32:35 +00:00
|
|
|
|
2012-11-10 20:41:08 +00:00
|
|
|
StationResolverObject object(statspec, NULL, cur_tile, CBID_STATION_LAND_SLOPE_CHECK,
|
|
|
|
(slope << 4) | (slope ^ (axis == AXIS_Y && HasBit(slope, CORNER_W) != HasBit(slope, CORNER_E) ? SLOPE_EW : 0)),
|
|
|
|
(numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
|
|
|
|
object.station_scope.axis = axis;
|
2011-07-11 16:32:35 +00:00
|
|
|
|
|
|
|
const SpriteGroup *group = ResolveStation(&object);
|
|
|
|
uint16 cb_res = group != NULL ? group->GetCallbackResult() : CALLBACK_FAILED;
|
|
|
|
|
|
|
|
/* Failed callback means success. */
|
|
|
|
if (cb_res == CALLBACK_FAILED) return CommandCost();
|
|
|
|
|
2011-11-08 17:24:31 +00:00
|
|
|
/* The meaning of bit 10 is inverted for a grf version < 8. */
|
|
|
|
if (statspec->grf_prop.grffile->grf_version < 8) ToggleBit(cb_res, 10);
|
|
|
|
return GetErrorMessageFromLocationCallbackResult(cb_res, statspec->grf_prop.grffile->grfid, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
2011-07-11 16:32:35 +00:00
|
|
|
}
|
|
|
|
|
2006-05-04 19:27:41 +00:00
|
|
|
|
2006-04-19 07:17:00 +00:00
|
|
|
/**
|
|
|
|
* Allocate a StationSpec to a Station. This is called once per build operation.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param statspec StationSpec to allocate.
|
2006-04-19 07:17:00 +00:00
|
|
|
* @param st Station to allocate it to.
|
|
|
|
* @param exec Whether to actually allocate the spec.
|
|
|
|
* @return Index within the Station's spec list, or -1 if the allocation failed.
|
|
|
|
*/
|
2009-07-21 11:11:05 +00:00
|
|
|
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
|
2006-04-19 07:17:00 +00:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
|
2008-04-23 22:16:41 +00:00
|
|
|
if (statspec == NULL || st == NULL) return 0;
|
2006-04-19 07:17:00 +00:00
|
|
|
|
2006-05-08 13:35:25 +00:00
|
|
|
for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
|
2006-04-19 07:17:00 +00:00
|
|
|
if (st->speclist[i].spec == NULL && st->speclist[i].grfid == 0) break;
|
|
|
|
}
|
|
|
|
|
2009-01-10 14:30:01 +00:00
|
|
|
if (i == MAX_SPECLIST) {
|
|
|
|
/* As final effort when the spec list is already full...
|
|
|
|
* try to find the same spec and return that one. This might
|
2013-01-08 22:46:42 +00:00
|
|
|
* result in slightly "wrong" (as per specs) looking stations,
|
2009-01-10 14:30:01 +00:00
|
|
|
* but it's fairly unlikely that one reaches the limit anyways.
|
|
|
|
*/
|
|
|
|
for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
|
|
|
|
if (st->speclist[i].spec == statspec) return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2006-05-03 11:19:17 +00:00
|
|
|
|
|
|
|
if (exec) {
|
|
|
|
if (i >= st->num_specs) {
|
|
|
|
st->num_specs = i + 1;
|
2007-01-11 17:29:39 +00:00
|
|
|
st->speclist = ReallocT(st->speclist, st->num_specs);
|
2006-05-03 11:19:17 +00:00
|
|
|
|
|
|
|
if (st->num_specs == 2) {
|
|
|
|
/* Initial allocation */
|
|
|
|
st->speclist[0].spec = NULL;
|
|
|
|
st->speclist[0].grfid = 0;
|
|
|
|
st->speclist[0].localidx = 0;
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-03 11:19:17 +00:00
|
|
|
|
|
|
|
st->speclist[i].spec = statspec;
|
2010-08-07 20:52:45 +00:00
|
|
|
st->speclist[i].grfid = statspec->grf_prop.grffile->grfid;
|
|
|
|
st->speclist[i].localidx = statspec->grf_prop.local_id;
|
2013-01-10 18:58:22 +00:00
|
|
|
|
2013-01-11 07:39:25 +00:00
|
|
|
StationUpdateCachedTriggers(st);
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
2006-05-03 11:19:17 +00:00
|
|
|
return i;
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Deallocate a StationSpec from a Station. Called when removing a single station tile.
|
2006-04-19 07:17:00 +00:00
|
|
|
* @param st Station to work with.
|
|
|
|
* @param specindex Index of the custom station within the Station's spec list.
|
|
|
|
* @return Indicates whether the StationSpec was deallocated.
|
|
|
|
*/
|
2009-07-21 11:11:05 +00:00
|
|
|
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
|
2006-04-19 07:17:00 +00:00
|
|
|
{
|
|
|
|
/* specindex of 0 (default) is never freeable */
|
2006-07-29 17:39:58 +00:00
|
|
|
if (specindex == 0) return;
|
2006-04-19 07:17:00 +00:00
|
|
|
|
2009-07-21 11:11:05 +00:00
|
|
|
ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE);
|
2006-04-19 07:17:00 +00:00
|
|
|
/* Check all tiles over the station to check if the specindex is still in use */
|
2010-01-04 18:30:10 +00:00
|
|
|
TILE_AREA_LOOP(tile, area) {
|
2009-08-03 09:10:28 +00:00
|
|
|
if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
|
|
|
|
return;
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
2009-07-21 11:11:05 +00:00
|
|
|
}
|
2006-04-19 07:17:00 +00:00
|
|
|
|
2006-07-29 17:39:58 +00:00
|
|
|
/* This specindex is no longer in use, so deallocate it */
|
|
|
|
st->speclist[specindex].spec = NULL;
|
|
|
|
st->speclist[specindex].grfid = 0;
|
|
|
|
st->speclist[specindex].localidx = 0;
|
|
|
|
|
|
|
|
/* If this was the highest spec index, reallocate */
|
|
|
|
if (specindex == st->num_specs - 1) {
|
2008-03-15 13:21:31 +00:00
|
|
|
for (; st->speclist[st->num_specs - 1].grfid == 0 && st->num_specs > 1; st->num_specs--) {}
|
2006-07-29 17:39:58 +00:00
|
|
|
|
|
|
|
if (st->num_specs > 1) {
|
2007-01-11 17:29:39 +00:00
|
|
|
st->speclist = ReallocT(st->speclist, st->num_specs);
|
2006-07-29 17:39:58 +00:00
|
|
|
} else {
|
|
|
|
free(st->speclist);
|
|
|
|
st->num_specs = 0;
|
|
|
|
st->speclist = NULL;
|
2008-04-19 23:19:12 +00:00
|
|
|
st->cached_anim_triggers = 0;
|
2013-01-11 07:39:25 +00:00
|
|
|
st->cached_cargo_triggers = 0;
|
2008-04-19 23:19:12 +00:00
|
|
|
return;
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-19 23:19:12 +00:00
|
|
|
|
2013-01-11 07:39:25 +00:00
|
|
|
StationUpdateCachedTriggers(st);
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
2006-05-06 20:48:40 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Draw representation of a station tile for GUI purposes.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param x Position x of image.
|
|
|
|
* @param y Position y of image.
|
|
|
|
* @param axis Axis.
|
2006-05-06 20:48:40 +00:00
|
|
|
* @param railtype Rail type.
|
|
|
|
* @param sclass, station Type of station.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param station station ID
|
2006-05-06 20:48:40 +00:00
|
|
|
* @return True if the tile was drawn (allows for fallback to default graphic)
|
|
|
|
*/
|
|
|
|
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
|
|
|
|
{
|
2011-05-29 16:56:22 +00:00
|
|
|
const DrawTileSprites *sprites = NULL;
|
2006-05-06 20:48:40 +00:00
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
|
2010-01-21 01:38:13 +00:00
|
|
|
PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company);
|
2006-05-06 20:48:40 +00:00
|
|
|
uint tile = 2;
|
|
|
|
|
2012-04-22 16:28:14 +00:00
|
|
|
const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station);
|
2006-05-06 20:48:40 +00:00
|
|
|
if (statspec == NULL) return false;
|
|
|
|
|
2009-09-14 12:22:57 +00:00
|
|
|
if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
|
2006-05-06 20:48:40 +00:00
|
|
|
uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE);
|
|
|
|
if (callback != CALLBACK_FAILED) tile = callback;
|
|
|
|
}
|
|
|
|
|
2011-05-29 16:56:22 +00:00
|
|
|
uint32 total_offset = rti->GetRailtypeSpriteOffset();
|
|
|
|
uint32 relocation = 0;
|
|
|
|
uint32 ground_relocation = 0;
|
|
|
|
const NewGRFSpriteLayout *layout = NULL;
|
|
|
|
DrawTileSprites tmp_rail_layout;
|
|
|
|
|
2006-05-06 20:48:40 +00:00
|
|
|
if (statspec->renderdata == NULL) {
|
2007-07-16 23:55:22 +00:00
|
|
|
sprites = GetStationTileLayout(STATION_RAIL, tile + axis);
|
2006-05-06 20:48:40 +00:00
|
|
|
} else {
|
2011-05-29 16:56:22 +00:00
|
|
|
layout = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis];
|
|
|
|
if (!layout->NeedsPreprocessing()) {
|
|
|
|
sprites = layout;
|
|
|
|
layout = NULL;
|
|
|
|
}
|
2006-05-06 20:48:40 +00:00
|
|
|
}
|
|
|
|
|
2011-05-29 16:56:22 +00:00
|
|
|
if (layout != NULL) {
|
|
|
|
/* Sprite layout which needs preprocessing */
|
|
|
|
bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND);
|
2011-09-11 15:10:09 +00:00
|
|
|
uint32 var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
|
2011-05-29 16:56:22 +00:00
|
|
|
uint8 var10;
|
|
|
|
FOR_EACH_SET_BIT(var10, var10_values) {
|
|
|
|
uint32 var10_relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE, var10);
|
|
|
|
layout->ProcessRegisters(var10, var10_relocation, separate_ground);
|
2011-05-14 13:12:47 +00:00
|
|
|
}
|
2011-05-29 16:56:22 +00:00
|
|
|
|
|
|
|
tmp_rail_layout.seq = layout->GetLayout(&tmp_rail_layout.ground);
|
|
|
|
sprites = &tmp_rail_layout;
|
|
|
|
total_offset = 0;
|
2006-05-07 10:58:53 +00:00
|
|
|
} else {
|
2011-05-29 16:56:22 +00:00
|
|
|
/* Simple sprite layout */
|
|
|
|
ground_relocation = relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE, 0);
|
|
|
|
if (HasBit(sprites->ground.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
|
|
|
|
ground_relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE, 1);
|
|
|
|
}
|
|
|
|
ground_relocation += rti->fallback_railtype;
|
2006-05-07 10:58:53 +00:00
|
|
|
}
|
2006-05-06 20:48:40 +00:00
|
|
|
|
2011-05-29 16:56:22 +00:00
|
|
|
SpriteID image = sprites->ground.sprite;
|
|
|
|
PaletteID pal = sprites->ground.pal;
|
2012-12-23 15:38:54 +00:00
|
|
|
RailTrackOffset overlay_offset;
|
|
|
|
if (rti != NULL && rti->UsesOverlay() && SplitGroundSpriteForOverlay(NULL, &image, &overlay_offset)) {
|
|
|
|
SpriteID ground = GetCustomRailSprite(rti, INVALID_TILE, RTSG_GROUND);
|
|
|
|
DrawSprite(image, PAL_NONE, x, y);
|
|
|
|
DrawSprite(ground + overlay_offset, PAL_NONE, x, y);
|
|
|
|
} else {
|
|
|
|
image += HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? ground_relocation : total_offset;
|
|
|
|
if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += ground_relocation;
|
|
|
|
DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
|
|
|
|
}
|
2006-05-06 20:48:40 +00:00
|
|
|
|
2011-05-29 16:56:22 +00:00
|
|
|
DrawRailTileSeqInGUI(x, y, sprites, total_offset, relocation, palette);
|
2006-05-06 20:48:40 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-08-01 06:08:11 +00:00
|
|
|
|
2008-07-25 22:37:34 +00:00
|
|
|
const StationSpec *GetStationSpec(TileIndex t)
|
2006-05-06 22:08:14 +00:00
|
|
|
{
|
2009-07-22 08:59:57 +00:00
|
|
|
if (!IsCustomStationSpecIndex(t)) return NULL;
|
2006-05-06 22:08:14 +00:00
|
|
|
|
2009-07-22 08:59:57 +00:00
|
|
|
const BaseStation *st = BaseStation::GetByTile(t);
|
|
|
|
uint specindex = GetCustomStationSpecIndex(t);
|
|
|
|
return specindex < st->num_specs ? st->speclist[specindex].spec : NULL;
|
2006-08-01 06:08:11 +00:00
|
|
|
}
|
2006-05-06 22:08:14 +00:00
|
|
|
|
|
|
|
|
2010-11-20 14:15:02 +00:00
|
|
|
/**
|
|
|
|
* Check whether a rail station tile is NOT traversable.
|
|
|
|
* @param tile %Tile to test.
|
|
|
|
* @return Station tile is blocked.
|
|
|
|
* @note This could be cached (during build) in the map array to save on all the dereferencing.
|
|
|
|
*/
|
2006-08-01 06:08:11 +00:00
|
|
|
bool IsStationTileBlocked(TileIndex tile)
|
|
|
|
{
|
2009-01-10 00:31:47 +00:00
|
|
|
const StationSpec *statspec = GetStationSpec(tile);
|
2006-08-01 06:08:11 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
return statspec != NULL && HasBit(statspec->blocked, GetStationGfx(tile));
|
2006-05-06 22:08:14 +00:00
|
|
|
}
|
2006-05-08 21:59:36 +00:00
|
|
|
|
2010-11-20 14:15:02 +00:00
|
|
|
/**
|
2012-07-15 16:17:22 +00:00
|
|
|
* Check if a rail station tile shall have pylons when electrified.
|
2010-11-20 14:15:02 +00:00
|
|
|
* @param tile %Tile to test.
|
2012-07-15 16:17:22 +00:00
|
|
|
* @return Tile shall have pylons.
|
2010-11-20 14:15:02 +00:00
|
|
|
* @note This could be cached (during build) in the map array to save on all the dereferencing.
|
|
|
|
*/
|
2012-07-15 16:17:22 +00:00
|
|
|
bool CanStationTileHavePylons(TileIndex tile)
|
2006-05-08 21:59:36 +00:00
|
|
|
{
|
2009-01-10 00:31:47 +00:00
|
|
|
const StationSpec *statspec = GetStationSpec(tile);
|
2012-07-15 16:17:22 +00:00
|
|
|
uint gfx = GetStationGfx(tile);
|
|
|
|
/* Default stations do not draw pylons under roofs (gfx >= 4) */
|
|
|
|
return statspec != NULL ? HasBit(statspec->pylons, gfx) : gfx < 4;
|
|
|
|
}
|
2006-05-08 21:59:36 +00:00
|
|
|
|
2012-07-15 16:17:22 +00:00
|
|
|
/**
|
|
|
|
* Check if a rail station tile shall have wires when electrified.
|
|
|
|
* @param tile %Tile to test.
|
|
|
|
* @return Tile shall have wires.
|
|
|
|
* @note This could be cached (during build) in the map array to save on all the dereferencing.
|
|
|
|
*/
|
|
|
|
bool CanStationTileHaveWires(TileIndex tile)
|
|
|
|
{
|
|
|
|
const StationSpec *statspec = GetStationSpec(tile);
|
|
|
|
return statspec == NULL || !HasBit(statspec->wires, GetStationGfx(tile));
|
2006-05-08 21:59:36 +00:00
|
|
|
}
|
2008-04-19 23:19:12 +00:00
|
|
|
|
2011-10-31 22:31:35 +00:00
|
|
|
/** Wrapper for animation control, see #GetStationCallback. */
|
|
|
|
uint16 GetAnimStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, int extra_data)
|
|
|
|
{
|
|
|
|
return GetStationCallback(callback, param1, param2, statspec, st, tile);
|
|
|
|
}
|
|
|
|
|
2010-08-26 17:01:17 +00:00
|
|
|
/** Helper class for animation control. */
|
2011-10-31 22:31:35 +00:00
|
|
|
struct StationAnimationBase : public AnimationBase<StationAnimationBase, StationSpec, BaseStation, int, GetAnimStationCallback> {
|
2010-08-26 17:01:17 +00:00
|
|
|
static const CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED;
|
|
|
|
static const CallbackID cb_animation_next_frame = CBID_STATION_ANIM_NEXT_FRAME;
|
|
|
|
|
|
|
|
static const StationCallbackMask cbm_animation_speed = CBM_STATION_ANIMATION_SPEED;
|
|
|
|
static const StationCallbackMask cbm_animation_next_frame = CBM_STATION_ANIMATION_NEXT_FRAME;
|
|
|
|
};
|
|
|
|
|
2008-04-19 23:19:12 +00:00
|
|
|
void AnimateStationTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
const StationSpec *ss = GetStationSpec(tile);
|
|
|
|
if (ss == NULL) return;
|
|
|
|
|
2010-08-26 17:01:17 +00:00
|
|
|
StationAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, HasBit(ss->flags, SSF_CB141_RANDOM_BITS));
|
2008-04-19 23:19:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 20:32:52 +00:00
|
|
|
void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type)
|
2008-04-19 23:19:12 +00:00
|
|
|
{
|
|
|
|
/* List of coverage areas for each animation trigger */
|
|
|
|
static const TriggerArea tas[] = {
|
|
|
|
TA_TILE, TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_WHOLE
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Get Station if it wasn't supplied */
|
2009-07-17 19:44:13 +00:00
|
|
|
if (st == NULL) st = BaseStation::GetByTile(tile);
|
2008-04-19 23:19:12 +00:00
|
|
|
|
|
|
|
/* Check the cached animation trigger bitmask to see if we need
|
|
|
|
* to bother with any further processing. */
|
|
|
|
if (!HasBit(st->cached_anim_triggers, trigger)) return;
|
|
|
|
|
|
|
|
uint16 random_bits = Random();
|
2009-07-21 11:11:05 +00:00
|
|
|
ETileArea area = ETileArea(st, tile, tas[trigger]);
|
2008-04-19 23:19:12 +00:00
|
|
|
|
2009-07-21 11:11:05 +00:00
|
|
|
/* Check all tiles over the station to check if the specindex is still in use */
|
2010-01-04 18:30:10 +00:00
|
|
|
TILE_AREA_LOOP(tile, area) {
|
2010-01-01 18:19:26 +00:00
|
|
|
if (st->TileBelongsToRailStation(tile)) {
|
|
|
|
const StationSpec *ss = GetStationSpec(tile);
|
2010-08-26 15:31:40 +00:00
|
|
|
if (ss != NULL && HasBit(ss->animation.triggers, trigger)) {
|
2010-01-01 18:19:26 +00:00
|
|
|
CargoID cargo;
|
|
|
|
if (cargo_type == CT_INVALID) {
|
|
|
|
cargo = CT_INVALID;
|
|
|
|
} else {
|
2012-05-25 17:23:19 +00:00
|
|
|
cargo = ss->grf_prop.grffile->cargo_map[cargo_type];
|
2008-04-19 23:19:12 +00:00
|
|
|
}
|
2010-08-26 17:01:17 +00:00
|
|
|
StationAnimationBase::ChangeAnimationFrame(CBID_STATION_ANIM_START_STOP, ss, st, tile, (random_bits << 16) | Random(), (uint8)trigger | (cargo << 8));
|
2008-04-19 23:19:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:39:25 +00:00
|
|
|
/**
|
|
|
|
* Trigger station randomisation
|
|
|
|
* @param st station being triggered
|
|
|
|
* @param tile specific tile of platform to trigger
|
|
|
|
* @param trigger trigger type
|
|
|
|
* @param cargo_type cargo type causing trigger
|
|
|
|
*/
|
|
|
|
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type)
|
|
|
|
{
|
|
|
|
/* List of coverage areas for each animation trigger */
|
|
|
|
static const TriggerArea tas[] = {
|
|
|
|
TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Get Station if it wasn't supplied */
|
|
|
|
if (st == NULL) st = Station::GetByTile(tile);
|
|
|
|
|
|
|
|
/* Check the cached cargo trigger bitmask to see if we need
|
|
|
|
* to bother with any further processing. */
|
|
|
|
if (st->cached_cargo_triggers == 0) return;
|
|
|
|
if (cargo_type != CT_INVALID && !HasBit(st->cached_cargo_triggers, cargo_type)) return;
|
|
|
|
|
|
|
|
uint32 whole_reseed = 0;
|
|
|
|
ETileArea area = ETileArea(st, tile, tas[trigger]);
|
|
|
|
|
|
|
|
uint32 empty_mask = 0;
|
|
|
|
if (trigger == SRT_CARGO_TAKEN) {
|
|
|
|
/* Create a bitmask of completely empty cargo types to be matched */
|
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
|
|
|
if (st->goods[i].cargo.Empty()) {
|
|
|
|
SetBit(empty_mask, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert trigger to bit */
|
|
|
|
uint8 trigger_bit = 1 << trigger;
|
|
|
|
|
|
|
|
/* Check all tiles over the station to check if the specindex is still in use */
|
|
|
|
TILE_AREA_LOOP(tile, area) {
|
|
|
|
if (st->TileBelongsToRailStation(tile)) {
|
|
|
|
const StationSpec *ss = GetStationSpec(tile);
|
|
|
|
if (ss == NULL) continue;
|
|
|
|
|
|
|
|
/* Cargo taken "will only be triggered if all of those
|
|
|
|
* cargo types have no more cargo waiting." */
|
|
|
|
if (trigger == SRT_CARGO_TAKEN) {
|
|
|
|
if ((ss->cargo_triggers & ~empty_mask) != 0) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cargo_type == CT_INVALID || HasBit(ss->cargo_triggers, cargo_type)) {
|
|
|
|
StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
|
|
|
|
object.trigger = trigger_bit;
|
|
|
|
|
|
|
|
const SpriteGroup *group = ResolveStation(&object);
|
|
|
|
if (group == NULL) continue;
|
|
|
|
|
|
|
|
uint32 reseed = object.GetReseedSum();
|
|
|
|
if (reseed != 0) {
|
|
|
|
whole_reseed |= reseed;
|
|
|
|
reseed >>= 16;
|
|
|
|
|
|
|
|
/* Set individual tile random bits */
|
|
|
|
uint8 random_bits = GetStationTileRandomBits(tile);
|
|
|
|
random_bits &= ~reseed;
|
|
|
|
random_bits |= Random() & reseed;
|
|
|
|
SetStationTileRandomBits(tile, random_bits);
|
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update whole station random bits */
|
|
|
|
if ((whole_reseed & 0xFFFF) != 0) {
|
|
|
|
st->random_bits &= ~whole_reseed;
|
|
|
|
st->random_bits |= Random() & whole_reseed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-19 23:19:12 +00:00
|
|
|
/**
|
|
|
|
* Update the cached animation trigger bitmask for a station.
|
|
|
|
* @param st Station to update.
|
|
|
|
*/
|
2013-01-11 07:39:25 +00:00
|
|
|
void StationUpdateCachedTriggers(BaseStation *st)
|
2008-04-19 23:19:12 +00:00
|
|
|
{
|
|
|
|
st->cached_anim_triggers = 0;
|
2013-01-11 07:39:25 +00:00
|
|
|
st->cached_cargo_triggers = 0;
|
2008-04-19 23:19:12 +00:00
|
|
|
|
|
|
|
/* Combine animation trigger bitmask for all station specs
|
|
|
|
* of this station. */
|
|
|
|
for (uint i = 0; i < st->num_specs; i++) {
|
|
|
|
const StationSpec *ss = st->speclist[i].spec;
|
2013-01-11 07:39:25 +00:00
|
|
|
if (ss != NULL) {
|
|
|
|
st->cached_anim_triggers |= ss->animation.triggers;
|
|
|
|
st->cached_cargo_triggers |= ss->cargo_triggers;
|
|
|
|
}
|
2008-04-19 23:19:12 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-24 13:35:18 +00:00
|
|
|
|