LuaAI

LuaAI

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

LuaAI

Post 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
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Post by BrainDamage »

thanks for the patch :-), i applied it in a git branch for the moment
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Post by REVENGE »

Eh? Could you clarify what this does again?
Post Reply

Return to “Lua Scripts”