call will probably be replaced with a direct call-out placed into the Sim table, as
well as some of its sub-routines (like finding the square of the distance between
2 points).
The LuaSim scripts (I've currently got 3 defined, mod rules, map gaia, and cob
helper), all receive the standard call-ins for unit events (creation, deletion, team
change), They also get some type specific call-ins (ex: the mod rules script gets
the AllowUnitCreation() call-in, so that it can block unit creation under custom
conditions).
Mod Rules: let's the mod have finer control of the game, optional
Map Gaia: allows map creators to place gaia units in their maps, optional
COB helper: COB->LUA calls, probably wont be optional
COB -> LUA calls:
BOS:
Code: Select all
// the "lua_" prefix is the key
var = lua_GetNearestEnemy(300)
Code: Select all
function GetNearestEnemy(unitID, radius)
local px, py, pz = Sim.GetUnitPosition(unitID)
if (px == nil) then
return
end
local nearDist = 1.0e20
local nearUnit
local units = Sim.GetUnitsInCylinder(px, pz, radius)
for _,enemyID in ipairs(units) do
if (not Sim.IsUnitAllied(enemyID)) then
local ex, ey, ez = Sim.GetUnitPosition(enemyID)
if (ex ~= nil) then
local dx, dy, dz = (px - ex), (py - ey), (pz - ez)
local dist = (dx * dx) + (dy * dy) + (dz + dz)
if (dist < nearDist) then
nearUnit = enemyID
nearDist = dist
end
end
end
end
if (nearUnit == nil) then
return -1
else
return nearUnit
end
end
LUA -> COB calls:
modrules.lua:
Code: Select all
Sim.COBScript(unitID, "CustomScript", arg1, arg2, arg3)
Code: Select all
CustomScript(arg1, arg2, arg3) ...