newgrf_object.h

Go to the documentation of this file.
00001 /* $Id$ */
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 "economy_func.h"
00017 #include "tile_cmd.h"
00018 #include "object_type.h"
00019 #include "newgrf_animation_type.h"
00020 #include "newgrf_class.h"
00021 #include "newgrf_commons.h"
00022 
00024 enum ObjectFlags {
00025   OBJECT_FLAG_NONE               =       0, 
00026   OBJECT_FLAG_ONLY_IN_SCENEDIT   = 1 <<  0, 
00027   OBJECT_FLAG_CANNOT_REMOVE      = 1 <<  1, 
00028   OBJECT_FLAG_AUTOREMOVE         = 1 <<  2, 
00029   OBJECT_FLAG_BUILT_ON_WATER     = 1 <<  3, 
00030   OBJECT_FLAG_CLEAR_INCOME       = 1 <<  4, 
00031   OBJECT_FLAG_HAS_NO_FOUNDATION  = 1 <<  5, 
00032   OBJECT_FLAG_ANIMATION          = 1 <<  6, 
00033   OBJECT_FLAG_ONLY_IN_GAME       = 1 <<  7, 
00034   OBJECT_FLAG_2CC_COLOUR         = 1 <<  8, 
00035   OBJECT_FLAG_NOT_ON_LAND        = 1 <<  9, 
00036   OBJECT_FLAG_DRAW_WATER         = 1 << 10, 
00037   OBJECT_FLAG_ALLOW_UNDER_BRIDGE = 1 << 11, 
00038   OBJECT_FLAG_ANIM_RANDOM_BITS   = 1 << 12, 
00039 };
00040 DECLARE_ENUM_AS_BIT_SET(ObjectFlags)
00041 
00042 void ResetObjects();
00043 
00045 enum ObjectClassID {
00046   OBJECT_CLASS_BEGIN   =    0, 
00047   OBJECT_CLASS_MAX     =   32, 
00048   INVALID_OBJECT_CLASS = 0xFF, 
00049 };
00051 DECLARE_POSTFIX_INCREMENT(ObjectClassID)
00052 
00053 
00054 struct ObjectSpec {
00055   /* 2 because of the "normal" and "buy" sprite stacks. */
00056   GRFFilePropsBase<2> grf_prop; 
00057   ObjectClassID cls_id;         
00058   StringID name;                
00059 
00060   uint8 climate;                
00061   uint8 size;                   
00062   uint8 build_cost_multiplier;  
00063   uint8 clear_cost_multiplier;  
00064   Date introduction_date;       
00065   Date end_of_life_date;        
00066   ObjectFlags flags;            
00067   AnimationInfo animation;      
00068   uint16 callback_mask;         
00069   uint8 height;                 
00070   uint8 views;                  
00071   bool enabled;                 
00072 
00077   Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); }
00078 
00083   Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); }
00084 
00085   bool IsAvailable() const;
00086   uint Index() const;
00087 
00088   static const ObjectSpec *Get(ObjectType index);
00089   static const ObjectSpec *GetByTile(TileIndex tile);
00090 };
00091 
00093 typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass;
00094 
00096 static const CargoID CT_PURCHASE_OBJECT = 1;
00097 
00098 uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile, uint8 view = 0);
00099 
00100 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec);
00101 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view);
00102 void AnimateNewObjectTile(TileIndex tile);
00103 void TriggerObjectTileAnimation(const Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
00104 void TriggerObjectAnimation(const Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
00105 
00106 #endif /* NEWGRF_OBJECT_H */

Generated on Wed Apr 13 00:47:51 2011 for OpenTTD by  doxygen 1.6.1