(svn r20649) -Codechange: implement classes for objects

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
rubidium 14 years ago
parent 1ec1f1ef37
commit f9a9b0ed4a

@ -2059,6 +2059,9 @@ STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND :{BLACK}Raise a
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

@ -6796,6 +6796,7 @@ static void ResetNewGRFData()
ResetIndustries();
/* Reset the objects. */
ObjectClass::Reset();
ResetObjects();
/* Reset station classes */

@ -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 <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)

@ -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<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass;
#endif /* NEWGRF_OBJECT_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[] = {

Loading…
Cancel
Save