Mercurial > hg > openttd
changeset 15959:05c7c6cf6deb draft
(svn r20647) -Codechange: update some of the object spec information
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 28 Aug 2010 17:29:12 +0000 |
parents | c3b5855fd386 |
children | 110078252843 |
files | src/newgrf.cpp src/newgrf_animation_type.h src/newgrf_callbacks.h src/newgrf_object.cpp src/newgrf_object.h src/object_cmd.cpp src/object_type.h src/table/object_land.h |
diffstat | 8 files changed, 81 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -35,6 +35,7 @@ #include "newgrf_industries.h" #include "newgrf_airporttiles.h" #include "newgrf_airport.h" +#include "newgrf_object.h" #include "rev.h" #include "fios.h" #include "strings_func.h" @@ -6794,6 +6795,9 @@ ResetCustomIndustries(); ResetIndustries(); + /* Reset the objects. */ + ResetObjects(); + /* Reset station classes */ StationClass::Reset(); ResetCustomStations();
--- a/src/newgrf_animation_type.h +++ b/src/newgrf_animation_type.h @@ -53,4 +53,11 @@ AAT_STATION_250_TICKS, ///< Triggered every 250 ticks (for all tiles at the same time). }; +/** Animation triggers for objects. */ +enum ObjectAnimationTrigger { + OAT_BUILT, ///< Triggered when the object is built (for all tiles at the same time). + OAT_TILELOOP, ///< Triggered in the periodic tile loop. + OAT_250_TICKS, ///< Triggered every 250 ticks (for all tiles at the same time). +}; + #endif /* NEWGRF_ANIMATION_TYPE_H */
--- a/src/newgrf_callbacks.h +++ b/src/newgrf_callbacks.h @@ -251,6 +251,27 @@ /** Called to determine text to show as airport layout name. */ CBID_AIRPORT_LAYOUT_NAME = 0x156, // 15 bit callback + + /** Callback done for each tile of an object to check the slope. */ + CBID_OBJECT_LAND_SLOPE_CHECK = 0x157, // 15 bit callback, not implemented + + /** Determine the next animation frame for a house. */ + CBID_OBJECT_ANIMATION_NEXT_FRAME = 0x158, // 15 bit callback, not implemented + + /** Called for periodically starting or stopping the animation. */ + CBID_OBJECT_ANIMATION_START_STOP = 0x159, // 15 bit callback, not implemented + + /** Called to indicate how long the current animation frame should last. */ + CBID_OBJECT_ANIMATION_SPEED = 0x15A, // 8 bit callback, not implemented + + /** Called to determine the colour of a town building. */ + CBID_OBJECT_COLOUR = 0x15B, // 15 bit callback, not implemented + + /** Called to determine more text in the fund object window */ + CBID_OBJECT_FUND_MORE_TEXT = 0x15C, // 15 bit callback, not implemented + + /** Called to determine if one can alter the ground below an object tile */ + CBID_OBJECT_AUTOSLOPE = 0x15D, // 15 bit callback, not implemented }; /** @@ -347,6 +368,18 @@ }; /** + * Callback masks for objects + */ +enum ObjectCallbackMask { + CBM_OBJ_SLOPE_CHECK = 0, ///< decides slope suitability + CBM_OBJ_ANIMATION_NEXT_FRAME = 1, ///< decides next animation frame + CBM_OBJ_ANIMATION_SPEED = 2, ///< decides animation speed + CBM_OBJ_COLOUR = 3, ///< decide the color of the building + CBM_OBJ_FUND_MORE_TEXT = 4, ///< additional text in fund window + CBM_OBJ_AUTOSLOPE = 5, ///< decides allowance of autosloping +}; + +/** * Callback masks for airport tiles */ enum AirportTileCallbackMask {
--- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -10,15 +10,18 @@ /** @file newgrf_object.cpp Handling of object NewGRFs. */ #include "stdafx.h" +#include "core/mem_func.hpp" #include "newgrf_object.h" #include "object_map.h" -extern const ObjectSpec _original_objects[]; +extern const ObjectSpec _original_objects[NEW_OBJECT_OFFSET]; +/** All the object specifications. */ +static ObjectSpec _object_specs[NUM_OBJECTS]; /* static */ const ObjectSpec *ObjectSpec::Get(ObjectType index) { - assert(index < OBJECT_MAX); - return &_original_objects[index]; + assert(index < NUM_OBJECTS); + return &_object_specs[index]; } /* static */ const ObjectSpec *ObjectSpec::GetByTile(TileIndex tile) @@ -26,3 +29,13 @@ return ObjectSpec::Get(GetObjectType(tile)); } +/** This function initialize the spec arrays of objects. */ +void ResetObjects() +{ + /* Clean the pool. */ + MemSetT(_object_specs, 0, lengthof(_object_specs)); + + /* And add our originals. */ + MemCpyT(_object_specs, _original_objects, lengthof(_original_objects)); +} +
--- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -31,9 +31,11 @@ OBJECT_FLAG_NOT_ON_LAND = 1 << 9, ///< Object can not be on land, implicitly sets #OBJECT_FLAG_BUILT_ON_WATER. OBJECT_FLAG_DRAW_WATER = 1 << 10, ///< Object wants to be drawn on water. OBJECT_FLAG_ALLOW_UNDER_BRIDGE = 1 << 11, ///< Object can built under a bridge. + OBJECT_FLAG_ANIM_RANDOM_BITS = 1 << 12, ///< Object wants random bits in "next animation frame" callback }; DECLARE_ENUM_AS_BIT_SET(ObjectFlags) +void ResetObjects(); /** An object that isn't use for transport, industries or houses. */ struct ObjectSpec { @@ -42,6 +44,7 @@ uint8 build_cost_multiplier; ///< Build cost multiplier per tile. uint8 clear_cost_multiplier; ///< Clear cost multiplier per tile. ObjectFlags flags; ///< Flags/settings related to the object. + bool enabled; ///< Is this spec enabled? /** * Get the cost for building a structure of this type.
--- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -121,9 +121,9 @@ CommandCost cost(EXPENSES_PROPERTY); ObjectType type = (ObjectType)GB(p1, 0, 8); - if (type >= OBJECT_MAX) return CMD_ERROR; + const ObjectSpec *spec = ObjectSpec::Get(type); + if (!spec->enabled) return CMD_ERROR; - const ObjectSpec *spec = ObjectSpec::Get(type); if (spec->flags & OBJECT_FLAG_ONLY_IN_SCENEDIT && (_game_mode != GM_EDITOR || _current_company != OWNER_NONE)) return CMD_ERROR; if (spec->flags & OBJECT_FLAG_ONLY_IN_GAME && (_game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR; @@ -195,6 +195,10 @@ { ObjectType type = GetObjectType(ti->tile); const ObjectSpec *spec = ObjectSpec::Get(type); + + /* Fall back for when the object doesn't exist anymore. */ + if (!spec->enabled) type = OBJECT_TRANSMITTER; + if ((spec->flags & OBJECT_FLAG_HAS_NO_FOUNDATION) == 0) DrawFoundation(ti, GetFoundation_Object(ti->tile, ti->tileh)); const DrawTileSprites *dts = NULL;
--- a/src/object_type.h +++ b/src/object_type.h @@ -13,14 +13,17 @@ #define OBJECT_TYPE_H /** Types of objects. */ -enum ObjectType { - OBJECT_TRANSMITTER = 0, ///< The large antenna - OBJECT_LIGHTHOUSE = 1, ///< The nice lighthouse - OBJECT_STATUE = 2, ///< Statue in towns - OBJECT_OWNED_LAND = 3, ///< Owned land 'flag' - OBJECT_HQ = 4, ///< HeadQuarter of a player - OBJECT_MAX, -}; +typedef uint16 ObjectType; + +static const ObjectType OBJECT_TRANSMITTER = 0; ///< The large antenna +static const ObjectType OBJECT_LIGHTHOUSE = 1; ///< The nice lighthouse +static const ObjectType OBJECT_STATUE = 2; ///< Statue in towns +static const ObjectType OBJECT_OWNED_LAND = 3; ///< Owned land 'flag' +static const ObjectType OBJECT_HQ = 4; ///< HeadQuarter of a player + +static const ObjectType NEW_OBJECT_OFFSET = 5; ///< Offset for new objects +static const ObjectType NUM_OBJECTS = 256; ///< Number of supported objects +static const ObjectType INVALID_OBJECT_TYPE = 0xFFFF; ///< An invalid object /** Unique identifier for an object. */ typedef uint16 ObjectID;
--- 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) { name, size, build_cost_multiplier, clear_cost_multiplier, flags } +#define M(name, size, build_cost_multiplier, clear_cost_multiplier, flags) { name, size, build_cost_multiplier, clear_cost_multiplier, flags, true } /** Specification of the original object structures. */ extern const ObjectSpec _original_objects[] = {