Mercurial > hg > openttd
changeset 15961:a67ed3bc5610 draft
(svn r20649) -Codechange: implement classes for objects
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 28 Aug 2010 17:32:30 +0000 |
parents | 110078252843 |
children | 397063a81cfa |
files | src/lang/english.txt src/newgrf.cpp src/newgrf_object.cpp src/newgrf_object.h src/table/object_land.h |
diffstat | 5 files changed, 40 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2059,6 +2059,9 @@ 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
--- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -6796,6 +6796,7 @@ ResetIndustries(); /* Reset the objects. */ + ObjectClass::Reset(); ResetObjects(); /* Reset station classes */
--- 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 @@ MemCpyT(_object_specs, _original_objects, lengthof(_original_objects)); } +template <typename Tspec, typename Tid, Tid Tmax> +/* static */ void NewGRFClass<Tspec, Tid, Tmax>::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)
--- 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 @@ 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 @@ static const ObjectSpec *GetByTile(TileIndex tile); }; +/** Struct containing information relating to station classes. */ +typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass; + #endif /* NEWGRF_OBJECT_H */
--- a/src/table/object_land.h +++ b/src/table/object_land.h @@ -123,7 +123,7 @@ #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[] = {