Skip to content

Commit 5fa5d86

Browse files
committed
Fix race condition for flareups so player always gets credit
1 parent c330faf commit 5fa5d86

File tree

8 files changed

+77
-30
lines changed

8 files changed

+77
-30
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ then
1313
exit
1414
fi
1515

16-
nodemon -x "~/.dotnet/dotnet build --verbosity normal --configuration Release -p:BattleTechGameDir='$BTPATH' && rm -f 'WarTechIIC.zip' && cd '$BTPATH/Mods/WarTechIIC' && zip -x WartechIIC.log -x WartechIIC.1.log -rq '$PWD/WarTechIIC.zip' ." -w src/ -w WarTechIIC.csproj -e .
16+
nodemon -x "~/.dotnet/dotnet build --verbosity normal --configuration Release -p:BattleTechGameDir='$BTPATH' && rm -f 'WarTechIIC.zip' && cd '$BTPATH/Mods/WarTechIIC' && zip -x WartechIIC.log -x WartechIIC.log.1 -rq '$PWD/WarTechIIC.zip' ." -w src/ -w WarTechIIC.csproj -e .

src/Attack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public virtual string completionText() {
188188
case CompletionResult.DefenderWonUnemployed: return "{1} drives the invasion by {0} from {2}.";
189189
case CompletionResult.DefenderWonEmployerLost: return "{1} drives away the forces {0} sent to invade {2}. Your contract ends on a sour note with the invasion's defeat.";
190190
case CompletionResult.DefenderWonReward: return "{1} drives away the forces {0} sent to invade {2}, leaving you to celebrate victory with your crew - and with a bonus from your employer.";
191-
case CompletionResult.DefenderWonNoReward: return "{0} drives away the forces {1} sent to invade {2}, but your contact informs you that there will be no bonus forthcoming, since you failed to win at least half the offered missions.";
191+
case CompletionResult.DefenderWonNoReward: return "{1} drives away the forces {0} sent to invade {2}, but your contact informs you that there will be no bonus forthcoming, since you failed to win at least half the offered missions.";
192192
}
193193

194194
return "Something went wrong. Attacker: {0}. Defender: {1}. Location: {2}.";

src/ContractManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static Contract getNewProceduralContract(FactionValue employer, FactionVa
7070
MapAndEncounters level = activeMaps.GetNext(false);
7171

7272
var MapEncounterContractData = WIIC.sim.FillMapEncounterContractData(system, difficultyRange, potentialContracts, validParticipants, level);
73+
7374
while (!MapEncounterContractData.HasContracts && activeMaps.ActiveListCount > 0) {
7475
level = activeMaps.GetNext(false);
7576
MapEncounterContractData = WIIC.sim.FillMapEncounterContractData(system, difficultyRange, potentialContracts, validParticipants, level);
@@ -86,7 +87,7 @@ public static Contract getNewProceduralContract(FactionValue employer, FactionVa
8687
GameContext gameContext = new GameContext(WIIC.sim.Context);
8788
gameContext.SetObject(GameContextObjectTagEnum.TargetStarSystem, system);
8889

89-
Contract contract = WIIC.sim.CreateProceduralContract(system, true, level, MapEncounterContractData, gameContext);
90+
Contract contract = WIIC.sim.CreateProceduralContract(system, false, level, MapEncounterContractData, gameContext);
9091

9192
// Restore system and faction to previous values, now that we've forced the game to generate our desired contract.
9293
system.Def.contractEmployerIDs = oldEmployers;

src/ExtendedContract.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ public virtual void acceptContract(string contract) {
321321
}
322322

323323
public virtual void launchContract(Entry entry, Contract contract) {
324+
WIIC.l.Log($"Offering {type} mission ID={contract.Override.ID}.");
324325
if (contract.Override.contractRewardOverride < 0) {
325326
WIIC.l.Log($"contractRewardOverride < 0, generating.");
326327
contract.Override.contractRewardOverride = WIIC.sim.CalculateContractValueByContractType(contract.ContractTypeValue, contract.Override.finalDifficulty, WIIC.sim.Constants.Finances.ContractPricePerDifficulty, WIIC.sim.Constants.Finances.ContractPriceVariance, 0);
@@ -355,10 +356,11 @@ public virtual void launchContract(Entry entry, Contract contract) {
355356

356357
WIIC.l.Log(message);
357358

359+
WIIC.l.Log($"Do we still have ID? ID={contract.Override.ID}.");
358360
SimGameInterruptManager queue = WIIC.sim.GetInterruptQueue();
359361
queue.QueuePauseNotification(title, message, WIIC.sim.GetCrewPortrait(SimGameCrew.Crew_Sumire), string.Empty, delegate {
360362
try {
361-
WIIC.l.Log($"Accepted {type} mission {contract.Override.ID}.");
363+
WIIC.l.Log($"Accepted {type} mission ID={contract.Override.ID}.");
362364

363365
if (!WIIC.sim.CurSystem.SystemContracts.Contains(contract)) {
364366
// Add it to the command center, so that it gets persisted in the pre-drop save.
@@ -386,6 +388,7 @@ public virtual void launchContract(Entry entry, Contract contract) {
386388
if (!queue.IsOpen) {
387389
queue.DisplayIfAvailable();
388390
}
391+
WIIC.l.Log($"Do we still have ID2? ID={contract.Override.ID}.");
389392
}
390393

391394
public virtual void applyDeclinePenalty(DeclinePenalty declinePenalty) {

src/data/mod.json

100755100644
Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
{
2-
"Name": "WarTechIIC",
3-
"Enabled": true,
4-
"Version": "1.0.0",
5-
"Author": "BlueWinds",
6-
"DLL": "WarTechIIC.dll",
7-
"DependsOn": [],
8-
"CustomResourceTypes": [
9-
"ExtendedContractType",
10-
"ExtendedConversation",
11-
"Campaign"
12-
],
13-
"Manifest": [
14-
{ "Type": "ContractOverride", "Path": "contracts" },
15-
{ "Type": "BaseDescriptionDef", "Path": "descriptions" },
16-
{ "Type": "ExtendedContractType", "Path": "extendedContracts" },
17-
{ "Type": "Campaign", "Path": "campaigns" }
18-
],
19-
"Logs": {
20-
"WartechIIC.log": {
21-
"Includes": [
22-
{ "LoggerNames": ["WartechIIC"] }
23-
]
24-
}
25-
}
2+
"Name": "WarTechIIC",
3+
"Enabled": true,
4+
"Hidden": true,
5+
"Version": "1.0.1",
6+
"Author": "BlueWinds",
7+
"DLL": "WarTechIIC.dll",
8+
"DependsOn": [],
9+
"CustomResourceTypes": [
10+
"ExtendedContractType",
11+
"ExtendedConversation",
12+
"Campaign"
13+
],
14+
"Manifest": [
15+
{
16+
"Type": "ContractOverride",
17+
"Path": "contracts"
18+
},
19+
{
20+
"Type": "BaseDescriptionDef",
21+
"Path": "descriptions"
22+
},
23+
{
24+
"Type": "ExtendedContractType",
25+
"Path": "extendedContracts"
26+
},
27+
{
28+
"Type": "Campaign",
29+
"Path": "campaigns"
30+
}
31+
],
32+
"Logs": {
33+
"WartechIIC.log": {
34+
"Include": [
35+
"WartechIIC"
36+
]
37+
}
38+
}
2639
}

src/patches/AAR_ContractObjectivesWidget.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ private static void Postfix(AAR_ContractObjectivesWidget __instance) {
1717
Contract contract = __instance.theContract;
1818
ExtendedContract ec = Utilities.currentExtendedContract();
1919

20+
WIIC.l.Log($"AAR_ContractObjectivesWidget_FillInObjectives: ec={ec}, currentContractName={ec.currentContractName}, Override.ID={contract.Override.ID}");
21+
2022
// Player not working here
2123
if (ec == null || ec.currentContractName != contract.Override.ID) {
2224
return;
@@ -74,7 +76,7 @@ public static class AAR_ContractObjectivesWidget_Init {
7476
private static void Postfix(AAR_ContractObjectivesWidget __instance) {
7577
try {
7678
ExtendedContract ec = Utilities.currentExtendedContract();
77-
WIIC.l.Log($"AAR_ContractObjectivesWidget_Init: contract: {__instance.theContract.Name}, ec={ec}");
79+
WIIC.l.Log($"AAR_ContractObjectivesWidget_Init: ID={__instance.theContract.Override.ID}, ec={ec}");
7880

7981
string eventId = null;
8082

src/patches/AAR_SalvageScreen.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Harmony;
3+
using Localize;
4+
using BattleTech;
5+
using BattleTech.Framework;
6+
using BattleTech.UI;
7+
using UnityEngine;
8+
using HBS;
9+
using HBS.Extensions;
10+
11+
namespace WarTechIIC {
12+
[HarmonyPatch(typeof(AAR_SalvageScreen), "OnCompleted")]
13+
public static class AAR_SalvageScreen_OnCompleted {
14+
private static void Postfix(AAR_SalvageScreen __instance) {
15+
try {
16+
Contract contract = __instance.contract;
17+
ExtendedContract ec = Utilities.currentExtendedContract();
18+
19+
WIIC.l.Log($"AAR_SalvageScreen_OnCompleted: ec={ec}, currentContractName={ec.currentContractName}, Override.ID={contract.Override.ID}");
20+
21+
if (ec?.currentContractName == contract.Override.ID) {
22+
ec.currentContractName = null;
23+
}
24+
} catch (Exception e) {
25+
WIIC.l.LogException(e);
26+
}
27+
}
28+
}
29+
}

src/patches/Contract.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public static void Postfix(Contract __instance, MissionResult result, bool isGoo
2828
return;
2929
}
3030

31-
current.currentContractName = null;
3231
if (__instance.Name != current.currentContractName || current as Attack == null) {
3332
return;
3433
}

0 commit comments

Comments
 (0)