[python] dynamic control of available promos?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
I have a pickup truck unit in my mod which is highly configurable by promotions. You can add a machine gun, armor, eventually an anti-tank gun, etc. (I hope to have different art for the different combinations but that is a volunteer effort.) There is a technology, engines, which enables a few of the promos and also enables a city building, garage. Today the garage gives new wheeled units a few XP, like a barracks.

My original idea was that as the truck is out in the wilderness gaining experience, it can immediately add on the machine gun, armor etc promotions without coming back to the city. But, players hardly ever use the garage and I was thinking of removing it. Last night I had a different idea: what if these various promos can only be added *in* a garage. That is, the unit would go out, get experience, and then come back to the garage to have the new weapons or armor added. That definitely fits the feel of a truck gradually getting more weaponized.

For this to work, the truck needs to have certain promotions available in the field, and certain additional promotions available only when it is in a city with a garage.

Has anybody ever tried to use python to dynamically control which promotions are available based on the location of the unit? If there was a gameutils callback like canPromote/cannotPromote, like unitCannotMoveInto, this would be trivial. I cannot find any related callback. Any suggestions on how to accomplish this?
 
I'd think the easier approach would be to add a <bRequiresCity> and/or <bRequiresBuildingClass> tag to promotionInfos. Then you would be able to directly limit a promotion that is otherwise available to the unit to only be available while in a City, and with the appropriate building.

As an approach for just python, I'm at a loss, there is no Promotion related Callback, and the best I can see in Python is an "onPromote" def. So exposing the right bits to Python would still require DLL work. I guess you could set up a call in onPromote which would refund the promotion instantly if they did take it out in the field. Or try to get creative in CvMainInterface.py and make the promotions only show up while in a city.
 
I am still resisting learning to modify the SDK, so it would be a python solution. I have mastered adding action buttons (with help!) in python; you mention modifying maininterface. I could try pretending all these location-specific promos are really actions you can only take when (a) XP > level and (b) in a city and (c) city has garage. It would look right to the player, it's just a bunch of buttons, but some of them are the game's promotions and some of them are my action buttons. That may be worth a try.
 
Just remember that doing it this way will NOT prevent the AI from selecting the promotions. And now that I think about it a bit more, it might completley fail to work without informing the DLL that those buttons are being skipped. I remember I once added a few buttons to MainInterface and it just pretended that each one was actually the button which "belonged" there before my modifications (and those buttons pushed past the previous endpoint were just pretty pictures, nothing happened when you interacted with them)
 
I am able to get multiple, working action buttons in python. But good point on the AI, my approach will not work. Unless somebody has a clever suggestion I will give up on this until such day as I start to modify the SDK.
 
Well, you could make it be an action button that requires the unit to be isPromotionReady(), and a result of the action is removing the PromotionReady state (setPromotionReady(false)) and increasing their level by 1 (setLevel(getLevel + 1)). Then make the promotion itself impossible to obtain except when forced by your action button.
 
That part I can do. But, I cannot find a way to make the AI evaluate among these promotions and other promotions and then pick. As I think about it more, I also probably could not get the AI to understand about moving the unit back to a city with a garage for the promotion anyway. Unimplementable overall.
 
In TAM there are "metal" weapons promotions (eg copper, bronze, iron, steel). If you have access to the correct techs + resources, and pass through a city with a forge, the qualifying unit types get the upgrade.

I don't know if there was anything to coerce the AI into going to get the upgrade.

Even if there wasn't, you may just want to do something similar. Enable "AT gun" through a tech (eg "We found a stash of AT weapons"), and then when a truck with the right promos passes through a city with a garage it will get that promo.

You could also use the same method as with the gas trucks. Once a truck is ready, just send it to the coordinate of a garage!
 
If I understand correctly, you are saying that a unit's weapons automagically upgrade when they move through a city with a forge. So if I have a swordsman with copper weapons, and I have the tech for iron weapons, and that unit moves through a city with a forge, then that swordsman automagically gets iron weapons.

As a human player, I would want to make sure to rotate units off the front through cities to get the upgrade. If the AI doesn't do that, then it would only get the upgrades "by accident" and probably not very often.

I was thinking of something slightly different, more along the lines of upgrading a warrior to an axeman with the promotion. That amounts to replacing the "club" weapon with an "axe", resulting in a different base strength and different bonuses vs other unit types. It is not something that would automatically happen. You would want to choose this upgrade vs some other upgrade, like City Raider.

For now I have given up on this idea, and I will allow this to happen with a standard promotion in the field.
 
Back
Top Bottom