aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-01-03 18:48:00 +0100
committerorwell96 <mono96.mml@gmail.com>2017-01-03 18:48:00 +0100
commita9d43ce2ca3bfd703428d248c0839e53ffd76f27 (patch)
tree761a6ef8f693c01702e3be024fdf3e38624adcc2
parentcc6cf09ac83efa0bfaaecddb2a8fe49d136cca57 (diff)
downloadadvtrains-a9d43ce2ca3bfd703428d248c0839e53ffd76f27.tar.gz
advtrains-a9d43ce2ca3bfd703428d248c0839e53ffd76f27.tar.bz2
advtrains-a9d43ce2ca3bfd703428d248c0839e53ffd76f27.zip
add API documentation
-rw-r--r--advtrains/api_doc.txt114
-rw-r--r--advtrains/wagons.lua6
2 files changed, 117 insertions, 3 deletions
diff --git a/advtrains/api_doc.txt b/advtrains/api_doc.txt
new file mode 100644
index 0000000..22132c3
--- /dev/null
+++ b/advtrains/api_doc.txt
@@ -0,0 +1,114 @@
+Advanced Trains [advtrains] API documentation
+--------
+To use the API, mods must depend on 'advtrains'.
+All boolean values in definition tables default to 'false' and can be omitted.
+### Wagons
+Wagons are registered using the function
+
+advtrains.register_wagon(name, prototype, description, inventory_image)
+- 'name' is the internal name of the wagon. It is registered inside the 'advtrains:' namespace.
+ Example: A wagon with name="engine_tgv" will be registered as "advtrains:engine_tgv".
+- 'prototype' is the lua entity prototype. The regular definition keys for luaentites apply. Additional required and optional properties see below. DO NOT define 'on_step', 'on_activate', 'on_punch', 'on_rightclick' and 'get_staticdata' since these will be overridden. Use 'custom_*' instead.
+- 'description' is the description of the inventory item that is used to place the wagon.
+- 'inventory_image' is the inventory image of said item.
+
+# Wagon prototype properties
+{
+ ... all regular luaentity properties (mesh, textures, collisionbox a.s.o)...
+ drives_on = {default=true},
+ ^- used to define the tracktypes (see below) that wagon can drive on. The tracktype identifiers are given as keys, similar to privileges)
+ max_speed = 10,
+ ^- optional, default 10: defines the maximum speed this wagon can drive. The maximum speed of a train is determined by the wagon with the lowest max_speed value.
+ seats = {
+ {
+ name="Left front window",
+ ^- display name of this seat
+ attach_offset={x=0, y=10, z=0},
+ ^- this value is passed to 'set_attach'
+ view_offset={x=0, y=6, z=0},
+ ^- player:set_eye_offset is called with this parameter.
+ driving_ctrl_access=false,
+ ^- If the seat is a driver stand, and players sitting here should get access to the train's driving control.
+
+ },
+ },
+ ^- contains zero or more seat definitions. A seat is a place where a player can be attached when getting on a wagon.
+ wagon_span=2,
+ ^- How far this wagon extends from its base position. Is the half of the wagon length.
+ ^- Used to determine in which distance the other wagons have to be positioned. Will require tweaking.
+ drops = {"default:steelblock 3"}
+ ^- List of itemstrings what to drop when the wagon is destroyed
+
+ has_inventory = false
+ ^- If this wagon has an inventory. The inventory is saved with the wagon.
+ ^- the following settings are ignored if not.
+ inventory_list_sizes = {
+ box=8*6,
+ },
+ ^- List of assignments of type list_name=size.
+ ^- For every entry, an inventory list is created with the specified size.
+ get_inventory_formspec = function(self, player_name)
+ return "<a formspec>"
+ end,
+ ^- Function that should return the formspec to be displayed when <player> requests to open the wagon's inventory
+ ^- Use "list[detached:advtrains_wgn_"..self.unique_id..";<list_name>;<X>,<Y>;<W>,<H>;<Start>]" to display a wagon's inventory list.
+
+ custom_on_step = function(self, dtime) end
+ ^- optional: Execute custom code on every step
+ custom_on_activate = function(self, dtime_s) end
+ ^- optional: Execute custom code on activate. Staticdata does not need to be saved and restored since all properties written in 'self' are preserved over unloads.
+ update_animation = function(self, velocity) end
+ ^- optional: Function that is called whenever the train's velocity changes or every 2 seconds. Used to call 'self.object:update_animation()' if needed.
+
+}
+
+# Notes on wagons
+
+- Every wagon has the field 'unique_id' which assigns each wagon a random id.
+- All properties written in the lua entity (self) are saved and restored automatically. Minetest's internal staticdata is only used to save the unique_id of the wagon, which serves as a key in an externally saved table.
+- Assuming Z Axis as the axis parallel to the tracks and Y Axis as the one pointing into the sky, wagon models should be dimensioned in a way that:
+ - their origin is centered in X and Z direction
+ - their origin lies 0.5 units above the bottom of the model
+ - the overall extent in X and Y direction is <=3 units
+- wagon_span is then the distance between the model origin and the Z axis extent.
+
+### Tracks
+Most modders will be satisfied with the built-in tracks. If cog railways, maglev trains and mine trains are added, it is necessary to understand the definition of tracks. Although the tracks API is there, explaining it would require more effort than me creating the wanted definitions myself. Contact me if you need to register your own rails using my registration functions.
+
+However, it is still possible to register single rails by understanding the node properties of rails.
+minetest.register_node(nodename, {
+ ... usual node definition ...
+ groups = {
+ advtrains_track_<tracktype>=1
+ ^- this group tells that the node is a track
+ not_blocking_trains=1,
+ ^- this group tells that the node should not block trains although it's walkable.
+ },
+ connect1 = 0,
+ connect2 = 8,
+ ^- These values tell the direction (horizontal) the rail ends are pointing to. 0 means +Z, then rotation values increase clockwise. For a translation of directions to positions see helpers.lua.
+ rely1=0,
+ rely2=0,
+ ^- the Y height of the rail end 1/2. A value of >=1 means that the rail end points to the next y layer at rely-1
+ railheight=0,
+ ^- the height value of this rail that is saved in the path. usually the median of rely1 and rely2.
+
+ can_dig=function(pos)
+ return not advtrains.is_train_at_pos(pos)
+ end,
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.reset_trackdb_position(pos)
+ end,
+ after_place_node=function(pos)
+ advtrains.reset_trackdb_position(pos)
+ end,
+ ^- the code in these 3 functions is required for advtrains to work.
+
+ advtrains = {
+ on_train_enter=function(pos, train_id) end
+ ^- called when a train enters the rail
+ on_train_leave=function(pos, train_id) end
+ ^- called when a train leaves the rail
+ }
+}) \ No newline at end of file
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index fdd2b2e..495f914 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -73,7 +73,7 @@ function wagon:on_activate(sd_uid, dtime_s)
end
if self.custom_on_activate then
- self:custom_on_activate(staticdata_table, dtime_s)
+ self:custom_on_activate(dtime_s)
end
end
@@ -460,7 +460,7 @@ function wagon:show_get_on_form(pname)
if not self.initialized then return end
if #self.seats==0 then
if self.has_inventory and self.get_inventory_formspec then
- minetest.show_formspec(pname, "advtrains_inv_"..self.unique_id, self:get_inventory_formspec())
+ minetest.show_formspec(pname, "advtrains_inv_"..self.unique_id, self:get_inventory_formspec(pname))
end
return
end
@@ -487,7 +487,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if wagon.is_wagon and wagon.initialized and wagon.unique_id==uid then
if fields.inv then
if wagon.has_inventory and wagon.get_inventory_formspec then
- minetest.show_formspec(player:get_player_name(), "advtrains_inv_"..uid, wagon:get_inventory_formspec())
+ minetest.show_formspec(player:get_player_name(), "advtrains_inv_"..uid, wagon:get_inventory_formspec(player:get_player_name()))
end
elseif fields.seat then
local val=minetest.explode_textlist_event(fields.seat)