Commit bd64a487d07ec15a6398da04b9639be4307fb09b

Authored by dg
1 parent 5d879c68

Added luadocs for core.* functions


git-svn-id: http://svn.net-core.org/repos/t-engine4@2334 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -787,14 +787,14 @@ function _M:setupCommands()
787 787 -- HOTKEY_HOTPAGE3 = function(sym, ctrl, shift, alt, meta, unicode, isup) self.player:setHotkeyPage(isup and 1 or 3) end,
788 788
789 789 -- Party commands
790   - SWITCH_PARTY_1 = not_wild(function() self.party:setPlayer(1) end),
791   - SWITCH_PARTY_2 = not_wild(function() self.party:setPlayer(2) end),
792   - SWITCH_PARTY_3 = not_wild(function() self.party:setPlayer(3) end),
793   - SWITCH_PARTY_4 = not_wild(function() self.party:setPlayer(4) end),
794   - SWITCH_PARTY_5 = not_wild(function() self.party:setPlayer(5) end),
795   - SWITCH_PARTY_6 = not_wild(function() self.party:setPlayer(6) end),
796   - SWITCH_PARTY_7 = not_wild(function() self.party:setPlayer(7) end),
797   - SWITCH_PARTY_8 = not_wild(function() self.party:setPlayer(8) end),
  790 + SWITCH_PARTY_1 = not_wild(function() self.party:select(1) end),
  791 + SWITCH_PARTY_2 = not_wild(function() self.party:select(2) end),
  792 + SWITCH_PARTY_3 = not_wild(function() self.party:select(3) end),
  793 + SWITCH_PARTY_4 = not_wild(function() self.party:select(4) end),
  794 + SWITCH_PARTY_5 = not_wild(function() self.party:select(5) end),
  795 + SWITCH_PARTY_6 = not_wild(function() self.party:select(6) end),
  796 + SWITCH_PARTY_7 = not_wild(function() self.party:select(7) end),
  797 + SWITCH_PARTY_8 = not_wild(function() self.party:select(8) end),
798 798 SWITCH_PARTY = not_wild(function() self:registerDialog(require("mod.dialogs.PartySelect").new()) end),
799 799
800 800 -- Actions
... ...
... ... @@ -20,6 +20,7 @@
20 20 require "engine.class"
21 21 require "engine.Entity"
22 22 local Map = require "engine.Map"
  23 +local PartyOrder = require "mod.dialogs.PartyOrder"
23 24
24 25 module(..., package.seeall, class.inherit(
25 26 engine.Entity
... ... @@ -165,3 +166,67 @@ function _M:findSuitablePlayer(type)
165 166 end
166 167 return false
167 168 end
  169 +
  170 +function _M:canOrder(actor, order, vocal)
  171 + if not actor then return false end
  172 + if actor == game.player then return false end
  173 +
  174 + if not self.members[actor] then
  175 +-- print("[PARTY] error trying to order, not a member of party: ", actor.uid, actor.name)
  176 + return false
  177 + end
  178 + if self.members[actor].control ~= "full" or self.members[actor].control ~= "order" or not self.members[actor].orders then
  179 +-- print("[PARTY] error trying to order, not controlable: ", actor.uid, actor.name)
  180 + return false
  181 + end
  182 + if actor.dead or (game.level and not game.level:hasEntity(actor)) then
  183 + if vocal then game.logPlayer(game.player, "Can not give orders to this creature.") end
  184 + return false
  185 + end
  186 + if actor.on_can_order and not actor:on_can_order(vocal) then return false end
  187 + if order and not self.members[actor].orders[order] then
  188 +-- print("[PARTY] error trying to order, unknown order: ", actor.uid, actor.name)
  189 + return false
  190 + end
  191 + return true
  192 +end
  193 +
  194 +function _M:giveOrders(actor)
  195 + if type(actor) == "number" then actor = self.m_list[actor] end
  196 +
  197 + local ok, err = self:canOrder(actor, nil, true)
  198 + if not ok then return nil, err end
  199 +
  200 + local def = self.members[actor]
  201 +
  202 + game:registerDialog(PartyOrder.new(actor, def))
  203 +
  204 + return true
  205 +end
  206 +
  207 +function _M:giveOrder(actor, order)
  208 + if type(actor) == "number" then actor = self.m_list[actor] end
  209 +
  210 + local ok, err = self:canOrder(actor, order, true)
  211 + if not ok then return nil, err end
  212 +
  213 + local def = self.members[actor]
  214 +
  215 + if order == "leash" then
  216 + elseif order == "behavior" then
  217 +-- game:registerDialog(require
  218 + end
  219 +
  220 + return true
  221 +end
  222 +
  223 +function _M:select(actor)
  224 + if not actor then return false end
  225 + if type(actor) == "number" then actor = self.m_list[actor] end
  226 + if actor == game.player then return false end
  227 +
  228 + if self:canControl(actor) then return self:setPlayer(actor)
  229 + elseif self:canOrder(actor) then return self:giveOrders(actor)
  230 + end
  231 + return false
  232 +end
... ...
... ... @@ -120,7 +120,7 @@ function _M:makePortrait(a, current, x, y)
120 120
121 121 self:mouseTooltip("#GOLD##{bold}#"..a.name.."\n#WHITE##{normal}#Level: "..a.level.."\n"..def.title, 36, 36, x, y, function()
122 122 if def.control == "full" then
123   - game.party:setPlayer(a)
  123 + game.party:select(a)
124 124 end
125 125 end)
126 126
... ...
... ... @@ -133,7 +133,10 @@ newTalent{
133 133 action = function(self, t)
134 134 if not self.alchemy_golem then
135 135 self.alchemy_golem = game.zone:finishEntity(game.level, "actor", makeGolem())
136   - game.party:addMember(self.alchemy_golem, {control="full", type="golem", title="Golem"})
  136 + game.party:addMember(self.alchemy_golem, {
  137 + control="full", type="golem", title="Golem",
  138 + orders = {leash=true, behavior=true},
  139 + })
137 140 if not self.alchemy_golem then return end
138 141 self.alchemy_golem.faction = self.faction
139 142 self.alchemy_golem.name = "golem (servant of "..self.name..")"
... ...
... ... @@ -43,15 +43,14 @@ function _M:use(item)
43 43 if not item then return end
44 44 game:unregisterDialog(self)
45 45
46   - game.party:setPlayer(item.actor)
  46 + game.party:select(item.actor)
47 47 end
48 48
49 49 function _M:generateList()
50 50 local list = {}
51 51
52 52 for i, act in ipairs(game.party.m_list) do
53   - local def = game.party.members[act]
54   - if def.control == "full" and not act.dead then
  53 + if game.party:canControl(act) or game.party:canOrder(act) then
55 54 list[#list+1] = {name=act.name, actor=act}
56 55 end
57 56 end
... ...
  1 +--- T-Engine display API
  2 +
  3 +module "core.display"
  4 +
  5 +-- {"setTextBlended", set_text_aa},
  6 +--- Set the anti-aliasing status of fonts.
  7 +-- @param status Enable anti-aliasing if true.
  8 +function setTextBlended (status)
  9 +
  10 +-- {"getTextBlended", get_text_aa},
  11 +--- Get the anti-aliasing status of fonts.
  12 +function getTextBlended ()
  13 +
  14 +-- {"forceRedraw", sdl_redraw_screen},
  15 +--- Forces redrawing of the T-Engine display.
  16 +function forceRedraw ()
  17 +
  18 +-- {"fullscreen", sdl_fullscreen},
  19 +--- Toggle fullscreen mode.
  20 +function fullscreen ()
  21 +
  22 +-- {"size", sdl_screen_size},
  23 +--- Set the fullscreen dimensions.
  24 +-- @param width Width in pixels.
  25 +-- @param height Height in pixels.
  26 +function size (width, height)
  27 +
  28 +-- {"newFont", sdl_new_font},
  29 +--- Load a TrueType font.
  30 +-- @param path Font file path relative to the module directory.
  31 +-- @param size The font size.
  32 +-- @return The font userdata.
  33 +function newFont (path, size)
  34 +
  35 +-- {"newSurface", sdl_new_surface},
  36 +--- Create a new SDL surface.
  37 +-- @param width Surface width in pixels.
  38 +-- @param height Surface height in pixels.
  39 +-- @return An SDL surface userdata.
  40 +function newSurface ()
  41 +
  42 +-- {"newTile", sdl_new_tile},
  43 +--- Create a new SDL surface based on a tile.
  44 +-- @param width Surface width in pixels.
  45 +-- @param height Surface height in pixels.
  46 +-- @param font A TrueType font userdata.
  47 +-- @param char An ASCII character to display in the tile.
  48 +-- @param x Horizontal offset to draw the character on the tile (in pixels).
  49 +-- @param y Vertical offset to draw the character on the tile (in pixels).
  50 +-- @param fr Foreground red color (0-255).
  51 +-- @param fg Foreground green color (0-255).
  52 +-- @param fb Foreground blue color (0-255).
  53 +-- @param br Background red color (0-255).
  54 +-- @param bg Background green color (0-255).
  55 +-- @param bb Background blue color (0-255).
  56 +-- @param alpha Alpha factor (0-1).
  57 +-- @return An SDL surface userdata.
  58 +function newTile (width, height, font, char, x, y, fr, fg, fb, br, bg, bb, alpha)
  59 +
  60 +-- {"newFBO", gl_new_fbo},
  61 +--- Creates a new frame buffer object (FBO).
  62 +-- @param width Width of the FBO (in pixels).
  63 +-- @param height Height of the FBO (in pixels).
  64 +-- @return The FBO userdata.
  65 +function newFBO (width, height)
  66 +
  67 +-- {"drawQuad", gl_draw_quad},
  68 +--- Draw a rectangle.
  69 +-- @param x Horizontal offset to start the rectangle (in pixels).
  70 +-- @param y Vertical offset to start the rectangle (in pixels).
  71 +-- @param w Width in pixels.
  72 +-- @param h Height in pixels.
  73 +-- @param r Red color (0-255).
  74 +-- @param g Green color (0-255).
  75 +-- @param b Blue color (0-255).
  76 +-- @param a Alpha factor (0-1).
  77 +-- @param txt Optional OpenGL texture userdata.
  78 +function drawQuad (x, y, w, h, r, g, b, a, txt)
  79 +
  80 +-- {"FBOActive", gl_fbo_is_active},
  81 +--- Check if Frame Buffer Objects are active.
  82 +-- @return Boolean, true if FBOs are active.
  83 +function FBOActive ()
  84 +
  85 +-- {"disableFBO", gl_fbo_disable},
  86 +--- Disable Frame Buffer Objects.
  87 +function disableFBO ()
  88 +
  89 +-- {"drawStringNewSurface", sdl_surface_drawstring_newsurface},
  90 +--- Create a SDL surface of a string.
  91 +-- @param font TrueType font userdata.
  92 +-- @param string String to put on the surface.
  93 +-- @param r Red color of the font (0-255).
  94 +-- @param g Green color of the font (0-255).
  95 +-- @param b Blue color of the font (0-255).
  96 +-- @return An SDL surface userdata.
  97 +function drawStringNewSurface (font, string, r, g, b)
  98 +
  99 +-- {"drawStringBlendedNewSurface", sdl_surface_drawstring_newsurface_aa},
  100 +--- Creates a SDL surface of an anti-aliased string, if possible.
  101 +-- @param font TrueType font userdata.
  102 +-- @param string String to put on the surface.
  103 +-- @param r Red color of the font (0-255).
  104 +-- @param g Green color of the font (0-255).
  105 +-- @param b Blue color of the font (0-255).
  106 +-- @return An SDL surface userdata.
  107 +function drawStringBlendedNewSurface (font, string, r, g, b)
  108 +
  109 +-- {"loadImage", sdl_load_image},
  110 +--- Creates a SDL surface from an image.
  111 +-- @param path Image path relative to the module directory.
  112 +-- @return An SDL surface.
  113 +function loadImage (path)
  114 +
  115 +-- {"setWindowTitle", sdl_set_window_title},
  116 +--- Set the window's title.
  117 +-- @param title The string to use as a title.
  118 +function setWindowTitle (title)
  119 +
  120 +-- {"setWindowSize", sdl_set_window_size},
  121 +--- Set the window dimensions.
  122 +-- @param width Width in pixels.
  123 +-- @param height Height in pixels.
  124 +function setWindowSize (width, height)
  125 +
  126 +-- {"getModesList", sdl_get_modes_list},
  127 +--- Find potential window sizes.
  128 +-- @return A table of tables containing {w=width, h=height}.
  129 +function getModesList ()
  130 +
  131 +-- {"setMouseCursor", sdl_set_mouse_cursor},
  132 +--- Set images for the mouse cursor.
  133 +-- @param ox Horizontal offset (in pixels) of the surface relative to the cursor position.
  134 +-- @param ox Veritcal offset (in pixels) of the surface relative to the cursor position.
  135 +-- @param surface_up SDL surface to use when the mouse button is up.
  136 +-- @param surface_down SDL surface to use when the mouse button is down.
  137 +function setMouseCursor (ox, oy, surface_up, surface_down)
\ No newline at end of file
... ...
  1 +--- T-Engine game API
  2 +
  3 +module "core.game"
  4 +
  5 +-- {"reboot", lua_reboot_lua},
  6 +--- Reboot the Lua environment.
  7 +function reboot ()
  8 +
  9 +-- {"set_current_game", lua_set_current_game},
  10 +--- Sets the current game.
  11 +-- This allows the Lua code to be notified to tick, display and handle quitting.
  12 +-- @param game The Lua game object.
  13 +function set_current_game (game)
  14 +
  15 +-- {"exit_engine", lua_exit_engine},
  16 +--- Tell the C core to quit.
  17 +function exit_engine ()
  18 +
  19 +-- {"getTime", lua_get_time},
  20 +--- Returns the SDL time.
  21 +-- @return The SDL time.
  22 +function getTime ()
  23 +
  24 +-- {"sleep", lua_sleep},
  25 +--- Put the engine to sleep.
  26 +-- @param ms The number of milliseconds to sleep for.
  27 +function sleep (ms)
  28 +
  29 +-- {"setRealtime", lua_set_realtime},
  30 +--- Set the game's frames-per-second rate.
  31 +-- @param fps The frames-per-second.
  32 +function setRealTime (fps)
  33 +
  34 +-- {"setFPS", lua_set_fps},
  35 +--- Set the display's frames-per-second rate.
  36 +-- @param fps The frames-per-second.
  37 +function setFPS (fps)
\ No newline at end of file
... ...
  1 +--- T-Engine key API
  2 +module "core.key"
  3 +
  4 +-- {"set_current_handler", lua_set_current_keyhandler},
  5 +--- Sets the Lua keyboard handler.
  6 +-- The keyboard events are then collected by the C core and passed to handler.
  7 +-- @param handler The Lua handler object.
  8 +function set_current_handler (handler)
  9 +
  10 +-- {"modState", lua_get_mod_state},
  11 +--- Check if a modifier key is being pressed.
  12 +-- @param mod The modifier to check for: "ctrl", "shift", "alt" or "meta".
  13 +-- @return A boolean telling whether the modifier is pressed (true) or not (false).
  14 +function modState (mod)
\ No newline at end of file
... ...
  1 +--- T-Engine mouse API
  2 +
  3 +module "core.mouse
  4 +-- {"get", lua_get_mouse},
  5 +--- Finds the position of the mouse cursor.
  6 +-- @return The x, y position (in pixels???) of the mouse cursor.
  7 +function get ()
  8 +
  9 +-- {"set", lua_set_mouse},
  10 +--- Moves the mouse cursor.
  11 +-- @param x The x-pixel-coordinate to move the mouse to.
  12 +-- @param y The y-pixel-coordinate to move the mouse to.
  13 +function set (x, y)
  14 +
  15 +-- {"set_current_handler", lua_set_current_mousehandler},
  16 +--- Sets the Lua mouse handler.
  17 +-- The mouse events are then collected by the C core and passed to handler.
  18 +-- @param handler The Lua handler object.
  19 +function set_current_handler (handler)
\ No newline at end of file
... ...
  1 +--- T-Engine random number generator API
  2 +-- Uses the SIMD oriented Fast Mersenne Twister.
  3 +
  4 +module "rng"
  5 +-- {"float", rng_float},
  6 +--- Select a random floating point number from a uniform distribution.
  7 +-- @param min The lower limit of the distribution.
  8 +-- @param max The upper limit of the distribution.
  9 +-- @return The randomly selected number.
  10 +function float (min, max)
  11 +
  12 +-- {"__call", rng_call},
  13 +-- GOING TO LEAVE THIS ONE OUT
  14 +-- @param arg1 The upper limit if no arg2, otherwise the lower limit.
  15 +-- @param arg2 The upper limit, or nothing.
  16 +-- @return
  17 +function __call (arg1, arg2)
  18 +
  19 +-- {"range", rng_range},
  20 +--- Select a random integer from a uniform distribution.
  21 +-- @param min The lower limit of the distribution.
  22 +-- @param max The upper limit of the distribution.
  23 +-- @return The randomly selected integer.
  24 +function range (min, max)
  25 +
  26 +-- {"avg", rng_avg},
  27 +--- The average of several repeated calls to the range function.
  28 +-- @param min The lower limit of the distribution.
  29 +-- @param max The upper limir of the distribution.
  30 +-- @param size The number of samples (default 2).
  31 +-- @return The average from size samples.
  32 +-- @see range
  33 +function avg (min, max, size)
  34 +
  35 +-- {"dice", rng_dice},
  36 +--- The sum of a series of dice rolls.
  37 +-- @param rolls The number of rolls of dice to simulate. (3 in 3d6)
  38 +-- @param sides How many sides the dice has. (6 in 3d6)
  39 +-- @return The sum of the dice rolls.
  40 +function dice (rolls, sides)
  41 +
  42 +-- {"seed", rng_seed},
  43 +--- Set the seed for the random number generator.
  44 +-- The RNG will be re-initialized after setting the seed.
  45 +-- @param new_seed The new seed, unless the number is negative in which case the clock time will be used.
  46 +function seed (new_seed)
  47 +
  48 +-- {"chance", rng_chance},
  49 +--- Decide if a one in X chance occurs.
  50 +-- @param odds The X in "1 in X". As the X increases, the odds of success decrease accordingly, with a 100/X% chance of returning true.
  51 +-- @return A boolean representing success.
  52 +function chance (odds)
  53 +
  54 +-- {"percent", rng_percent},
  55 +--- Decide if something should occur based on a percent chance.
  56 +-- @param success The percent chance (0-100) to return true.
  57 +-- @return A boolean representing success.
  58 +function percent (success)
  59 +
  60 +-- {"normal", rng_normal},
  61 +--- Select an integer from a normal distribution.
  62 +-- @param mean The mean of the normal distribution
  63 +-- @param stdev The standard deviation of the normal distribution.
  64 +-- @return The selected integer.
  65 +-- @see normalFloat
  66 +function normal (mean, stdev)
  67 +
  68 +-- {"normalFloat", rng_normal_float},
  69 +--- Select a floating point number from a normal distribution.
  70 +-- Uses the Box-Muller transform.
  71 +-- @param mean The mean of the normal distribution
  72 +-- @param stdev The standard deviation of the normal distribution.
  73 +-- @return The selected floating point number.
  74 +-- @see normal
  75 +function normalFloat (mean, stdev)
... ...
1 1 #!/bin/sh
2 2 rm -rf doc
3 3 cd game/engines/default/
4   -luadoc --nofiles -d ../../../doc `find engine -name '*lua'`
  4 + luadoc --nofiles -d ../../../doc `find ../../../src/ -name 'core*luadoc'` `find engine -name '*lua'`
5 5 cd -
6   -
... ...