• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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