Staredit Network > Forums > SC1 UMS Mapmaking Assistance > Topic: Incremental Unit Cost
Incremental Unit Cost
Jun 29 2019, 6:34 am
By: junj  

Jun 29 2019, 6:34 am junj Post #1



I want to have incremental costs (similar to upgrades), when I buy units from a building. Is there a way to do this? I am using EUDs and I can't figure out a way to do this.



None.

Jun 29 2019, 10:08 am Suicidal Insanity Post #2

I see you !

Can't you have a trigger that detects units created at the building location, and it updates the units.dat cost setting?




Jun 29 2019, 10:58 am NudeRaider Post #3

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

It's possible without EUDs if you're willing to use a refund system.

The idea is that you have a variable 'cost' that stores the increase in price, while the actual unit price always stays the same. If they built a unit you check if they have at least as much minerals as the value of 'cost'. If not, you refund the unit base price and remove the unit. If yes, you remove as much minerals as the value of 'cost'.

'Cost' could be stored in custom score to display on the leader board, but any regular death counter (DC) works. Optionally you can also display the added cost in a mineral block next to the factory building.
The comparison of minerals and 'cost' is done via binary countoffs. Here's an example for an increased cost of up to 7 (4+2+1) minerals. Higher increase just means more countoff triggers - which can be added retroactively without needing to change anything else.

A note before you jump into the triggers: Read all the green comments first to understand the structure, otherwise the sheer amount of text might be overwhelming although it's all just mechanically written down.

C: Current Player brings at least 1 Marine to 'building exit'
A: Set dc 'check' to 1 for Current Player
A: Set deaths of 'refund' to 0 for Current Player

// Transfer 'cost' and amount of subtracted minerals to 'refund'
C: Current Player has suffered exactly 1 deaths of 'check'
C: Current Player has accumulated at least 4 Minerals
C: Current Player 'cost' is at least 4
A: Subtract 4 Minerals for Current Player
A: Subtract 4 from 'cost' for Current Player
A: Add 4 to 'refund' for Current Player

C: Current Player has suffered exactly 1 deaths of 'check'
C: Current Player has accumulated at least 2 Minerals
C: Current Player 'cost' is at least 2
A: Subtract 2 Minerals for Current Player
A: Subtract 2 from 'cost' for Current Player
A: Add 2 to 'refund' for Current Player

C: Current Player has suffered exactly 1 deaths of 'check'
C: Current Player has accumulated at least 1 Minerals
C: Current Player 'cost' is at least 1
A: Subtract 1 Minerals for Current Player
A: Subtract 1 from 'cost' for Current Player
A: Add 1 to 'refund' for Current Player

// Player had enough minerals if 'cost' has been reduced to 0:
// Add X (= increase in cost per unit) to 'cost'

C: Current Player has suffered exactly 1 deaths of 'check'
C: Current Player 'cost' is exactly 0
A: Set deaths of 'check' to 2 for Current Player
A: Move 1 Marine from 'building exit' to 'spawn zone'
A: Add X to 'cost' for Current Player

// 'check'=2 => Unit has been built successfully => rebuild 'cost'
C: Current Player has suffered exactly 2 deaths of 'check'
C: Current Player 'refund' is at least 4
A: Add 4 to 'cost' for Current Player

C: Current Player has suffered exactly 2 deaths of 'check'
C: Current Player 'refund' is at least 2
A: Add 2 to 'cost' for Current Player

C: Current Player has suffered exactly 2 deaths of 'check'
C: Current Player 'refund' is at least 1
A: Add 1 to 'cost' for Current Player

// Player had NOT enough minerals if 'cost' has NOT been reduced to 0:
// Y is the base cost of the unit

C: Current Player has suffered exactly 1 deaths of 'check'
C: Current Player 'cost' is at least 1
A: Set deaths of 'check' to 3 for Current Player
A: Display text for Current Player: "You don't have enough minerals to build that. Check the increased costs! Your investment will be refunded."
A: Add Y Minerals for Current Player
A: Remove 1 Marine for Current Player at 'building exit'

// 'check'=3 => Error, not enough minerals => rebuild 'cost' and refund minerals
C: Current Player has suffered exactly 3 deaths of 'check'
C: Current Player 'refund' is at least 4
A: Add 4 to 'cost' for Current Player
A: Add 4 Minerals for Current Player

C: Current Player has suffered exactly 3 deaths of 'check'
C: Current Player 'refund' is at least 2
A: Add 2 to 'cost' for Current Player
A: Add 2 Minerals for Current Player

C: Current Player has suffered exactly 3 deaths of 'check'
C: Current Player 'refund' is at least 1
A: Add 1 to 'cost' for Current Player
A: Add 1 Minerals for Current Player

// Reset variable(s):
C: Always
A: Set 'check' to 0 for Current Player

Notes:
  • Trigger owner should be the player force(s)
  • Trigger order is crucial or it won't work
  • Make sure to prevent units from being brought back to 'building exit'
  • Everything happens within 1 trigger loop
  • To include gas costs you'd need to copy the system and use a 2nd set of variables. Use 'check' to link both systems. So instead of taking action when 'check' is determined to 2 use it to start the gas triggers.
  • Trigger-wise this looks unwieldy, but it really is just a lot of copy and paste and in-game it should work pretty well.
  • If you want to do this for multiple units, you theoretically would have to make a copy of this system for every unit and store the cost in a separate variable. But by clever use of 'check' you can reuse the count-off parts which you probably have not just 3 (2^(3+1)-1) of like in my example here, but maybe 10 if you want to raise cost by up to 2^(10+1)-1 = 2047 Minerals.





Jun 29 2019, 12:02 pm Suicidal Insanity Post #4

I see you !

If you can only train one type of unit per building you could refine that system and only give ownership of the building to the player if he has enough monies.




Jun 29 2019, 3:46 pm MTiger156 Post #5



A little more elaboration to the original question would be useful.
Is unit cost determined by how many a player commands (not counting dead), or by the total bought (including dead)?
The trickiest part is making the game properly detect newly made units. I would recommend putting the production buildings in a corner of the map (off the "field of play") if possible.

That way, you have a single trigger per unit such as...
(assuming cost is determined by total bought)

C: player brings at least 1 (unit) to (production area)
A: move 1 (unit) from (production area) to (field of play)
EUD Action: "AddDatFile" -> units.dat -> (unit) -> mineral cost -> (value to add)

Note: these triggers would need to be built in EUD Editor's "Trigger Editor" in order to mix normal and EUD actions like this.




Jun 29 2019, 4:51 pm junj Post #6



The way I am currently doing this, It's an upgrade (replaced upgrade icon with a unit icon) that you research with a gas detection system. When user has 0 gas the unit gets created at a location. The problem with that though is I am stuck on 1 location. I want to make the unit go to multiple locations depending on where the unit was researched/bought.



None.

Jun 29 2019, 7:04 pm MTiger156 Post #7



I see. The "multiple location" problem is very difficult because the unit creation is the action, not condition. While this is a good attempt without heavy EUDs, improving on this method would involve much more extensive work. You would need to program numerous upgrade types for all the possible unit types and spawn locations.

(# of unit types) X (number of spawn locations)

...and even if that was accomplished, the cost of each unit would become inconsistent based on the frequency each location is used.
I highly recommend switching the buy mechanic to production buildings (1 barracks / factory / starport / ETC per spawn location).

As an example with 2 spawn locations, each unit's triggers would look like:

C: player brings at least 1 (unit) to (production loc. 1)
A: move 1 (unit) from (production loc. 1) to (spawn loc. 1)
A: set switch "increment (unit) cost"

C: player brings at least 1 (unit) to (production loc. 2)
A: move 1 (unit) from (production loc. 2) to (spawn loc. 2)
A: set switch "increment (unit) cost"

C: switch "increment (unit) cost" is set
A: EUD "AddDatFile" -> units.dat -> (unit) -> gas cost -> (value to add)
A: clear switch "increment (unit) cost"

There is no need to go through the custom upgrade/gas checking this way.




Jun 29 2019, 9:44 pm NudeRaider Post #8

We can't explain the universe, just describe it; and we don't know whether our theories are true, we just know they're not wrong. >Harald Lesch

incidentially the non-EUD solution doesn't suffer from the location limitation as long as you have free locations to place at the building exit.

But with EUDs, can't you detect when an upgrade is being researched in a building? Should be possible to center a location on this building then.




Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[05:43 pm]
Zoan -- NudeRaider
NudeRaider shouted: Zoan yes you can.
oh, yeah you’re right. Then yeah if you use an ai script it should be easy to farm unfinished buildings in some unused area on the map and just move them around, right?
[2019-10-17. : 6:06 am]
NudeRaider -- KrayZee
KrayZee shouted: Voyager7456 Somehow I misread your shout. "Glad I can entertain you in Nude" as if you sent a racy photo, video or something.
nah, he just made a comment that had us laughing very hard.
[2019-10-17. : 6:02 am]
NudeRaider -- Zoan
Zoan shouted: sraw531 you can’t move buildings afaik
yes you can.
[2019-10-16. : 10:03 pm]
Dem0n -- no
[2019-10-16. : 8:26 pm]
GGmano -- Is here a forum only for temple siege?
[2019-10-16. : 4:20 pm]
KrayZee -- Voyager7456
Voyager7456 shouted: Glad I can entertain you Nude
Somehow I misread your shout. "Glad I can entertain you in Nude" as if you sent a racy photo, video or something.
[2019-10-16. : 2:26 pm]
martosss -- Moose
Moose shouted: martosss IIRC, the plan was to go 64-bit only eventually so they're interested in differences between the versions
well I might have found 1 bug for them to fix - some maps load on 32 bit, but not on 64 bit game version
[2019-10-16. : 2:19 pm]
Zoan -- sraw531
sraw531 shouted: I'm pretty sure you would move the building away at some point. When you do so, you can give it to someone else. I was thinking nexi because its possible you could encourage the computer to expand to a specific spot
you can’t move buildings afaik
[2019-10-16. : 10:10 am]
Moose -- martosss
martosss shouted: jjf28 OK, I have 1 more question - are you using 32 bit SC:R or 64 bit ? In game settings there's an option to switch to 32, is it checked? I just tried hosting the map with 64-bit SC:R and it failed... I ticked the option to use 32 bit SC:R => it worked and map was hosted. So I guess the issue still exists for 64 bit SC:R ? I also tried calling a friend and he couldn't see the map when he entered the lobby. Weird, I might have to report this to Blizzard?
IIRC, the plan was to go 64-bit only eventually so they're interested in differences between the versions
[2019-10-16. : 5:27 am]
O)FaRTy1billion[MM] -- or a magic box :(
Please log in to shout.


Members Online: Oh_Man, Roy, ikucesus, MTiger156, yxevyt