Page 1 of 1
Lua spells not always using mana or energy
Posted: Thu Oct 10, 2013 7:59 pm
by Lord Estraven
I've noticed that the Golemcraft realm in my T2 fork doesn't always use mana, or take a turn to cast. About 4 times out of 5, golem summoning spells are cast instantly and without any mana use. Obviously this is really bad, and not intended behavior.
I have the spells and the mkey defined correctly AFAICT, and the schools system is supposed to handle turns and mana pretty much automatically; so I'm left wondering if there's a bug somewhere in the Lua subsystem. For the record this is still based on 2.3.9-ah (the last version using Lua).
(And yes, if I had my druthers I'd rewrite the whole thing in Python/TkInter or something, and solve the interface proble too. Unfortunately I have neither the time nor the expertise at thsi point.)
Re: Lua spells not always using mana or energy
Posted: Fri Oct 11, 2013 1:56 pm
by Faeryan
This is most likely not related at all but reminds me of monster possession in which you can often use abilities without cost.
Just wondering if it's possible your spells to be linked into those skills or something.
Re: Lua spells not always using mana or energy
Posted: Fri Oct 11, 2013 2:40 pm
by Lord Estraven
Probably not; Golemcraft uses the Lua subsystem, whereas Possession is implemented entirely in C. You're right though - I had seen that with Possessor powers... Thanks in any case.
Re: Lua spells not always using mana or energy
Posted: Tue Oct 15, 2013 6:25 pm
by AnonymousHero
I seem to vaguely recall noticing something like the following while rewriting to C: (It's been a while, so YMMV.)
The "use-mana-and-energy" flag being returned by the Lua coda was essentially random (arbitrary) due to some sort of interface problem between the Lua and the C code. I can't really recall why, exactly, but perhaps it had something to do with using 32-bit in the return type declared in the *.pkg file versus 64-bit in the *.h file for the same function. (I recall at least one such instance, but I can't really remember if it had anything to do with this particular issue.)
Or maybe it was just a question of the Lua code not actually returning anything and the C code just assuming that something had been returned and using the un-initialized variable.
EDIT: For clarity, I'd missed a negation.
Re: Lua spells not always using mana or energy
Posted: Tue Oct 15, 2013 10:28 pm
by Lord Estraven
Thank you (and blech). I will see if I can do something about it.
Re: Lua spells not always using mana or energy
Posted: Fri Oct 18, 2013 3:46 pm
by Lord Estraven
Hmm. I am having some trouble finding the function that indicates spell success... There is lua_spell_success(), aka magic_power_success(), but it is never called anywhere in the code. Do you recall what functions might be involved?
Re: Lua spells not always using mana or energy
Posted: Sun Oct 20, 2013 7:20 am
by AnonymousHero
I think it was "cast_school_spell", but you should probably double-check everything which adjustst "p_ptr->msp" (directly or indirectly through adjust_power).
Re: Lua spells not always using mana or energy
Posted: Fri Nov 01, 2013 1:11 pm
by Lord Estraven
Okay, the problem seems to be that the cost is only exacted if the spell fails. Weird.
(cast_school_spell() in lib/core/s_aux.lua does have a flag for disabling spell costs, but I don't think that's getting triggered. And anyway this doesn't happen with other spell schools...)
Re: Lua spells not always using mana or energy
Posted: Thu Dec 26, 2013 2:14 pm
by Lord Estraven
GOT IT. Finally. The problem is that Lua functions that do not return TRUE result in spells not using SP or energy. My functions were not returning anything, and so didn't work properly.