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.)
Lua spells not always using mana or energy
Moderator: Moderator
-
- Uruivellas
- Posts: 718
- Joined: Tue Dec 13, 2005 12:35 am
Re: Lua spells not always using mana or energy
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.
Just wondering if it's possible your spells to be linked into those skills or something.
Stronk is a potent combatant with a terrifying appearance.
-
- Uruivellas
- Posts: 718
- Joined: Tue Dec 13, 2005 12:35 am
Re: Lua spells not always using mana or energy
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.
-
- Spiderkin
- Posts: 482
- Joined: Sat Mar 18, 2006 12:48 pm
Re: Lua spells not always using mana or energy
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.
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.
Last edited by AnonymousHero on Sun Oct 20, 2013 7:15 am, edited 1 time in total.
-
- Uruivellas
- Posts: 718
- Joined: Tue Dec 13, 2005 12:35 am
Re: Lua spells not always using mana or energy
Thank you (and blech). I will see if I can do something about it.
-
- Uruivellas
- Posts: 718
- Joined: Tue Dec 13, 2005 12:35 am
Re: Lua spells not always using mana or energy
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?
-
- Spiderkin
- Posts: 482
- Joined: Sat Mar 18, 2006 12:48 pm
Re: Lua spells not always using mana or energy
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).
-
- Uruivellas
- Posts: 718
- Joined: Tue Dec 13, 2005 12:35 am
Re: Lua spells not always using mana or energy
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...)
(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...)
-
- Uruivellas
- Posts: 718
- Joined: Tue Dec 13, 2005 12:35 am
Re: Lua spells not always using mana or energy
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.