• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Changing the cost of a unit at run-time

Status
Not open for further replies.
Level 4
Joined
Nov 23, 2007
Messages
113
There is a function GetUnitGoldCost(unitId) etc, but I can't find any way of setting the cost of a unit/upgrade at run time.

I realize this can be done in the object editor when creating the map, but I want to change the cost of certain things depending on game conditions.

For example, how could you change the cost of upgrade to a keep and/or castle using a trigger/jass code?

Is this possible?

Thanks
 
Level 12
Joined
Mar 16, 2006
Messages
992
By creating multiple versions of the same unit using different costs for each variation, you can achieve this effect with a few simple triggers.
 
Level 4
Joined
Nov 23, 2007
Messages
113
From what you're saying, I understand you mean to create different versions of the unit/upgrade with different costs in the object editor, then select from there at run-time. However, I want the code to be able to run on a map that contains default data. I don't want it to be dependent on the map being edited. This is why I need to be able to change the cost at run time.

It's actually to fix a bug in the AI where in a melee map GetUnitGoldCost() returns the combined costs of (for example) a castle (1065 gold) when in realitiy it only costs 360 gold. So what happens is the AI wait until they get 1065 gold to upgrade to a castle thus putting them at a disadvantage over the human player.

To fix this inconsistency in the AI, I at least need to be able to change the cost temporarily, but at run-time only (so it can run with any map - even melee).

Actually, what would be better is if I could change UseRelativeUpgradeCosts at run-time (game constant) since this is the root of the AI bug which does not take this into consideration. But I see no way to access it using code either :( But I'd still have to change the upgrade cost.

THere must be some way to change the cost of an upgrade/unit on the fly in trigger/jass code (I hope).
 
Last edited by a moderator:
Level 4
Joined
Nov 23, 2007
Messages
113
Thanks for the info.

I'll just have to fix the bug in common.ai by writing my own OneBuildLoop() in my AI files instead of calling PlayGame() in main(). Not a big deal, but I was hoping there was a quicker/easier solution.
 
Status
Not open for further replies.
Top