Magic/Square Selection demo mod

Hmmmm... thats interesting because I use negative numbers in the mercenaries mod, great statesman, great doctor and haven't seen any issues...
 
OK, I added the workaround from the action buttons mod and it seems to be working. The first turn two of the buttons were grayed out but after that they work fine.

Someone help me understand the whole negative number thing. We're using negative numbers just so we do collide with the index of an existing button, right? Is there no way to find out how many buttons already exist and then index up from there? Or am I completely missing the point?

Roger Bacon
 
RogerBacon said:
OK, I added the workaround from the action buttons mod and it seems to be working. The first turn two of the buttons were grayed out but after that they work fine.

Someone help me understand the whole negative number thing. We're using negative numbers just so we do collide with the index of an existing button, right? Is there no way to find out how many buttons already exist and then index up from there? Or am I completely missing the point?

Roger Bacon
That's what I had presumed.

I did a test once and I seem to remember that there are ~ 300. Starting at 1000 would certainly work.
 
Yes, that would work, but you'd get the same problem (assuming I am correct about what it is) - if there are only really 300 actions, then action #1000 would also be outside the limits for that array. As far as I can tell, the only way to get Civ4 to pass the action to the cannotHandleAction in the python is to give it an invalid action. There may be a better way, but I haven't found it.
 
Fair enough.

Was having a poke around today and found that some of the negative numbers seemed to activate mouseover info on the actions, which was a bit strange.
 
In the SpellDemo code there is a hurtAll function. I want to modify it so that if a unit dies due to the spell the caster gets 1 exp. The arguments passed in inner are (caster,targetPlot). Is caster the unit? I seem to remember that it is the player's id. How would I modify the spell so that it knows the unit that cast it?

Roger Bacon

[edit]

Never mind. caster is the unit. I'll post the code here just in case anyone want to know it. It was pretty easy.

Does anyone know how to get the correct amount of experience a unit is supposed to get for killing another unit instead of just using 1?

Code:
for i in range(targetPlot.getNumUnits()):
			targetPlot.getUnit(i).changeDamage(amount,gc.getGame().getActivePlayer()) # not sure what the second arg does
			if (targetPlot.getUnit(i).getDamage() >= 100): # Unit died
				caster.setExperience(caster.getExperience()+1, 999)
 
talchas said:
I believe that the reason my thing works at all is that C++ is lazy and accessing a negative array (or something) index works - it just points to some random bit of memory. You can see this if you do "print CyGlobalContext().getPromotionInfo(-1).getSomeProperty()" in the python console - sometimes it will work and give gibberish, sometimes it will error out. Theres a semi-workaround in the ActionButtons mod which essentially goes through and sees which ones crash out and which ones work, and only uses the ones that work, but I haven't backported the changes here because not as many people seemed to be using it. When Firaxis can release the new patch and the SDK, I'll release a new version of ActionButtons that doesn't rely on this hack.
Talchas,

Since I couldn't find your workaround in the action buttons mod I am now just starting off the action buttons number using a random number. Since doing this I haven't gotten the C++ error. Its a hack but I haven't run into any issues yet...
 
The workaround was to link a specific number to a specific action only in CvMainInterface, when each was added succesfully. The inside of the loop was stuck in a try/except to catch the error.
 
This is awesome because it can be used to make a Civ 3 catapult for Civ 4. As we all know the Civ 4 "suicide catapults" are far from realistic. This mod could bring back the long-ranged artillary units.
 
Back
Top Bottom