ToME: the Tales of Maj'Eyal
http://forums.te4.org/

Lua spells not always using mana or energy
http://forums.te4.org/viewtopic.php?f=1&t=38953
Page 1 of 1

Author:  Lord Estraven [ Thu Oct 10, 2013 7:59 pm ]
Post subject:  Lua spells not always using mana or energy

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.)

Author:  Faeryan [ Fri Oct 11, 2013 1:56 pm ]
Post subject:  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.

Author:  Lord Estraven [ Fri Oct 11, 2013 2:40 pm ]
Post subject:  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.

Author:  AnonymousHero [ Tue Oct 15, 2013 6:25 pm ]
Post subject:  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.

Author:  Lord Estraven [ Tue Oct 15, 2013 10:28 pm ]
Post subject:  Re: Lua spells not always using mana or energy

Thank you (and blech). I will see if I can do something about it.

Author:  Lord Estraven [ Fri Oct 18, 2013 3:46 pm ]
Post subject:  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?

Author:  AnonymousHero [ Sun Oct 20, 2013 7:20 am ]
Post subject:  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).

Author:  Lord Estraven [ Fri Nov 01, 2013 1:11 pm ]
Post subject:  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...)

Author:  Lord Estraven [ Thu Dec 26, 2013 2:14 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/