Page 1 of 1

LuaAI

Posted: 20 Oct 2007, 06:48
by trepan
http://spring.clan-sy.com/fisheye/chang ... g/?cs=4601

Code: Select all

4601 created by trepan on 20 October 2007, 05:01:36 +0100 (32 minutes ago) (patch)

* Added the LuaAI interface to unitsync  [GetLuaAICount() & GetLuaAIName(int)]
 - the list is loaded from LuaAI.lua in the mod archive
 - the LuaAI name should be set as the AIDLL value in the script,
   prefixed with  "LuaAI:"  (to distinguish it from a DLL ai)
 - I'll be committing the Spring.GetTeamLuaAI(teamID) soon, then LuaRules
   can read which teams are set for which LuaAI control mode, and act accordingly
 - LuaRules can decide how much cheating is allowed by limiting the function calls
   available to AIs, and using permission modifying call like CallAsTeam() 
Example LuaAI.lua file:

Code: Select all

return {
  Easy = {
    description = '',
    author = 'John Smith',
    options = {
      cheat    = { type = 'bool',   def = false },
      useNukes = { type = 'bool',   def = true  },
      favColor = { type = 'string', def = 'black' },
      period   = { type = 'number', def = 30, min = 10, max = 60, step = 2 },
      taunts   = { type = 'list',   def = 1,
        items = {
          'quiet',
          'annoying',
          'rude',
        }
      }, 
    },   
  },     
  Medium = {
    description = 'medium',
    author = 'Jane Smith', 
  },
  Hard = {
    description = 'Hard AI',
    author = 'Yoda',
  },
}
NOTE For now, only the key name is being used from LuaAI.lua,
the rest of the example file is there to demonstrate how extra data and
options could be added to the format at a later date.

P.S. I've also added pathfinding to the lua interface (not committed yet)

P.P.S. For C++ AIs, I've added the following unsynced call to CAICallback:

Code: Select all

  // NOTES:
  // 1. 'data' can be NULL to skip passing in a string
  // 2. if inSize is less than 0, the data size is calculated using strlen()
  // 3. the return data is subject to lua garbage collection,
  //    copy it if you wish to continue using it
  const char* CallLuaRules(const char* data, int inSize = -1, int* outSize = NULL);
P.P.P.S. Here's the diff that adds LuaAI to SpringLobby, it might
serve as a reference to other lobby coders:
http://trepan.bzflag.bz/noshow/SpringLo ... -0694.diff

Image

Posted: 20 Oct 2007, 13:29
by BrainDamage
thanks for the patch :-), i applied it in a git branch for the moment

Posted: 21 Oct 2007, 07:21
by REVENGE
Eh? Could you clarify what this does again?