# newgrf_object.h

Go to the documentation of this file.

    00001 /* $Id: newgrf_object.h 26085 2013-11-24 14:41:19Z frosch $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef NEWGRF_OBJECT_H
    00013 #define NEWGRF_OBJECT_H
    00014
    00015 #include "newgrf_callbacks.h"
    00016 #include "newgrf_spritegroup.h"
    00017 #include "newgrf_town.h"
    00018 #include "economy_func.h"
    00019 #include "date_type.h"
    00020 #include "object_type.h"
    00021 #include "newgrf_animation_type.h"
    00022 #include "newgrf_class.h"
    00023 #include "newgrf_commons.h"
    00024
    00026 enum ObjectFlags {
    00027   OBJECT_FLAG_NONE               =       0,
    00028   OBJECT_FLAG_ONLY_IN_SCENEDIT   = 1 <<  0,
    00029   OBJECT_FLAG_CANNOT_REMOVE      = 1 <<  1,
    00030   OBJECT_FLAG_AUTOREMOVE         = 1 <<  2,
    00031   OBJECT_FLAG_BUILT_ON_WATER     = 1 <<  3,
    00032   OBJECT_FLAG_CLEAR_INCOME       = 1 <<  4,
    00033   OBJECT_FLAG_HAS_NO_FOUNDATION  = 1 <<  5,
    00034   OBJECT_FLAG_ANIMATION          = 1 <<  6,
    00035   OBJECT_FLAG_ONLY_IN_GAME       = 1 <<  7,
    00036   OBJECT_FLAG_2CC_COLOUR         = 1 <<  8,
    00037   OBJECT_FLAG_NOT_ON_LAND        = 1 <<  9,
    00038   OBJECT_FLAG_DRAW_WATER         = 1 << 10,
    00039   OBJECT_FLAG_ALLOW_UNDER_BRIDGE = 1 << 11,
    00040   OBJECT_FLAG_ANIM_RANDOM_BITS   = 1 << 12,
    00041   OBJECT_FLAG_SCALE_BY_WATER     = 1 << 13,
    00042 };
    00043 DECLARE_ENUM_AS_BIT_SET(ObjectFlags)
    00044
    00045 void ResetObjects();
    00046
    00048 enum ObjectClassID {
    00049   OBJECT_CLASS_BEGIN   =    0,
    00050   OBJECT_CLASS_MAX     = 0xFF,
    00051   INVALID_OBJECT_CLASS = 0xFF,
    00052 };
    00054 DECLARE_POSTFIX_INCREMENT(ObjectClassID)
    00055
    00056
    00060 struct ObjectSpec {
    00061   /* 2 because of the "normal" and "buy" sprite stacks. */
    00062   GRFFilePropsBase<2> grf_prop;
    00063   ObjectClassID cls_id;
    00064   StringID name;
    00065
    00066   uint8 climate;
    00067   uint8 size;
    00068   uint8 build_cost_multiplier;
    00069   uint8 clear_cost_multiplier;
    00070   Date introduction_date;
    00071   Date end_of_life_date;
    00072   ObjectFlags flags;
    00073   AnimationInfo animation;
    00074   uint16 callback_mask;
    00075   uint8 height;
    00076   uint8 views;
    00077   uint8 generate_amount;
    00078   bool enabled;
    00079
    00084   Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); }
    00085
    00090   Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); }
    00091
    00092   bool IsEverAvailable() const;
    00093   bool WasEverAvailable() const;
    00094   bool IsAvailable() const;
    00095   uint Index() const;
    00096
    00097   static const ObjectSpec *Get(ObjectType index);
    00098   static const ObjectSpec *GetByTile(TileIndex tile);
    00099 };
    00100
    00102 struct ObjectScopeResolver : public ScopeResolver {
    00103   struct Object *obj;
    00104   TileIndex tile;
    00105   uint8 view;
    00106
    00107   ObjectScopeResolver(ResolverObject &ro, Object *obj, TileIndex tile, uint8 view = 0);
    00108
    00109   /* virtual */ uint32 GetRandomBits() const;
    00110   /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
    00111 };
    00112
    00114 struct ObjectResolverObject : public ResolverObject {
    00115   ObjectScopeResolver object_scope;
    00116   TownScopeResolver *town_scope;
    00117
    00118   ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0,
    00119       CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
    00120   ~ObjectResolverObject();
    00121
    00122   /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
    00123   {
    00124     switch (scope) {
    00125       case VSG_SCOPE_SELF:
    00126         return &this->object_scope;
    00127
    00128       case VSG_SCOPE_PARENT: {
    00129         TownScopeResolver *tsr = this->GetTown();
    00130         if (tsr != NULL) return tsr;
    00131         /* FALL-THROUGH */
    00132       }
    00133
    00134       default: return ResolverObject::GetScope(scope, relative);
    00135     }
    00136   }
    00137
    00138 private:
    00139   TownScopeResolver *GetTown();
    00140 };
    00141
    00143 typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass;
    00144
    00146 static const CargoID CT_PURCHASE_OBJECT = 1;
    00147
    00148 uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view = 0);
    00149
    00150 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
    00151 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view);
    00152 void AnimateNewObjectTile(TileIndex tile);
    00153 void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
    00154 void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
    00155
    00156 #endif /* NEWGRF_OBJECT_H */