Alpha Centauri 2

Sid Meier's Alpha Centauri & Alien Crossfire => Modding => Topic started by: Yitzi on February 08, 2013, 04:15:06 AM

Title: Another thing I discovered about the unit cost formula
Post by: Yitzi on February 08, 2013, 04:15:06 AM
The minimum weapon cost is not equal to half the armor cost as the datalinks say, but rather half the sum of the armor cost and chassis cost.  (It doesn't give extra cost for a unit with bonuses in multiple areas unless it's actually above 1, though).  Thus, a 1/4/2 unit costs 3X(4+2)/4=4.5, rounded up to 5 rows.
Title: Re: Another thing I discovered about the unit cost formula
Post by: TarMinyatur on February 16, 2013, 05:26:51 PM
Let's look at a 6-5-10 Needlejet, Fission reactor. The workshop says it costs 70 minerals.

Armor cost is doubled for Air. So Armor = 10?

Minimum Weapon Cost = 1/2 x (A + S)
W = 1/2 x (10 + 10)
W = 1/2 x 20
W = 10?

Cost is calculated as if the unit were a "10"-"10"-10?

Cost = W x (A + S) x 1/16   ; Reactor = 1/4, Air multiple = 1/4. So together = 1/16.
Cost = 10 x 20 x 1/16
Cost = 12.5 rows
Add + 1 row because W & A > 1. That's 13.5 rows.
Round up to 14, which is 140 minerals. This isn't the right formula.

Hmm, let's say that the Minimum Weapon value for Air units is indeed "1/2 x A".
Minimum Weapon Cost = 1/2 x 10 = 5
But Missiles have > 5 value, so ignore the 5? Stay with the 6.

Calculate a 6-"10"-10...

Cost = W x (A+S) x 1/16
Cost = 6 x 20 x 1/16
Cost = 7.5 rows
Add + 1 row because W & A > 1. That gives 8.5. Round up to 9?
Total Cost = 90 minerals. That's still more than 70.

What if Air units don't obey the "If W & A > 1, then +1 row" rule?
Well, that brings the cost down to 80 minerals.

Hmm, what if the Minimum Weapon can be less than the weapon's attack rating?
If so, we calculate for a "5"-"10"-10...

Cost = 5 x 20 x 1/16 =  6.25 rows
Round up to 7. Finally, we get 70 minerals.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on February 17, 2013, 01:01:39 AM
A 6-5-10 needlejet only has an 8-movement chassis; the other 2 are because air units get +2 movement per reactor.  Thus, it should be 9X(10+8)/16=11, plus 2, which isn't right.  Furthermore, 8/5/10 needlejets cost more, but 5/5/10 needlejets don't cost less, so that means that it's treating the weapon cost as either 6 or 7.  If it's 7, then 7X18/16 rounds up to 8, which doesn't work, so it must be a weapon cost of 6, for 6X(10+8) rounds up to 7. 

Now, this would seem to support your theory about air units ignoring the "if armor and weapon both more than 1" rule (further borne out by the fact that a 1/5/10 costs as much as a 6/5/10, whereas a 1/4/1 does not cost as much as a 2/4/1), but there's a complication: If we look at a 2/6/10, it costs 10 rows, but a 1/6/10 costs only 9 rows, so that rule does apply, sometimes.  So for armored air units it's a bit of a mystery at the moment.
But it gets worse...Remember that a 1/6/10 costs 9 rows with a fission reactor?  Well, with a fusion reactor it costs 14 rows.  i.e. armored aircraft can go up in price as you improve the reactor.  So clearly something special is going on in that case.
Title: Re: Another thing I discovered about the unit cost formula
Post by: TarMinyatur on February 19, 2013, 02:58:22 AM
Interesting.

A 1-4-1 Infantry, with Fission reactor, costs 30 minerals.

Let's see...

That would be a "2.5"-4-1 unit. Round that to 2-4-1 or 3-4-1.

"2" x 5 x 1/8 = 1.25 rows
That's 20 minerals.

or

"3" x 5 x 1/8 = 1.875 rows
That's 20 minerals, too.

How can a 1-4-1 cost 30 minerals? Does the code upgrade the weapon from Laser to Impactor? There is no level-3 weapon by default. So Hand = 1, Laser = 2, Impactor = 3 to 4, Gatling = 5, etc

A "4"-4-1 would cost 4 x 5 x 1/8 = 2.5 rows, which is 30 minerals.

Odd, if true.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on February 19, 2013, 03:20:45 AM
I think that it's rounding to 3, but when the cost is halved for infantry, it actually increases it a bit then halves it rounding up (the easiest way to see this is supply crawlers; if they were actually halved, they'd cost 8X(1+1)/8=2 rows, not 3 rows as they actually do.)
Title: Re: Another thing I discovered about the unit cost formula
Post by: TarMinyatur on February 19, 2013, 03:21:16 PM
Ah, I see. Thanks.

The 1-4-1 is initially a "3"-4-1, as figured by Minimum_W = 1/2 (4+1)

Perhaps that W, a three, is multiplied by 1/2 for Speed-1 units. So we get a "1.5" weapon, which is rounded up to a 2.

Calculate for a "2"-4-1 Silksteel Garrison
Cost = 2 x 5 x 1/4  ; reactor multiple is 1/4
Cost = 2.5
Round up to 3 rows
30 minerals

I also wondered why Fusion reactors increased the cost of Formers.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on February 19, 2013, 03:25:06 PM
Fusion reactors increase former cost because formers only cost 2 rows but fusion reactors set a minimum of 3 rows cost.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on February 19, 2013, 05:17:14 PM
Ok, I've looked at the actual program, and think I have the formula (my first post was wrong, by the way), so I'll post it once I take care of a few things.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on February 19, 2013, 06:26:39 PM
Ok, the actual formula (which someone else can take care of posting to the wiki), if I read things right:
Except where otherwise noted, all fractions are rounded toward 0 (down if positive, up if negative).  Major divergences from the datalinks formula are italicized.
-Find the cost of the unit's armor.  If it is a sea unit, divide by 2; if it is an air unit with armor cost more than 1, multiply by twice its reactor value.
-Take the new armor cost, halve it, and add 1.  If the weapon costs less than this, use this instead of weapon cost.
-Find the cost of the unit's chassis.  If it is a sea unit, add the unit's reactor; if it is an air unit add twice the unit's reactor (which, without mods, brings it up to its speed).
-Using these modified values, calculate WeaponX(Armor+Speed)/2^(Reactor+1), rounding normally (less than .5 rounds down; more than .5 rounds up)
-If the (modified) chassis cost is 1, divide by 2 and add 1.
-If the unmodified weapon and armor cost are both more than 1, add 1.  If it is a land unit and the chassis cost is also more than 1, add another 1.
-If it is a sea unit which is not an probe team, divide by two, rounding up.
-If it is an air unit, divide the result by 4 if it is a combat unit, or 2 for a noncombat unit.
-However, unless the (modified) weapon cost, armor cost, chassis cost, and reactor are all 1, there is a minimum of ReactorX2-(Reactor/2)
-Now add 25% for each point of ability cost, rounding normally.  This is the unit cost in rows.
-Planet buster missiles ignore all of the above calculations; their cost in rows is simply the weapon cost.
Title: Re: Another thing I discovered about the unit cost formula
Post by: TarMinyatur on February 20, 2013, 12:07:11 AM
...Find the cost of the unit's chassis.  If it a sea unit, add the unit's reactor; if it is an air unit add twice the unit's reactor (which, without mods, brings it up to its speed).
-Using these modified values, calculate WeaponX(Armor+Speed)/2^(Chassis+1), rounding normally (less than .5 rounds down; more than .5 rounds up)
...
-However, unless the (modified) weapon cost, armor cost, chassis cost, and reactor are all 1, there is a minimum of chassisX2-(chassis/2)

Thanks. I am grateful to see this math.

Should "Reactor" replace "Chassis" in the places I've made bold in your quote?
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on February 20, 2013, 12:45:49 AM
...Find the cost of the unit's chassis.  If it a sea unit, add the unit's reactor; if it is an air unit add twice the unit's reactor (which, without mods, brings it up to its speed).
-Using these modified values, calculate WeaponX(Armor+Speed)/2^(Chassis+1), rounding normally (less than .5 rounds down; more than .5 rounds up)
...
-However, unless the (modified) weapon cost, armor cost, chassis cost, and reactor are all 1, there is a minimum of chassisX2-(chassis/2)

Thanks. I am grateful to see this math.

Should "Reactor" replace "Chassis" in the places I've made bold in your quote?

Yes it should, my goof.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Fal on May 03, 2013, 03:31:45 PM
Sorry to revive an old topic, but I can't get the math to work out correctly in some cases.  I was looking to compare the cost of basic terraformers, crawlers, and colony pods between infantry and foil chassis versions.  Here are the costs:

Land Formers - 2 Rows
Sea Formers - 4 Rows
Land Crawlers - 3 Rows
Sea Crawlers - 5 Rows
Land Colony Pods - 3 Rows
Sea Colony Pods - 7 Rows

These are the equipment costs for each of the 3 modules:
Terraformers - 6
Crawlers - 8
Colony Pods - 10

I assume my mistake comes in rounding somewhere, but I can't figure out how to change it to make all of these numbers come out correctly.  To start with, the "weapon" cost of these units always exceeds the minimum based on armor, so we can ignore that step.  The chassis cost is also simple - 1 for the infantry's, 5 for the foils (4 base + 1 reactor).  The armor cost for the infantry chassis is 1, but I'm unsure for the foil.  According to your post I should divide the armor cost by 2, so 1 / 2 = 0.5.  I'm not sure if that rounds to 0 or 1.

Regardless, the armor + chassis cost for infantry units is 2 and for foil units is 5 or 6.  With that in mind, here are my calculations.

Infantry Terraformer - 6 * 2 / 4 = 3
Infantry Crawler - 8 * 2 / 4 = 4
Infantry Colony Pod - 10 * 2 / 4 = 5

Since their modified chassis cost is 1 we divide by 2 and add 1:

Terraformer - 3 / 2 = 1.5.  To make the cost come out correctly we have to round down to 1, then add 1 for 1 + 1 = 2 Rows.
Crawler - 4 / 2 = 2 + 1 = 3 Rows
Colony Pod - 5 / 2 = 2.5.  To make the cost come out correctly we have to round down to 2, then add 1 for 2 + 1 = 3 Rows.

This makes me think that a number ending in exactly .5 always rounds down.  But when we get to the sea units we run into a problem.  Based on the above, assume the armor cost is 0 and therefore armor + chassis cost is 5:

Foil Terraformer - 6 * 5 / 4 = 7.5, rounds to 7
Foil Crawler - 8 * 5 / 4 = 10
Foil Colony Pod - 10 * 5 / 4 = 12.5, rounds to 12

Since these are non-artifact sea units we divide these values by 2 for the final cost:

Terraformer - 7 / 2 = 3.5, rounds to 3 which is incorrect
Crawler - 10 / 2 = 5, correct
Colony Pod - 12 / 2 = 6, incorrect

If we assume that armor has a minimum cost of 1 then our armor + chassis cost is 6.  Let's do the math again for this scenario:

Foil Terraformer = 6 * 6 / 4 = 9
Foil Crawler = 8 * 6 / 4 = 12
Foil Colony Pod = 10 * 6 / 4 = 15

Divide by 2 for being non-artifact sea units:

Terraformer - 9 / 2 = 4.5, round down to 4, correct
Crawler - 12 / 2 = 6, incorrect
Colony Pod - 15 / 2 = 7.5, round down to 7, correct

I can't find a consistent rounding logic to make all of the numbers work out.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on May 03, 2013, 05:34:22 PM
Quote
Infantry Terraformer - 6 * 2 / 4 = 3
Infantry Crawler - 8 * 2 / 4 = 4
Infantry Colony Pod - 10 * 2 / 4 = 5

Since their modified chassis cost is 1 we divide by 2 and add 1:

Terraformer - 3 / 2 = 1.5.  To make the cost come out correctly we have to round down to 1, then add 1 for 1 + 1 = 2 Rows.
Crawler - 4 / 2 = 2 + 1 = 3 Rows
Colony Pod - 5 / 2 = 2.5.  To make the cost come out correctly we have to round down to 2, then add 1 for 2 + 1 = 3 Rows.

This makes me think that a number ending in exactly .5 always rounds down.

That is correct; you always round down, except for the "divide by reactor-based amount" step where .5 or higher rounds up.

If you notice, I actually mentioned the rounding rules in my post: You round toward 0 (i.e. down if it's a positive number) for most steps, but when it's time to calculate WeaponX(Armor+Speed)/2^(Reactor+1), you round up for .5 or more.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Fal on May 03, 2013, 05:54:04 PM
I still get the wrong value for sea colony pods then.  Equipment cost is 10, armor cost is modified to 0 (1 / 2 = 0.5, round down to 0), chassis cost is 5 (4 + 1 reactor).  Then the formula would be

10 * 5 / 4 = 12.5, which now rounds up to 13.  Since this is a non-artifact sea unit we divide by 2, so 13 / 2 = 6.5, this time rounding down to 6 rows.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Yitzi on May 03, 2013, 06:55:58 PM
You are correct; I had made a mistake in my formula.  It's fixed now: When halving the total cost for sea units, you round up if it was odd.  So the rules for rounding are:

When dividing by 2^(reactor+1) or halving the value for sea units, round up if more than .5, down if less than .5.  For all other cases, round down.
Title: Re: Another thing I discovered about the unit cost formula
Post by: Fal on May 03, 2013, 07:14:02 PM
Sounds like everything works out then, cool :)
Title: Re: Another thing I discovered about the unit cost formula
Post by: Alpha Centauri Bear on October 26, 2018, 12:39:40 AM
Sorry for reviving this topic but I found another questionable example.
scout rover: 1-1-2*1.
Up to step 8 it calculates as 1. Now at step 9 it should apply minimum cost of Reactor*2-(Reactor/2) since its speed is 2 and it is not an exemption. For fission reactor this minimum computes as 1*2-1/2 = 1.5. Where should we round it to? Based on default rounding rule each step value should round down. So it should make it as 1? Which is incorrect as scout rover costs 2. So should we round this minimum up then? It would be another exception from generic rounding rule. Or maybe I don't understand the rounding rule right. Maybe it is not the each step value calculate but every division should be rounded down. In this case the 1/2 part would be rounded to 0 and minimum would compute as 2. Which is correct.
Title: Re: Another thing I discovered about the unit cost formula
Post by: bvanevery on October 27, 2018, 04:28:38 PM
In general I find integer math to be an archaic game design concept, best avoided in new titles.  What is SMAC's tech tree except a collection of gradually marching integer increments?  It could all be done away with, if there was some consistent regime for increasing various stats by floating point values.
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 4: index+Modifications.english (default), TopicRating/.english (default), PortaMx/PortaMx.english (default), OharaYTEmbed.english (default).
Style sheets: 0: .
Files included: 31 - 840KB. (show)
Queries used: 14.

[Show Queries]