Fox, on 07 April 2014 - 02:26 AM, said:
Edit: Is it possible to add a mean to read the values from pre-defined gamevars used for weapons, but by specifying the weapon?
For example, if I want to play the select sound of a weapon, I need all this:
ifvare player[THISACTOR].curr_weapon KNEE_WEAPON
ifvarg WEAPON0_SELECTSOUND 0
soundvar WEAPON0_SELECTSOUND
(...)
ifvare player[THISACTOR].curr_weapon GROW_WEAPON
ifvarg WEAPON11_SELECTSOUND 0
soundvar WEAPON11_SELECTSOUND
While it's much shorter in the source code...
Yeah, that's what you get when you expose an array as separate variables with numbered suffixes. Of course, the author of this is hardly to blame... back then, there were no system gamearrays, and that semi-solution worked for their use case.
On the C side, the WEAPONx_* variables conceptually form an array of arrays: per-player, per-weapon. In the Lunatic build, this is also what's concretely there:
#ifdef LUNATIC
[weapondata_t is a struct type]
weapondata_t g_playerWeapon[MAXPLAYERS][MAX_WEAPONS];
#else
[You don't really want to see this, but for the next argument's sake...]
// pointers to weapon gamevar data
intptr_t *aplWeaponClip[MAX_WEAPONS]; // number of items in magazine
intptr_t *aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire)
[...]
#endif
If we want to expose these as array to CON, one possible solution in
LunaCON is to expose g_playerWeapon[0] -- that is, the weapon settings for the first player -- as a system gamearray of size MAX_WEAPONS. For C-CON, the aplWeapon* declarations are a bit harder to understand: they're arrays that store, for each weapon data member and each weapon index, a pointer to an array of size MAXPLAYERS (i.e. a per-player gamevar, which is what the WEAPONx_* gamevars are!). So it's structured totally inside-out from what you'd naturally write, and reinterpreting that as a player-by-weapon array is hopeless.
So, since a hypothetic weapondata[] system gamearray would only be a LunaCON-only thing, there's probably no point at all -- Lunatic (i.e. the Lua interface) already supports access to g_playerWeapon[][] in a fashion that I find pretty pleasing: player[].weapon gets you a reference to that player's weapon data, and you can index that with either weapon name strings or weapon indices! Look, from test.lua:
local WEAPON = gv.WEAPON
(...)
gameevent{ "JUMP", flags = actor.FLAGS.chain_beg,
function(actori, playeri, dist)
local ps = player[playeri]
(...)
local pistol = ps.weapon.PISTOL
if (pistol.shoots ~= D.RPG) then
pistol.shoots = D.RPG
else
pistol.shoots = D.SHOTSPARK1
end
ps.weapon[WEAPON.PISTOL].firesound = D.LIGHTNING_SLAP
(...)
end
}
NOTE: this interface is not yet documented, but I think that I will keep it.