summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-28 19:48:46 +0000
committerrubidium <rubidium@openttd.org>2010-08-28 19:48:46 +0000
commita8b992f4fd93429dad018ac77056bf5672c97528 (patch)
tree420d9c9a1d5410a55d4dcf4f14cac3e3802d33ce /src
parent60655522ca6f97d0de3476b3d79e5b9d77e3812f (diff)
downloadopenttd-a8b992f4fd93429dad018ac77056bf5672c97528.tar.xz
(svn r20673) -Codechange: add support for inspecting objects
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/newgrf_debug_gui.cpp3
-rw-r--r--src/newgrf_object.cpp10
-rw-r--r--src/table/newgrf_debug_data.h52
4 files changed, 65 insertions, 1 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 4e9c45588..06cb4eeb4 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2419,6 +2419,7 @@ STR_NEWGRF_INSPECT_PARENT_BUTTON :{BLACK}Parent
STR_NEWGRF_INSPECT_PARENT_TOOLTIP :{BLACK}Inspect the object of the parent scope
STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT :{STRING1} at {HEX}
+STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT :Object
STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE :Rail type
STR_NEWGRF_INSPECT_QUERY_CAPTION :{WHITE}NewGRF variable 60+x parameter (hexadecimal)
diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp
index aba4d93bf..ef2802bf9 100644
--- a/src/newgrf_debug_gui.cpp
+++ b/src/newgrf_debug_gui.cpp
@@ -21,12 +21,14 @@
#include "engine_base.h"
#include "industry.h"
+#include "object_base.h"
#include "station_base.h"
#include "town.h"
#include "vehicle_base.h"
#include "newgrf_airporttiles.h"
#include "newgrf_debug.h"
+#include "newgrf_object.h"
#include "newgrf_spritegroup.h"
#include "newgrf_station.h"
#include "newgrf_town.h"
@@ -515,6 +517,7 @@ GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
case MP_ROAD: return IsLevelCrossing(tile) ? GSF_RAILTYPES : GSF_INVALID;
case MP_HOUSE: return GSF_HOUSES;
case MP_INDUSTRY: return GSF_INDUSTRYTILES;
+ case MP_OBJECT: return GSF_OBJECTS;
case MP_STATION:
switch (GetStationType(tile)) {
diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp
index 2fe37db8e..3fca86dda 100644
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -529,3 +529,13 @@ void TriggerObjectAnimation(const Object *o, ObjectAnimationTrigger trigger, con
TriggerObjectTileAnimation(o, tile, trigger, spec);
}
}
+
+/**
+ * Resolve an object's spec and such so we can get a variable.
+ * @param ro The resolver object to fill.
+ * @param index The object tile to get the data from.
+ */
+void GetObjectResolver(ResolverObject *ro, uint index)
+{
+ NewObjectResolver(ro, ObjectSpec::GetByTile(index), Object::GetByTile(index), index);
+}
diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h
index 8e3177f5d..0af8ebf71 100644
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -311,6 +311,56 @@ static const NIFeature _nif_industry = {
};
+/*** NewGRF objects ***/
+
+#define NICO(cb_id, bit) NIC(cb_id, ObjectSpec, callback_mask, bit)
+static const NICallback _nic_objects[] = {
+ NICO(CBID_OBJECT_LAND_SLOPE_CHECK, CBM_OBJ_SLOPE_CHECK),
+ NICO(CBID_OBJECT_ANIMATION_NEXT_FRAME, CBM_OBJ_ANIMATION_NEXT_FRAME),
+ NICO(CBID_OBJECT_ANIMATION_START_STOP, CBM_NO_BIT),
+ NICO(CBID_OBJECT_ANIMATION_SPEED, CBM_OBJ_ANIMATION_SPEED),
+ NICO(CBID_OBJECT_COLOUR, CBM_OBJ_COLOUR),
+ NICO(CBID_OBJECT_FUND_MORE_TEXT, CBM_OBJ_FUND_MORE_TEXT),
+ NICO(CBID_OBJECT_AUTOSLOPE, CBM_OBJ_AUTOSLOPE),
+ NIC_END()
+};
+
+static const NIVariable _niv_objects[] = {
+ NIV(0x40, "relative position"),
+ NIV(0x41, "tile information"),
+ NIV(0x42, "construction date"),
+ NIV(0x43, "animation counter"),
+ NIV(0x44, "object founder"),
+ NIV(0x45, "get town zone and Manhattan distance of closest town"),
+ NIV(0x46, "get square of Euclidean distance of closes town"),
+ NIV(0x60, "get object ID at offset"),
+ NIV(0x61, "get random tile bits at offset"),
+ NIV(0x62, "land info of nearby tiles"),
+ NIV(0x63, "animation stage of nearby tiles"),
+ NIV(0x64, "distance on nearest object with given type"),
+ NIV(0x65, "count of object and distance of closest instance"),
+ NIV_END()
+};
+
+class NIHObject : public NIHelper {
+ bool IsInspectable(uint index) const { return ObjectSpec::GetByTile(index)->grf_prop.grffile != NULL; }
+ uint GetParent(uint index) const { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Object::GetByTile(index)->town->index); }
+ const void *GetInstance(uint index)const { return Object::GetByTile(index); }
+ const void *GetSpec(uint index) const { return ObjectSpec::GetByTile(index); }
+ void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, index); }
+ void Resolve(ResolverObject *ro, uint32 index) const { extern void GetObjectResolver(ResolverObject *ro, uint index); GetObjectResolver(ro, index); }
+};
+
+static const NIFeature _nif_object = {
+ NULL,
+ _nic_objects,
+ _niv_objects,
+ new NIHObject(),
+ 0,
+ 0
+};
+
+
/*** NewGRF rail types ***/
static const NIVariable _niv_railtypes[] = {
@@ -419,7 +469,7 @@ static const NIFeature * const _nifeatures[] = {
NULL, // GSF_SOUNDFX (has no "physical" objects)
NULL, // GSF_AIRPORTS (feature not implemented)
NULL, // GSF_SIGNALS (feature not implemented)
- NULL, // GSF_OBJECTS (feature not implemented)
+ &_nif_object, // GSF_OBJECTS
&_nif_railtype, // GSF_RAILTYPES
&_nif_airporttile, // GSF_AIRPORTTILES
&_nif_town, // GSF_FAKE_TOWNS