Modify upgrade costs?

Dizzy75

Warlord
Joined
Mar 22, 2006
Messages
245
Hello modders,

Does anyone know of a way to modify the cost of a unit upgrade for a specific unit?

Here's my overall goal: I want to create a unique unit upgrade progression

Unit 1 -> Unit 2 -> Unit 3

where Unit 2 and Unit 3 are each unlocked by successively higher techs. That part is no problem.

However, I want to make it so that Units 2 and 3 cannot be built in cities; that is, the only way to obtain them is by upgrading Unit 1.

I can remove them from the city build list by setting <Cost> to -1. However, when I do this, the cost to upgrade Unit 1 -> Unit 2 becomes only 10 gold, which I assume is some sort of global minimum. Does anyone know of a way to increase this? Or does anyone know of another way to remove units from the city build list?
 
Can be achieved via LUA using GameEvents.PlayerCanTrain(playerID, unitTypeID)

EDIT: I just realized the correct function is GameEvents.CityCanTrain(ownerID, cityID, unitTypeID). The original one I c/p above checks if the player can construct the unit (i.e. making units unique via LUA function).

This event returns a boolean result based on your criteria entered within the function.

Thus all units are buildable, but the function above checks if player has selected unit 2/3 and then returns false meaning not allowed to be built in city. You can get more specific within the function and check which city is trying to build it so that you can further restrict by location.

Hope this help.
 
Thanks for the response - good to know disabling units can be done another way. I think that may be a bit too "intrusive" for me, though! Just out of curiosity, would this mean the unit appears in the Build menu, but is grayed out?

I suppose it's not a big deal, and the game probably wasn't designed to accommodate a mechanic like this. Thanks, though!
 
Have not tried it yet (plan to in my mod), but from what I have read it removes it from the list as opposed to greyed out.
 
Found the solution: There's a column in the "UnitPromotions" table called "UpgradeDiscount". Set it to a (large) negative integer and you can increase a specific unit's upgrade costs (of course, you have to assign the promotion to the unit). I missed it because I was assuming it was a unit property, rather than a possible promotion.

Combined with setting Cost to -1, this removes the unit from all city build menus while still allowing you to upgrade to the unit at a "reasonable" cost. :) No need to mess around with LUAs!
 
Different question: It seems that you can enable units/buildings to be purchased with Faith without taking any Beliefs (like Holy Warriors) via the <RequiresFaithPurchaseEnabled> flag. However, if you do this, the unit/building will ALWAYS show up in the city Purchase menu.

In other words, it ignores all requirements, such as Tech or prerequisite buildings (although you can't do it unless you've founded a religion). For example, you could get a Giant Death Robot to show up in the purchase menu as soon as you found a religion. I wonder if there's any way to enforce requirements even if you enable purchasing with Faith?
 
Top Bottom