(svn r16864) -Codechange: make Waypoints a subclass of BaseStation.

pull/155/head
rubidium 15 years ago
parent 4ca5ce8904
commit 3927fd6be7

@ -7,6 +7,7 @@
#include "landscape.h"
#include "debug.h"
#include "station_base.h"
#include "waypoint.h"
#include "roadstop_base.h"
#include "newgrf_commons.h"
#include "newgrf_station.h"
@ -466,7 +467,7 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by
return res;
}
/* General station properties */
/* General station variables */
case 0x82: return 50;
case 0x84: return st->string_id;
case 0x86: return 0;
@ -530,12 +531,43 @@ uint32 Station::GetNewGRFVariable(const ResolverObject *object, byte variable, b
}
}
DEBUG(grf, 1, "Unhandled station property 0x%X", variable);
DEBUG(grf, 1, "Unhandled station variable 0x%X", variable);
*available = false;
return UINT_MAX;
}
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;
}
static const SpriteGroup *StationResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
{
@ -865,14 +897,20 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
const StationSpec *GetStationSpec(TileIndex t)
{
const BaseStation *st;
uint specindex;
if (IsRailwayStationTile(t)) {
if (!IsCustomStationSpecIndex(t)) return NULL;
if (!IsCustomStationSpecIndex(t)) return NULL;
const BaseStation *st = BaseStation::GetByTile(t);
uint specindex = GetCustomStationSpecIndex(t);
return specindex < st->num_specs ? st->speclist[specindex].spec : NULL;
}
st = BaseStation::GetByTile(t);
specindex = GetCustomStationSpecIndex(t);
return specindex < st->num_specs ? st->speclist[specindex].spec : NULL;
if (IsRailWaypointTile(t)) {
const BaseStation *st = BaseStation::GetByTile(t);
return st->num_specs != 0 ? st->speclist[0].spec : NULL;
}
return NULL;
}

@ -1938,13 +1938,10 @@ static void DrawTile_Track(TileInfo *ti)
}
} else {
/* look for customization */
const Waypoint *wp = Waypoint::GetByTile(ti->tile);
const StationSpec *statspec = GetStationSpec(ti->tile);
if (wp->num_specs != 0) {
const StationSpec *statspec = wp->speclist->spec;
/* emulate station tile - open with building */
const Station *st = ComposeWaypointStation(ti->tile);
if (statspec != NULL) {
const BaseStation *st = BaseStation::GetByTile(ti->tile);
uint gfx = 2;
if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) {

@ -52,6 +52,7 @@ Station::Station(TileIndex tile) :
/* static */ BaseStation *BaseStation::GetByTile(TileIndex tile)
{
if (IsRailWaypointTile(tile)) return Waypoint::GetByTile(tile);
return Station::GetByTile(tile);
}

@ -42,27 +42,6 @@ void WaypointsDailyLoop()
}
}
/**
* This hacks together some dummy one-shot Station structure for a waypoint.
* @param tile on which to work
* @return pointer to a Station
*/
Station *ComposeWaypointStation(TileIndex tile)
{
Waypoint *wp = Waypoint::GetByTile(tile);
/* instead of 'static Station stat' use byte array to avoid Station's destructor call upon exit. As
* a side effect, the station is not constructed now. */
static byte stat_raw[sizeof(Station)];
static Station &stat = *(Station*)stat_raw;
stat.train_tile = stat.xy = wp->xy;
stat.town = wp->town;
stat.build_date = wp->build_date;
return &stat;
}
/**
* Draw a waypoint
* @param x coordinate
@ -82,8 +61,6 @@ void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
Waypoint::~Waypoint()
{
free(this->name);
if (CleaningPool()) return;
DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);

@ -17,27 +17,21 @@
typedef Pool<Waypoint, WaypointID, 32, 64000> WaypointPool;
extern WaypointPool _waypoint_pool;
struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool> {
TileIndex xy; ///< Tile of waypoint
Town *town; ///< Town associated with the waypoint
struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool>, BaseStation {
uint16 town_cn; ///< The Nth waypoint for this town (consecutive number)
char *name; ///< Custom name. If not set, town + town_cn is used for naming
ViewportSign sign; ///< Dimensions of sign (not saved)
Date build_date; ///< Date of construction
OwnerByte owner; ///< Whom this waypoint belongs to
uint8 num_specs; ///< NOSAVE: Number of specs in the speclist
StationSpecList *speclist; ///< List of station specs of this station
byte delete_ctr; ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
Waypoint(TileIndex tile = INVALID_TILE) : xy(tile) { }
Waypoint(TileIndex tile = INVALID_TILE) : BaseStation(tile) { }
~Waypoint();
void UpdateVirtCoord();
/* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
{
return this->delete_ctr == 0 && this->xy == tile;
}
/* virtual */ uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const;
void AssignStationSpec(uint index);
/**
@ -55,7 +49,6 @@ struct Waypoint : WaypointPool::PoolItem<&_waypoint_pool> {
#define FOR_ALL_WAYPOINTS(var) FOR_ALL_WAYPOINTS_FROM(var, 0)
CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags, bool justremove);
Station *ComposeWaypointStation(TileIndex tile);
void ShowWaypointWindow(const Waypoint *wp);
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype);
void UpdateAllWaypointVirtCoords();

Loading…
Cancel
Save