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

Veteran Mapper

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

Veteran Mapper

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.
[09:24 pm]
Moose -- denis
[05:00 pm]
lil-Inferno -- benis
[10:41 am]
v9bettel -- Nice
[01:39 am]
Ultraviolet -- no u elky skeleton guy, I'll use em better
[2024-4-18. : 10:50 pm]
Vrael -- Ultraviolet
Ultraviolet shouted: How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
hey cut it out I'm getting all the minerals
[2024-4-18. : 10:11 pm]
Ultraviolet -- :P
[2024-4-18. : 10:11 pm]
Ultraviolet -- How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
[2024-4-17. : 11:50 pm]
O)FaRTy1billion[MM] -- nice, now i have more than enough
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- if i don't gamble them away first
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- o, due to a donation i now have enough minerals to send you minerals
Please log in to shout.


Members Online: jjf28