OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

newgrf_object.h
Go to the documentation of this file.
1 /* $Id: newgrf_object.h 27893 2017-08-13 18:38:42Z frosch $ */
2
3 /*
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/>.
8 */
9
12 #ifndef NEWGRF_OBJECT_H
13 #define NEWGRF_OBJECT_H
14
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"
24
26 enum ObjectFlags {
27 OBJECT_FLAG_NONE = 0,
28 OBJECT_FLAG_ONLY_IN_SCENEDIT = 1 << 0,
29 OBJECT_FLAG_CANNOT_REMOVE = 1 << 1,
30 OBJECT_FLAG_AUTOREMOVE = 1 << 2,
31 OBJECT_FLAG_BUILT_ON_WATER = 1 << 3,
32 OBJECT_FLAG_CLEAR_INCOME = 1 << 4,
33 OBJECT_FLAG_HAS_NO_FOUNDATION = 1 << 5,
34 OBJECT_FLAG_ANIMATION = 1 << 6,
35 OBJECT_FLAG_ONLY_IN_GAME = 1 << 7,
36 OBJECT_FLAG_2CC_COLOUR = 1 << 8,
37 OBJECT_FLAG_NOT_ON_LAND = 1 << 9,
38 OBJECT_FLAG_DRAW_WATER = 1 << 10,
39 OBJECT_FLAG_ALLOW_UNDER_BRIDGE = 1 << 11,
40 OBJECT_FLAG_ANIM_RANDOM_BITS = 1 << 12,
41 OBJECT_FLAG_SCALE_BY_WATER = 1 << 13,
42 };
43 DECLARE_ENUM_AS_BIT_SET(ObjectFlags)
44
45 void ResetObjects();
46
48 enum ObjectClassID {
49 OBJECT_CLASS_BEGIN = 0,
50 OBJECT_CLASS_MAX = 0xFF,
51 INVALID_OBJECT_CLASS = 0xFF,
52 };
54 DECLARE_POSTFIX_INCREMENT(ObjectClassID)
55
56
60 struct ObjectSpec {
61 /* 2 because of the "normal" and "buy" sprite stacks. */
62 GRFFilePropsBase<2> grf_prop;
63 ObjectClassID cls_id;
64 StringID name;
65
66 uint8 climate;
67 uint8 size;
68 uint8 build_cost_multiplier;
69 uint8 clear_cost_multiplier;
70 Date introduction_date;
71 Date end_of_life_date;
72 ObjectFlags flags;
73 AnimationInfo animation;
74 uint16 callback_mask;
75 uint8 height;
76 uint8 views;
77 uint8 generate_amount;
78 bool enabled;
79
84 Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); }
85
90 Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); }
91
92 bool IsEverAvailable() const;
93 bool WasEverAvailable() const;
94 bool IsAvailable() const;
95 uint Index() const;
96
97 static const ObjectSpec *Get(ObjectType index);
98 static const ObjectSpec *GetByTile(TileIndex tile);
99 };
100
102 struct ObjectScopeResolver : public ScopeResolver {
103 struct Object *obj;
104 TileIndex tile;
105 uint8 view;
106
107 ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0);
108
109 /* virtual */ uint32 GetRandomBits() const;
110 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
111 };
112
114 struct ObjectResolverObject : public ResolverObject {
115 ObjectScopeResolver object_scope;
116 TownScopeResolver *town_scope;
117
118 ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0,
119 CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
120 ~ObjectResolverObject();
121
122 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
123 {
124 switch (scope) {
125 case VSG_SCOPE_SELF:
126 return &this->object_scope;
127
128 case VSG_SCOPE_PARENT: {
129 TownScopeResolver *tsr = this->GetTown();
130 if (tsr != NULL) return tsr;
131 }
132 FALLTHROUGH;
133
134 default:
135 return ResolverObject::GetScope(scope, relative);
136 }
137 }
138
139 private:
140 TownScopeResolver *GetTown();
141 };
142
144 typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass;
145
147 static const CargoID CT_PURCHASE_OBJECT = 1;
148
149 uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0);
150
151 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
152 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view);
153 void AnimateNewObjectTile(TileIndex tile);
154 void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
155 void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
156
157 #endif /* NEWGRF_OBJECT_H */