Skip to content

Commit

Permalink
include more data in Report world event
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Jamrozik committed Jun 24, 2024
1 parent 135f735 commit 067fe52
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/game-lib/Controller/TimeAdvancementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public TimeAdvancementController(

CreateMissionSites(state);

// kja add to the report money change and intel change
_worldEvents.Add(new WorldEvent(_eventIdGen.Generate, GameEventName.ReportEvent, [fundingChange, supportChange]));
_worldEvents.Add(
new WorldEvent(
_eventIdGen.Generate,
GameEventName.ReportEvent,
[moneyChange, intelChange, fundingChange, supportChange]));
var worldEvents = new List<WorldEvent>(_worldEvents);
_worldEvents.Clear();

Expand Down
16 changes: 8 additions & 8 deletions src/game-lib/Model/MissionSiteModifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public MissionSiteModifiers(
{
}

// kja introduce FactionsRuleset for this and other Faction based rules
// kja2-refact introduce FactionsRuleset for this and other Faction based rules
public static MissionSiteModifiers Compute(IRandomGen randomGen, Faction faction)
{
// kja these formulas should depend on factions.
// kja2-feat these formulas should depend on factions.
// E.g.:
// - Black Lotus is average / baseline
// - EXALT provides more intel than average
Expand All @@ -77,22 +77,22 @@ public static MissionSiteModifiers Compute(IRandomGen randomGen, Faction faction
// - much less funding
// - and support rewards and penalties are amplified

int baseMoneyReward = faction.Power / Ruleset.FactionPowerPrecision;
int baseMoneyReward = faction.Power / Ruleset.FactionPowerResolution;
(int moneyReward, _) = randomGen.RollVariation(baseMoneyReward, -50, 50, 100);

int baseIntelReward = faction.Power / Ruleset.FactionPowerPrecision;
int baseIntelReward = faction.Power / Ruleset.FactionPowerResolution;
(int intelReward, _) = randomGen.RollVariation(baseIntelReward, -50, 50, 100);

int baseFundingReward = 5 + faction.Power / 10 / Ruleset.FactionPowerPrecision;
int baseFundingReward = 5 + faction.Power / 10 / Ruleset.FactionPowerResolution;
(int fundingReward, _) = randomGen.RollVariation(baseFundingReward, -50, 50, 100);

int baseFundingPenalty = 1 + faction.Power / 10 / Ruleset.FactionPowerPrecision;
int baseFundingPenalty = 1 + faction.Power / 10 / Ruleset.FactionPowerResolution;
(int fundingPenalty, _) = randomGen.RollVariation(baseFundingPenalty, -50, 50, 100);

int baseSupportReward = 20 + faction.Power / 10 / Ruleset.FactionPowerPrecision;
int baseSupportReward = 20 + faction.Power / 10 / Ruleset.FactionPowerResolution;
(int supportReward, _) = randomGen.RollVariation(baseSupportReward, -50, 50, 100);

int baseSupportPenalty = 20 + faction.Power / 10 / Ruleset.FactionPowerPrecision;
int baseSupportPenalty = 20 + faction.Power / 10 / Ruleset.FactionPowerResolution;
(int supportPenalty, _) = randomGen.RollVariation(baseSupportPenalty, -50, 50, 100);

return new MissionSiteModifiers(
Expand Down
8 changes: 4 additions & 4 deletions src/game-lib/Model/Ruleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Ruleset
public const int InitialSupport = 30;
public const int InitialMaxTransportCapacity = 4;

public const int FactionPowerPrecision = 10;
public const int FactionPowerResolution = 10;
public const int FactionPowerIncreaseAccumulationThreshold = 100;

// For more example factions data, see:
Expand All @@ -35,7 +35,7 @@ public static class Ruleset

public const int MissionSiteSurvivalBaseDifficultyRequirement = 30;
public static readonly Range FactionMissionSiteCountdownRange = new Range(3, 10);
public const int MissionSiteDifficultyRollPrecision = 100;
public const int MissionSiteDifficultyRollResolution = 100;
public static readonly (int min, int max) MissionSiteDifficultyVariationRange = (min: -30, max: 30);
public const int MissionSiteTurnsUntilExpiration = 3;

Expand Down Expand Up @@ -84,11 +84,11 @@ public static (int difficulty, int baseDifficulty, float variationRoll) RollMiss
// As such, if difficulty per turn would grow at least as fast as Ruleset.AgentTrainingCoefficient,
// then at some point missions would become impossible, as eventually even the most experienced
// agents would die, and any new agents would never be able to catch up with mission difficulty.
int baseDifficulty = factionPower / FactionPowerPrecision;
int baseDifficulty = factionPower / FactionPowerResolution;
(int difficulty, float variationRoll) = randomGen.RollVariation(
baseValue: baseDifficulty,
range: MissionSiteDifficultyVariationRange,
precision: MissionSiteDifficultyRollPrecision);
precision: MissionSiteDifficultyRollResolution);
return (difficulty, baseDifficulty, variationRoll);
}

Expand Down
2 changes: 1 addition & 1 deletion src/game-lib/State/GameSessionTurn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public GameSessionTurn(
GameState? endState = null,
PlayerActionEvent? advanceTimeEvent = null)
{
EventsUntilStartState = eventsUntilStartState ?? [new WorldEvent(0, GameEventName.ReportEvent, [0, 0])];
EventsUntilStartState = eventsUntilStartState ?? [new WorldEvent(0, GameEventName.ReportEvent, [0, 0, 0, 0])];
StartState = startState;
EventsInTurn = eventsInTurn ?? new List<PlayerActionEvent>();
EndState = endState ?? StartState.Clone();
Expand Down
16 changes: 10 additions & 6 deletions web/src/lib/rendering/renderGameEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const playerActionNameToDisplayMap: {
},
ReportEvent: {
displayedType: 'Report',
displayedDetails: `Funding change: $IDs[0], Support change: $IDs[1]`,
displayedDetails: `Change: Money: $IDs[0] Intel: $IDs[1] Funding: $IDs[2] Support: $IDs[3]`,
},
}

Expand Down Expand Up @@ -85,10 +85,13 @@ function formatString(
let formatted = template
if (!_.isNil(ids)) {
if (!_.isEmpty(ids)) {
formatted = _.replace(formatted, '$IDs[0]', ids[0]!.toString())
}
if (ids.length >= 2) {
formatted = _.replace(formatted, '$IDs[1]', ids[1]!.toString())
for (const index of _.rangeRight(ids.length)) {
formatted = _.replace(
formatted,
`$IDs[${index}]`,
ids[index]!.toString(),
)
}
}
formatted = _.replace(formatted, '$IDs[1..]', logIds(ids.slice(1)))
formatted = _.replace(formatted, '$IDs', logIds(ids))
Expand All @@ -101,5 +104,6 @@ function formatString(
}

function logIds(ids: number[]): string {
return str(ids.sort((left, right) => left - right))
// The "[...id]: spread here is used to avoid mutating the "ids" array."
return str([...ids].sort((left, right) => left - right))
}

0 comments on commit 067fe52

Please sign in to comment.