# HG changeset patch # User rubidium # Date 2010-08-28 17:32:30 # Node ID b2083610fae0c0aa11a37aa2a12c0c15b9b8b5b6 # Parent 217ba3ee892aa6fc16bbdc0c6b61691d8fb73ea5 (svn r20649) -Codechange: implement classes for objects diff --git a/src/lang/english.txt b/src/lang/english.txt --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2059,6 +2059,9 @@ STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_O STR_LANDSCAPING_LEVEL_LAND_TOOLTIP :{BLACK}Level land STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND :{BLACK}Purchase land for future use +STR_OBJECT_CLASS_LTHS :Lighthouses +STR_OBJECT_CLASS_TRNS :Transmitters + # Tree planting window (last two for SE only) STR_PLANT_TREE_CAPTION :{WHITE}Trees STR_PLANT_TREE_TOOLTIP :{BLACK}Select tree type to plant diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -6796,6 +6796,7 @@ static void ResetNewGRFData() ResetIndustries(); /* Reset the objects. */ + ObjectClass::Reset(); ResetObjects(); /* Reset station classes */ diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -11,8 +11,11 @@ #include "stdafx.h" #include "core/mem_func.hpp" +#include "newgrf.h" +#include "newgrf_class_func.h" #include "newgrf_object.h" #include "object_map.h" +#include "openttd.h" /** The override manager for our objects. */ ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE); @@ -42,3 +45,21 @@ void ResetObjects() MemCpyT(_object_specs, _original_objects, lengthof(_original_objects)); } +template +/* static */ void NewGRFClass::InsertDefaults() +{ + /* We only add the transmitters in the scenario editor. */ + if (_game_mode != GM_EDITOR) return; + + ObjectClassID cls = ObjectClass::Allocate('LTHS'); + ObjectClass::SetName(cls, STR_OBJECT_CLASS_LTHS); + _object_specs[OBJECT_LIGHTHOUSE].cls_id = cls; + ObjectClass::Assign(&_object_specs[OBJECT_LIGHTHOUSE]); + + cls = ObjectClass::Allocate('TRNS'); + ObjectClass::SetName(cls, STR_OBJECT_CLASS_TRNS); + _object_specs[OBJECT_TRANSMITTER].cls_id = cls; + ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]); +} + +INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectClass, ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX) diff --git a/src/newgrf_object.h b/src/newgrf_object.h --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -15,6 +15,7 @@ #include "economy_func.h" #include "strings_type.h" #include "object_type.h" +#include "newgrf_class.h" #include "newgrf_commons.h" /** Various object behaviours. */ @@ -38,10 +39,20 @@ DECLARE_ENUM_AS_BIT_SET(ObjectFlags) void ResetObjects(); +/** Class IDs for objects. */ +enum ObjectClassID { + OBJECT_CLASS_BEGIN = 0, ///< The lowest valid value + OBJECT_CLASS_MAX = 32, ///< Maximum number of classes. + INVALID_OBJECT_CLASS = 0xFF, ///< Class for the less fortunate. +}; +/** Allow incrementing of ObjectClassID variables */ +DECLARE_POSTFIX_INCREMENT(ObjectClassID) + /** An object that isn't use for transport, industries or houses. */ struct ObjectSpec { /* 2 because of the "normal" and "buy" sprite stacks. */ GRFFilePropsBase<2> grf_prop; ///< Properties related the the grf file + ObjectClassID cls_id; ///< The class to which this spec belongs. StringID name; ///< The name for this object. uint8 size; ///< The size of this objects; low nibble for X, high nibble for Y. @@ -77,4 +88,7 @@ struct ObjectSpec { static const ObjectSpec *GetByTile(TileIndex tile); }; +/** Struct containing information relating to station classes. */ +typedef NewGRFClass ObjectClass; + #endif /* NEWGRF_OBJECT_H */ diff --git a/src/table/object_land.h b/src/table/object_land.h --- a/src/table/object_land.h +++ b/src/table/object_land.h @@ -123,7 +123,7 @@ static const DrawTileSprites _object_hq[ #undef TILE_SPRITE_LINE -#define M(name, size, build_cost_multiplier, clear_cost_multiplier, flags) { GRFFilePropsBase<2>(), name, size, build_cost_multiplier, clear_cost_multiplier, flags, true } +#define M(name, size, build_cost_multiplier, clear_cost_multiplier, flags) { GRFFilePropsBase<2>(), INVALID_OBJECT_CLASS, name, size, build_cost_multiplier, clear_cost_multiplier, flags, true } /** Specification of the original object structures. */ extern const ObjectSpec _original_objects[] = {