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/>.
|
|
|
|
*/
|
|
|
|
|
2006-02-03 15:51:00 +00:00
|
|
|
/** @file newgrf_station.h Header file for NewGRF stations */
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2006-02-03 15:51:00 +00:00
|
|
|
#ifndef NEWGRF_STATION_H
|
|
|
|
#define NEWGRF_STATION_H
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2010-08-26 15:31:40 +00:00
|
|
|
#include "newgrf_animation_type.h"
|
2007-07-25 19:06:29 +00:00
|
|
|
#include "newgrf_callbacks.h"
|
2010-08-07 22:07:07 +00:00
|
|
|
#include "newgrf_class.h"
|
2010-08-07 20:52:45 +00:00
|
|
|
#include "newgrf_commons.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "cargo_type.h"
|
|
|
|
#include "station_type.h"
|
|
|
|
#include "rail_type.h"
|
2012-11-10 20:41:08 +00:00
|
|
|
#include "newgrf_spritegroup.h"
|
|
|
|
#include "newgrf_town.h"
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/** Scope resolver for stations. */
|
2012-11-10 20:41:08 +00:00
|
|
|
struct StationScopeResolver : public ScopeResolver {
|
2012-11-10 20:46:39 +00:00
|
|
|
TileIndex tile; ///< %Tile of the station.
|
|
|
|
struct BaseStation *st; ///< Instance of the station.
|
|
|
|
const struct StationSpec *statspec; ///< Station (type) specification.
|
|
|
|
CargoID cargo_type; ///< Type of cargo of the station.
|
|
|
|
Axis axis; ///< Station axis, used only for the slope check callback.
|
2012-11-10 20:41:08 +00:00
|
|
|
|
2018-03-11 13:19:41 +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.
|
|
|
|
*/
|
|
|
|
StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile)
|
|
|
|
: ScopeResolver(ro), tile(tile), st(st), statspec(statspec), cargo_type(CT_INVALID), axis(INVALID_AXIS)
|
|
|
|
{
|
|
|
|
}
|
2012-11-10 20:41:08 +00:00
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
uint32 GetRandomBits() const override;
|
|
|
|
uint32 GetTriggers() const override;
|
2012-11-10 20:41:08 +00:00
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
|
2012-11-10 20:41:08 +00:00
|
|
|
};
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/** Station resolver. */
|
2012-11-10 20:41:08 +00:00
|
|
|
struct StationResolverObject : public ResolverObject {
|
2012-11-10 20:46:39 +00:00
|
|
|
StationScopeResolver station_scope; ///< The station scope resolver.
|
|
|
|
TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call).
|
2012-11-10 20:41:08 +00:00
|
|
|
|
|
|
|
StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
|
|
|
|
CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
|
|
|
|
~StationResolverObject();
|
|
|
|
|
|
|
|
TownScopeResolver *GetTown();
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
|
2012-11-10 20:41:08 +00:00
|
|
|
{
|
|
|
|
switch (scope) {
|
|
|
|
case VSG_SCOPE_SELF:
|
|
|
|
return &this->station_scope;
|
|
|
|
|
|
|
|
case VSG_SCOPE_PARENT: {
|
|
|
|
TownScopeResolver *tsr = this->GetTown();
|
2019-04-10 21:07:06 +00:00
|
|
|
if (tsr != nullptr) return tsr;
|
2017-08-15 15:56:34 +00:00
|
|
|
FALLTHROUGH;
|
2012-11-10 20:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2012-11-10 20:45:59 +00:00
|
|
|
return ResolverObject::GetScope(scope, relative);
|
2012-11-10 20:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
|
2020-01-26 12:45:51 +00:00
|
|
|
|
|
|
|
GrfSpecFeature GetFeature() const override;
|
|
|
|
uint32 GetDebugID() const override;
|
2012-11-10 20:41:08 +00:00
|
|
|
};
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2019-04-22 07:19:04 +00:00
|
|
|
enum StationClassID : byte {
|
2007-01-10 18:56:51 +00:00
|
|
|
STAT_CLASS_BEGIN = 0, ///< the lowest valid value
|
|
|
|
STAT_CLASS_DFLT = 0, ///< Default station class.
|
|
|
|
STAT_CLASS_WAYP, ///< Waypoint class.
|
2019-04-22 07:19:04 +00:00
|
|
|
STAT_CLASS_MAX = 255, ///< Maximum number of classes.
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2010-04-17 13:31:41 +00:00
|
|
|
template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
|
2007-01-10 18:56:51 +00:00
|
|
|
|
|
|
|
/** Allow incrementing of StationClassID variables */
|
2010-03-23 22:25:43 +00:00
|
|
|
DECLARE_POSTFIX_INCREMENT(StationClassID)
|
2007-01-10 18:56:51 +00:00
|
|
|
|
2009-04-05 08:01:36 +00:00
|
|
|
enum StationSpecFlags {
|
|
|
|
SSF_SEPARATE_GROUND, ///< Use different sprite set for ground sprites.
|
|
|
|
SSF_DIV_BY_STATION_SIZE, ///< Divide cargo amount by station size.
|
|
|
|
SSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits.
|
|
|
|
SSF_CUSTOM_FOUNDATIONS, ///< Draw custom foundations.
|
|
|
|
SSF_EXTENDED_FOUNDATIONS, ///< Extended foundation block instead of simple.
|
|
|
|
};
|
|
|
|
|
2013-01-11 07:39:25 +00:00
|
|
|
/** Randomisation triggers for stations */
|
|
|
|
enum StationRandomTrigger {
|
|
|
|
SRT_NEW_CARGO, ///< Trigger station on new cargo arrival.
|
|
|
|
SRT_CARGO_TAKEN, ///< Trigger station when cargo is completely taken.
|
|
|
|
SRT_TRAIN_ARRIVES, ///< Trigger platform when train arrives.
|
|
|
|
SRT_TRAIN_DEPARTS, ///< Trigger platform when train leaves.
|
|
|
|
SRT_TRAIN_LOADS, ///< Trigger platform when train loads/unloads.
|
|
|
|
SRT_PATH_RESERVATION, ///< Trigger platform when train reserves path.
|
|
|
|
};
|
|
|
|
|
2005-11-12 00:19:34 +00:00
|
|
|
/* Station layout for given dimensions - it is a two-dimensional array
|
|
|
|
* where index is computed as (x * platforms) + platform. */
|
|
|
|
typedef byte *StationLayout;
|
|
|
|
|
2010-08-02 20:32:39 +00:00
|
|
|
/** Station specification. */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct StationSpec {
|
2010-08-10 15:51:33 +00:00
|
|
|
/**
|
|
|
|
* Properties related the the grf file.
|
|
|
|
* NUM_CARGO real cargo plus three pseudo cargo sprite groups.
|
|
|
|
* Used for obtaining the sprite offset of custom sprites, and for
|
|
|
|
* evaluating callbacks.
|
|
|
|
*/
|
|
|
|
GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
|
2010-08-07 21:39:30 +00:00
|
|
|
StationClassID cls_id; ///< The class to which this spec belongs.
|
|
|
|
StringID name; ///< Name of this station.
|
2005-11-12 00:19:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bitmask of number of platforms available for the station.
|
2013-01-08 22:46:42 +00:00
|
|
|
* 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms.
|
2005-11-12 00:19:34 +00:00
|
|
|
*/
|
2006-04-11 13:00:06 +00:00
|
|
|
byte disallowed_platforms;
|
2005-11-12 00:19:34 +00:00
|
|
|
/**
|
|
|
|
* Bitmask of platform lengths available for the station.
|
2013-01-08 22:46:42 +00:00
|
|
|
* 0..6 correspond to 1..7, while bit 7 corresponds to >7 tiles long.
|
2005-11-12 00:19:34 +00:00
|
|
|
*/
|
2006-04-11 13:00:06 +00:00
|
|
|
byte disallowed_lengths;
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Number of tile layouts.
|
2005-11-12 00:19:34 +00:00
|
|
|
* A minimum of 8 is required is required for stations.
|
|
|
|
* 0-1 = plain platform
|
|
|
|
* 2-3 = platform with building
|
|
|
|
* 4-5 = platform with roof, left side
|
|
|
|
* 6-7 = platform with roof, right side
|
|
|
|
*/
|
2006-04-16 18:57:07 +00:00
|
|
|
uint tiles;
|
2011-05-14 17:25:45 +00:00
|
|
|
NewGRFSpriteLayout *renderdata; ///< Array of tile layouts.
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Cargo threshold for choosing between little and lots of cargo
|
2006-04-11 13:00:06 +00:00
|
|
|
* @note little/lots are equivalent to the moving/loading states for vehicles
|
|
|
|
*/
|
|
|
|
uint16 cargo_threshold;
|
|
|
|
|
2018-05-21 21:08:39 +00:00
|
|
|
CargoTypes cargo_triggers; ///< Bitmask of cargo types which cause trigger re-randomizing
|
2006-04-11 13:00:06 +00:00
|
|
|
|
2009-09-14 12:22:57 +00:00
|
|
|
byte callback_mask; ///< Bitmask of station callbacks that have to be called
|
2006-04-11 13:00:06 +00:00
|
|
|
|
|
|
|
byte flags; ///< Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size
|
|
|
|
|
|
|
|
byte pylons; ///< Bitmask of base tiles (0 - 7) which should contain elrail pylons
|
|
|
|
byte wires; ///< Bitmask of base tiles (0 - 7) which should contain elrail wires
|
|
|
|
byte blocked; ///< Bitmask of base tiles (0 - 7) which are blocked to trains
|
|
|
|
|
2010-08-26 15:31:40 +00:00
|
|
|
AnimationInfo animation;
|
|
|
|
|
2005-11-12 00:19:34 +00:00
|
|
|
byte lengths;
|
|
|
|
byte *platforms;
|
|
|
|
StationLayout **layouts;
|
2006-11-08 12:17:14 +00:00
|
|
|
bool copied_layouts;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2010-08-07 22:07:07 +00:00
|
|
|
/** Struct containing information relating to station classes. */
|
|
|
|
typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
|
2005-11-12 00:19:34 +00:00
|
|
|
|
2008-07-25 22:37:34 +00:00
|
|
|
const StationSpec *GetStationSpec(TileIndex t);
|
2006-04-23 18:37:06 +00:00
|
|
|
|
2006-05-06 22:30:36 +00:00
|
|
|
/* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
|
|
|
|
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
|
|
|
|
|
2011-06-12 20:34:03 +00:00
|
|
|
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10 = 0);
|
2011-06-12 20:34:37 +00:00
|
|
|
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info);
|
2011-06-12 20:32:52 +00:00
|
|
|
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
|
2011-07-11 16:32:35 +00:00
|
|
|
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks);
|
2006-02-03 23:02:01 +00:00
|
|
|
|
2006-04-19 07:17:00 +00:00
|
|
|
/* Allocate a StationSpec to a Station. This is called once per build operation. */
|
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
|
|
|
|
|
|
|
/* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
|
2009-07-21 11:11:05 +00:00
|
|
|
void DeallocateSpecFromStation(BaseStation *st, byte specindex);
|
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. */
|
|
|
|
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
|
|
|
|
|
2008-04-19 23:19:12 +00:00
|
|
|
void AnimateStationTile(TileIndex tile);
|
2011-06-12 20:32:52 +00:00
|
|
|
void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
|
2013-01-11 07:39:25 +00:00
|
|
|
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
|
|
|
|
void StationUpdateCachedTriggers(BaseStation *st);
|
2008-04-19 23:19:12 +00:00
|
|
|
|
2006-02-03 15:51:00 +00:00
|
|
|
#endif /* NEWGRF_STATION_H */
|