OpenTTD
newgrf_object.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef NEWGRF_OBJECT_H
11 #define NEWGRF_OBJECT_H
12 
13 #include "newgrf_callbacks.h"
14 #include "newgrf_spritegroup.h"
15 #include "newgrf_town.h"
16 #include "economy_func.h"
17 #include "date_type.h"
18 #include "object_type.h"
19 #include "newgrf_animation_type.h"
20 #include "newgrf_class.h"
21 #include "newgrf_commons.h"
22 
40 };
42 
43 void ResetObjects();
44 
50 };
53 
54 
58 struct ObjectSpec {
59  /* 2 because of the "normal" and "buy" sprite stacks. */
63 
64  uint8 climate;
65  uint8 size;
72  uint16 callback_mask;
73  uint8 height;
74  uint8 views;
76  bool enabled;
77 
82  Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); }
83 
88  Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); }
89 
90  bool IsEverAvailable() const;
91  bool WasEverAvailable() const;
92  bool IsAvailable() const;
93  uint Index() const;
94 
95  static const ObjectSpec *Get(ObjectType index);
96  static const ObjectSpec *GetByTile(TileIndex tile);
97 };
98 
101  struct Object *obj;
103  uint8 view;
104 
112  ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0)
113  : ScopeResolver(ro), obj(obj), tile(tile), view(view)
114  {
115  }
116 
117  uint32 GetRandomBits() const override;
118  uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
119 };
120 
125 
126  ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0,
127  CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
129 
130  ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
131  {
132  switch (scope) {
133  case VSG_SCOPE_SELF:
134  return &this->object_scope;
135 
136  case VSG_SCOPE_PARENT: {
137  TownScopeResolver *tsr = this->GetTown();
138  if (tsr != nullptr) return tsr;
139  FALLTHROUGH;
140  }
141 
142  default:
143  return ResolverObject::GetScope(scope, relative);
144  }
145  }
146 
147 private:
148  TownScopeResolver *GetTown();
149 };
150 
153 
155 static const CargoID CT_PURCHASE_OBJECT = 1;
156 
157 uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0);
158 
159 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
160 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view);
163 void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
164 
165 #endif /* NEWGRF_OBJECT_H */
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Maximum number of classes.
Definition: newgrf_object.h:48
ObjectFlags
Various object behaviours.
Definition: newgrf_object.h:24
Object wants 2CC colour mapping.
Definition: newgrf_object.h:34
ObjectFlags flags
Flags/settings related to the object.
Definition: newgrf_object.h:70
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
Money GetBuildCost() const
Get the cost for building a structure of this type.
Definition: newgrf_object.h:82
ResolverObject & ro
Surrounding resolver object.
uint8 build_cost_multiplier
Build cost multiplier per tile.
Definition: newgrf_object.h:66
VarSpriteGroupScope
Just nothing.
Definition: newgrf_object.h:25
Interface for SpriteGroup-s to access the gamestate.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:60
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
Class for the less fortunate.
Definition: newgrf_object.h:49
Definitions related to NewGRF animation.
Object can not be removed.
Definition: newgrf_object.h:27
Object wants to be drawn on water.
Definition: newgrf_object.h:36
Set when using the callback resolve system, but not to resolve a callback.
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:58
Date end_of_life_date
When can&#39;t this object be built anymore.
Definition: newgrf_object.h:69
Object get automatically removed (like "owned land").
Definition: newgrf_object.h:28
static const CargoID CT_PURCHASE_OBJECT
Mapping of purchase for objects.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
Date introduction_date
From when can this object be built.
Definition: newgrf_object.h:68
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Used by the resolver to get values for feature 0F deterministic spritegroups.
NewGRFClass< ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX > ObjectClass
Struct containing information relating to object classes.
Callbacks that NewGRFs could implement.
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
Definition: economy.cpp:942
Object scope resolver.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
Definition: newgrf_object.h:65
ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view=0)
Constructor of an object scope resolver.
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
Definition: newgrf_object.h:73
ObjectScopeResolver object_scope
The object scope resolver.
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:19
uint8 view
The view of the object.
bool enabled
Is this spec enabled?
Definition: newgrf_object.h:76
Action 2 handling.
Types related to object tiles.
Object can only be built in game.
Definition: newgrf_object.h:33
struct Object * obj
The object the callback is ran for.
Money GetClearCost() const
Get the cost for clearing a structure of this type.
Definition: newgrf_object.h:88
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
TileIndex tile
The tile related to the object.
Object can only be constructed in the scenario editor.
Definition: newgrf_object.h:26
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
AnimationInfo animation
Information about the animation.
Definition: newgrf_object.h:71
Scope resolver for a town.
Definition: newgrf_town.h:22
uint16 callback_mask
Bitmask of requested/allowed callbacks.
Definition: newgrf_object.h:72
An object, such as transmitter, on the map.
Definition: object_base.h:23
uint8 views
The number of views.
Definition: newgrf_object.h:74
When object is cleared a positive income is generated instead of a cost.
Definition: newgrf_object.h:30
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
Object can not be on land, implicitly sets OBJECT_FLAG_BUILT_ON_WATER.
Definition: newgrf_object.h:35
Resolved object itself.
uint16 ObjectType
Types of objects.
Definition: object_type.h:14
Object wants random bits in "next animation frame" callback.
Definition: newgrf_object.h:38
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
The lowest valid value.
Definition: newgrf_object.h:47
Object has animated tiles.
Definition: newgrf_object.h:32
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
StringID name
The name for this object.
Definition: newgrf_object.h:62
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view=0)
Perform a callback for an object.
Header file for classes to be used by e.g.
uint8 clear_cost_multiplier
Clear cost multiplier per tile.
Definition: newgrf_object.h:67
Object count is roughly scaled by water amount at edges.
Definition: newgrf_object.h:39
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Functions related to the economy.
Related object of the resolved one.
uint32 GetRandomBits() const override
Get a few random bits.
uint8 generate_amount
Number of objects which are attempted to be generated per 256^2 map during world generation.
Definition: newgrf_object.h:75
ObjectAnimationTrigger
Animation triggers for objects.
Types related to the dates in OpenTTD.
This file simplyfies and embeds a common mechanism of loading/saving and mapping of grf entities...
Information about animation.
int32 Date
The type to store our dates in.
Definition: date_type.h:14
A resolver object to be used with feature 0F spritegroups.
const struct GRFFile * grffile
grf file that introduced this entity
CallbackID
List of implemented NewGRF callbacks.
Object can be built on water (not required).
Definition: newgrf_object.h:29
Object can built under a bridge.
Definition: newgrf_object.h:37
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
Functions to handle the town part of NewGRF towns.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
ObjectClassID cls_id
The class to which this spec belongs.
Definition: newgrf_object.h:61
uint8 climate
In which climates is this object available?
Definition: newgrf_object.h:64
Do not display foundations when on a slope.
Definition: newgrf_object.h:31
void ResetObjects()
This function initialize the spec arrays of objects.
ObjectClassID
Class IDs for objects.
Definition: newgrf_object.h:46