|
|
|
/*
|
|
|
|
* 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 = 64000U;
|
|
|
|
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.
|
|
|
|
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 {
|
|
|
|
ROADSTOP_DRAW_MODE_NONE = 0,
|
|
|
|
ROADSTOP_DRAW_MODE_ROAD = 1 << 0, ///< 0b01, Draw the road itself
|
|
|
|
ROADSTOP_DRAW_MODE_OVERLAY = 1 << 1, ///< 0b10, Draw the road overlay for roadstops, e.g. pavement
|
|
|
|
};
|
|
|
|
DECLARE_ENUM_AS_BIT_SET(RoadStopDrawMode)
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
const RoadTypeInfo *rti; ///< Road type info
|
|
|
|
|
|
|
|
RoadStopScopeResolver(ResolverObject& ro, BaseStation* st, const RoadStopSpec *roadstopspec, TileIndex tile, const RoadTypeInfo *rti, StationType type, uint8 view = 0)
|
|
|
|
: ScopeResolver(ro), tile(tile), st(st), roadstopspec(roadstopspec), type(type), view(view), rti(rti)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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).
|
|
|
|
|
|
|
|
RoadStopResolverObject(const RoadStopSpec* roadstopspec, BaseStation* st, TileIndex tile, const RoadTypeInfo *rti, StationType type, uint8 view, CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
|
|
|
|
~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 {
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
CargoTypes cargo_triggers = 0; ///< Bitmask of cargo types which cause trigger re-randomizing
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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 */
|