OpenTTD
newgrf_object.h
Go to the documentation of this file.
1 /* $Id: newgrf_object.h 27984 2018-03-11 13:19:41Z 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 
42 };
44 
45 void ResetObjects();
46 
52 };
55 
56 
60 struct ObjectSpec {
61  /* 2 because of the "normal" and "buy" sprite stacks. */
65 
66  uint8 climate;
67  uint8 size;
74  uint16 callback_mask;
75  uint8 height;
76  uint8 views;
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 
103  struct Object *obj;
105  uint8 view;
106 
114  ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0)
115  : ScopeResolver(ro), obj(obj), tile(tile), view(view)
116  {
117  }
118 
119  /* virtual */ uint32 GetRandomBits() const;
120  /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
121 };
122 
127 
128  ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0,
129  CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
131 
132  /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
133  {
134  switch (scope) {
135  case VSG_SCOPE_SELF:
136  return &this->object_scope;
137 
138  case VSG_SCOPE_PARENT: {
139  TownScopeResolver *tsr = this->GetTown();
140  if (tsr != NULL) return tsr;
141  }
142  FALLTHROUGH;
143 
144  default:
145  return ResolverObject::GetScope(scope, relative);
146  }
147  }
148 
149 private:
150  TownScopeResolver *GetTown();
151 };
152 
155 
157 static const CargoID CT_PURCHASE_OBJECT = 1;
158 
159 uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0);
160 
161 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
162 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view);
165 void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
166 
167 #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:50
ObjectFlags
Various object behaviours.
Definition: newgrf_object.h:26
Object wants 2CC colour mapping.
Definition: newgrf_object.h:36
ObjectFlags flags
Flags/settings related to the object.
Definition: newgrf_object.h:72
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
Money GetBuildCost() const
Get the cost for building a structure of this type.
Definition: newgrf_object.h:84
ResolverObject & ro
Surrounding resolver object.
uint8 build_cost_multiplier
Build cost multiplier per tile.
Definition: newgrf_object.h:68
VarSpriteGroupScope
Just nothing.
Definition: newgrf_object.h:27
Interface for SpriteGroup-s to access the gamestate.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:62
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
Class for the less fortunate.
Definition: newgrf_object.h:51
Definitions related to NewGRF animation.
Object can not be removed.
Definition: newgrf_object.h:29
Object wants to be drawn on water.
Definition: newgrf_object.h:38
Set when using the callback resolve system, but not to resolve a callback.
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
Date end_of_life_date
When can&#39;t this object be built anymore.
Definition: newgrf_object.h:71
Object get automatically removed (like "owned land").
Definition: newgrf_object.h:30
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:70
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:958
Object scope resolver.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
Definition: newgrf_object.h:67
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:75
ObjectScopeResolver object_scope
The object scope resolver.
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
uint8 view
The view of the object.
bool enabled
Is this spec enabled?
Definition: newgrf_object.h:78
Action 2 handling.
Types related to object tiles.
Object can only be built in game.
Definition: newgrf_object.h:35
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:90
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:28
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:73
Scope resolver for a town.
Definition: newgrf_town.h:24
uint16 callback_mask
Bitmask of requested/allowed callbacks.
Definition: newgrf_object.h:74
An object, such as transmitter, on the map.
Definition: object_base.h:25
uint8 views
The number of views.
Definition: newgrf_object.h:76
When object is cleared a positive income is generated instead of a cost.
Definition: newgrf_object.h:32
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Object can not be on land, implicitly sets OBJECT_FLAG_BUILT_ON_WATER.
Definition: newgrf_object.h:37
Resolved object itself.
uint16 ObjectType
Types of objects.
Definition: object_type.h:16
Object wants random bits in "next animation frame" callback.
Definition: newgrf_object.h:40
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
The lowest valid value.
Definition: newgrf_object.h:49
Object has animated tiles.
Definition: newgrf_object.h:34
StringID name
The name for this object.
Definition: newgrf_object.h:64
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:69
Object count is roughly scaled by water amount at edges.
Definition: newgrf_object.h:41
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Functions related to the economy.
Related object of the resolved one.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Used by the resolver to get values for feature 0F deterministic spritegroups.
uint8 generate_amount
Number of objects which are attempted to be generated per 256^2 map during world generation.
Definition: newgrf_object.h:77
ObjectAnimationTrigger
Animation triggers for objects.
uint32 GetRandomBits() const
Get a few random bits.
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:16
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:31
Object can built under a bridge.
Definition: newgrf_object.h:39
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:22
#define DECLARE_POSTFIX_INCREMENT(type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:16
ObjectClassID cls_id
The class to which this spec belongs.
Definition: newgrf_object.h:63
uint8 climate
In which climates is this object available?
Definition: newgrf_object.h:66
Do not display foundations when on a slope.
Definition: newgrf_object.h:33
void ResetObjects()
This function initialize the spec arrays of objects.
ObjectClassID
Class IDs for objects.
Definition: newgrf_object.h:48