Fox, on 08 July 2013 - 10:00 PM, said:
Is it possible to add MAX_WEAPONS as a read-only gamevar? On theory it should always equal 12, but I had like to use the proper value used in the source code.
That's a good idea. Revision 3944 adds three pre
defined labels to CON: MAX_WEAPONS as per your request, MAXSTATUS and MAXSPRITES.
It is strongly encouraged to use symbolic names instead of "magic" literal numbers whereever possible. In the present case, MAX_WEAPONS could simply have been
defined in the CON code by hand. The benefits:
- It makes the code much more readable, conveying intent (e.g. "over the indices of which objects does this loop iterate") to the reader.
- Some of the values may be only constant for a given build. For example, on Wii, the engine is built with the V7 map limits due to memory limitations. There, MAXSPRITES is the sprite limit of the V7 engine, 4096. CON code that uses the magic number 16384 in its place will break when executed on the Wii.
- It is aesthetically more appealing in that it is a reduction of redundancy. For example, should MAX_WEAPONS be bumped to, say, 14 in the future, all that would be needed (assuming pre-3944) is to change the one define directive instead of every instance of the literal number.
- In CON, redefinitions of labels are ignored. LunaCON warns you whenever it encounters a define attempting to give an already defined name a different value. Thus, a bump of some "constant" on our side such would not go unnoticed.
Quote
Is it possible to add a WEAPONx_var for the sprite spawned by the tossweapon command, plus a WEAPONx_FLAGS bitfield for the explosion?
The case with
tossweapon is that it can be reasonably reimplemented in the scripting language. Here's an example in pseudo-Lunatic code ("pseudo" because it has been simplified for demonstration purposes and does not represent code that can be run as-is):
function tossweapon(pli) -- pli: player index
local ps = player[pli]
local cw = ps.weapon[ps.curr_weapon].workslike
if (not (cw >= 0 and cw < MAX_WEAPONS)) then
return
end
if (krandand(1) ~= 0) then -- check the lowest bit of a pseudo-random number from krand()
spawn(C.WeaponPickupSprites[cw], ps.i) -- access array on the C side
elseif (cw==RPG_WEAPON or cw==HANDBOMB_WEAPON) then
spawn(EXPLOSION2, ps.i)
end
end
One issue here is that WeaponPickupSprites[] resides on the C side for which there is no direct access from scripting. However, the array effectively has constant elements: they are only ever updated to account for dynamic tile remapping. Thus, you could simply place a gamearray (in CON) or a table with the elements initialized (in Lunatic) in its place -- the tile values are already the "dynamic" ones on the scripting side.
So you could implement
tossweapon as e.g. CON "
state tossweap". Of course, it would not magically change the
tossweapon's issued from GAME.CON, you'd still need to change every instance of
tossweapon with a "
state tossweap" invocation there. My point is that scripting systems ought to provide reliable
primitives on which the user can build instead of dozens of special cases.
Quote
What would be necessary to add entirely new weapons? You can mimic it by changing the values for WEAPONx_var, but there are things you can't do. For example define a priority flag for a "custom" weapon...
I assume you mean "add entirely new weapon functionality" here instead of merely "more weapon slots". It's complicated because the interaction with hard-coded weapon behavior is... not exactly what you'd call "specified". So the very first step should be some research into how precisely it "works", then one could talk about how to provide richer scripting functionality (hint: light-heartedly exposing members to scripting is not a good way to design an interface; even if I'm not a proponent of the "everything has to be encapsulated in a function or method" school, at the very least good documentation should be provided whenever a member is directly accessible).
Edit: I don't specifically have the weapon-related documentation on the Wiki in mind. In case it's better than I made it sound, please forgive me for being in a rant mood
.