post-kerbin-mining-corporation / FarFutureTechnologies

Adds speculative, far-off technologies for mining, propulsion and power generation to Kerbal Space Program
27 stars 20 forks source link

Modifying antimatterScienceCostPerUnit does not work fully as intended #160

Closed Spacemike closed 3 years ago

Spacemike commented 3 years ago

Let me give a bit of an example to explain the issue, say you have exactly 500 science that you want to all turn into antimatter, by keeping the antimatterScienceCostPerUnit as 1, it will use 500 science and give you 500 antimatter. However, if you change this value to 0.1, you'd expect the game the take that 500 science and give you 5000, but instead, it only gives you 50 antimatter and uses 5 science instead. I believe the cause of this issue is line 77 in the AntimatterManager.cs file under the FillTanks() function. The current operation going on there is: double scienceMaxAM = ResearchAndDevelopment.Instance.Science FarFutureTechnologySettings.antimatterScienceCostPerUnit; Which, I believe should be division instead of multiplication, since 500 0.1 = 50 instead of 500/0.1 = 5000. Although, one thing to take note of was that this would cause a divide by zero error if you tried to turn off the science consumption. And I did also notice how you had a variable called "cost" that you declared but don't actually seem to use anywhere, so, unless I'm a confused on something, this should work fine: `(Random Text because github's code thing doesn't want to work properly for the first line)

      double toLoad = 0d;
      double partAM = 0d;
      double partMaxAM = 0d;
      double toLoadAgain = 0d;

      // Find tank capacities
      tank.part.GetConnectedResourceTotals(PartResourceLibrary.Instance.GetDefinition(tank.FuelName).id,
      ResourceFlowMode.NO_FLOW, out partAM, out partMaxAM, true);

      if (totalAntimatterLoad < partMaxAM)
        toLoad = partMaxAM - totalAntimatterLoad;
      else
        toLoad = partMaxAM;

      if (FarFutureTechnologySettings.antimatterScienceCostPerUnit != 0) {
        double scienceMaxAM = ResearchAndDevelopment.Instance.Science / FarFutureTechnologySettings.antimatterScienceCostPerUnit;
        toLoadAgain = Math.Min(scienceMaxAM, toLoad);
        ResearchAndDevelopment.Instance.AddScience((float)-toLoadAgain* FarFutureTechnologySettings.antimatterScienceCostPerUnit, TransactionReasons.RnDPartPurchase);
      } else
        toLoadAgain = toLoad;

      totalAntimatterLoad -= toLoadAgain;

      tank.part.RequestResource(tank.FuelName, -toLoadAgain, ResourceFlowMode.NO_FLOW);`
ChrisAdderley commented 3 years ago

Fixed in 1.1.1