Skip to content

Commit

Permalink
Log individual maintenance components & many more
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jun 30, 2023
1 parent 3c6261f commit 79f1f5e
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 48 deletions.
58 changes: 37 additions & 21 deletions Source/CareerLog/CareerLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public LogPeriod CurrentPeriod
{
get
{
if (!IsEnabled) return null;

double time = KSPUtils.GetUT();
while (time > NextPeriodStart)
{
Expand Down Expand Up @@ -598,12 +600,21 @@ private CareerLogDto CreateLogDto(LogPeriod logPeriod)
currentSci = logPeriod.CurrentSci,
rndQueueLength = logPeriod.RnDQueueLength,
scienceEarned = logPeriod.ScienceEarned,
salaryEngineers = logPeriod.SalaryEngineers,
salaryResearchers = logPeriod.SalaryResearchers,
salaryCrew = logPeriod.SalaryCrew,
programFunds = logPeriod.ProgramFunds,
otherFundsEarned = logPeriod.OtherFundsEarned,
launchFees = logPeriod.LaunchFees,
vesselPurchase = logPeriod.VesselPurchase,
vesselRecovery = logPeriod.VesselRecovery,
lcMaintenance = logPeriod.LCMaintenance,
facilityMaintenance = logPeriod.FacilityMaintenance,
maintenanceFees = logPeriod.MaintenanceFees,
trainingFees = logPeriod.TrainingFees,
toolingFees = logPeriod.ToolingFees,
entryCosts = logPeriod.EntryCosts,
spentUnlockCredit = logPeriod.SpentUnlockCredit,
constructionFees = logPeriod.ConstructionFees,
otherFees = logPeriod.OtherFees,
subsidySize = logPeriod.SubsidySize,
Expand Down Expand Up @@ -677,7 +688,7 @@ private void SettingsChanged()

private void CurrenciesModified(CurrencyModifierQuery query)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

float fundsDelta = query.GetTotal(Currency.Funds);
if (fundsDelta != 0f)
Expand All @@ -694,16 +705,11 @@ private void CurrenciesModified(CurrencyModifierQuery query)

private void FundsChanged(float changeDelta, TransactionReasons reason)
{
TransactionReasonsRP0 reasonRP0 = reason.RP0();

_prevFundsChangeAmount = changeDelta;
_prevFundsChangeReason = reason;

if (reason == TransactionReasons.ContractPenalty || reason == TransactionReasons.ContractDecline ||
reason == TransactionReasons.ContractAdvance || reason == TransactionReasons.ContractReward)
{
CurrentPeriod.ContractRewards += changeDelta;
return;
}

if (reason == TransactionReasons.Mission)
{
CurrentPeriod.ProgramFunds += changeDelta;
Expand All @@ -722,19 +728,31 @@ private void FundsChanged(float changeDelta, TransactionReasons reason)
return;
}

if (reason == TransactionReasons.VesselRollout || reason == TransactionReasons.VesselRecovery)
if (reasonRP0 == TransactionReasonsRP0.VesselPurchase)
{
CurrentPeriod.VesselPurchase -= changeDelta;
return;
}

if (reasonRP0 == TransactionReasonsRP0.Rollouts)
{
CurrentPeriod.LaunchFees -= changeDelta;
return;
}

if (reason == TransactionReasonsRP0.PartOrUpgradeUnlock.Stock())
if (reasonRP0 == TransactionReasonsRP0.VesselRecovery)
{
CurrentPeriod.VesselRecovery += changeDelta;
return;
}

if (reasonRP0 == TransactionReasonsRP0.PartOrUpgradeUnlock)
{
CurrentPeriod.EntryCosts -= changeDelta;
return;
}

if (reason == TransactionReasons.StructureConstruction)
if (reasonRP0 == TransactionReasonsRP0.StructureConstruction)
{
CurrentPeriod.ConstructionFees -= changeDelta;
return;
Expand All @@ -761,7 +779,7 @@ private void RepChanged(float repDelta, TransactionReasons reason)

private void ContractAccepted(Contract c)
{
if (CareerEventScope.ShouldIgnore || c.AutoAccept) return; // Do not record the Accept event for record contracts
if (CareerEventScope.ShouldIgnore || !IsEnabled || c.AutoAccept) return; // Do not record the Accept event for record contracts

_contractDict.Add(new ContractEvent(KSPUtils.GetUT())
{
Expand All @@ -775,7 +793,7 @@ private void ContractAccepted(Contract c)

private void ContractCompleted(Contract c)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

_contractDict.Add(new ContractEvent(KSPUtils.GetUT())
{
Expand All @@ -789,7 +807,7 @@ private void ContractCompleted(Contract c)

private void ContractCancelled(Contract c)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

// KSP first takes the contract penalty and then fires the contract events
double fundsChange = 0;
Expand All @@ -811,7 +829,7 @@ private void ContractCancelled(Contract c)

private void ContractFailed(Contract c)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

string internalName = GetContractInternalName(c);
double ut = KSPUtils.GetUT();
Expand Down Expand Up @@ -848,7 +866,7 @@ public void ProgramCompleted(Program p)

private void VesselSituationChange(GameEvents.HostedFromToAction<Vessel, Vessel.Situations> ev)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

// KJR can clobber the vessel back to prelaunch state in case of clamp wobble. Need to exclude such events.
if (!_launched && ev.from == Vessel.Situations.PRELAUNCH && ev.host == FlightGlobals.ActiveVessel)
Expand All @@ -870,7 +888,7 @@ private void VesselSituationChange(GameEvents.HostedFromToAction<Vessel, Vessel.

private void CrewKilled(EventReport data)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

if (!HighLogic.CurrentGame.CrewRoster.Tourist.Any(c => c.name == data.sender)) // Do not count tourist/test animal deaths
{
Expand Down Expand Up @@ -902,8 +920,6 @@ private float GetSciPointTotalFromKCT()

private void OnKctTechCompleted(TechItem tech)
{
if (CareerEventScope.ShouldIgnore) return;

AddTechEvent(tech);
}

Expand Down Expand Up @@ -987,7 +1003,7 @@ private void AddFacilityConstructionEvent(FacilityUpgrade data, ConstructionStat

private void AddLCConstructionEvent(LCConstruction data, LCItem lc, ConstructionState state)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

Guid modId = data?.modId ?? lc.ModID; // Should only happen when LCs are created through code and thus do not have Construction items
if (!_lcs.Any(logLC => logLC.ModID == modId))
Expand All @@ -1007,7 +1023,7 @@ private void AddLCConstructionEvent(LCConstruction data, LCItem lc, Construction

private void AddPadConstructionEvent(PadConstruction data, KCT_LaunchPad lp, ConstructionState state)
{
if (CareerEventScope.ShouldIgnore) return;
if (CareerEventScope.ShouldIgnore || !IsEnabled) return;

Guid id = data?.id ?? lp.id;
LCItem lc = data?.LC ?? lp.LC;
Expand Down
18 changes: 18 additions & 0 deletions Source/CareerLog/CareerLogDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ internal class CareerLogDto
public double currentSci;
public int rndQueueLength;
public double scienceEarned;
public double salaryEngineers;
public double salaryResearchers;
public double salaryCrew;
public double programFunds;
public double otherFundsEarned;
public double launchFees;
public double vesselPurchase;
public double vesselRecovery;
public double lcMaintenance;
public double facilityMaintenance;
public double maintenanceFees;
public double trainingFees;
public double toolingFees;
public double entryCosts;
public double spentUnlockCredit;
public double constructionFees;
public double otherFees;
public double subsidySize;
Expand All @@ -49,12 +58,21 @@ public override string ToString()
$"{nameof(currentSci)}: {currentSci}, " +
$"{nameof(rndQueueLength)}: {rndQueueLength}, " +
$"{nameof(scienceEarned)}: {scienceEarned}, " +
$"{nameof(salaryEngineers)}: {salaryEngineers}, " +
$"{nameof(salaryResearchers)}: {salaryResearchers}, " +
$"{nameof(salaryCrew)}: {salaryCrew}, " +
$"{nameof(programFunds)}: {programFunds}, " +
$"{nameof(otherFundsEarned)}: {otherFundsEarned}, " +
$"{nameof(launchFees)}: {launchFees}, " +
$"{nameof(vesselPurchase)}: {vesselPurchase}, " +
$"{nameof(vesselRecovery)}: {vesselRecovery}, " +
$"{nameof(lcMaintenance)}: {lcMaintenance}, " +
$"{nameof(facilityMaintenance)}: {facilityMaintenance}, " +
$"{nameof(maintenanceFees)}: {maintenanceFees}, " +
$"{nameof(trainingFees)}: {trainingFees}, " +
$"{nameof(toolingFees)}: {toolingFees}, " +
$"{nameof(entryCosts)}: {entryCosts}, " +
$"{nameof(spentUnlockCredit)}: {spentUnlockCredit}, " +
$"{nameof(constructionFees)}: {constructionFees}, " +
$"{nameof(otherFees)}: {otherFees}, " +
$"{nameof(subsidySize)}: {subsidySize}, " +
Expand Down
27 changes: 27 additions & 0 deletions Source/CareerLog/LogPeriod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,45 @@ public class LogPeriod : IConfigNode
[Persistent]
public double ScienceEarned;

[Persistent]
public double SalaryEngineers;

[Persistent]
public double SalaryResearchers;

[Persistent]
public double SalaryCrew;

[Persistent]
public double LaunchFees;

[Persistent]
public double VesselPurchase;

[Persistent]
public double VesselRecovery;

[Persistent]
public double LCMaintenance;

[Persistent]
public double FacilityMaintenance;

[Persistent]
public double MaintenanceFees;

[Persistent]
public double TrainingFees;

[Persistent]
public double ToolingFees;

[Persistent]
public double EntryCosts;

[Persistent]
public double SpentUnlockCredit;

[Persistent]
public double ConstructionFees;

Expand Down
2 changes: 1 addition & 1 deletion Source/KerbalConstructionTime/KerbalConstructionTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ public static void PopUpVesselError(List<BuildListVessel> errored)
foreach (BuildListVessel blv in errored)
{
blv.RemoveFromBuildList(out _);
Utilities.AddFunds(blv.GetTotalCost(), TransactionReasons.VesselRollout);
Utilities.AddFunds(blv.GetTotalCost(), RP0.TransactionReasonsRP0.VesselPurchase);
//remove any associated recon_rollout
}
});
Expand Down
19 changes: 10 additions & 9 deletions Source/KerbalConstructionTime/Utilities/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,7 @@ public static double SpendFunds(double toSpend, TransactionReasons reason)

public static double SpendFunds(double toSpend, TransactionReasonsRP0 reason)
{
if (!CurrentGameIsCareer())
return 0;
KCTDebug.Log($"Removing funds: {toSpend}, New total: {Funding.Instance.Funds - toSpend}");
Funding.Instance.AddFunds(-toSpend, reason.Stock());
return Funding.Instance.Funds;
return SpendFunds(toSpend, reason.Stock());
}

public static double AddFunds(double toAdd, TransactionReasons reason)
Expand All @@ -413,6 +409,11 @@ public static double AddFunds(double toAdd, TransactionReasons reason)
return Funding.Instance.Funds;
}

public static double AddFunds(double toAdd, TransactionReasonsRP0 reason)
{
return AddFunds(toAdd, reason.Stock());
}

public static void ProcessSciPointTotalChange(float changeDelta)
{
// Earned point totals shouldn't decrease. This would only make sense when done through the cheat menu.
Expand Down Expand Up @@ -540,7 +541,7 @@ public static void TryAddVesselToBuildList(BuildListVessel blv, bool skipPartChe

public static void AddVesselToBuildList(BuildListVessel blv)
{
SpendFunds(blv.GetTotalCost(), TransactionReasons.VesselRollout);
SpendFunds(blv.GetTotalCost(), TransactionReasonsRP0.VesselPurchase);

if (blv.Type == BuildListVessel.ListType.SPH)
blv.launchSite = "Runway";
Expand Down Expand Up @@ -596,11 +597,11 @@ public static void TrySaveShipEdits(BuildListVessel editableShip)
usedShipsCost += v.GetTotalCost();
v.RemoveFromBuildList(out _);
}
AddFunds(usedShipsCost, TransactionReasons.VesselRollout);
AddFunds(usedShipsCost, TransactionReasonsRP0.VesselPurchase);

var validator = new VesselBuildValidator();
validator.SuccessAction = (postEditShip2) => SaveShipEdits(editableShip, postEditShip2);
validator.FailureAction = () => SpendFunds(usedShipsCost, TransactionReasons.VesselRollout);
validator.FailureAction = () => SpendFunds(usedShipsCost, TransactionReasonsRP0.VesselPurchase);

validator.ProcessVessel(postEditShip);
}
Expand Down Expand Up @@ -1604,7 +1605,7 @@ public static void ScrapVessel(BuildListVessel b)
{
b.RemoveFromBuildList(out _);
}
AddFunds(b.GetTotalCost(), TransactionReasons.VesselRollout);
AddFunds(b.GetTotalCost(), TransactionReasonsRP0.VesselPurchase);
}

public static void ChangeEngineers(LCItem currentLC, int delta)
Expand Down
Loading

0 comments on commit 79f1f5e

Please sign in to comment.