Module engine.Entity
Functions
_M:addTemporaryValue (prop, v, noupdate) | Computes a "temporary" value into a property Example: You cant to give an actor a boost to life_regen, but you do not want it to be permanent You cannot simply increase life_regen, so you use this method which will increase it AND store the increase. |
_M:added () | Call when the entity is actually added to a level/whatever This helps ensuring uniqueness of uniques |
_M:attr (prop, v, fix) | Increases/decreases an attribute The attributes are just actor properties, but this ensures they are numbers and not booleans thus making them compatible with temporary values system |
_M:changeUid (newuid) | Change the entity's uid *WARNING*: ONLY DO THIS IF YOU KNOW WHAT YOU ARE DOING!. |
_M:check (prop, ...) | Check for an entity's property If not a function it returns it directly, otherwise it calls the function with the extra parameters |
_M:cloned (src) | If we are cloned we need a new uid |
_M:getDisplayString (tstr) | Get a string that will display in text the texture of this entity |
_M:getEntityFinalSurface (tiles, w, h) | Get the entity image as an sdl surface and texture for the given tiles and size |
_M:getMapObjects (tiles, mos, z) | Get all "map objects" representing this entity Do not touch unless you *KNOW* what you are doing. You do *NOT* need this, this is used by the engine.Map class automatically. *DO NOT TOUCH!!!* |
_M:init (t, no_default) | Initialize an entity Any subclass MUST call this constructor |
_M:invalidateAllMO () | Invalidates the whole MO repository |
_M:loadList (file, no_default, res, mod, loaded) | Loads a list of entities from a definition file |
_M:loaded () | If we are loaded we need a new uid |
_M:makeMapObject (tiles, idx) | Create the "map object" representing this entity Do not touch unless you *KNOW* what you are doing. You do *NOT* need this, this is used by the engine.Map class automatically. *DO NOT TOUCH!!!* |
_M:onTemporaryValueChange (prop, v, base) | Called when a temporary value changes (added or deleted) This does nothing by default, you can overload it to react to changes |
_M:removeTemporaryValue (prop, id, noupdate) | Removes a temporary value, see addTemporaryValue() |
_M:removed () | Call when the entity is actually removed from existence This helps ensuring uniqueness of uniques. |
_M:resetMoveAnim () | Reset movement animation for the entity - removes any anim |
_M:resolve (t, last, on_entity) | Resolves an entity This is called when generating the final clones of an entity for use in a level. |
_M:setMoveAnim (oldx, oldy, speed, blur) | Setup movement animation for the entity The entity is supposed to posses a correctly set x and y pair of fields - set to the current (new) position |
_M:setupMinimapInfo (mo, map) | Setup minimap color for this entity You may overload this method to customize your minimap |
_M:toScreen (tiles, x, y, w, h) | Displays an entity somewhere on screen, outside the map |
Functions
- _M:addTemporaryValue (prop, v, noupdate)
-
Computes a "temporary" value into a property Example: You cant to give an actor a boost to life_regen, but you do not want it to be permanent
You cannot simply increase life_regen, so you use this method which will increase it AND store the increase. it will return an "increase id" that can be passed to removeTemporaryValue() to remove the effect.Parameters
- prop: the property to affect. This can be either a string or a table of strings, the latter allowing nested properties to be modified.
- v: the value to add. This should either be a number or a table of properties and numbers.
- noupdate: if true the actual property is not changed and needs to be changed by the caller
Return value:
an id that can be passed to removeTemporaryValue() to delete this value - _M:added ()
- Call when the entity is actually added to a level/whatever This helps ensuring uniqueness of uniques
- _M:attr (prop, v, fix)
-
Increases/decreases an attribute The attributes are just actor properties, but this ensures they are numbers and not booleans thus making them compatible with temporary values system
Parameters
- prop: the property to use
- v: the value to add, if nil this the function return
- fix: forces the value to v, do not add
Return value:
nil if v was specified. If not then it returns the current value if it exists and is not 0 otherwise returns nil - _M:changeUid (newuid)
-
Change the entity's uid *WARNING*: ONLY DO THIS IF YOU KNOW WHAT YOU ARE DOING!. YOU DO NOT !
Parameters
- newuid:
- _M:check (prop, ...)
-
Check for an entity's property If not a function it returns it directly, otherwise it calls the function with the extra parameters
Parameters
- prop: the property name to check
- ...:
- _M:cloned (src)
-
If we are cloned we need a new uid
Parameters
- src:
- _M:getDisplayString (tstr)
-
Get a string that will display in text the texture of this entity
Parameters
- tstr:
- _M:getEntityFinalSurface (tiles, w, h)
-
Get the entity image as an sdl surface and texture for the given tiles and size
Parameters
- tiles: a Tiles instance that will handle the tiles (usually pass it the current Map.tiles)
- w: the width
- h: the height
Return value:
the sdl surface and the texture - _M:getMapObjects (tiles, mos, z)
-
Get all "map objects" representing this entity Do not touch unless you *KNOW* what you are doing.
You do *NOT* need this, this is used by the engine.Map class automatically.
*DO NOT TOUCH!!!*Parameters
- tiles:
- mos:
- z:
- _M:init (t, no_default)
-
Initialize an entity Any subclass MUST call this constructor
Parameters
- t: a table defining the basic properties of the entity
- no_default:
Usage:
Entity.new{display='#', color_r=255, color_g=255, color_b=255} - _M:invalidateAllMO ()
- Invalidates the whole MO repository
- _M:loadList (file, no_default, res, mod, loaded)
-
Loads a list of entities from a definition file
Parameters
- file: the file to load from
- no_default: if true then no default values will be assigned
- res: the table to load into, defaults to a new one
- mod: an optional function to which will be passed each entity as they are created. Can be used to adjust some values on the fly
- loaded:
Usage:
MyEntityClass:loadList("/data/my_entities_def.lua") - _M:loaded ()
- If we are loaded we need a new uid
- _M:makeMapObject (tiles, idx)
-
Create the "map object" representing this entity Do not touch unless you *KNOW* what you are doing.
You do *NOT* need this, this is used by the engine.Map class automatically.
*DO NOT TOUCH!!!*Parameters
- tiles:
- idx:
- _M:onTemporaryValueChange (prop, v, base)
-
Called when a temporary value changes (added or deleted) This does nothing by default, you can overload it to react to changes
Parameters
- prop: the property changing
- v: the value of the change
- base: the base table of prop
- _M:removeTemporaryValue (prop, id, noupdate)
-
Removes a temporary value, see addTemporaryValue()
Parameters
- prop: the property to affect
- id: the id of the increase to delete
- noupdate: if true the actual property is not changed and needs to be changed by the caller
- _M:removed ()
- Call when the entity is actually removed from existence This helps ensuring uniqueness of uniques. This recursively removes inventories too, if you need anything special, overload this
- _M:resetMoveAnim ()
- Reset movement animation for the entity - removes any anim
- _M:resolve (t, last, on_entity)
-
Resolves an entity This is called when generating the final clones of an entity for use in a level. This can be used to make random enchants on objects, random properties on actors, ... by default this only looks for properties with a table value containing a __resolver field
Parameters
- t:
- last:
- on_entity:
- _M:setMoveAnim (oldx, oldy, speed, blur)
-
Setup movement animation for the entity The entity is supposed to posses a correctly set x and y pair of fields - set to the current (new) position
Parameters
- oldx: the coords from where the animation will seem to come from
- oldy: the coords from where the animation will seem to come from
- speed: the number of frames the animation lasts (frames are normalized to 30/sec no matter the actual FPS)
- blur: apply a motion blur effect of this number of frames
- _M:setupMinimapInfo (mo, map)
-
Setup minimap color for this entity You may overload this method to customize your minimap
Parameters
- mo:
- map:
- _M:toScreen (tiles, x, y, w, h)
-
Displays an entity somewhere on screen, outside the map
Parameters
- tiles: a Tiles instance that will handle the tiles (usually pass it the current Map.tiles, it will if this is null)
- x:
- y:
- w: the width
- h: the height
Return value:
the sdl surface and the texture