diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..09569d3c28 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "recoil-lua-library"] + path = recoil-lua-library + url = https://github.com/beyond-all-reason/recoil-lua-library diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000000..6f20e54ef9 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "diagnostics.globalsRegex": ["CMD_.*"], + "diagnostics.globals": [ + "Spring", + "gadget", + "widget", + "VFS", + "UnitDefs", + "UnitDefNames", + "FeatureDefs", + "ModularCommDefsShared", + "piece", + "GG", + "Script", + "WG", + "widgetHandler", + "widget", + "GameData", + "Shared", + "gadget", + "DEFS", + "LOG", + "FeatureDefNames", + "SendToUnsynced", + "CMD", + "WeaponDefs", + "CMDTYPE", + "WeaponDefNames" + //,{ "name": "script", "include": "scripts/**.lua" } + ], + "runtime.version": "Lua 5.1", + "diagnostics.disable": [ + "duplicate-set-field", + "cast-local-type" // because it is frequently used + ], + "completion.requireSeparator": "/", + "runtime.path": [ + "?", + "?.lua" + ], + "runtime.special": { + "include":"require", + "VFS.Include":"require", + "shard_include": "require" + }, + "workspace.library": [ + "recoil-lua-library/**" + ], + "workspace.ignoreDir": [ + "scripts/**" + ] +} \ No newline at end of file diff --git a/.typedefs/LuaGlobal.lua b/.typedefs/LuaGlobal.lua new file mode 100644 index 0000000000..a0d80684d8 --- /dev/null +++ b/.typedefs/LuaGlobal.lua @@ -0,0 +1,13 @@ +---Just nil, number, string and boolean datatypes are allowed as arguments! NO tables, userdatas, ... +---@param ... nil|number|string|boolean +function SendToUnsynced(...)end + +---@param teamID integer +---@param f function +---@param ... any +function CallAsTeam(teamID,f,...)end + +---@param access {ctrl:number|nil,read:number|nil,select:number|nil} +---@param f function +---@param ... any +function CallAsTeam(access,f,...)end \ No newline at end of file diff --git a/.typedefs/SpringDefines less.lua b/.typedefs/SpringDefines less.lua new file mode 100644 index 0000000000..b7df339b16 --- /dev/null +++ b/.typedefs/SpringDefines less.lua @@ -0,0 +1,73 @@ +-- ---@diagnostic disable: missing-return + +---@class table:{[any]:any} +---@class list:{[integer]:T} + +---@class UnitId : integer +---@class UnitDefId:integer + +---@class PlayerId:integer +---@class TeamId:integer +---@class AllyteamId:integer +--[==[ +---@class timeSec:number + +---@class frame:integer +---@operator div(framePerSec):timeSec +---@class framePerSec:integer +---@operator mul(timeSec):frame + +---@class WldDist:number +---@operator div(frame):WldSpeed +---@operator add(WldDist):WldDist +---@operator add(WldSpeed):WldDist +---@alias WldxPos WldDist +---@alias WldyPos WldDist +---@alias WldzPos WldDist +--[=[ +---@class WldxPos:number +---@operator div(frame):WldxVel +---@operator add(WldxPos):WldxPos +---@operator add(WldxVel):WldxPos +---@class WldyPos:number +---@operator div(frame):WldyVel +---@operator add(WldyPos):WldyPos +---@operator add(WldyVel):WldyPos +---@class WldzPos:number +---@operator div(frame):WldzVel +---@operator add(WldzPos):WldzPos +---@operator add(WldzVel):WldzPos +]=] + +---@class WldSpeed:number +---@operator mul(frame):WldDist +---@operator unm:WldSpeed + +---@alias WldxVel WldSpeed +---@alias WldyVel WldSpeed +---@alias WldzVel WldSpeed +]==] + +---@type {[UnitDefId]:table} +UnitDefs={} + +---@type {[string]:table} +UnitDefNames={} + +---@class WeaponDefId:integer + + +---@type table +WeaponDefs={} + +---@type table +WeaponDefNames={} + +---@class ProjectileId:number + +---@generic T +---@param v T +---@param recurse boolean|nil +---@param appendTo T|nil +---@return T +function Spring.Utilities.CopyTable(v,recurse,appendTo) end \ No newline at end of file diff --git a/LuaRules/Gadgets/unit_tech_k.lua b/LuaRules/Gadgets/unit_tech_k.lua index c576d81f64..74b528d89b 100644 --- a/LuaRules/Gadgets/unit_tech_k.lua +++ b/LuaRules/Gadgets/unit_tech_k.lua @@ -26,6 +26,7 @@ local autoAiTech = Spring.GetModOptions().aiusetechk ~= "0" local IterableMap = VFS.Include("LuaRules/Gadgets/Include/IterableMap.lua") local modCommands, modCmdMap = VFS.Include("LuaRules/Configs/modCommandsDefs.lua") local CMD_TECH_UP = Spring.Utilities.CMD.TECH_UP + local techCommandData = modCmdMap[CMD_TECH_UP] if not gadgetHandler:IsSyncedCode() then diff --git a/LuaUI/Widgets/chili/Headers/autolocalizer.lua b/LuaUI/Widgets/chili/Headers/autolocalizer.lua index 982bf73c6f..e8bd729b11 100644 --- a/LuaUI/Widgets/chili/Headers/autolocalizer.lua +++ b/LuaUI/Widgets/chili/Headers/autolocalizer.lua @@ -152,7 +152,6 @@ local function MyLoadString(str, filename) return chunk, str2 end - function VFS.Include(filename, enviroment, mode) local str = LoadFileSafe(filename, mode) diff --git a/LuaUI/Widgets/gui_sensor_ranges_radar_preview.lua b/LuaUI/Widgets/gui_sensor_ranges_radar_preview.lua index 219bc3d6d7..a781ad4505 100644 --- a/LuaUI/Widgets/gui_sensor_ranges_radar_preview.lua +++ b/LuaUI/Widgets/gui_sensor_ranges_radar_preview.lua @@ -118,7 +118,7 @@ end local function GetRadarUnitToDraw() if selectedRadarUnitID and options.showOnSelected.value then - unitDefID = Spring.GetUnitDefID(selectedRadarUnitID) + local unitDefID = Spring.GetUnitDefID(selectedRadarUnitID) if not unitDefID then selectedRadarUnitID = false return diff --git a/LuaUI/utils.lua b/LuaUI/utils.lua index 3bf4f599f6..6aac391d9c 100644 --- a/LuaUI/utils.lua +++ b/LuaUI/utils.lua @@ -12,6 +12,12 @@ function Basename(fullpath) return base, path end +---Load, compiles, run, return +---@param filename string +---@param envTable table|nil +---@param VFSMODE number|nil +---@return any ...any +---@diagnostic disable-next-line: lowercase-global function include(filename, envTable, VFSMODE) --[[ support legacy header paths for the time being in case people use them in their local widgets ]] diff --git a/recoil-lua-library b/recoil-lua-library new file mode 160000 index 0000000000..dd7ecc7789 --- /dev/null +++ b/recoil-lua-library @@ -0,0 +1 @@ +Subproject commit dd7ecc7789c124c72ce3f616bf8531d61b42dfdd diff --git a/scripts/.luarc.json b/scripts/.luarc.json new file mode 100644 index 0000000000..d3bfccb1ef --- /dev/null +++ b/scripts/.luarc.json @@ -0,0 +1,51 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "diagnostics.globalsRegex": ["CMD_.*"], + "diagnostics.globals": [ + "VFS", + "UnitDefs", + "UnitDefNames", + "FeatureDefs", + "ModularCommDefsShared", + "piece", + "GG", + "Script", + "WG", + "widgetHandler", + "widget", + "GameData", + "Shared", + "gadget", + "DEFS", + "LOG", + "FeatureDefNames", + "SendToUnsynced", + "CMD", + "WeaponDefs", + "CMDTYPE", + "WeaponDefNames", + "script" + + //,{ "name": "script", "include": "scripts/**.lua" } + ], + "runtime.version": "Lua 5.1", + "diagnostics.disable": [ + "duplicate-set-field", + "lowercase-global", + "cast-local-type" + ], + "completion.requireSeparator": "/", + "runtime.path": [ + "?", + "?.lua" + ], + "runtime.special": { + "include":"require", + "VFS.Include":"require" + }, + "workspace.library": [ + ".." + ], + "Lua.workspace.checkThirdParty": false + +} \ No newline at end of file diff --git a/scripts/.typedefs.lua b/scripts/.typedefs.lua new file mode 100644 index 0000000000..b833ff420e --- /dev/null +++ b/scripts/.typedefs.lua @@ -0,0 +1,223 @@ +---@meta + +---@type integer +unitID=unitID + +---@type integer +unitDefID=unitDefID + +---@type table +UnitDef=UnitDef + +---@enum axis +local axises={ + x_axis=1, + y_axis=2, + z_axis=3, +} + +x_axis=axises.x_axis +y_axis=axises.y_axis +z_axis=axises.z_axis + +---@class Piece:integer + +---Get the piece number by piece name +---@param ... string +---@return Piece ...Piece +function piece(...)end + +---@param piece Piece +---@param visible boolean +function SetPieceVisibility(piece,visible)end + +-- local su=Spring.UnitScript + +---@param piece Piece +function Show(piece)end + +---@param piece Piece +function Hide(piece)end + +---Move piece along axis to the destination position. +--- +---If speed is given, the piece isn't moved immediately, but will move there at the desired speed. +--- +---The X axis is mirrored compared to BOS/COB scripts, to match the direction of the X axis in Spring world space. +---@param piece Piece +---@param axis axis +---@param destination number +---@param speed? number +function Move(piece, axis, destination, speed)end + +---Turn piece around axis to the destination angle. +--- +---If speed is given, the piece isn't rotated immediately, but will turn at the desired angular velocity. +--- +---Angles are in radians. +--- +---Always uses the shortest angular towards destination degree, and if at exactly 180 degrees opposite, will go counter-clockwise. +---@param piece Piece +---@param axis axis +---@param destination number +---@param speed? number +function Turn(piece, axis, destination, speed)end + +---Makes piece spin around axis at the desired angular velocity. +--- +---If accel is given, the piece does not start at this velocity at once, but will accelerate to it. +--- +---Both negative and positive angular velocities are supported. +--- +---Accel should always be positive, even if speed is negative. +---@param piece Piece +---@param axis axis +---@param speed number +---@param accel? number +function Spin(piece, axis, speed, accel)end + +---Stops a piece from spinning around the given axis. +--- +---If decel is given, the piece does not stop at once, but will decelerate to it. +--- +---Decel should always be positive. +--- +---This function is similar to Spin(piece, axis, 0, decel), however, StopSpin also frees up the animation record. +---@param piece Piece +---@param axis axis +---@param decel? number +function StopSpin(piece, axis, decel)end + +---@param piece Piece +---@param axis axis +function IsInTurn(piece, axis)end + +---@param piece Piece +---@param axis axis +function IsInMove(piece, axis)end + +---@param piece Piece +---@param axis axis +function IsInSpin(piece, axis)end + +---Get the current translation of a piece. The returned numbers match the values passed into Move and Turn. +---@param piece Piece +---@return number x,number y,number z +function GetPieceTranslation(piece)end + + +---Get the current Rotation of a piece. The returned numbers match the values passed into Move and Turn. +---@param piece Piece +---@return number x,number y,number z +function GetPieceRotation(piece)end + +---Get the piece's position (px, py, pz) and direction (dx, dy, dz) in unit space. +--- +---This is quite similar to Spring.GetUnitPiecePosDir, however that function returns in world space. +---@param piece Piece +---@return number px,number py,number pz,number dx,number dy,number dz +function GetPiecePosDir(piece)end + +---Starts a new (animation) thread, which will execute the function 'fun'. +--- +---All arguments except the function to run are passed as-is as arguments to 'fun'. +--- +---COB-Threads has a decent description on COB threads, which are mimicked here in Lua using coroutines. +---@generic params +---@param fun fun(...:params) +---@param ... `params` +function StartThread(fun,...)end + +---SetSignalMask assigns a mask to the currently running thread (any new threads started by this one will inherit the signal mask). +---@param mask integer +function SetSignalMask(mask)end + +---Signal immediately stops all threads of this unit for which the bitwise and of mask and signal is not zero. +---@param signal integer +function Signal(signal)end + +---Waits until the piece has stopped moving along the axis. +---If the piece is not animating, this functions return at once. +---@param piece Piece +---@param axis axis +function WaitForMove(piece, axis)end + +---Waits until the piece has stopped turning around the axis. +---If the piece is not animating, this functions return at once. +---@param piece Piece +---@param axis axis +function WaitForTurn(piece, axis)end + +---Waits a number of milliseconds before returning. +---@param milliseconds number +function Sleep(milliseconds)end + +---Emits a CEG effect or weapon from the given piece. The id is based on one of the effect or weapon ids defined in the units unitdef. +--- +---If the piece has no geometry, then the sfx is emitted in the +z direction from the origin of the piece. +--- +---If the piece has 1 vertex, the emit dir is the vector from the origin to the the position of the first vertex the emit position is the origin of the piece. +--- +---If there is more than one vertex in the piece, then the emit vector is the vector pointing from v[0] to v[1], and the emit position is v[0]. +---@param piece Piece +---@param sfxid SFX|integer +function EmitSfx(piece, sfxid)end + +---Same as COB's show _inside_ FireWeaponX. +---@param piece Piece +function ShowFlare(piece)end + +---Explodes a piece, optionally creating a particle which flies off. Typically used inside Killed. +--- +---Explode does not hide the piece by itself; if using it outside Killed you may want to Hide the piece immediately after. +--- +---The flags may be any combination of: +--- +---`SFX.NONE`: do nothing after creating a heatcloud. Other flags have no effect, except NO_HEATCLOUD. If that is given too, the call is a no-op. +--- +---`SFX.SHATTER`: shatter the piece in many fragments. Only the NO_HEATCLOUD flag has any effect if this is present. +--- +---`SFX.EXPLODE` | `SFX.EXPLODE_ON_HIT`: the piece that flies of should explode when it hits something. +--- +---`SFX.FALL`: the piece should be affected by gravity (this is currently always forced on by Spring, to prevent pieces that float in air indefinitely). +--- +---`SFX.SMOKE`: leave smoke trail. +--- +---`SFX.FIRE`: the piece is on fire when it flies off. +--- +---`SFX.NO_CEG_TRAIL`: disable a CEG trail, if present. +--- +---`SFX.NO_HEATCLOUD`: suppress the heat cloud that's shown by default. +---@param piece Piece +---@param ... SFX flags +function Explode(piece,...)end + + +---Attaches another unit (a passenger, as this is designed for transports) to this unit. For AttachUnit, piece specifies the attachment point. +--- +---Attaching to piece -1 makes the passenger unit enter a void state whereby it will never: +--- +---take damage, even from Lua (but can be killed by Lua) +--- +---be rendered through any engine path (nor their icons) +--- +---be intersect-able by either synced or unsynced rays +--- +---block any other objects from existing on top of them +--- +---be selectable +---@param piece Piece +---@param passengerID integer +function AttachUnit(piece, passengerID)end + +---Detaches passenger +---@param passengerID integer +function DropUnit(passengerID)end + +---@param cobValue COB +---@param ... any +function GetUnitValue(cobValue,...)end + +---@param cobValue COB +---@param ... any +function SetUnitValue(cobValue,...)end \ No newline at end of file diff --git a/scripts/dronelight.lua b/scripts/dronelight.lua index 72d9611272..15896c179a 100644 --- a/scripts/dronelight.lua +++ b/scripts/dronelight.lua @@ -7,6 +7,7 @@ local blades = {piece('b1', 'b2', 'b3', 'b4', 'b5', 'b6')} --constants local rotorSpeed = math.rad(1080) local rotorAccel = math.rad(240) +local pivotSpeed = math.rad(180) --variables diff --git a/scripts/platehover.lua b/scripts/platehover.lua index 9c8a1eb387..821d174406 100644 --- a/scripts/platehover.lua +++ b/scripts/platehover.lua @@ -32,7 +32,7 @@ local function Close() SetUnitValue(COB.YARD_OPEN, 0) --SetUnitValue(COB.BUGGER_OFF, 0) - SetInBuildDistance(fals) + SetInBuildDistance(false) Move (nano, y_axis, 0, 17.5) WaitForMove (nano, y_axis) diff --git a/scripts/raveparty.lua b/scripts/raveparty.lua index 77ae798743..c190d48b0c 100644 --- a/scripts/raveparty.lua +++ b/scripts/raveparty.lua @@ -23,6 +23,7 @@ local hpi = math.pi*0.5 local headingSpeed = math.rad(4) local pitchSpeed = math.rad(61) -- Float maths makes this exactly one revolution every 6 seconds. +local LOS_ACCESS = {inlos = true} guns[5].y = 11 guns[5].z = 7 diff --git a/scripts/shipheavyarty.lua b/scripts/shipheavyarty.lua index 04800f3517..ef500895ce 100644 --- a/scripts/shipheavyarty.lua +++ b/scripts/shipheavyarty.lua @@ -152,7 +152,7 @@ local function ExplodeTurret(num) for i=1,3 do if math.random() > 0.5 then Explode(barrels[num][i], SFX.FALL + SFX.SMOKE + SFX.EXPLODE) - Hide(barrels[num][i], SFX.FALL + SFX.SMOKE + SFX.EXPLODE) + Hide(barrels[num][i]) else Explode(barrels[num][i], SFX.SHATTER) end diff --git a/zero k.code-workspace b/zero k.code-workspace new file mode 100644 index 0000000000..dbeec103a0 --- /dev/null +++ b/zero k.code-workspace @@ -0,0 +1,11 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "scripts" + } + ], + "settings": {} +} \ No newline at end of file