2022-02-09 02:11:55 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file newgrf_roadstop.h NewGRF definitions and structures for road stops.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NEWGRF_ROADSTATION_H
|
|
|
|
#define NEWGRF_ROADSTATION_H
|
|
|
|
|
|
|
|
#include "newgrf_animation_type.h"
|
|
|
|
#include "newgrf_spritegroup.h"
|
|
|
|
#include "newgrf_class.h"
|
|
|
|
#include "newgrf_commons.h"
|
|
|
|
#include "newgrf_town.h"
|
|
|
|
#include "road.h"
|
|
|
|
|
|
|
|
/** The maximum amount of roadstops a single GRF is allowed to add */
|
|
|
|
static const int NUM_ROADSTOPS_PER_GRF = 255;
|
|
|
|
|
|
|
|
enum RoadStopClassID : byte {
|
|
|
|
ROADSTOP_CLASS_BEGIN = 0, ///< The lowest valid value
|
|
|
|
ROADSTOP_CLASS_DFLT = 0, ///< Default road stop class.
|
|
|
|
ROADSTOP_CLASS_WAYP, ///< Waypoint class.
|
|
|
|
ROADSTOP_CLASS_MAX = 255, ///< Maximum number of classes.
|
|
|
|
};
|
|
|
|
DECLARE_POSTFIX_INCREMENT(RoadStopClassID)
|
|
|
|
|
|
|
|
/* Some Triggers etc. */
|
|
|
|
enum RoadStopRandomTrigger {
|
|
|
|
RSRT_NEW_CARGO, ///< Trigger roadstop on arrival of new cargo.
|
|
|
|
RSRT_CARGO_TAKEN, ///< Trigger roadstop when cargo is completely taken.
|
2022-02-15 00:22:18 +00:00
|
|
|
RSRT_VEH_ARRIVES, ///< Trigger roadstop when road vehicle arrives.
|
|
|
|
RSRT_VEH_DEPARTS, ///< Trigger roadstop when road vehicle leaves.
|
2022-02-09 02:11:55 +00:00
|
|
|
RSRT_VEH_LOADS, ///< Trigger roadstop when road vehicle loads.
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Various different options for availability, restricting
|
|
|
|
* the roadstop to be only for busses or for trucks.
|
|
|
|
*/
|
|
|
|
enum RoadStopAvailabilityType : byte {
|
|
|
|
ROADSTOPTYPE_PASSENGER, ///< This RoadStop is for passenger (bus) stops.
|
|
|
|
ROADSTOPTYPE_FREIGHT, ///< This RoadStop is for freight (truck) stops.
|
|
|
|
ROADSTOPTYPE_ALL, ///< This RoadStop is for both types of station road stops.
|
|
|
|
|
|
|
|
ROADSTOPTYPE_END,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Different draw modes to disallow rendering of some parts of the stop
|
|
|
|
* or road.
|
|
|
|
*/
|
|
|
|
enum RoadStopDrawMode : byte {
|
2022-02-24 18:19:57 +00:00
|
|
|
ROADSTOP_DRAW_MODE_NONE = 0,
|
|
|
|
ROADSTOP_DRAW_MODE_ROAD = 1 << 0, ///< Bay stops: Draw the road itself
|
|
|
|
ROADSTOP_DRAW_MODE_OVERLAY = 1 << 1, ///< Drive-through stops: Draw the road overlay, e.g. pavement
|
|
|
|
ROADSTOP_DRAW_MODE_WAYP_GROUND = 1 << 2, ///< Waypoints: Draw the sprite layout ground tile (on top of the road)
|
2022-02-09 02:11:55 +00:00
|
|
|
};
|
|
|
|
DECLARE_ENUM_AS_BIT_SET(RoadStopDrawMode)
|
|
|
|
|
2022-02-15 00:22:18 +00:00
|
|
|
enum RoadStopSpecFlags {
|
|
|
|
RSF_CB141_RANDOM_BITS, ///< Callback 141 needs random bits.
|
2022-02-25 12:42:32 +00:00
|
|
|
RSF_NO_ONE_WAY_OVERLAY, ///< Do not show one-way road overlays.
|
2022-04-15 10:47:57 +00:00
|
|
|
RSF_NO_CATENARY, ///< Do not show catenary.
|
2022-04-15 16:46:42 +00:00
|
|
|
RSF_DRIVE_THROUGH_ONLY, ///< Stop is drive-through only.
|
2022-02-15 00:22:18 +00:00
|
|
|
};
|
|
|
|
|
2022-02-15 18:21:32 +00:00
|
|
|
enum RoadStopSpecIntlFlags {
|
|
|
|
RSIF_BRIDGE_HEIGHTS_SET, ///< byte bridge_height[6] is set.
|
|
|
|
RSIF_BRIDGE_DISALLOWED_PILLARS_SET, ///< byte bridge_disallowed_pillars[6] is set.
|
|
|
|
};
|
|
|
|
|
2022-02-09 02:11:55 +00:00
|
|
|
/** Scope resolver for road stops. */
|
|
|
|
struct RoadStopScopeResolver : public ScopeResolver {
|
|
|
|
TileIndex tile; ///< %Tile of the station.
|
|
|
|
struct BaseStation *st; ///< Instance of the station.
|
|
|
|
const struct RoadStopSpec *roadstopspec; ///< Station (type) specification.
|
|
|
|
CargoID cargo_type; ///< Type of cargo of the station.
|
|
|
|
StationType type; ///< Station type.
|
|
|
|
uint8 view; ///< Station axis.
|
2022-02-16 19:03:41 +00:00
|
|
|
RoadType roadtype; ///< Road type (used when no tile)
|
2022-02-09 02:11:55 +00:00
|
|
|
|
2022-02-16 19:03:41 +00:00
|
|
|
RoadStopScopeResolver(ResolverObject& ro, BaseStation* st, const RoadStopSpec *roadstopspec, TileIndex tile, RoadType roadtype, StationType type, uint8 view = 0)
|
|
|
|
: ScopeResolver(ro), tile(tile), st(st), roadstopspec(roadstopspec), type(type), view(view), roadtype(roadtype)
|
2022-02-09 02:11:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 GetRandomBits() const override;
|
|
|
|
uint32 GetTriggers() const override;
|
|
|
|
|
|
|
|
uint32 GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Road stop resolver. */
|
|
|
|
struct RoadStopResolverObject : public ResolverObject {
|
|
|
|
RoadStopScopeResolver roadstop_scope; ///< The stop scope resolver.
|
|
|
|
TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call).
|
|
|
|
|
2022-02-16 19:03:41 +00:00
|
|
|
RoadStopResolverObject(const RoadStopSpec* roadstopspec, BaseStation* st, TileIndex tile, RoadType roadtype, StationType type, uint8 view, CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
|
2022-02-09 02:11:55 +00:00
|
|
|
~RoadStopResolverObject();
|
|
|
|
|
|
|
|
ScopeResolver* GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override {
|
|
|
|
switch (scope) {
|
|
|
|
case VSG_SCOPE_SELF: return &this->roadstop_scope;
|
|
|
|
case VSG_SCOPE_PARENT: {
|
|
|
|
TownScopeResolver *tsr = this->GetTown();
|
|
|
|
if (tsr != nullptr) return tsr;
|
|
|
|
FALLTHROUGH;
|
|
|
|
}
|
|
|
|
default: return ResolverObject::GetScope(scope, relative);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TownScopeResolver *GetTown();
|
|
|
|
|
|
|
|
const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Road stop specification. */
|
|
|
|
struct RoadStopSpec {
|
2022-02-14 00:26:52 +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;
|
2022-02-09 02:11:55 +00:00
|
|
|
RoadStopClassID cls_id; ///< The class to which this spec belongs.
|
|
|
|
int spec_id; ///< The ID of this spec inside the class.
|
|
|
|
StringID name; ///< Name of this stop
|
|
|
|
|
|
|
|
RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL;
|
|
|
|
RoadStopDrawMode draw_mode = ROADSTOP_DRAW_MODE_ROAD | ROADSTOP_DRAW_MODE_OVERLAY;
|
2022-02-15 00:22:18 +00:00
|
|
|
uint8 callback_mask = 0;
|
|
|
|
uint8 flags = 0;
|
2022-02-15 18:21:32 +00:00
|
|
|
uint8 internal_flags = 0; ///< Bitmask of internal spec flags (RoadStopSpecIntlFlags)
|
2022-02-09 02:11:55 +00:00
|
|
|
|
|
|
|
CargoTypes cargo_triggers = 0; ///< Bitmask of cargo types which cause trigger re-randomizing
|
|
|
|
|
2022-02-15 00:22:18 +00:00
|
|
|
AnimationInfo animation;
|
|
|
|
|
2022-02-15 18:21:32 +00:00
|
|
|
byte bridge_height[6]; ///< Minimum height for a bridge above, 0 for none
|
|
|
|
byte bridge_disallowed_pillars[6]; ///< Disallowed pillar flags for a bridge above
|
|
|
|
|
2022-02-24 21:13:46 +00:00
|
|
|
uint8 build_cost_multiplier = 16; ///< Build cost multiplier per tile.
|
|
|
|
uint8 clear_cost_multiplier = 16; ///< Clear cost multiplier per tile.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cost for building a road stop of this type.
|
|
|
|
* @return The cost for building.
|
|
|
|
*/
|
|
|
|
Money GetBuildCost(Price category) const { return GetPrice(category, this->build_cost_multiplier, this->grf_prop.grffile, -4); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cost for clearing a road stop of this type.
|
|
|
|
* @return The cost for clearing.
|
|
|
|
*/
|
|
|
|
Money GetClearCost(Price category) const { return GetPrice(category, this->clear_cost_multiplier, this->grf_prop.grffile, -4); }
|
|
|
|
|
2022-02-09 02:11:55 +00:00
|
|
|
static const RoadStopSpec *Get(uint16 index);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct EnumPropsT<RoadStopClassID> : MakeEnumPropsT<RoadStopClassID, byte, ROADSTOP_CLASS_BEGIN, ROADSTOP_CLASS_MAX, ROADSTOP_CLASS_MAX, 8> {};
|
|
|
|
|
|
|
|
typedef NewGRFClass<RoadStopSpec, RoadStopClassID, ROADSTOP_CLASS_MAX> RoadStopClass;
|
|
|
|
|
|
|
|
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view);
|
|
|
|
|
2022-02-16 19:03:41 +00:00
|
|
|
uint16 GetRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8 view);
|
2022-02-15 00:22:18 +00:00
|
|
|
|
|
|
|
void AnimateRoadStopTile(TileIndex tile);
|
|
|
|
uint8 GetRoadStopTileAnimationSpeed(TileIndex tile);
|
|
|
|
void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
|
2022-02-09 02:11:55 +00:00
|
|
|
void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
|
|
|
|
|
|
|
|
bool GetIfNewStopsByType(RoadStopType rs);
|
|
|
|
bool GetIfClassHasNewStopsByType(RoadStopClass *roadstopclass, RoadStopType rs);
|
|
|
|
bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs);
|
|
|
|
|
|
|
|
uint GetCountOfCompatibleStopsByType(RoadStopClass *roadstopclass, RoadStopType rs);
|
|
|
|
|
|
|
|
const RoadStopSpec *GetRoadStopSpec(TileIndex t);
|
|
|
|
int AllocateRoadStopSpecToStation(const RoadStopSpec *statspec, BaseStation *st, bool exec);
|
|
|
|
void DeallocateRoadStopSpecFromStation(BaseStation *st, byte specindex);
|
|
|
|
void StationUpdateRoadStopCachedTriggers(BaseStation *st);
|
|
|
|
|
|
|
|
#endif /* NEWGRF_ROADSTATION_H */
|