mirror of https://github.com/OpenTTD/OpenTTD
(svn r21454) -Codechange: add support for object variable 48
parent
cd6180a46d
commit
5d0da9492e
|
@ -237,6 +237,9 @@ static uint32 ObjectGetVariable(const ResolverObject *object, byte variable, byt
|
||||||
/* Object founder information */
|
/* Object founder information */
|
||||||
case 0x44: return _current_company;
|
case 0x44: return _current_company;
|
||||||
|
|
||||||
|
/* Object view */
|
||||||
|
case 0x48: return object->u.object.view;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Disallow the rest:
|
* Disallow the rest:
|
||||||
* 0x40: Relative position is passed as parameter during construction.
|
* 0x40: Relative position is passed as parameter during construction.
|
||||||
|
@ -284,6 +287,9 @@ static uint32 ObjectGetVariable(const ResolverObject *object, byte variable, byt
|
||||||
/* Object colour */
|
/* Object colour */
|
||||||
case 0x47: return o->colour;
|
case 0x47: return o->colour;
|
||||||
|
|
||||||
|
/* Object view */
|
||||||
|
case 0x48: return o->view;
|
||||||
|
|
||||||
/* Get object ID at offset param */
|
/* Get object ID at offset param */
|
||||||
case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, tile), object->grffile->grfid);
|
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.
|
* 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->GetRandomBits = ObjectGetRandomBits;
|
||||||
res->GetTriggers = ObjectGetTriggers;
|
res->GetTriggers = ObjectGetTriggers;
|
||||||
|
@ -348,6 +354,7 @@ static void NewObjectResolver(ResolverObject *res, const ObjectSpec *spec, const
|
||||||
|
|
||||||
res->u.object.o = o;
|
res->u.object.o = o;
|
||||||
res->u.object.tile = tile;
|
res->u.object.tile = tile;
|
||||||
|
res->u.object.view = view;
|
||||||
|
|
||||||
res->callback = CBID_NO_CALLBACK;
|
res->callback = CBID_NO_CALLBACK;
|
||||||
res->callback_param1 = 0;
|
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 spec The specification of the object / the entry point.
|
||||||
* @param o The object to call the callback for.
|
* @param o The object to call the callback for.
|
||||||
* @param tile The tile the callback is called 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.
|
* @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;
|
ResolverObject object;
|
||||||
NewObjectResolver(&object, spec, o, tile);
|
NewObjectResolver(&object, spec, o, tile, view);
|
||||||
object.callback = callback;
|
object.callback = callback;
|
||||||
object.callback_param1 = param1;
|
object.callback_param1 = param1;
|
||||||
object.callback_param2 = param2;
|
object.callback_param2 = param2;
|
||||||
|
@ -433,11 +441,12 @@ void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
|
||||||
* @param x Position x of image.
|
* @param x Position x of image.
|
||||||
* @param y Position y of image.
|
* @param y Position y of image.
|
||||||
* @param spec Object spec to draw.
|
* @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;
|
ResolverObject object;
|
||||||
NewObjectResolver(&object, spec, NULL, INVALID_TILE);
|
NewObjectResolver(&object, spec, NULL, INVALID_TILE, view);
|
||||||
|
|
||||||
const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, NULL), &object);
|
const SpriteGroup *group = SpriteGroup::Resolve(GetObjectSpriteGroup(spec, NULL), &object);
|
||||||
if (group == NULL || group->type != SGT_TILELAYOUT) return;
|
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);
|
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. */
|
/** 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_speed = CBID_OBJECT_ANIMATION_SPEED;
|
||||||
static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME;
|
static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME;
|
||||||
|
|
||||||
|
|
|
@ -117,10 +117,10 @@ typedef NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX> ObjectClass;
|
||||||
/** Mapping of purchase for objects. */
|
/** Mapping of purchase for objects. */
|
||||||
static const CargoID CT_PURCHASE_OBJECT = 1;
|
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 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 AnimateNewObjectTile(TileIndex tile);
|
||||||
void TriggerObjectTileAnimation(const Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
|
void TriggerObjectTileAnimation(const Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
|
||||||
void TriggerObjectAnimation(const Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
|
void TriggerObjectAnimation(const Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec);
|
||||||
|
|
|
@ -357,6 +357,7 @@ struct ResolverObject {
|
||||||
struct {
|
struct {
|
||||||
const struct Object *o; ///< The object the callback is ran for.
|
const struct Object *o; ///< The object the callback is ran for.
|
||||||
TileIndex tile; ///< The tile related to the object.
|
TileIndex tile; ///< The tile related to the object.
|
||||||
|
uint8 view; ///< The view of the object.
|
||||||
} object;
|
} object;
|
||||||
} u;
|
} u;
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
uint16 callback = CALLBACK_FAILED;
|
uint16 callback = CALLBACK_FAILED;
|
||||||
if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) {
|
if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) {
|
||||||
TileIndex diff = t - tile;
|
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) {
|
if (callback == CALLBACK_FAILED) {
|
||||||
|
|
|
@ -170,7 +170,7 @@ public:
|
||||||
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
|
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
|
||||||
DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, this->object_height + OBJECT_MARGIN, dts, PAL_NONE);
|
DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, this->object_height + OBJECT_MARGIN, dts, PAL_NONE);
|
||||||
} else {
|
} 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;
|
_cur_dpi = old_dpi;
|
||||||
}
|
}
|
||||||
|
|
|
@ -334,6 +334,7 @@ static const NIVariable _niv_objects[] = {
|
||||||
NIV(0x45, "get town zone and Manhattan distance of closest town"),
|
NIV(0x45, "get town zone and Manhattan distance of closest town"),
|
||||||
NIV(0x46, "get square of Euclidean distance of closes town"),
|
NIV(0x46, "get square of Euclidean distance of closes town"),
|
||||||
NIV(0x47, "colour"),
|
NIV(0x47, "colour"),
|
||||||
|
NIV(0x48, "view"),
|
||||||
NIV(0x60, "get object ID at offset"),
|
NIV(0x60, "get object ID at offset"),
|
||||||
NIV(0x61, "get random tile bits at offset"),
|
NIV(0x61, "get random tile bits at offset"),
|
||||||
NIV(0x62, "land info of nearby tiles"),
|
NIV(0x62, "land info of nearby tiles"),
|
||||||
|
|
Loading…
Reference in New Issue