Files
@ r28242:62b1dfcb422f
Branch filter:
Location: cpp/openttd-patchpack/source/src/newgrf_object.h - annotation
r28242:62b1dfcb422f
7.9 KiB
text/x-c
Change: [CMake] Use explicit list for regression (#11541)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15962:a51ebdf99ec8 r19728:faf243fdb82c r19728:faf243fdb82c r15940:064272152529 r27166:64e04a3ef9b1 r15940:064272152529 r15952:5f49686d97e6 r15951:b2083610fae0 r15950:217ba3ee892a r15940:064272152529 r15940:064272152529 r27737:728d55b97775 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r20830:fa96e375cac0 r20830:fa96e375cac0 r15940:064272152529 r15940:064272152529 r15940:064272152529 r27737:728d55b97775 r26437:31785ae094bd r15949:1632bafb6884 r15940:064272152529 r15951:b2083610fae0 r27737:728d55b97775 r15951:b2083610fae0 r20787:4277e29f8672 r15951:b2083610fae0 r15951:b2083610fae0 r15951:b2083610fae0 r15951:b2083610fae0 r15951:b2083610fae0 r20824:947e971df341 r20824:947e971df341 r20824:947e971df341 r20824:947e971df341 r15940:064272152529 r15950:217ba3ee892a r15950:217ba3ee892a r26769:9b8215567de1 r15951:b2083610fae0 r15943:830b62bff1b4 r15950:217ba3ee892a r27737:728d55b97775 r27737:728d55b97775 r27737:728d55b97775 r27737:728d55b97775 r27166:64e04a3ef9b1 r27166:64e04a3ef9b1 r15943:830b62bff1b4 r27737:728d55b97775 r27737:728d55b97775 r27737:728d55b97775 r27737:728d55b97775 r26769:9b8215567de1 r26769:9b8215567de1 r26769:9b8215567de1 r26769:9b8215567de1 r26769:9b8215567de1 r26769:9b8215567de1 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r17440:b3000afa4be8 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r15940:064272152529 r17440:b3000afa4be8 r15940:064272152529 r19257:75e0d2a624f7 r20831:4b3594a96970 r17138:5078c9240593 r15954:be63e4d3dfa6 r15954:be63e4d3dfa6 r27037:fd6e1ed8dd82 r27036:80cf2fa850d3 r15940:064272152529 r15940:064272152529 r27035:b10b476e56e4 r27035:b10b476e56e4 r15940:064272152529 r15940:064272152529 r19738:837a139219f0 r19728:faf243fdb82c r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r27737:728d55b97775 r19728:faf243fdb82c r22756:8ffd1846f871 r22756:8ffd1846f871 r22756:8ffd1846f871 r22756:8ffd1846f871 r22756:8ffd1846f871 r22756:8ffd1846f871 r22756:8ffd1846f871 r27737:728d55b97775 r24069:49625df81342 r22756:8ffd1846f871 r22756:8ffd1846f871 r19728:faf243fdb82c r27737:728d55b97775 r27942:f7389062d120 r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r19738:837a139219f0 r19738:837a139219f0 r19728:faf243fdb82c r27737:728d55b97775 r27737:728d55b97775 r19728:faf243fdb82c r19728:faf243fdb82c r23497:a0ab44ebd2fa r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r23607:36c15679007d r22850:1d6a79ca3a7c r19728:faf243fdb82c r19728:faf243fdb82c r22672:3473f7daf422 r22672:3473f7daf422 r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r24069:49625df81342 r27737:728d55b97775 r24069:49625df81342 r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r19728:faf243fdb82c r20833:1e58b6394fb5 r15951:b2083610fae0 r15951:b2083610fae0 r27462:267046492f9f r27462:267046492f9f r15957:71ffc94a16b5 r27737:728d55b97775 r15962:a51ebdf99ec8 r15962:a51ebdf99ec8 r27737:728d55b97775 r15964:69583adf1ac1 r17762:129a62225055 r17762:129a62225055 r15962:a51ebdf99ec8 r15940:064272152529 | /*
* 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_object.h Functions related to NewGRF objects. */
#ifndef NEWGRF_OBJECT_H
#define NEWGRF_OBJECT_H
#include "newgrf_callbacks.h"
#include "newgrf_spritegroup.h"
#include "newgrf_town.h"
#include "economy_func.h"
#include "timer/timer_game_calendar.h"
#include "object_type.h"
#include "newgrf_animation_type.h"
#include "newgrf_class.h"
#include "newgrf_commons.h"
/** Various object behaviours. */
enum ObjectFlags : uint16_t {
OBJECT_FLAG_NONE = 0, ///< Just nothing.
OBJECT_FLAG_ONLY_IN_SCENEDIT = 1 << 0, ///< Object can only be constructed in the scenario editor.
OBJECT_FLAG_CANNOT_REMOVE = 1 << 1, ///< Object can not be removed.
OBJECT_FLAG_AUTOREMOVE = 1 << 2, ///< Object get automatically removed (like "owned land").
OBJECT_FLAG_BUILT_ON_WATER = 1 << 3, ///< Object can be built on water (not required).
OBJECT_FLAG_CLEAR_INCOME = 1 << 4, ///< When object is cleared a positive income is generated instead of a cost.
OBJECT_FLAG_HAS_NO_FOUNDATION = 1 << 5, ///< Do not display foundations when on a slope.
OBJECT_FLAG_ANIMATION = 1 << 6, ///< Object has animated tiles.
OBJECT_FLAG_ONLY_IN_GAME = 1 << 7, ///< Object can only be built in game.
OBJECT_FLAG_2CC_COLOUR = 1 << 8, ///< Object wants 2CC colour mapping.
OBJECT_FLAG_NOT_ON_LAND = 1 << 9, ///< Object can not be on land, implicitly sets #OBJECT_FLAG_BUILT_ON_WATER.
OBJECT_FLAG_DRAW_WATER = 1 << 10, ///< Object wants to be drawn on water.
OBJECT_FLAG_ALLOW_UNDER_BRIDGE = 1 << 11, ///< Object can built under a bridge.
OBJECT_FLAG_ANIM_RANDOM_BITS = 1 << 12, ///< Object wants random bits in "next animation frame" callback.
OBJECT_FLAG_SCALE_BY_WATER = 1 << 13, ///< Object count is roughly scaled by water amount at edges.
};
DECLARE_ENUM_AS_BIT_SET(ObjectFlags)
static const uint8_t OBJECT_SIZE_1X1 = 0x11; ///< The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X, high nibble for Y.
void ResetObjects();
/** Class IDs for objects. */
enum ObjectClassID : uint8_t {
OBJECT_CLASS_BEGIN = 0, ///< The lowest valid value
OBJECT_CLASS_MAX = 0xFF, ///< Maximum number of classes.
INVALID_OBJECT_CLASS = 0xFF, ///< Class for the less fortunate.
};
/** Allow incrementing of ObjectClassID variables */
DECLARE_POSTFIX_INCREMENT(ObjectClassID)
/** An object that isn't use for transport, industries or houses.
* @note If you change this struct, adopt the initialization of
* default objects in table/object_land.h
*/
struct ObjectSpec {
/* 2 because of the "normal" and "buy" sprite stacks. */
GRFFilePropsBase<2> grf_prop; ///< Properties related the the grf file
AnimationInfo animation; ///< Information about the animation.
ObjectClassID cls_id; ///< The class to which this spec belongs.
StringID name; ///< The name for this object.
uint8_t climate; ///< In which climates is this object available?
uint8_t size; ///< The size of this objects; low nibble for X, high nibble for Y.
uint8_t build_cost_multiplier; ///< Build cost multiplier per tile.
uint8_t clear_cost_multiplier; ///< Clear cost multiplier per tile.
TimerGameCalendar::Date introduction_date; ///< From when can this object be built.
TimerGameCalendar::Date end_of_life_date; ///< When can't this object be built anymore.
ObjectFlags flags; ///< Flags/settings related to the object.
uint16_t callback_mask; ///< Bitmask of requested/allowed callbacks.
uint8_t height; ///< The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
uint8_t views; ///< The number of views.
uint8_t generate_amount; ///< Number of objects which are attempted to be generated per 256^2 map during world generation.
/**
* Test if this object is enabled.
* @return True iif this object is enabled.
*/
bool IsEnabled() const { return this->views > 0; }
/**
* Get the cost for building a structure of this type.
* @return The cost for building.
*/
Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); }
/**
* Get the cost for clearing a structure of this type.
* @return The cost for clearing.
*/
Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); }
bool IsEverAvailable() const;
bool WasEverAvailable() const;
bool IsAvailable() const;
uint Index() const;
static const std::vector<ObjectSpec> &Specs();
static size_t Count();
static const ObjectSpec *Get(ObjectType index);
static const ObjectSpec *GetByTile(TileIndex tile);
static void BindToClasses();
};
/** Object scope resolver. */
struct ObjectScopeResolver : public ScopeResolver {
struct Object *obj; ///< The object the callback is ran for.
const ObjectSpec *spec; ///< Specification of the object type.
TileIndex tile; ///< The tile related to the object.
uint8_t view; ///< The view of the object.
/**
* Constructor of an object scope resolver.
* @param ro Surrounding resolver.
* @param obj Object being resolved.
* @param tile %Tile of the object.
* @param view View of the object.
*/
ObjectScopeResolver(ResolverObject &ro, Object *obj, const ObjectSpec *spec, TileIndex tile, uint8_t view = 0)
: ScopeResolver(ro), obj(obj), spec(spec), tile(tile), view(view)
{
}
uint32_t GetRandomBits() const override;
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override;
};
/** A resolver object to be used with feature 0F spritegroups. */
struct ObjectResolverObject : public ResolverObject {
ObjectScopeResolver object_scope; ///< The object scope resolver.
TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call).
ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view = 0,
CallbackID callback = CBID_NO_CALLBACK, uint32_t param1 = 0, uint32_t param2 = 0);
~ObjectResolverObject();
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
{
switch (scope) {
case VSG_SCOPE_SELF:
return &this->object_scope;
case VSG_SCOPE_PARENT: {
TownScopeResolver *tsr = this->GetTown();
if (tsr != nullptr) return tsr;
FALLTHROUGH;
}
default:
return ResolverObject::GetScope(scope, relative);
}
}
GrfSpecFeature GetFeature() const override;
uint32_t GetDebugID() const override;
private:
TownScopeResolver *GetTown();
};
/** Struct containing information relating to object classes. */
typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass;
static const size_t OBJECT_SPRITE_GROUP_DEFAULT = 0;
static const size_t OBJECT_SPRITE_GROUP_PURCHASE = 1;
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view = 0);
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view);
void AnimateNewObjectTile(TileIndex tile);
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
#endif /* NEWGRF_OBJECT_H */
|