promotion with duration ... in python?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
I have been trying to come up with a good system for "precious fuel" as shown in the Mad Max movies. There is a quantitative resource thread, which is under development, and a fuel modcomp which is done but doesn't do quite what I want. I thought of another way to do it with a set of 5 promotions representing fuel levels.

Level 5 is "full tank", level 4 is "3/4 tank", ... level 1 is "Out Of Gas". What I would like to do is give the "full tank" promotion to a unit when it is created or refueled. Then after 5 turns, it loses the "full" promotion and gains the "3/4 tank" promotion. After another 5 turns it goes to "1/2 tank", etc. None of the promotions make any difference except "Out of Gas". The OOG promotion has a huge move penalty (-5?) and a huge strength penalty (-75%). Tanker trucks would have a mission which resets the promotions for all the units in the stack.

I know the AI won't deal with this. But the other two threads, so far, have the exact same problem. Also, I know this would be a huge pain for WWII type simulations; but it is perfect for "precious fuel" situations like mine.

So, the question is: I don't think I will have time to master the SDK; of course anything is possible in the SDK. Can this be done in python? Is there an existing example which does this, or a standalone snippet which shows the secret? I have written mapscripts and small event handlers in python, so that programming part is no problem.
 
I don't know of a close example, but that's not saying too much :/ I do know that it can definitely be done in python. Basically you need to use pickle to save scriptdata foreach unit consuming fuel, and process all those units, maybe in onBeginGameTurn (which is called when the player ends his turn).

Handling the promos could be done in a number of ways. One way is to have a list containing the sequence, and then just have the scriptdata hold the current list index.

self.timers = ["GAS_100","GAS_75" .. "GAS_0"]

iGas = gc.getInfoTypeForString(self.timers[j])

where j is the data stored in the unit's scriptdata.

except that instead of using gc.getGame() it would be for the unit, and you'd have to have similar code to reset the index when the fuel truck happened. There would be a 2nd variable that would store the count till the next promo change.

The processing looks something like:
Code:
            iP1 = gc.getInfoTypeForString('PROMOTION_GAS_100')
            iP2 = gc.getInfoTypeForString('PROMOTION_GAS_75')
            iP3 = gc.getInfoTypeForString('PROMOTION_GAS_0')
	    for pUnit in py.getUnitList():
	            iUnit = pUnit.getUnitType()
	            if ( iUnit == self.iConsul1ID or iUnit == self.iConsul2ID or iUnit == self.iConsul3ID ):
                          rfreScriptData = pickle.loads( gc.getGame().getScriptData() )
                          j = rfreScriptData['iLegioVCount'] + 1
	                  rfreScriptData['iLegioVCount'] = iNewCount
                          gc.getGame().setScriptData( pickle.dumps(rfreScriptData) )
                          iGas = gc.getInfoTypeForString(self.timers[j])
	                  pUnit.setHasPromotion(iP1, False)
	                  pUnit.setHasPromotion(iP2, False)
	                  pUnit.setHasPromotion(iP3, False)
                          pUnit.setHasPromotion(iGas,True)

The unitType can be used to filter out non-gas units.

Make sure none of this class of promotions is set, and then set the active one.

Also there needs to be code in onUnitCreated to initialize the scriptdata when a unit is created.
 
Why exactly do you need this? Why not just use Grey Fox's fuel modcomp? Instead of stopping all movement when a unit runs out of fuel, simply give it a promotion that does what you said. It's not hard at all - if you can do Python, you can do C++. :)
 
I am not sure if you noticed my post here on the fuel modcomp thread last week. I need a couple of things which the fuel modcomp does not provide.

Although I am a pretty good programmer, the instructions for downloading the five year old compiler release and setting up the project in order to compile the SDK seem pretty ... intimidating. On the other hand, with no previous knowledge of python, I have written a decent mapscript and some interesting event handlers in the past few days.

So I would prefer to see how far I can get with python instead of using the SDK.

BTW, I have the "fuel usage" part completely working, and I'm now trying to get a new mission button to work so that the fuel truck will do something.
 
Well, assuming you can actually download the compiler (it's a pain if you're on dial up), you'll find C++ a much better means of implementing this. It's really not as bad as it first appears, honest! :) I suppose you could do it in Python, but since it's applied to every unit each turn it will likely slow the game down a bit. I ran into the same trouble while trying to do QR solely in Python.

In Grey Fox's mod, having the game give a low fuel promotion to a unit when it runs out of gas is trivial. I've already done it. The special resupply mission is another story entirely. I'm not even sure if that can be done solely in Python, unless you change an existing mission to accommodate it. (I haven't ever coded any new missions, so I don't know.)
 
Couldn't the "mission" be just being in the same plot at the end of the players turn?

It could be done like a spy mission too, just by looking at how many moves are available to the truck at the end of the turn.

If you want the truck to be able to drive around and refuel, then can't a key-combo be used to perform the mission?
 
@gaius: The resupply mission is critical to me. It may be that you have a number of units about to run out of fuel, and you need to choose which ones to refuel. I am sure C++ is better than Python, it's just that adding a new python file is so easy. No recompiles, much less worry about integration with others' work, and so forth.

I'm not planning to use air missions, so there certainly are missions around which I could repurpose. But, I don't quite see how to connect that to my python code which will actually change the fuel-related promotions on the units. Do you know the magic recipe for that?

@primordial: I don't want the mission to happen automatically since the player may have to choose. I have not looked into how to use key combinations; I suppose your suggestion is that I could easily bind something obscure, like shift-alt-control-R, to perform the refuel. I would prefer to have something which is visible in the interface, so I can enable/disable the graphic when appropriate. I think few players will remember key combinations. If I absolutely get stuck on the button approach, I will look into the key combination approach.
 
Update: I have gotten action buttons in python working, and the entire system is done. You can play it by downloading the release in the first post in my Fury Road thread in my sig.
 
Back
Top Bottom