Difference between revisions of "Modding:Thing"

From DoomRL Wiki

Jump to: navigation, search
m (just small stuff here)
 
(5 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
{|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
 
{|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
 
  ! colspan="3" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Thing'''
 
  ! colspan="3" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Thing'''
  {{APITable
+
  {{Table3Col
 
   |es=background: #333;
 
   |es=background: #333;
 
   |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px;
 
   |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px;
 
   |c2=vertical-align:top; padding:0px 2px;
 
   |c2=vertical-align:top; padding:0px 2px;
 
   |c3=padding:0px 2px;
 
   |c3=padding:0px 2px;
   |Byte|id|Determines the type of thing (e.g. former human, chaingun, etc) that this is. An item and a being may have the same id without being the same type of thing. This property is read-only.
+
   |Byte|id|Numeric identifier, preferred by engine. Unique across like object types. ''Readonly''.
   |String|sid|Ids and sids are in one-to-one correspondence. It is generally preferable to write out sids rather than ids to make code more readable. This property is read-only.
+
   |String|sid|String identifier, preferred by Lua. Unique across like object types. ''Readonly''.
   |DWord|uid|Every instantiated thing has a distinct uid. (In theory, the game could run out of uids and be forced to repeat, but there are enough possibilities that this is inplausible.) This property is read-only.
+
   |DWord|uid|Unique identifier across all instantiated objects. ''Readonly''.
   |Char|picture|The character used to represent the thing when it is on the map.
+
   |Char|picture|ASCII character used to represent object in game.
   |[[Modding:Constants#Colors|Color]]|color|The color used to draw the picture when the thing is on the map. This color is sometimes used in menus as well.
+
   |[[Modding:Constants#Colors|Color]]|color|Color used to paint object in game and in menus.
   |String|name|This string is used to describe the thing in various game messages.
+
   |String|name|Name of object.
   |String|nameplural|This is the plural of the name string, used in a few game messages.
+
   |String|nameplural|Name used when referring to multiple objects.
   |Word|sprite|This determines the sprite that is used to represent the thing in the graphical version.
+
   |Word|sprite|Sprite ID used to represent object in graphical mode.
   |LongInt|x|This is the things x-coordinate on the map. Typically, this is 0 if the thing isnt on the map. This property is read-only.
+
   |LongInt|x|X-coordinate of objcet on map. ''Readonly''.
   |LongInt|y|This is the things y-coordinate on the map. Typically, this is 0 if the thing isnt on the map. This property is read-only.
+
   |LongInt|y|Y-coordinate of objcet on map. ''Readonly''.
   |Integer|res_bullet|This is the bullet resistance associated with the thing.
+
   |Integer|res_bullet|Resistance of object to bullet damage.
   |Integer|res_melee|This is the melee resistance associated with the thing.
+
   |Integer|res_melee|Resistance of object to melee damage.
   |Integer|res_shrapnel|This is the shrapnel resistance associated with the thing.
+
   |Integer|res_shrapnel|Resistance of object to shrapnel damage.
   |Integer|res_acid|This is the acid resistance associated with the thing.
+
   |Integer|res_acid|Resistance of object to acid damage.
   |Integer|res_fire|This is the fire resistance associated with the thing.
+
   |Integer|res_fire|Resistance of object to fire damage.
   |Integer|res_plasma|This is the plasma resistance associated with the thing.
+
   |Integer|res_plasma|Resistance of object to plasma damage.
   |userdata|__ptr|This is a pointer to the pascal object representing the thing. When the pascal object is deallocated, this field is set to nil.
+
   |userdata|__ptr|Pointer to pascal object used by engine. Nil if deallocated.  ''Readonly''.
 
  }}
 
  }}
 
|}
 
|}
Line 33: Line 33:
 
== API ==
 
== API ==
  
{|style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
+
{|class="wikitable" style="border: 2px solid darkred; border-spacing: 0; font-size: 90%; margin: 0.25em 0.5em;"
|colspan=2 style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Thing'''
+
! colspan="2" style="background: darkred; color: yellow; font-size: 120%; text-align: center"|'''Thing Procedures'''
|-
+
{{Table2Col
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
  |es=background: #333;
|thing.[[#thing_displace|displace]]([[Modding:Thing|Thing]] self, [[Modding:Coord|Coord]] where)  
+
  |c1=font-weight:bold; text-align:right; vertical-align:top; padding:0px 2px;
|-style="background: #333;"
+
  |c2=padding:0px 2px;
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_displace|displace]]([[Modding:Thing|'''Thing''']] self, [[Modding:Coord|'''Coord''']] where)
|thing.[[#thing_destroy|destroy]]([[Modding:Thing|Thing]] self)  
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_destroy|destroy]]([[Modding:Thing|'''Thing''']] self)
|-
+
  |boolean|[[Modding:Thing|'''Thing''']].[[#thing_flags_get|flags_get]]([[Modding:Thing|'''Thing''']] self, [[Modding:Constants#Flags|'''Flag''']] flag)
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''boolean'''
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_flags_set|flags_set]]([[Modding:Thing|'''Thing''']] self, [[Modding:Constants#Flags|'''Flag''']] flag, '''boolean''' value)
|thing.[[#thing_flags_get|flags_get]]([[Modding:Thing|Thing]] self, [[Modding:Constants#Flags|Flag]] flag)  
+
  |value|[[Modding:Thing|'''Thing''']].[[#thing_property_get|property_get]]([[Modding:Thing|'''Thing''']] self, '''string''' property)
|-style="background: #333;"
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_property_set|property_set]]([[Modding:Thing|'''Thing''']] self, '''string''' property, '''value''' value)
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
  |integer|[[Modding:Thing|'''Thing''']].[[#thing_res_get|res_get]]([[Modding:Thing|'''Thing''']] self, [[Modding:Constants#Resistance|'''Resistance''']] resistance)
|thing.[[#thing_flags_set|flags_set]]([[Modding:Thing|Thing]] self, [[Modding:Constants#Flags|Flag]] flag, '''boolean''' value)  
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_res_set|res_set]]([[Modding:Thing|'''Thing''']] self, [[Modding:Constants#Resistance|'''Resistance''']] resistance, '''integer''' value)
|-
+
  |[[Modding:Coord|'''Coord''']]|[[Modding:Thing|'''Thing''']].[[#thing_get_position|get_position]]()
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''value'''
+
  |integer|[[Modding:Thing|'''Thing''']].[[#thing_distance_to|distance_to]]([[Modding:Coord|'''Coord''']] other)
|thing.[[#thing_property_get|property_get]]([[Modding:Thing|Thing]] self, '''string''' property)  
+
  |integer|[[Modding:Thing|'''Thing''']].[[#thing_distance_to|distance_to]]([[Modding:Thing|'''Thing''']] other)
|-style="background: #333;"
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_add_property|add_property]]('''string''' key, '''value''' value)
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_remove_property|remove_property]]('''string''' key)
|thing.[[#thing_property_set|property_set]]([[Modding:Thing|Thing]] self, '''string''' property, '''value''' value)  
+
  |boolean|[[Modding:Thing|'''Thing''']].[[#thing_has_property|has_property]]('''string''' key)
|-
+
  |value|[[Modding:Thing|'''Thing''']].[[#thing_get_property|get_property]]('''string''' key)
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''integer'''
+
  |void|[[Modding:Thing|'''Thing''']].[[#thing_set_property|set_property]]('''string''' key, '''value''' value)
|thing.[[#thing_res_get|res_get]]([[Modding:Thing|Thing]] self, [[Modding:Constants#Resistance|Resistance]] resistance)  
+
}}
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
|thing.[[#thing_res_set|res_set]]([[Modding:Thing|Thing]] self, [[Modding:Constants#Resistance|Resistance]] resistance, '''integer''' value)  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|[[Modding:Coord|Coord]]
+
|[[Modding:Thing|Thing]]:[[#thing_get_position|get_position]]()  
+
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''integer'''
+
|[[Modding:Thing|Thing]]:[[#thing_distance_to|distance_to]]([[Modding:Thing|Thing]] or [[Modding:Coord|Coord]] other)  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
|[[Modding:Thing|Thing]]:[[#thing_add_property|add_property]]('''string''' key, '''value''' value)  
+
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
|[[Modding:Thing|Thing]]:[[#thing_remove_property|remove_property]]('''string''' key)  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''boolean'''
+
|[[Modding:Thing|Thing]]:[[#thing_has_property|has_property]]('''string''' key)  
+
|-style="background: #333;"
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''value'''
+
|[[Modding:Thing|Thing]]:[[#thing_get_property|get_property]]('''string''' key)  
+
|-
+
|style="text-align: right; vertical-align:top; padding-right: 2ex;"|'''void'''
+
|[[Modding:Thing|Thing]]:[[#thing_set_property|set_property]]('''string''' key, '''value''' value)  
+
 
|}
 
|}
  
 
{{Anchor|thing_displace}}
 
{{Anchor|thing_displace}}
;thing.displace([[Modding:Thing|Thing]] self, [[Modding:Coord|Coord]] where)  
+
;thing.displace([[Modding:Thing|Thing]] self, [[Modding:Coord|Coord]] where)
 
:Changes the thing's position to ''where''. This doesn't do any collision checking, so be careful.
 
:Changes the thing's position to ''where''. This doesn't do any collision checking, so be careful.
 
----
 
----
 
{{Anchor|thing_destroy}}
 
{{Anchor|thing_destroy}}
;thing.destroy([[Modding:Thing|Thing]] self)  
+
;thing.destroy([[Modding:Thing|Thing]] self)
 
:Deallocates the memory associated with the thing. Generally, the item or being-specific versions should be used instead (although even these are rarely useful to modders).
 
:Deallocates the memory associated with the thing. Generally, the item or being-specific versions should be used instead (although even these are rarely useful to modders).
 
----
 
----
Line 96: Line 72:
 
----
 
----
 
{{Anchor|thing_flags_set}}
 
{{Anchor|thing_flags_set}}
;thing.flags_set([[Modding:Thing|Thing]] self, [[Modding:Constants#Flags|Flag]] flag, '''boolean''' value)  
+
;thing.flags_set([[Modding:Thing|Thing]] self, [[Modding:Constants#Flags|Flag]] flag, '''boolean''' value)
;[[Modding:Thing|Thing]].flags[[[Modding:Constants#Flags|Flag]] flag] = '''boolean''' value  
+
;[[Modding:Thing|Thing]].flags[[[Modding:Constants#Flags|Flag]] flag] = '''boolean''' value
 
:Sets or clears the given flag from the thing's flag set.
 
:Sets or clears the given flag from the thing's flag set.
 
----
 
----
Line 105: Line 81:
 
----
 
----
 
{{Anchor|thing_property_set}}
 
{{Anchor|thing_property_set}}
;thing.property_set([[Modding:Thing|Thing]] self, '''string''' property, '''value''' value)  
+
;thing.property_set([[Modding:Thing|Thing]] self, '''string''' property, '''value''' value)
 
:Sets the value of the given built-in property. This should usually be avoided in favor of [[#thing_get_property|get_property]].
 
:Sets the value of the given built-in property. This should usually be avoided in favor of [[#thing_get_property|get_property]].
 
----
 
----
Line 114: Line 90:
 
----
 
----
 
{{Anchor|thing_res_set}}
 
{{Anchor|thing_res_set}}
;thing.res_set([[Modding:Thing|Thing]] self, [[Modding:Constants#Resistance|Resistance]] resistance, '''integer''' value)  
+
;thing.res_set([[Modding:Thing|Thing]] self, [[Modding:Constants#Resistance|Resistance]] resistance, '''integer''' value)
;[[Modding:Thing|Thing]].resistance[[[Modding:Constants#Resistance|Resistance]] resistance] = '''integer''' value  
+
;[[Modding:Thing|Thing]].resistance[[[Modding:Constants#Resistance|Resistance]] resistance] = '''integer''' value
 
:Sets the given resistance of the thing.
 
:Sets the given resistance of the thing.
 
----
 
----
Line 127: Line 103:
 
----
 
----
 
{{Anchor|thing_add_property}}
 
{{Anchor|thing_add_property}}
;[[Modding:Thing|Thing]]:add_property('''string''' key, '''value''' value)  
+
;[[Modding:Thing|Thing]]:add_property('''string''' key, '''value''' value)
 
:Adds a custom property to the thing with the given initial value. ''value'' is optional; it defaults to false.
 
:Adds a custom property to the thing with the given initial value. ''value'' is optional; it defaults to false.
 
----
 
----
 
{{Anchor|thing_remove_property}}
 
{{Anchor|thing_remove_property}}
;[[Modding:Thing|Thing]]:remove_property('''string''' key)  
+
;[[Modding:Thing|Thing]]:remove_property('''string''' key)
 
:Removes the given custom property from the thing.
 
:Removes the given custom property from the thing.
 
----
 
----
Line 144: Line 120:
 
----
 
----
 
{{Anchor|thing_set_property}}
 
{{Anchor|thing_set_property}}
;[[Modding:Thing|Thing]]:set_property('''string''' key, '''value''' value)  
+
;[[Modding:Thing|Thing]]:set_property('''string''' key, '''value''' value)
;[[Modding:Thing|Thing]]['''string''' key] = '''value''' value  
+
;[[Modding:Thing|Thing]]['''string''' key] = '''value''' value
 
:Sets the given built-in or custom property of the thing to the given value. Usually the dot notation for table indexing is used.
 
:Sets the given built-in or custom property of the thing to the given value. Usually the dot notation for table indexing is used.

Latest revision as of 20:42, 19 October 2011

A thing in DoomRL is a base class that is inherited by beings and items (and the player). This means that beings and items are also things. The thing class is responsible for positioning, flags, resistances, and custom properties.

Properties

Thing
Byte id Numeric identifier, preferred by engine. Unique across like object types. Readonly.
String sid String identifier, preferred by Lua. Unique across like object types. Readonly.
DWord uid Unique identifier across all instantiated objects. Readonly.
Char picture ASCII character used to represent object in game.
Color color Color used to paint object in game and in menus.
String name Name of object.
String nameplural Name used when referring to multiple objects.
Word sprite Sprite ID used to represent object in graphical mode.
LongInt x X-coordinate of objcet on map. Readonly.
LongInt y Y-coordinate of objcet on map. Readonly.
Integer res_bullet Resistance of object to bullet damage.
Integer res_melee Resistance of object to melee damage.
Integer res_shrapnel Resistance of object to shrapnel damage.
Integer res_acid Resistance of object to acid damage.
Integer res_fire Resistance of object to fire damage.
Integer res_plasma Resistance of object to plasma damage.
userdata __ptr Pointer to pascal object used by engine. Nil if deallocated. Readonly.


API

Thing Procedures
void Thing.displace(Thing self, Coord where)
void Thing.destroy(Thing self)
boolean Thing.flags_get(Thing self, Flag flag)
void Thing.flags_set(Thing self, Flag flag, boolean value)
value Thing.property_get(Thing self, string property)
void Thing.property_set(Thing self, string property, value value)
integer Thing.res_get(Thing self, Resistance resistance)
void Thing.res_set(Thing self, Resistance resistance, integer value)
Coord Thing.get_position()
integer Thing.distance_to(Coord other)
integer Thing.distance_to(Thing other)
void Thing.add_property(string key, value value)
void Thing.remove_property(string key)
boolean Thing.has_property(string key)
value Thing.get_property(string key)
void Thing.set_property(string key, value value)

thing.displace(Thing self, Coord where)
Changes the thing's position to where. This doesn't do any collision checking, so be careful.

thing.destroy(Thing self)
Deallocates the memory associated with the thing. Generally, the item or being-specific versions should be used instead (although even these are rarely useful to modders).

thing.flags_get(Thing self, Flag flag) → boolean
Thing.flags[Flag flag] → boolean
Determines whether the given flag is present in the thing's flag set.

thing.flags_set(Thing self, Flag flag, boolean value)
Thing.flags[Flag flag] = boolean value
Sets or clears the given flag from the thing's flag set.

thing.property_get(Thing self, string property) → value
Gets value of the given built-in property. This should usually be avoided in favor of set_property.

thing.property_set(Thing self, string property, value value)
Sets the value of the given built-in property. This should usually be avoided in favor of get_property.

thing.res_get(Thing self, Resistance resistance) → integer
Thing.resistance[Resistance resistance] → integer
Gets the given resistance of the thing.

thing.res_set(Thing self, Resistance resistance, integer value)
Thing.resistance[Resistance resistance] = integer value
Sets the given resistance of the thing.

Thing:get_position() → Coord
Returns the thing's position. This is a newly allocated coord; it is independent of the thing.

Thing:distance_to(Thing or Coord other) → integer
Returns the distance from the thing to another position or thing.

Thing:add_property(string key, value value)
Adds a custom property to the thing with the given initial value. value is optional; it defaults to false.

Thing:remove_property(string key)
Removes the given custom property from the thing.

Thing:has_property(string key) → boolean
Determines whether the thing has a custom property with the given name.

Thing:get_property(string key) → value
Thing[string key] → value
Gets the value of the given built-in or custom property. Usually the dot notation for table indexing is used.

Thing:set_property(string key, value value)
Thing[string key] = value value
Sets the given built-in or custom property of the thing to the given value. Usually the dot notation for table indexing is used.
Personal tools