2010-08-27 22:21:23 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2010-08-28 18:49:39 +00:00
|
|
|
#include "newgrf_callbacks.h"
|
2012-11-10 20:40:46 +00:00
|
|
|
#include "newgrf_spritegroup.h"
|
|
|
|
#include "newgrf_town.h"
|
2010-08-27 22:21:23 +00:00
|
|
|
#include "economy_func.h"
|
2012-01-03 20:26:05 +00:00
|
|
|
#include "date_type.h"
|
2010-08-27 22:21:23 +00:00
|
|
|
#include "object_type.h"
|
2010-08-28 17:35:00 +00:00
|
|
|
#include "newgrf_animation_type.h"
|
2010-08-28 17:32:30 +00:00
|
|
|
#include "newgrf_class.h"
|
2010-08-28 17:30:55 +00:00
|
|
|
#include "newgrf_commons.h"
|
2010-08-27 22:21:23 +00:00
|
|
|
|
|
|
|
/** Various object behaviours. */
|
|
|
|
enum ObjectFlags {
|
|
|
|
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.
|
2013-10-17 21:31:53 +00:00
|
|
|
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.
|
2010-08-27 22:21:23 +00:00
|
|
|
};
|
|
|
|
DECLARE_ENUM_AS_BIT_SET(ObjectFlags)
|
|
|
|
|
2010-08-28 17:29:12 +00:00
|
|
|
void ResetObjects();
|
2010-08-27 22:21:23 +00:00
|
|
|
|
2010-08-28 17:32:30 +00:00
|
|
|
/** Class IDs for objects. */
|
|
|
|
enum ObjectClassID {
|
|
|
|
OBJECT_CLASS_BEGIN = 0, ///< The lowest valid value
|
2013-10-12 16:30:05 +00:00
|
|
|
OBJECT_CLASS_MAX = 0xFF, ///< Maximum number of classes.
|
2010-08-28 17:32:30 +00:00
|
|
|
INVALID_OBJECT_CLASS = 0xFF, ///< Class for the less fortunate.
|
|
|
|
};
|
|
|
|
/** Allow incrementing of ObjectClassID variables */
|
|
|
|
DECLARE_POSTFIX_INCREMENT(ObjectClassID)
|
|
|
|
|
2013-10-16 19:11:34 +00:00
|
|
|
/** 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
|
|
|
|
*/
|
2010-08-27 22:21:23 +00:00
|
|
|
struct ObjectSpec {
|
2010-08-28 17:30:55 +00:00
|
|
|
/* 2 because of the "normal" and "buy" sprite stacks. */
|
|
|
|
GRFFilePropsBase<2> grf_prop; ///< Properties related the the grf file
|
2010-08-28 17:32:30 +00:00
|
|
|
ObjectClassID cls_id; ///< The class to which this spec belongs.
|
2010-08-27 22:43:27 +00:00
|
|
|
StringID name; ///< The name for this object.
|
2010-08-28 17:30:55 +00:00
|
|
|
|
2010-08-28 17:35:00 +00:00
|
|
|
uint8 climate; ///< In which climates is this object available?
|
2010-08-27 22:43:27 +00:00
|
|
|
uint8 size; ///< The size of this objects; low nibble for X, high nibble for Y.
|
|
|
|
uint8 build_cost_multiplier; ///< Build cost multiplier per tile.
|
|
|
|
uint8 clear_cost_multiplier; ///< Clear cost multiplier per tile.
|
2010-08-28 17:35:00 +00:00
|
|
|
Date introduction_date; ///< From when can this object be built.
|
|
|
|
Date end_of_life_date; ///< When can't this object be built anymore.
|
2010-08-27 22:43:27 +00:00
|
|
|
ObjectFlags flags; ///< Flags/settings related to the object.
|
2010-08-28 17:35:00 +00:00
|
|
|
AnimationInfo animation; ///< Information about the animation.
|
|
|
|
uint16 callback_mask; ///< Bitmask of requested/allowed callbacks.
|
|
|
|
uint8 height; ///< The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
|
2010-12-10 21:30:26 +00:00
|
|
|
uint8 views; ///< The number of views.
|
2013-10-17 21:27:08 +00:00
|
|
|
uint8 generate_amount; ///< Number of objects which are attempted to be generated per 256^2 map during world generation.
|
2010-08-28 17:29:12 +00:00
|
|
|
bool enabled; ///< Is this spec enabled?
|
2010-08-27 22:21:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cost for building a structure of this type.
|
|
|
|
* @return The cost for building.
|
|
|
|
*/
|
2011-03-05 18:28:10 +00:00
|
|
|
Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); }
|
2010-08-27 22:21:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the cost for clearing a structure of this type.
|
|
|
|
* @return The cost for clearing.
|
|
|
|
*/
|
2011-03-05 18:28:10 +00:00
|
|
|
Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); }
|
2010-08-27 22:21:23 +00:00
|
|
|
|
2012-04-22 16:27:45 +00:00
|
|
|
bool IsEverAvailable() const;
|
2013-10-17 21:37:25 +00:00
|
|
|
bool WasEverAvailable() const;
|
2011-01-22 09:53:15 +00:00
|
|
|
bool IsAvailable() const;
|
2010-08-28 17:38:07 +00:00
|
|
|
uint Index() const;
|
|
|
|
|
2010-08-27 22:21:23 +00:00
|
|
|
static const ObjectSpec *Get(ObjectType index);
|
|
|
|
static const ObjectSpec *GetByTile(TileIndex tile);
|
|
|
|
};
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/** Object scope resolver. */
|
2012-11-10 20:40:46 +00:00
|
|
|
struct ObjectScopeResolver : public ScopeResolver {
|
|
|
|
struct Object *obj; ///< The object the callback is ran for.
|
|
|
|
TileIndex tile; ///< The tile related to the object.
|
|
|
|
uint8 view; ///< The view of the object.
|
|
|
|
|
2013-11-24 14:41:19 +00:00
|
|
|
ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0);
|
2012-11-10 20:40:46 +00:00
|
|
|
|
|
|
|
/* virtual */ uint32 GetRandomBits() const;
|
|
|
|
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A resolver object to be used with feature 0F spritegroups. */
|
|
|
|
struct ObjectResolverObject : public ResolverObject {
|
2012-11-10 20:46:39 +00:00
|
|
|
ObjectScopeResolver object_scope; ///< The object scope resolver.
|
|
|
|
TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call).
|
2012-11-10 20:40:46 +00:00
|
|
|
|
|
|
|
ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0,
|
|
|
|
CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
|
|
|
|
~ObjectResolverObject();
|
|
|
|
|
|
|
|
/* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
|
|
|
|
{
|
|
|
|
switch (scope) {
|
|
|
|
case VSG_SCOPE_SELF:
|
|
|
|
return &this->object_scope;
|
|
|
|
|
|
|
|
case VSG_SCOPE_PARENT: {
|
|
|
|
TownScopeResolver *tsr = this->GetTown();
|
|
|
|
if (tsr != NULL) return tsr;
|
|
|
|
/* FALL-THROUGH */
|
|
|
|
}
|
|
|
|
|
2012-11-10 20:45:59 +00:00
|
|
|
default: return ResolverObject::GetScope(scope, relative);
|
2012-11-10 20:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TownScopeResolver *GetTown();
|
|
|
|
};
|
|
|
|
|
2013-10-17 21:41:59 +00:00
|
|
|
/** Struct containing information relating to object classes. */
|
2010-08-28 17:32:30 +00:00
|
|
|
typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass;
|
|
|
|
|
2010-08-28 18:22:24 +00:00
|
|
|
/** Mapping of purchase for objects. */
|
|
|
|
static const CargoID CT_PURCHASE_OBJECT = 1;
|
|
|
|
|
2011-06-12 20:36:33 +00:00
|
|
|
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0);
|
2010-08-28 18:49:39 +00:00
|
|
|
|
|
|
|
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
|
2010-12-10 21:32:52 +00:00
|
|
|
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view);
|
2010-08-28 18:51:47 +00:00
|
|
|
void AnimateNewObjectTile(TileIndex tile);
|
2011-06-12 20:32:52 +00:00
|
|
|
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
|
|
|
|
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
|
2010-08-28 18:49:39 +00:00
|
|
|
|
2010-08-27 22:21:23 +00:00
|
|
|
#endif /* NEWGRF_OBJECT_H */
|