View Issue Details

IDProjectCategoryLast Update
0021206AI War 2[All Projects] Bug - GameplayMay 16, 2019 9:39 am
Reporterwm46Assigned Tox4000Bughunter 
Severityminor 
Status resolvedResolutionfixed 
Product VersionBETA 0.858 Hotfix: The Lobby... Ate My Galaxy? 
Fixed in VersionBETA 0.860 The Lobby Ate My Factions?? 
Summary0021206: Repair amounts from claiming neutrals flows and construction flows are shockingly off
DescriptionI've been doing a bit of digging in the code because I have been noticing that even though I fixed how fleet centerpieces were costing 0 metal to claim, the metal cost to claim is still very, very wrong.

To start with: I put in a bit of debugging code in the MetalFlowPlanning.cs to track down what metal was being spent, how much the HP was expected to change, and how much the hp changed. I also output the EffectiveDeltaTime and tested the claiming at 0.5x speed, 1x speed, and 2x speed. Here's the first two frames for each of the tests on an ArkOne (500,000 hp and 500,000 metal cost for reference):

2x speed:
Target = Ark One
   repairExpected = 499999
   portionNeedingRepair = 0.999755859375
   repairCost = 499877.9296875
   Adjusted repairExpected = 179.77978515625
   Adjusted repairCost = 179.736328125
   EffectiveDeltaTime = 0.19970703125

Target = Ark One
   repairExpected = 400145
   portionNeedingRepair = 0.800048828125
   repairCost = 400024.4140625
   Adjusted repairExpected = 179.790283203125
   Adjusted repairCost = 179.736328125
   EffectiveDeltaTime = 0.19970703125

Expected repair: 180 hp
Actual repair: 99,854 hp (555 : 1 ratio)

1x speed:
Target = Ark One
   repairExpected = 499999
   portionNeedingRepair = 0.999755859375
   repairCost = 499877.9296875
   Adjusted repairExpected = 89.889892578125
   Adjusted repairCost = 89.8681640625
   EffectiveDeltaTime = 0.099853515625

Target = Ark One
   repairExpected = 450072
   portionNeedingRepair = 0.89990234375
   repairCost = 449951.171875
   Adjusted repairExpected = 89.89208984375
   Adjusted repairCost = 89.8681640625
   EffectiveDeltaTime = 0.099853515625

Expected repair: 90 hp
Actual repair: 49,927 hp (555 : 1 ratio)

0.5x speed:
Target = Ark One
   repairExpected = 499999
   portionNeedingRepair = 0.999755859375
   repairCost = 499877.9296875
   Adjusted repairExpected = 44.8349609375
   Adjusted repairCost = 44.82421875
   EffectiveDeltaTime = 0.0498046875

Target = Ark One
   repairExpected = 475096
   portionNeedingRepair = 0.949951171875
   repairCost = 474975.5859375
   Adjusted repairExpected = 44.83544921875
   Adjusted repairCost = 44.82421875
   EffectiveDeltaTime = 0.0498046875

Expected repair: 45 hp
Actual repair: 24,903 hp (553 : 1 ratio)


Looking at the code in Faction.cs for how the metal flow is actually used is even more confusing because of how wrong things turn out. Here's a breakdown of the most important parts of the code:

(From External Code) metalToSpend = Unit Flowrate ( 900 for command station ) * DeltaTime ( 0.1 at 1x speed )
metalToSpend = metalToSpend ( 90 ) * percentMetalDeficitLastFrame ( assume not starved, 1.0 )

repairCost = TypeData.MetalCostToClaim ( 500,000 for Arks ) * ( HP Lost ( 499,999 ) / HP Max ( 500,000 ) ) * DeltaTime ( 0.1 )
repairExpected = TypeData.MetalCostToClaim ( 500,000 - Repairing by metal cost? )
repairExpected = repairExpected ( 500,000 ) * DeltaTime ( 0.1 )

ratio = metalToSpend ( 90 ) / repairCost ( 49,999.9 )
repairExpected = repairExpected ( 50,000 ) * ratio ( 0.0018 )
repairCost = metalToSpend ( 90 )

entity.HullRepair( repairExpected ( 90 ) )

90 != 49,927 ( !! )

Now I don't know why the metal cost and amount healed get multiplied by the DeltaTime. Those get canceled out in the end by being both in the numerator and denominator, so they wouldn't matter anyways. DeltaTime does affect the amount healed because the flow rate from XML is multiplied by DeltaTime before it gets sent to the core.

There's a minor error that's easily fixed in the code, when the amount to be healed is set to the metal cost instead of the missing HP.

The main thing is why is the healing done not equal to the number it's fed? The exact same calculation is done in the external code (slightly rearranged) which gives the proper answer of 90 when printed to a debug string. By all accounts the two numbers should be the exact same.

Anyone have any ideas?
TagsNo tags attached.

Activities

x4000Bughunter

May 15, 2019 4:36 pm

administrator   ~0051600

I don't have any super bright ideas on it, but I would not be opposed to the math on this being rewritten to something more sane. I kind of inherited the math in one state, and then had to rejigger it to do something else entirely. So that's probably why things are off.

wm46

May 16, 2019 4:12 am

reporter   ~0051613

Last edited: May 16, 2019 9:38 am

View 2 revisions

Fixed.

HullPointsLost and HullPoints needed to be cast to FInt when doing the division for calculating repairCost. Essentially it was always calculating the initial repair cost to be 0, dividing by 0 (and somehow not exploding), and healing for that amount.

Also added the same kind of healing logic to self construction, so constructing by 1% increases the hp by 1% (and also the shield too, always annoyed me how bubble shields spawned with 20% shield).

x4000Bughunter

May 16, 2019 9:39 am

administrator   ~0051615

Wonderful, thank you for this! I have a feeling that now we may wind up seeing a bunch of balance issues around metal costs, but at least those can be dealt with.

Issue History

Date Modified Username Field Change
May 15, 2019 2:15 am wm46 New Issue
May 15, 2019 4:36 pm x4000Bughunter Note Added: 0051600
May 16, 2019 4:12 am wm46 Note Added: 0051613
May 16, 2019 9:38 am x4000Bughunter Note Edited: 0051613 View Revisions
May 16, 2019 9:39 am x4000Bughunter Assigned To => x4000Bughunter
May 16, 2019 9:39 am x4000Bughunter Status new => resolved
May 16, 2019 9:39 am x4000Bughunter Resolution open => fixed
May 16, 2019 9:39 am x4000Bughunter Fixed in Version => BETA 0.860 The Lobby Ate My Factions??
May 16, 2019 9:39 am x4000Bughunter Note Added: 0051615