diff options
author | rubidium <rubidium@openttd.org> | 2010-12-10 21:32:52 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-10 21:32:52 +0000 |
commit | 5d0da9492e2c8f296f2689e3174e8d9832c7872d (patch) | |
tree | e271e6d6d625d0c5eea4ba0a9ef8ae4ca360923f /src | |
parent | cd6180a46d0f15f66f170fc89886980e7a49dab7 (diff) | |
download | openttd-5d0da9492e2c8f296f2689e3174e8d9832c7872d.tar.xz |
(svn r21454) -Codechange: add support for object variable 48
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_object.cpp | 36 | ||||
-rw-r--r-- | src/newgrf_object.h | 4 | ||||
-rw-r--r-- | src/newgrf_spritegroup.h | 1 | ||||
-rw-r--r-- | src/object_cmd.cpp | 2 | ||||
-rw-r--r-- | src/object_gui.cpp | 2 | ||||
-rw-r--r-- | src/table/newgrf_debug_data.h | 1 |
6 files changed, 36 insertions, 10 deletions
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 395234ee1..5b5e6e438 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -237,6 +237,9 @@ static uint32 ObjectGetVariable(const ResolverObject *object, byte variable, byt /* Object founder information */ case 0x44: return _current_company; + /* Object view */ + case 0x48: return object->u.object.view; + /* * Disallow the rest: * 0x40: Relative position is passed as parameter during construction. @@ -284,6 +287,9 @@ static uint32 ObjectGetVariable(const ResolverObject *object, byte variable, byt /* Object colour */ case 0x47: return o->colour; + /* Object view */ + case 0x48: return o->view; + /* Get object ID at offset param */ case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, tile), object->grffile->grfid); @@ -338,7 +344,7 @@ static const SpriteGroup *GetObjectSpriteGroup(const ObjectSpec *spec, const Obj /** * Returns a resolver object to be used with feature 0F spritegroups. */ -static void NewObjectResolver(ResolverObject *res, const ObjectSpec *spec, const Object *o, TileIndex tile) +static void NewObjectResolver(ResolverObject *res, const ObjectSpec *spec, const Object *o, TileIndex tile, uint8 view = 0) { res->GetRandomBits = ObjectGetRandomBits; res->GetTriggers = ObjectGetTriggers; @@ -348,6 +354,7 @@ static void NewObjectResolver(ResolverObject *res, const ObjectSpec *spec, const res->u.object.o = o; res->u.object.tile = tile; + res->u.object.view = view; res->callback = CBID_NO_CALLBACK; res->callback_param1 = 0; @@ -368,12 +375,13 @@ static void NewObjectResolver(ResolverObject *res, const ObjectSpec *spec, const * @param spec The specification of the object / the entry point. * @param o The object to call the callback for. * @param tile The tile the callback is called for. + * @param view The view of the object (only used when o == NULL). * @return The result of the callback. */ -uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile) +uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile, uint8 view) { ResolverObject object; - NewObjectResolver(&object, spec, o, tile); + NewObjectResolver(&object, spec, o, tile, view); object.callback = callback; object.callback_param1 = param1; object.callback_param2 = param2; @@ -433,11 +441,12 @@ void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec) * @param x Position x of image. * @param y Position y of image. * @param spec Object spec to draw. + * @param view The object's view. */ -void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec) +void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view) { ResolverObject object; - NewObjectResolver(&object, spec, NULL, INVALID_TILE); + NewObjectResolver(&object, spec, NULL, INVALID_TILE, view); const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, NULL), &object); if (group == NULL || group->type != SGT_TILELAYOUT) return; @@ -468,8 +477,23 @@ void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec) DrawNewGRFTileSeqInGUI(x, y, dts, 0, palette); } +/** + * Perform a callback for an object. + * @param callback The callback to perform. + * @param param1 The first parameter to pass to the NewGRF. + * @param param2 The second parameter to pass to the NewGRF. + * @param spec The specification of the object / the entry point. + * @param o The object to call the callback for. + * @param tile The tile the callback is called for. + * @return The result of the callback. + */ +uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile) +{ + return GetObjectCallback(callback, param1, param2, spec, o, tile); +} + /** Helper class for animation control. */ -struct ObjectAnimationBase : public AnimationBase<ObjectAnimationBase, ObjectSpec, Object, GetObjectCallback> { +struct ObjectAnimationBase : public AnimationBase<ObjectAnimationBase, ObjectSpec, Object, StubGetObjectCallback> { static const CallbackID cb_animation_speed = CBID_OBJECT_ANIMATION_SPEED; static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME; diff --git a/src/newgrf_object.h b/src/newgrf_object.h index 3b60e94e7..416b87a21 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -117,10 +117,10 @@ typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass; /** Mapping of purchase for objects. */ static const CargoID CT_PURCHASE_OBJECT = 1; -uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile); +uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, const Object *o, TileIndex tile, uint8 view = 0); void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec); -void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec); +void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view); void AnimateNewObjectTile(TileIndex tile); void TriggerObjectTileAnimation(const Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec); void TriggerObjectAnimation(const Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec); diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 80d4588a2..232382cba 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -357,6 +357,7 @@ struct ResolverObject { struct { const struct Object *o; ///< The object the callback is ran for. TileIndex tile; ///< The tile related to the object. + uint8 view; ///< The view of the object. } object; } u; diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 945a416d9..f5e3e0cf4 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -212,7 +212,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 uint16 callback = CALLBACK_FAILED; if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) { TileIndex diff = t - tile; - callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t, NULL), TileY(diff) << 4 | TileX(diff), spec, NULL, t); + callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t, NULL), TileY(diff) << 4 | TileX(diff), spec, NULL, t, view); } if (callback == CALLBACK_FAILED) { diff --git a/src/object_gui.cpp b/src/object_gui.cpp index a56fc051f..7a3c7cf07 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -170,7 +170,7 @@ public: const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id]; DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, this->object_height + OBJECT_MARGIN, dts, PAL_NONE); } else { - DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, this->object_height + OBJECT_MARGIN, spec); + DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, this->object_height + OBJECT_MARGIN, spec, 0); } _cur_dpi = old_dpi; } diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 701f4d553..240fd8ef0 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -334,6 +334,7 @@ static const NIVariable _niv_objects[] = { NIV(0x45, "get town zone and Manhattan distance of closest town"), NIV(0x46, "get square of Euclidean distance of closes town"), NIV(0x47, "colour"), + NIV(0x48, "view"), NIV(0x60, "get object ID at offset"), NIV(0x61, "get random tile bits at offset"), NIV(0x62, "land info of nearby tiles"), |