4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file newgrf_object.h Functions related to NewGRF objects. */
12 #ifndef NEWGRF_OBJECT_H
13 #define NEWGRF_OBJECT_H
15 #include "newgrf_callbacks.h"
16 #include "newgrf_spritegroup.h"
17 #include "newgrf_town.h"
18 #include "economy_func.h"
19 #include "date_type.h"
20 #include "object_type.h"
21 #include "newgrf_animation_type.h"
22 #include "newgrf_class.h"
23 #include "newgrf_commons.h"
26 /** Various object behaviours. */
28 OBJECT_FLAG_NONE
= 0, ///< Just nothing.
29 OBJECT_FLAG_ONLY_IN_SCENEDIT
= 1 << 0, ///< Object can only be constructed in the scenario editor.
30 OBJECT_FLAG_CANNOT_REMOVE
= 1 << 1, ///< Object can not be removed.
31 OBJECT_FLAG_AUTOREMOVE
= 1 << 2, ///< Object get automatically removed (like "owned land").
32 OBJECT_FLAG_BUILT_ON_WATER
= 1 << 3, ///< Object can be built on water (not required).
33 OBJECT_FLAG_CLEAR_INCOME
= 1 << 4, ///< When object is cleared a positive income is generated instead of a cost.
34 OBJECT_FLAG_HAS_NO_FOUNDATION
= 1 << 5, ///< Do not display foundations when on a slope.
35 OBJECT_FLAG_ANIMATION
= 1 << 6, ///< Object has animated tiles.
36 OBJECT_FLAG_ONLY_IN_GAME
= 1 << 7, ///< Object can only be built in game.
37 OBJECT_FLAG_2CC_COLOUR
= 1 << 8, ///< Object wants 2CC colour mapping.
38 OBJECT_FLAG_NOT_ON_LAND
= 1 << 9, ///< Object can not be on land, implicitly sets #OBJECT_FLAG_BUILT_ON_WATER.
39 OBJECT_FLAG_DRAW_WATER
= 1 << 10, ///< Object wants to be drawn on water.
40 OBJECT_FLAG_ALLOW_UNDER_BRIDGE
= 1 << 11, ///< Object can built under a bridge.
41 OBJECT_FLAG_ANIM_RANDOM_BITS
= 1 << 12, ///< Object wants random bits in "next animation frame" callback.
42 OBJECT_FLAG_SCALE_BY_WATER
= 1 << 13, ///< Object count is roughly scaled by water amount at edges.
44 DECLARE_ENUM_AS_BIT_SET(ObjectFlags
)
48 /** Class IDs for objects. */
50 OBJECT_CLASS_BEGIN
= 0, ///< The lowest valid value
51 OBJECT_CLASS_MAX
= 0xFF, ///< Maximum number of classes.
52 INVALID_OBJECT_CLASS
= 0xFF, ///< Class for the less fortunate.
54 /** Allow incrementing of ObjectClassID variables */
55 DECLARE_POSTFIX_INCREMENT(ObjectClassID
)
57 /** An object that isn't use for transport, industries or houses.
58 * @note If you change this struct, adopt the initialization of
59 * default objects in table/object_land.h
62 /* 2 because of the "normal" and "buy" sprite stacks. */
63 GRFFilePropsBase
<2> grf_prop
; ///< Properties related the the grf file
64 ObjectClassID cls_id
; ///< The class to which this spec belongs.
65 StringID name
; ///< The name for this object.
67 uint8 climate
; ///< In which climates is this object available?
68 uint8 size
; ///< The size of this objects; low nibble for X, high nibble for Y.
69 uint8 build_cost_multiplier
; ///< Build cost multiplier per tile.
70 uint8 clear_cost_multiplier
; ///< Clear cost multiplier per tile.
71 Date introduction_date
; ///< From when can this object be built.
72 Date end_of_life_date
; ///< When can't this object be built anymore.
73 ObjectFlags flags
; ///< Flags/settings related to the object.
74 AnimationInfo animation
; ///< Information about the animation.
75 uint16 callback_mask
; ///< Bitmask of requested/allowed callbacks.
76 uint8 height
; ///< The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
77 uint8 views
; ///< The number of views.
78 uint8 generate_amount
; ///< Number of objects which are attempted to be generated per 256^2 map during world generation.
79 bool enabled
; ///< Is this spec enabled?
82 * Get the cost for building a structure of this type.
83 * @return The cost for building.
85 Money
GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT
, this->build_cost_multiplier
, this->grf_prop
.grffile
, 0); }
88 * Get the cost for clearing a structure of this type.
89 * @return The cost for clearing.
91 Money
GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT
, this->clear_cost_multiplier
, this->grf_prop
.grffile
, 0); }
93 bool IsEverAvailable() const;
94 bool WasEverAvailable() const;
95 bool IsAvailable() const;
98 static const ObjectSpec
*Get(ObjectType index
);
99 static const ObjectSpec
*GetByTile(TileIndex tile
);
102 /** Object scope resolver. */
103 struct ObjectScopeResolver
: public ScopeResolver
{
104 const GRFFile
*const grffile
; ///< GRFFile the resolved SpriteGroup belongs to.
105 struct Object
*obj
; ///< The object the callback is ran for.
106 TileIndex tile
; ///< The tile related to the object.
107 uint8 view
; ///< The view of the object.
109 ObjectScopeResolver (const GRFFile
*grffile
, Object
*obj
, TileIndex tile
, uint8 view
= 0);
111 /* virtual */ uint32
GetRandomBits() const;
112 /* virtual */ uint32
GetVariable(byte variable
, uint32 parameter
, bool *available
) const;
115 /** A resolver object to be used with feature 0F spritegroups. */
116 struct ObjectResolverObject
: public ResolverObject
{
117 ObjectScopeResolver object_scope
; ///< The object scope resolver.
118 TownScopeResolver
*town_scope
; ///< The town scope resolver (created on the first call).
120 ObjectResolverObject(const ObjectSpec
*spec
, Object
*o
, TileIndex tile
, uint8 view
= 0,
121 CallbackID callback
= CBID_NO_CALLBACK
, uint32 param1
= 0, uint32 param2
= 0);
122 ~ObjectResolverObject();
124 /* virtual */ ScopeResolver
*GetScope(VarSpriteGroupScope scope
= VSG_SCOPE_SELF
, byte relative
= 0)
128 return &this->object_scope
;
130 case VSG_SCOPE_PARENT
: {
131 TownScopeResolver
*tsr
= this->GetTown();
132 if (tsr
!= NULL
) return tsr
;
136 default: return ResolverObject::GetScope(scope
, relative
);
141 TownScopeResolver
*GetTown();
144 /** Struct containing information relating to object classes. */
145 typedef NewGRFClass
<ObjectSpec
, ObjectClassID
, OBJECT_CLASS_MAX
> ObjectClass
;
147 /** Mapping of purchase for objects. */
148 static const CargoID CT_PURCHASE_OBJECT
= 1;
150 uint16
GetObjectCallback(CallbackID callback
, uint32 param1
, uint32 param2
, const ObjectSpec
*spec
, Object
*o
, TileIndex tile
, uint8 view
= 0);
152 void DrawNewObjectTile(TileInfo
*ti
, const ObjectSpec
*spec
);
153 void DrawNewObjectTileInGUI (BlitArea
*dpi
, int x
, int y
, const ObjectSpec
*spec
, uint8 view
);
154 void AnimateNewObjectTile(TileIndex tile
);
155 void TriggerObjectTileAnimation(Object
*o
, TileIndex tile
, ObjectAnimationTrigger trigger
, const ObjectSpec
*spec
);
156 void TriggerObjectAnimation(Object
*o
, ObjectAnimationTrigger trigger
, const ObjectSpec
*spec
);
158 #endif /* NEWGRF_OBJECT_H */