diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_animation_type.h | 7 | ||||
-rw-r--r-- | src/newgrf_callbacks.h | 33 | ||||
-rw-r--r-- | src/newgrf_object.cpp | 19 | ||||
-rw-r--r-- | src/newgrf_object.h | 3 | ||||
-rw-r--r-- | src/object_cmd.cpp | 8 | ||||
-rw-r--r-- | src/object_type.h | 19 | ||||
-rw-r--r-- | src/table/object_land.h | 2 |
8 files changed, 81 insertions, 14 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index d6babd6cf..3e0a8ff91 100644 --- 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 @@ static void ResetNewGRFData() ResetCustomIndustries(); ResetIndustries(); + /* Reset the objects. */ + ResetObjects(); + /* Reset station classes */ StationClass::Reset(); ResetCustomStations(); diff --git a/src/newgrf_animation_type.h b/src/newgrf_animation_type.h index 355aa8121..feb2bdfd8 100644 --- a/src/newgrf_animation_type.h +++ b/src/newgrf_animation_type.h @@ -53,4 +53,11 @@ enum AirpAnimationTrigger { 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 */ diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h index 911ca71c9..3cdd6abb0 100644 --- a/src/newgrf_callbacks.h +++ b/src/newgrf_callbacks.h @@ -251,6 +251,27 @@ enum CallbackID { /** 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 @@ enum IndustryTileCallbackMask { }; /** + * 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 { diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 4728f876a..e55ee7148 100644 --- 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 @@ extern const ObjectSpec _original_objects[]; 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)); +} + diff --git a/src/newgrf_object.h b/src/newgrf_object.h index 37429ab33..41eb8ab82 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -31,9 +31,11 @@ enum ObjectFlags { 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 @@ struct ObjectSpec { 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. diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index a8e8e5e19..564c9f9a6 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -121,9 +121,9 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 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; + 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 @@ static void DrawTile_Object(TileInfo *ti) { 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; diff --git a/src/object_type.h b/src/object_type.h index d074878b2..db06669dd 100644 --- 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; diff --git a/src/table/object_land.h b/src/table/object_land.h index 4932d278e..c5c05fe52 100644 --- 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) { 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[] = { |