Lua COB replacement

As some of you may have understood already from chat in certain lobby channels, I’m making Lua replacement for unit animations (COB).

I’ll put some Lua unit scripts in a branch in SVN once I get around to do some serious testing.

(Just as heads up so you know what’s happening, also I’ll use this topic to keep you up to date, and you could ask questions about it here if you have any. Of course there will be a topic on spring board too sometime, but not before I’ve done testing.)

If this means I don’t have to do cob anymore for unit animation, I will rewrite the infantry animations again - at least half of the bugs in the current ones are because cob is really painful to fight with sometimes. I’m quite excited to see examples of the new code :slight_smile:

Yeah it would mean that :stuck_out_tongue:

Though it depends on what you hate about COB whether it would be better. If it’s anything from not having real numbers to weird get syntax to scriptor, then Lua will be better. If you hate it because it isn’t skeletal animation or inverse kinematics then Lua won’t be better :wink:

I’ll post here once I’ve made some example script.

In the mean time at the top of this file there’s a big comment blob describing new callin/callouts and stuff (but note that on top of that I’ll write a framework in Lua, which will be the interface for game developers.)

I’ve only ever animated with COB, so I’m not expecting skeletal or IK. Sensible units and not using scriptor would be a vast improvement, really.

If lua will allow me to get rid of things like:

spin wheel1 around x-axis speed WHEEL_SPEED; spin wheel2 around x-axis speed WHEEL_SPEED; ... spin wheel10 around x-axis speed WHEEL_SPEED;
and replace that with a loop which changes piece name and applies some operation to it, that already would be great (there are lots of code like that in our tank scripts).

Yeah, what I have in mind combined with power of Lua (compared to COB in particular), would easily allow that.

local WHEEL_SPEED = ...
local X, Y, Z = 0, 1, 2
...
-- get piece numbers for the wheels
local wheels = { Piece("wheel1"), Piece("wheel2"), ..., Piece("wheel10") }
...
for _,piece in ipairs(wheels) do
  Spin(piece, X, WHEEL_SPEED)
end

As you may have noticed from commit messages, I’ve now made such a branch: branches/MemberFolders/Tobi/S44LuaUnitScript.sdd. This acts as a mutator for S44LiteRelease.sdd.

Lua unit scripts are defined in the scripts folder, just like BOS/COB scripts. If it is desired, this can be changed easily in LuaRules/Gadgets/unit_script.lua.

I’ve currently made one script. This is a port of FLOZi’s GERTiger.bos, with my own touch here and there.
(Like, wheels spin in correct direction when tank is driving in reverse :wink:)

As one example of the extra power Lua offers over BOS/COB, I’ve also written a gadget that loads and runs all *.lua scripts in scripts/library/ (again, the folder can be changed.) By convention, these scripts just put functions useful for Lua unit scripts in the GG.UnitScript table. (For example, I factored out the tread, wheels, smokeunit and rockunit animations.)

Both the unit scripts themselves get some Lua prepended before it is parsed. This allows one to predefine often used constructs as locals for all scripts at once. The respective files are gamedata/unit_script_header.lua and gamedata/unit_script_library_header.lua.

I’d say, browse around a bit through the mutator (it is tiny as of now anyway) and fire off any questions/comments you may have.

In HitWeapId_S44.h, am I right that:

#define AT_WEAPON	100

if (id == AT_WEAPON) { armour = ARMOUR; newDamage = 100; tempDamage = damage / 100; if (tempDamage == 0) return 0; else if (tempDamage >= armour) return 100; newDamage = (tempDamage/100 * get POW (ExCOBSCALE, ((0-QUALITY) * (armour/100 - tempDamage/100))))/COBSCALE; #ifdef DEBUG get PRINT (tempDamage, newDamage, newDamage * 10000 / tempDamage); #endif return newDamage * 10000 / tempDamage; } else return 100;
Is not used anymore?

(I don’t see any weapons with id 100…)

Correct, no longer used (replaced by Zerg’s armor system).

‘set ACTIVATION’ in StartMoving/StopMoving. Is this needed for anything, or just relic from OTA scripts?

It was required to make units drain energy when moving. However, I am unsure if they even do that anymore.

edit: looking at some tank fbis, it appears they infact do not.

All german tanks converted :mrgreen: