2005-11-12 00:19:34 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
2006-05-03 21:35:33 +00:00
|
|
|
#include "variables.h"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.h"
|
2005-11-12 00:19:34 +00:00
|
|
|
#include "debug.h"
|
2009-06-24 17:39:54 +00:00
|
|
|
#include "station_base.h"
|
2009-07-17 21:06:06 +00:00
|
|
|
#include "waypoint.h"
|
2009-06-23 21:44:48 +00:00
|
|
|
#include "roadstop_base.h"
|
2007-06-11 04:52:51 +00:00
|
|
|
#include "newgrf_commons.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"
|
2008-07-27 18:36:11 +00:00
|
|
|
#include "town.h"
|
2007-03-21 20:58:01 +00:00
|
|
|
#include "newgrf_town.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "gfx_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2008-04-20 08:22:59 +00:00
|
|
|
#include "animated_tile_func.h"
|
2008-04-20 08:43:31 +00:00
|
|
|
#include "functions.h"
|
2008-07-19 10:10:21 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2008-10-18 17:20:31 +00:00
|
|
|
#include "spritecache.h"
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2009-02-09 22:49:28 +00:00
|
|
|
static StationClass _station_classes[STAT_CLASS_MAX];
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2006-05-08 13:35:25 +00:00
|
|
|
enum {
|
|
|
|
MAX_SPECLIST = 255,
|
|
|
|
};
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
for (end = tile; IsRailwayStationTile(end + delta) && IsCompatibleTrainStationTile(tile, end + delta); end += delta) { /* Nothing */ }
|
|
|
|
for (start = tile; IsRailwayStationTile(start - delta) && IsCompatibleTrainStationTile(tile, start - delta); start -= delta) { /* Nothing */ }
|
|
|
|
|
|
|
|
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);
|
|
|
|
this->w++;
|
|
|
|
this->h++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-12 00:19:34 +00:00
|
|
|
/**
|
|
|
|
* Reset station classes to their default state.
|
|
|
|
* This includes initialising the Default and Waypoint classes with an empty
|
|
|
|
* entry, for standard stations and waypoints.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void ResetStationClasses()
|
2005-11-12 00:19:34 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
|
2008-01-16 18:34:53 +00:00
|
|
|
_station_classes[i].id = 0;
|
|
|
|
_station_classes[i].name = STR_EMPTY;
|
|
|
|
_station_classes[i].stations = 0;
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2008-01-16 18:34:53 +00:00
|
|
|
free(_station_classes[i].spec);
|
|
|
|
_station_classes[i].spec = NULL;
|
2005-11-12 00:19:34 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Set up initial data */
|
2008-01-16 18:34:53 +00:00
|
|
|
_station_classes[0].id = 'DFLT';
|
|
|
|
_station_classes[0].name = STR_STAT_CLASS_DFLT;
|
|
|
|
_station_classes[0].stations = 1;
|
|
|
|
_station_classes[0].spec = MallocT<StationSpec*>(1);
|
|
|
|
_station_classes[0].spec[0] = NULL;
|
|
|
|
|
|
|
|
_station_classes[1].id = 'WAYP';
|
|
|
|
_station_classes[1].name = STR_STAT_CLASS_WAYP;
|
|
|
|
_station_classes[1].stations = 1;
|
|
|
|
_station_classes[1].spec = MallocT<StationSpec*>(1);
|
|
|
|
_station_classes[1].spec[0] = NULL;
|
2005-11-12 00:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate a station class for the given class id.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param cls A 32 bit value identifying the class.
|
2008-01-16 18:34:53 +00:00
|
|
|
* @return Index into _station_classes of allocated class.
|
2005-11-12 00:19:34 +00:00
|
|
|
*/
|
2007-01-10 18:56:51 +00:00
|
|
|
StationClassID AllocateStationClass(uint32 cls)
|
2005-11-12 00:19:34 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
|
2008-01-16 18:34:53 +00:00
|
|
|
if (_station_classes[i].id == cls) {
|
2007-03-21 03:06:21 +00:00
|
|
|
/* ClassID is already allocated, so reuse it. */
|
2005-11-12 00:19:34 +00:00
|
|
|
return i;
|
2008-01-16 18:34:53 +00:00
|
|
|
} else if (_station_classes[i].id == 0) {
|
2007-03-21 03:06:21 +00:00
|
|
|
/* This class is empty, so allocate it to the ClassID. */
|
2008-01-16 18:34:53 +00:00
|
|
|
_station_classes[i].id = cls;
|
2005-11-12 00:19:34 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
grfmsg(2, "StationClassAllocate: already allocated %d classes, using default", STAT_CLASS_MAX);
|
2005-11-12 00:19:34 +00:00
|
|
|
return STAT_CLASS_DFLT;
|
|
|
|
}
|
|
|
|
|
2006-04-23 18:37:06 +00:00
|
|
|
/** Set the name of a custom station class */
|
|
|
|
void SetStationClassName(StationClassID sclass, StringID name)
|
|
|
|
{
|
|
|
|
assert(sclass < STAT_CLASS_MAX);
|
2008-01-16 18:34:53 +00:00
|
|
|
_station_classes[sclass].name = name;
|
2006-04-23 18:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Retrieve the name of a custom station class */
|
|
|
|
StringID GetStationClassName(StationClassID sclass)
|
|
|
|
{
|
|
|
|
assert(sclass < STAT_CLASS_MAX);
|
2008-01-16 18:34:53 +00:00
|
|
|
return _station_classes[sclass].name;
|
2006-04-23 18:37:06 +00:00
|
|
|
}
|
|
|
|
|
2006-04-19 07:17:00 +00:00
|
|
|
/**
|
|
|
|
* Get the number of station classes in use.
|
|
|
|
* @return Number of station classes.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
uint GetNumStationClasses()
|
2006-04-19 07:17:00 +00:00
|
|
|
{
|
|
|
|
uint i;
|
2008-03-15 13:21:31 +00:00
|
|
|
for (i = 0; i < STAT_CLASS_MAX && _station_classes[i].id != 0; i++) {}
|
2006-04-19 07:17:00 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2005-11-12 00:19:34 +00:00
|
|
|
/**
|
|
|
|
* Return the number of stations for the given station class.
|
|
|
|
* @param sclass Index of the station class.
|
|
|
|
* @return Number of stations in the class.
|
|
|
|
*/
|
|
|
|
uint GetNumCustomStations(StationClassID sclass)
|
|
|
|
{
|
|
|
|
assert(sclass < STAT_CLASS_MAX);
|
2008-01-16 18:34:53 +00:00
|
|
|
return _station_classes[sclass].stations;
|
2005-11-12 00:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tie a station spec to its station class.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param statspec The station spec.
|
2005-11-12 00:19:34 +00:00
|
|
|
*/
|
2006-04-27 18:28:56 +00:00
|
|
|
void SetCustomStationSpec(StationSpec *statspec)
|
2005-11-12 00:19:34 +00:00
|
|
|
{
|
|
|
|
StationClass *station_class;
|
|
|
|
int i;
|
|
|
|
|
2006-05-07 12:58:45 +00:00
|
|
|
/* If the station has already been allocated, don't reallocate it. */
|
|
|
|
if (statspec->allocated) return;
|
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
assert(statspec->sclass < STAT_CLASS_MAX);
|
2008-01-16 18:34:53 +00:00
|
|
|
station_class = &_station_classes[statspec->sclass];
|
2005-11-12 00:19:34 +00:00
|
|
|
|
|
|
|
i = station_class->stations++;
|
2007-01-11 17:29:39 +00:00
|
|
|
station_class->spec = ReallocT(station_class->spec, station_class->stations);
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
station_class->spec[i] = statspec;
|
2006-05-07 12:58:45 +00:00
|
|
|
statspec->allocated = true;
|
2005-11-12 00:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a station spec from a class.
|
|
|
|
* @param sclass Index of the station class.
|
|
|
|
* @param station The station index with the class.
|
|
|
|
* @return The station spec.
|
|
|
|
*/
|
2006-04-27 18:28:56 +00:00
|
|
|
const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station)
|
2005-11-12 00:19:34 +00:00
|
|
|
{
|
|
|
|
assert(sclass < STAT_CLASS_MAX);
|
2008-01-16 18:34:53 +00:00
|
|
|
if (station < _station_classes[sclass].stations)
|
|
|
|
return _station_classes[sclass].spec[station];
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/* If the custom station isn't defined any more, then the GRF file
|
|
|
|
* probably was not loaded. */
|
2005-11-12 00:19:34 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-02-03 23:02:01 +00:00
|
|
|
|
2009-02-09 22:49:28 +00:00
|
|
|
/**
|
|
|
|
* Retrieve a station spec by GRF location.
|
|
|
|
* @param grfid GRF ID of station spec.
|
|
|
|
* @param localidx Index within GRF file of station spec.
|
|
|
|
* @param index Pointer to return the index of the station spec in its station class. If NULL then not used.
|
|
|
|
* @return The station spec.
|
|
|
|
*/
|
|
|
|
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx, int *index)
|
2006-05-06 21:46:26 +00:00
|
|
|
{
|
|
|
|
uint j;
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
|
2008-01-16 18:34:53 +00:00
|
|
|
for (j = 0; j < _station_classes[i].stations; j++) {
|
|
|
|
const StationSpec *statspec = _station_classes[i].spec[j];
|
2006-05-06 21:46:26 +00:00
|
|
|
if (statspec == NULL) continue;
|
2009-02-09 22:49:28 +00:00
|
|
|
if (statspec->grffile->grfid == grfid && statspec->localidx == localidx) {
|
|
|
|
if (index != NULL) *index = j;
|
|
|
|
return statspec;
|
|
|
|
}
|
2006-05-06 21:46:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-06 09:31:06 +00:00
|
|
|
/* Evaluate a tile's position within a station, and return the result a bitstuffed format.
|
|
|
|
* if not centred: .TNLcCpP, if centred: .TNL..CP
|
|
|
|
* 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
|
|
|
|
* if centred, C/P start from the centre and c/p are not available.
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* Limit our sizes to 4 bits */
|
|
|
|
platforms = min(15, platforms);
|
|
|
|
length = min(15, length);
|
|
|
|
x = min(15, x);
|
|
|
|
y = min(15, y);
|
|
|
|
if (centred) {
|
|
|
|
x -= platforms / 2;
|
|
|
|
y -= length / 2;
|
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 {
|
|
|
|
SB(retval, 0, 4, y);
|
|
|
|
SB(retval, 4, 4, length - y - 1);
|
|
|
|
SB(retval, 8, 4, x);
|
|
|
|
SB(retval, 12, 4, platforms - x - 1);
|
|
|
|
}
|
|
|
|
SB(retval, 16, 4, length);
|
|
|
|
SB(retval, 20, 4, platforms);
|
|
|
|
SB(retval, 24, 4, tile);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Find the end of a railway station, from the tile, in the direction of delta.
|
|
|
|
* If check_type is set, we stop if the custom station type changes.
|
|
|
|
* If check_axis is set, we stop if the station direction changes.
|
|
|
|
*/
|
|
|
|
static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
|
|
|
|
{
|
|
|
|
bool waypoint;
|
|
|
|
byte orig_type = 0;
|
|
|
|
Axis orig_axis = AXIS_X;
|
|
|
|
|
|
|
|
waypoint = IsTileType(tile, MP_RAILWAY);
|
|
|
|
|
|
|
|
if (waypoint) {
|
|
|
|
if (check_axis) orig_axis = GetWaypointAxis(tile);
|
|
|
|
} else {
|
|
|
|
if (check_type) orig_type = GetCustomStationSpecIndex(tile);
|
|
|
|
if (check_axis) orig_axis = GetRailStationAxis(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
TileIndex new_tile = TILE_ADD(tile, delta);
|
|
|
|
|
|
|
|
if (waypoint) {
|
2008-09-09 12:26:25 +00:00
|
|
|
if (!IsRailWaypointTile(new_tile)) break;
|
2006-05-06 09:31:06 +00:00
|
|
|
if (check_axis && GetWaypointAxis(new_tile) != orig_axis) break;
|
|
|
|
} else {
|
|
|
|
if (!IsRailwayStationTile(new_tile)) break;
|
|
|
|
if (check_type && GetCustomStationSpecIndex(new_tile) != orig_type) break;
|
|
|
|
if (check_axis && GetRailStationAxis(new_tile) != orig_axis) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
Axis axis = IsTileType(tile, MP_RAILWAY) ? GetWaypointAxis(tile) : GetRailStationAxis(tile);
|
|
|
|
|
|
|
|
tx -= sx; ex -= sx;
|
|
|
|
ty -= sy; ey -= sy;
|
|
|
|
|
|
|
|
return GetPlatformInfo(axis, IsTileType(tile, MP_RAILWAY) ? 2 : GetStationGfx(tile), ex, ey, tx, ty, centred);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Axis axis = IsTileType(tile, MP_RAILWAY) ? GetWaypointAxis(tile) : GetRailStationAxis(tile);
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
static uint32 StationGetRandomBits(const ResolverObject *object)
|
|
|
|
{
|
2009-07-17 19:44:13 +00:00
|
|
|
const BaseStation *st = object->u.station.st;
|
2006-05-03 21:35:33 +00:00
|
|
|
const TileIndex tile = object->u.station.tile;
|
|
|
|
return (st == NULL ? 0 : st->random_bits) | (tile == INVALID_TILE ? 0 : GetStationTileRandomBits(tile) << 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32 StationGetTriggers(const ResolverObject *object)
|
|
|
|
{
|
2009-07-17 19:44:13 +00:00
|
|
|
const BaseStation *st = object->u.station.st;
|
2006-05-03 21:35:33 +00:00
|
|
|
return st == NULL ? 0 : st->waiting_triggers;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void StationSetTriggers(const ResolverObject *object, int triggers)
|
|
|
|
{
|
2009-07-17 19:44:13 +00:00
|
|
|
BaseStation *st = const_cast<BaseStation *>(object->u.station.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;
|
|
|
|
uint8 valid;
|
|
|
|
} _svc;
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2006-05-23 19:36:50 +00:00
|
|
|
static uint32 StationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
|
2006-02-03 23:02:01 +00:00
|
|
|
{
|
2009-07-17 19:44:13 +00:00
|
|
|
const BaseStation *st = object->u.station.st;
|
2006-05-06 09:31:06 +00:00
|
|
|
TileIndex tile = object->u.station.tile;
|
2006-05-03 21:35:33 +00:00
|
|
|
|
2007-03-21 20:58:01 +00:00
|
|
|
if (object->scope == VSG_SCOPE_PARENT) {
|
|
|
|
/* Pass the request on to the town of the station */
|
2008-07-27 18:36:11 +00:00
|
|
|
const Town *t;
|
2007-03-21 20:58:01 +00:00
|
|
|
|
|
|
|
if (st != NULL) {
|
|
|
|
t = st->town;
|
|
|
|
} else if (tile != INVALID_TILE) {
|
2008-07-27 18:36:11 +00:00
|
|
|
t = ClosestTownFromTile(tile, UINT_MAX);
|
2007-03-21 20:58:01 +00:00
|
|
|
} else {
|
|
|
|
*available = false;
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TownGetVariable(variable, parameter, available, t);
|
|
|
|
}
|
|
|
|
|
2006-05-03 21:35:33 +00:00
|
|
|
if (st == NULL) {
|
|
|
|
/* Station does not exist, so we're in a purchase list */
|
|
|
|
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?)
|
|
|
|
case 0x43: return _current_company; // Station owner
|
|
|
|
case 0x44: return 2; // PBS status
|
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:
|
2007-11-20 13:35:54 +00:00
|
|
|
if (!HasBit(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(tile, false, false, false); SetBit(_svc.valid, 0); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v40;
|
|
|
|
|
|
|
|
case 0x41:
|
2007-11-20 13:35:54 +00:00
|
|
|
if (!HasBit(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(tile, true, false, false); SetBit(_svc.valid, 1); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v41;
|
|
|
|
|
2007-06-11 04:52:51 +00:00
|
|
|
case 0x42: return GetTerrainType(tile) | (GetRailType(tile) << 8);
|
2007-03-21 03:06:21 +00:00
|
|
|
case 0x43: return st->owner; // Station owner
|
2008-08-02 22:57:03 +00:00
|
|
|
case 0x44:
|
2008-09-09 12:26:25 +00:00
|
|
|
if (IsRailWaypointTile(tile)) {
|
2009-07-22 08:52:41 +00:00
|
|
|
return HasDepotReservation(tile) ? 7 : 4;
|
2008-08-02 22:57:03 +00:00
|
|
|
} else {
|
2009-07-21 22:37:10 +00:00
|
|
|
return HasStationReservation(tile) ? 7 : 4; // PBS status
|
2008-08-02 22:57:03 +00:00
|
|
|
}
|
2007-07-11 16:37:20 +00:00
|
|
|
case 0x45:
|
2007-11-20 13:35:54 +00:00
|
|
|
if (!HasBit(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(tile); SetBit(_svc.valid, 2); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v45;
|
|
|
|
|
|
|
|
case 0x46:
|
2007-11-20 13:35:54 +00:00
|
|
|
if (!HasBit(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(tile, false, false, true); SetBit(_svc.valid, 3); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v46;
|
|
|
|
|
|
|
|
case 0x47:
|
2007-11-20 13:35:54 +00:00
|
|
|
if (!HasBit(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(tile, true, false, true); SetBit(_svc.valid, 4); }
|
2007-07-11 16:37:20 +00:00
|
|
|
return _svc.v47;
|
|
|
|
|
|
|
|
case 0x49:
|
2007-11-20 13:35:54 +00:00
|
|
|
if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(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
|
|
|
|
return GetStationAnimationFrame(tile);
|
|
|
|
|
2006-05-03 21:35:33 +00:00
|
|
|
/* Variables which use the parameter */
|
2007-04-13 19:32:18 +00:00
|
|
|
/* Variables 0x60 to 0x65 are handled separately below */
|
2008-04-17 06:53:52 +00:00
|
|
|
case 0x66: // Animation frame of nearby tile
|
|
|
|
if (parameter != 0) tile = GetNearbyTile(parameter, tile);
|
|
|
|
return st->TileBelongsToRailStation(tile) ? GetStationAnimationFrame(tile) : UINT_MAX;
|
|
|
|
|
|
|
|
case 0x67: { // Land info of nearby tile
|
2007-12-21 22:11:55 +00:00
|
|
|
Axis axis = GetRailStationAxis(tile);
|
|
|
|
|
|
|
|
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
|
|
|
|
|
2008-01-31 17:46:08 +00:00
|
|
|
Slope tileh = GetTileSlope(tile, NULL);
|
|
|
|
bool swap = (axis == AXIS_Y && HasBit(tileh, SLOPE_W) != HasBit(tileh, SLOPE_E));
|
|
|
|
|
|
|
|
return GetNearbyTileInformation(tile) ^ (swap ? SLOPE_EW : 0);
|
2007-12-21 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case 0x68: { // Station info of nearby tiles
|
|
|
|
TileIndex nearby_tile = GetNearbyTile(parameter, tile);
|
|
|
|
|
|
|
|
if (!IsRailwayStationTile(nearby_tile)) return 0xFFFFFFFF;
|
|
|
|
|
|
|
|
uint32 grfid = st->speclist[GetCustomStationSpecIndex(tile)].grfid;
|
|
|
|
bool perpendicular = GetRailStationAxis(tile) != GetRailStationAxis(nearby_tile);
|
|
|
|
bool same_station = st->TileBelongsToRailStation(nearby_tile);
|
|
|
|
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;
|
|
|
|
case 0x84: return st->string_id;
|
|
|
|
case 0x86: return 0;
|
|
|
|
case 0xF0: return st->facilities;
|
2007-11-19 18:38:10 +00:00
|
|
|
case 0xFA: return Clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
return st->GetNewGRFVariable(object, variable, parameter, available);
|
|
|
|
}
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
if (HasBit(this->goods[cargo_type].acceptance_pickup, GoodsEntry::PICKUP)) SetBit(value, cargo_type);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x8A: return this->had_vehicle_of_type;
|
|
|
|
case 0xF1: return this->airport_type;
|
|
|
|
case 0xF2: return this->truck_stops->status;
|
|
|
|
case 0xF3: return this->bus_stops->status;
|
|
|
|
case 0xF6: return this->airport_flags;
|
|
|
|
case 0xF7: return GB(this->airport_flags, 8, 8);
|
|
|
|
}
|
|
|
|
|
2007-04-13 19:32:18 +00:00
|
|
|
/* Handle cargo variables with parameter, 0x60 to 0x65 */
|
|
|
|
if (variable >= 0x60 && variable <= 0x65) {
|
|
|
|
CargoID c = GetCargoTranslation(parameter, object->u.station.statspec->grffile);
|
|
|
|
|
|
|
|
if (c == CT_INVALID) 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);
|
2007-04-13 19:32:18 +00:00
|
|
|
case 0x61: return ge->days_since_pickup;
|
|
|
|
case 0x62: return ge->rating;
|
2007-06-22 11:58:59 +00:00
|
|
|
case 0x63: return ge->cargo.DaysInTransit();
|
2007-04-13 19:32:18 +00:00
|
|
|
case 0x64: return ge->last_speed | (ge->last_age << 8);
|
2007-08-26 13:55:36 +00:00
|
|
|
case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 3;
|
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();
|
2007-08-26 13:55:36 +00:00
|
|
|
case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 7);
|
2006-05-04 07:26:30 +00:00
|
|
|
case 2: return g->days_since_pickup;
|
|
|
|
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
|
|
|
|
case 0x8A: return HVOT_TRAIN;
|
|
|
|
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
|
|
|
|
2009-05-23 12:13:42 +00:00
|
|
|
static const SpriteGroup *StationResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
|
2006-05-03 21:35:33 +00:00
|
|
|
{
|
2009-07-17 19:44:13 +00:00
|
|
|
const BaseStation *bst = object->u.station.st;
|
2006-05-03 21:35:33 +00:00
|
|
|
const StationSpec *statspec = object->u.station.statspec;
|
|
|
|
uint set;
|
|
|
|
|
|
|
|
uint cargo = 0;
|
2006-10-11 22:05:59 +00:00
|
|
|
CargoID cargo_type = object->u.station.cargo_type;
|
2006-02-03 23:02:01 +00:00
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
if (bst == NULL || statspec->sclass == STAT_CLASS_WAYP) {
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->loading[0];
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
const Station *st = Station::From(bst);
|
|
|
|
|
2006-10-11 22:05:59 +00:00
|
|
|
switch (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:
|
2006-10-11 22:05:59 +00:00
|
|
|
for (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:
|
2007-06-22 11:58:59 +00:00
|
|
|
cargo = st->goods[cargo_type].cargo.Count();
|
2006-10-11 22:05:59 +00:00
|
|
|
break;
|
2006-05-03 21:35:33 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 08:01:36 +00:00
|
|
|
if (HasBit(statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->trainst_w + st->trainst_h);
|
2006-05-03 21:35:33 +00:00
|
|
|
cargo = min(0xfff, cargo);
|
2006-02-03 23:02:01 +00:00
|
|
|
|
2006-05-03 21:35:33 +00:00
|
|
|
if (cargo > statspec->cargo_threshold) {
|
2009-05-23 12:13:42 +00:00
|
|
|
if (group->num_loading > 0) {
|
|
|
|
set = ((cargo - statspec->cargo_threshold) * group->num_loading) / (4096 - statspec->cargo_threshold);
|
|
|
|
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) {
|
|
|
|
set = (cargo * group->num_loaded) / (statspec->cargo_threshold + 1);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
static void NewStationResolver(ResolverObject *res, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
|
2006-05-03 21:35:33 +00:00
|
|
|
{
|
|
|
|
res->GetRandomBits = StationGetRandomBits;
|
|
|
|
res->GetTriggers = StationGetTriggers;
|
|
|
|
res->SetTriggers = StationSetTriggers;
|
|
|
|
res->GetVariable = StationGetVariable;
|
|
|
|
res->ResolveReal = StationResolveReal;
|
|
|
|
|
|
|
|
res->u.station.st = st;
|
|
|
|
res->u.station.statspec = statspec;
|
|
|
|
res->u.station.tile = tile;
|
|
|
|
|
2007-07-25 19:06:29 +00:00
|
|
|
res->callback = CBID_NO_CALLBACK;
|
2006-05-03 21:35:33 +00:00
|
|
|
res->callback_param1 = 0;
|
|
|
|
res->callback_param2 = 0;
|
|
|
|
res->last_value = 0;
|
|
|
|
res->trigger = 0;
|
|
|
|
res->reseed = 0;
|
2008-03-27 21:36:16 +00:00
|
|
|
res->count = 0;
|
2008-07-30 18:23:12 +00:00
|
|
|
res->grffile = (statspec != NULL ? statspec->grffile : NULL);
|
2006-02-03 23:02:01 +00:00
|
|
|
}
|
|
|
|
|
2007-01-26 20:39:36 +00:00
|
|
|
static const SpriteGroup *ResolveStation(ResolverObject *object)
|
2006-10-11 22:05:59 +00:00
|
|
|
{
|
|
|
|
const SpriteGroup *group;
|
2007-02-24 23:36:40 +00:00
|
|
|
CargoID ctype = CT_DEFAULT_NA;
|
2006-10-11 22:05:59 +00:00
|
|
|
|
2007-01-26 20:39:36 +00:00
|
|
|
if (object->u.station.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;
|
2009-07-20 16:30:37 +00:00
|
|
|
} else if (Station::IsExpected(object->u.station.st)) {
|
2009-07-17 19:44:13 +00:00
|
|
|
const Station *st = Station::From(object->u.station.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) {
|
|
|
|
if (object->u.station.statspec->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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 20:39:36 +00:00
|
|
|
group = object->u.station.statspec->spritegroup[ctype];
|
2006-10-11 22:05:59 +00:00
|
|
|
if (group == NULL) {
|
2007-02-24 23:36:40 +00:00
|
|
|
ctype = CT_DEFAULT;
|
2007-01-26 20:39:36 +00:00
|
|
|
group = object->u.station.statspec->spritegroup[ctype];
|
2006-10-11 22:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (group == NULL) return NULL;
|
|
|
|
|
|
|
|
/* Remember the cargo type we've picked */
|
|
|
|
object->u.station.cargo_type = ctype;
|
|
|
|
|
2007-07-11 16:37:20 +00:00
|
|
|
/* Invalidate all cached vars */
|
|
|
|
_svc.valid = 0;
|
|
|
|
|
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
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
SpriteID GetCustomStationRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile)
|
2006-02-03 23:02:01 +00:00
|
|
|
{
|
2006-05-03 21:35:33 +00:00
|
|
|
const SpriteGroup *group;
|
|
|
|
ResolverObject object;
|
|
|
|
|
|
|
|
NewStationResolver(&object, statspec, st, tile);
|
|
|
|
|
2007-01-26 20:39:36 +00:00
|
|
|
group = ResolveStation(&object);
|
2006-05-03 21:35:33 +00:00
|
|
|
if (group == NULL || group->type != SGT_RESULT) return 0;
|
2009-05-23 12:13:42 +00:00
|
|
|
return group->GetResult() - 0x42D;
|
2006-05-07 10:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile)
|
2006-05-07 10:58:53 +00:00
|
|
|
{
|
|
|
|
const SpriteGroup *group;
|
|
|
|
ResolverObject object;
|
|
|
|
|
|
|
|
NewStationResolver(&object, statspec, st, tile);
|
2009-04-05 08:06:40 +00:00
|
|
|
if (HasBit(statspec->flags, SSF_SEPARATE_GROUND)) {
|
|
|
|
object.callback_param1 = 1; // Indicate we are resolving the ground sprite
|
|
|
|
}
|
2006-05-07 10:58:53 +00:00
|
|
|
|
2007-01-26 20:39:36 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
|
2006-05-04 19:27:41 +00:00
|
|
|
{
|
|
|
|
const SpriteGroup *group;
|
|
|
|
ResolverObject object;
|
|
|
|
|
|
|
|
NewStationResolver(&object, statspec, st, tile);
|
|
|
|
|
|
|
|
object.callback = callback;
|
|
|
|
object.callback_param1 = param1;
|
|
|
|
object.callback_param2 = param2;
|
|
|
|
|
2007-01-26 20:39:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
* result in slighty "wrong" (as per specs) looking stations,
|
|
|
|
* 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;
|
2007-04-11 21:04:03 +00:00
|
|
|
st->speclist[i].grfid = statspec->grffile->grfid;
|
2006-05-03 11:19:17 +00:00
|
|
|
st->speclist[i].localidx = statspec->localidx;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Deallocate a StationSpec from a Station. Called when removing a single station tile.
|
|
|
|
* @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 */
|
2009-07-21 11:11:05 +00:00
|
|
|
for (uint y = 0; y < area.h; y++) {
|
|
|
|
for (uint x = 0; x < area.w; x++) {
|
|
|
|
if (st->TileBelongsToRailStation(area.tile) && GetCustomStationSpecIndex(area.tile) == specindex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
area.tile += TileDiffXY(1, 0);
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
2009-07-21 11:11:05 +00:00
|
|
|
area.tile += TileDiffXY(-area.w, 1);
|
|
|
|
}
|
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;
|
|
|
|
return;
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-19 23:19:12 +00:00
|
|
|
|
|
|
|
StationUpdateAnimTriggers(st);
|
2006-04-19 07:17:00 +00:00
|
|
|
}
|
2006-05-06 20:48:40 +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)
|
|
|
|
{
|
|
|
|
const StationSpec *statspec;
|
|
|
|
const DrawTileSprites *sprites;
|
|
|
|
const DrawTileSeqStruct *seq;
|
|
|
|
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
|
|
|
|
SpriteID relocation;
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image;
|
2009-02-09 02:57:15 +00:00
|
|
|
SpriteID palette = COMPANY_SPRITE_COLOUR(_local_company);
|
2006-05-06 20:48:40 +00:00
|
|
|
uint tile = 2;
|
|
|
|
|
|
|
|
statspec = GetCustomStationSpec(sclass, station);
|
|
|
|
if (statspec == NULL) return false;
|
|
|
|
|
|
|
|
relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE);
|
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(statspec->callbackmask, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2007-01-10 18:56:51 +00:00
|
|
|
sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis];
|
2006-05-06 20:48:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-15 18:40:42 +00:00
|
|
|
image = sprites->ground.sprite;
|
2008-11-22 16:04:11 +00:00
|
|
|
SpriteID pal = sprites->ground.pal;
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
|
2006-05-07 10:58:53 +00:00
|
|
|
image += GetCustomStationGroundRelocation(statspec, NULL, INVALID_TILE);
|
|
|
|
image += rti->custom_ground_offset;
|
|
|
|
} else {
|
|
|
|
image += rti->total_offset;
|
|
|
|
}
|
2006-05-06 20:48:40 +00:00
|
|
|
|
2008-11-22 16:04:11 +00:00
|
|
|
DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
|
2006-05-06 20:48:40 +00:00
|
|
|
|
2008-10-18 17:20:31 +00:00
|
|
|
Point child_offset = {0, 0};
|
|
|
|
|
2006-05-06 20:48:40 +00:00
|
|
|
foreach_draw_tile_seq(seq, sprites->seq) {
|
2008-02-15 18:34:26 +00:00
|
|
|
image = seq->image.sprite;
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
|
2006-05-07 10:58:53 +00:00
|
|
|
image += rti->total_offset;
|
|
|
|
} else {
|
|
|
|
image += relocation;
|
|
|
|
}
|
2006-05-06 20:48:40 +00:00
|
|
|
|
2008-11-22 16:04:11 +00:00
|
|
|
pal = SpriteLayoutPaletteTransform(image, seq->image.pal, palette);
|
2008-04-12 22:11:21 +00:00
|
|
|
|
2006-05-06 20:48:40 +00:00
|
|
|
if ((byte)seq->delta_z != 0x80) {
|
2008-10-18 17:20:31 +00:00
|
|
|
Point pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z);
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(image, pal, x + pt.x, y + pt.y);
|
2008-10-18 17:20:31 +00:00
|
|
|
|
|
|
|
const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
|
|
|
|
child_offset.x = pt.x + spr->x_offs;
|
|
|
|
child_offset.y = pt.y + spr->y_offs;
|
|
|
|
} else {
|
|
|
|
/* For stations and original spritelayouts delta_x and delta_y are signed */
|
|
|
|
DrawSprite(image, pal, x + child_offset.x + seq->delta_x, y + child_offset.y + seq->delta_y);
|
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-17 21:06:06 +00:00
|
|
|
if (IsRailwayStationTile(t)) {
|
|
|
|
if (!IsCustomStationSpecIndex(t)) return NULL;
|
2006-05-06 22:08:14 +00:00
|
|
|
|
2009-07-17 21:06:06 +00:00
|
|
|
const BaseStation *st = BaseStation::GetByTile(t);
|
|
|
|
uint specindex = GetCustomStationSpecIndex(t);
|
|
|
|
return specindex < st->num_specs ? st->speclist[specindex].spec : NULL;
|
|
|
|
}
|
2006-05-06 22:08:14 +00:00
|
|
|
|
2009-07-17 21:06:06 +00:00
|
|
|
if (IsRailWaypointTile(t)) {
|
|
|
|
const BaseStation *st = BaseStation::GetByTile(t);
|
2009-07-21 11:20:34 +00:00
|
|
|
return st->num_specs != 0 ? st->speclist[1].spec : NULL;
|
2009-07-17 21:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2006-08-01 06:08:11 +00:00
|
|
|
}
|
2006-05-06 22:08:14 +00:00
|
|
|
|
|
|
|
|
2006-08-01 06:08:11 +00:00
|
|
|
/* Check if a rail station tile is traversable.
|
|
|
|
* XXX This could be cached (during build) in the map array to save on all the dereferencing */
|
|
|
|
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
|
|
|
|
|
|
|
/* Check if a rail station tile is electrifiable.
|
|
|
|
* XXX This could be cached (during build) in the map array to save on all the dereferencing */
|
|
|
|
bool IsStationTileElectrifiable(TileIndex tile)
|
|
|
|
{
|
2009-01-10 00:31:47 +00:00
|
|
|
const StationSpec *statspec = GetStationSpec(tile);
|
2006-05-08 21:59:36 +00:00
|
|
|
|
2006-08-01 06:08:11 +00:00
|
|
|
return
|
|
|
|
statspec == NULL ||
|
2007-11-19 21:02:30 +00:00
|
|
|
HasBit(statspec->pylons, GetStationGfx(tile)) ||
|
|
|
|
!HasBit(statspec->wires, GetStationGfx(tile));
|
2006-05-08 21:59:36 +00:00
|
|
|
}
|
2008-04-19 23:19:12 +00:00
|
|
|
|
|
|
|
void AnimateStationTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
const StationSpec *ss = GetStationSpec(tile);
|
|
|
|
if (ss == NULL) return;
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
const BaseStation *st = BaseStation::GetByTile(tile);
|
2008-04-19 23:19:12 +00:00
|
|
|
|
|
|
|
uint8 animation_speed = ss->anim_speed;
|
|
|
|
|
|
|
|
if (HasBit(ss->callbackmask, CBM_STATION_ANIMATION_SPEED)) {
|
|
|
|
uint16 callback = GetStationCallback(CBID_STATION_ANIMATION_SPEED, 0, 0, ss, st, tile);
|
|
|
|
if (callback != CALLBACK_FAILED) animation_speed = Clamp(callback & 0xFF, 0, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_tick_counter % (1 << animation_speed) != 0) return;
|
|
|
|
|
|
|
|
uint8 frame = GetStationAnimationFrame(tile);
|
|
|
|
uint8 num_frames = ss->anim_frames;
|
|
|
|
|
|
|
|
bool frame_set_by_callback = false;
|
|
|
|
|
|
|
|
if (HasBit(ss->callbackmask, CBM_STATION_ANIMATION_NEXT_FRAME)) {
|
2009-04-05 08:01:36 +00:00
|
|
|
uint32 param = HasBit(ss->flags, SSF_CB141_RANDOM_BITS) ? Random() : 0;
|
2008-04-19 23:19:12 +00:00
|
|
|
uint16 callback = GetStationCallback(CBID_STATION_ANIM_NEXT_FRAME, param, 0, ss, st, tile);
|
|
|
|
|
|
|
|
if (callback != CALLBACK_FAILED) {
|
|
|
|
frame_set_by_callback = true;
|
|
|
|
|
|
|
|
switch (callback & 0xFF) {
|
|
|
|
case 0xFF:
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFE:
|
|
|
|
frame_set_by_callback = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
frame = callback & 0xFF;
|
|
|
|
break;
|
|
|
|
}
|
2008-04-21 11:29:01 +00:00
|
|
|
|
|
|
|
/* If the lower 7 bits of the upper byte of the callback
|
|
|
|
* result are not empty, it is a sound effect. */
|
|
|
|
if (GB(callback, 8, 7) != 0) PlayTileSound(ss->grffile, GB(callback, 8, 7), tile);
|
2008-04-19 23:19:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frame_set_by_callback) {
|
|
|
|
if (frame < num_frames) {
|
|
|
|
frame++;
|
|
|
|
} else if (frame == num_frames && HasBit(ss->anim_status, 0)) {
|
|
|
|
/* This animation loops, so start again from the beginning */
|
|
|
|
frame = 0;
|
|
|
|
} else {
|
|
|
|
/* This animation doesn't loop, so stay here */
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetStationAnimationFrame(tile, frame);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
static void ChangeStationAnimationFrame(const StationSpec *ss, const BaseStation *st, TileIndex tile, uint16 random_bits, StatAnimTrigger trigger, CargoID cargo_type)
|
2008-04-19 23:19:12 +00:00
|
|
|
{
|
|
|
|
uint16 callback = GetStationCallback(CBID_STATION_ANIM_START_STOP, (random_bits << 16) | Random(), (uint8)trigger | (cargo_type << 8), ss, st, tile);
|
|
|
|
if (callback == CALLBACK_FAILED) return;
|
|
|
|
|
|
|
|
switch (callback & 0xFF) {
|
|
|
|
case 0xFD: /* Do nothing. */ break;
|
|
|
|
case 0xFE: AddAnimatedTile(tile); break;
|
|
|
|
case 0xFF: DeleteAnimatedTile(tile); break;
|
|
|
|
default:
|
|
|
|
SetStationAnimationFrame(tile, callback);
|
|
|
|
AddAnimatedTile(tile);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-21 11:29:01 +00:00
|
|
|
|
|
|
|
/* If the lower 7 bits of the upper byte of the callback
|
|
|
|
* result are not empty, it is a sound effect. */
|
|
|
|
if (GB(callback, 8, 7) != 0) PlayTileSound(ss->grffile, GB(callback, 8, 7), tile);
|
2008-04-19 23:19:12 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 19:44:13 +00:00
|
|
|
void StationAnimationTrigger(const BaseStation *st, TileIndex tile, StatAnimTrigger 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 */
|
2008-04-19 23:19:12 +00:00
|
|
|
for (uint y = 0; y < area.h; y++) {
|
|
|
|
for (uint x = 0; x < area.w; x++) {
|
|
|
|
if (st->TileBelongsToRailStation(area.tile)) {
|
|
|
|
const StationSpec *ss = GetStationSpec(area.tile);
|
|
|
|
if (ss != NULL && HasBit(ss->anim_triggers, trigger)) {
|
|
|
|
CargoID cargo;
|
|
|
|
if (cargo_type == CT_INVALID) {
|
|
|
|
cargo = CT_INVALID;
|
|
|
|
} else {
|
|
|
|
cargo = GetReverseCargoTranslation(cargo_type, ss->grffile);
|
|
|
|
}
|
|
|
|
ChangeStationAnimationFrame(ss, st, area.tile, random_bits, trigger, cargo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
area.tile += TileDiffXY(1, 0);
|
|
|
|
}
|
|
|
|
area.tile += TileDiffXY(-area.w, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the cached animation trigger bitmask for a station.
|
|
|
|
* @param st Station to update.
|
|
|
|
*/
|
2009-07-17 19:44:13 +00:00
|
|
|
void StationUpdateAnimTriggers(BaseStation *st)
|
2008-04-19 23:19:12 +00:00
|
|
|
{
|
|
|
|
st->cached_anim_triggers = 0;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
if (ss != NULL) st->cached_anim_triggers |= ss->anim_triggers;
|
|
|
|
}
|
|
|
|
}
|