changeset 15985:a0d57736b4be draft

(svn r20673) -Codechange: add support for inspecting objects
author rubidium <rubidium@openttd.org>
date Sat, 28 Aug 2010 19:48:46 +0000
parents 7197f6328c3d
children 1446cdc9ea36
files src/lang/english.txt src/newgrf_debug_gui.cpp src/newgrf_object.cpp src/table/newgrf_debug_data.h
diffstat 4 files changed, 65 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2419,6 +2419,7 @@
 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)
--- 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 @@
 		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)) {
--- a/src/newgrf_object.cpp
+++ b/src/newgrf_object.cpp
@@ -529,3 +529,13 @@
 		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);
+}
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -311,6 +311,56 @@
 };
 
 
+/*** 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 @@
 	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