Skip to content

Commit

Permalink
randomize MissionSiteModifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Jamrozik committed Jun 22, 2024
1 parent 68a7ab1 commit 497f8a8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/game-lib/Lib/IRandomGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface IRandomGen
int Roll0To(int n);
int Roll(int min, int max);
int Roll((int min, int max) range);
int Roll(int @base, int min, int max);
float RollFloat(float min, float max);
int Roll(Range range);
T Pick<T>(List<T> items);
Expand Down
11 changes: 8 additions & 3 deletions src/game-lib/Lib/RandomGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public int Roll(int min, int max)
public int Roll((int min, int max) range)
{
return Roll(range.min, range.max);
}
}

public int Roll(int @base, int min, int max)
{
return @base + Roll(min, max);
}

public float RollFloat(float min, float max)
{
Expand Down Expand Up @@ -77,12 +82,12 @@ public virtual int RandomizeMissionSiteCountdown()

public (int result, float variationRoll) RollVariation(int baseValue, int min, int max, int precision)
{
// e.g. -15 = Roll(-30, 30)
// e.g. -15 = Roll(-30, 30)
int variationRoll = Roll(min, max);
// e.g. 85 = 100 + (-15)
int modifier = precision + variationRoll;
// e.g. 42 = 50 * 85 / 100
int result = baseValue * modifier / precision;
return (result, variationRoll: variationRoll / (float)precision);
}
}
}
2 changes: 1 addition & 1 deletion src/game-lib/Model/Faction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public List<MissionSite> CreateMissionSites(
var site = new MissionSite(
siteId,
this,
MissionSiteModifiers.Compute(),
MissionSiteModifiers.Compute(randomGen, this),
difficulty,
turnAppeared: state.Timeline.CurrentTurn,
expiresIn: Ruleset.MissionSiteTurnsUntilExpiration);
Expand Down
47 changes: 36 additions & 11 deletions src/game-lib/Model/MissionSiteModifiers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using UfoGameLib.Lib;

namespace UfoGameLib.Model;

Expand Down Expand Up @@ -63,20 +64,44 @@ public MissionSiteModifiers(
{
}

public static MissionSiteModifiers Compute()
// kja introduce FactionsRuleset for this and other Faction based rules
public static MissionSiteModifiers Compute(IRandomGen randomGen, Faction faction)
{
// kja add randomization logic to compute the modifiers.
// The formula I am thinking about will be something like that:
// 1. Base value = Some constant + Some value from faction power
// 2. Roll variation from 0.7 to 1.3 (like RollMissionSiteDifficulty)
// 3. Return the Base value * Rolled variation
// kja these formulas should depend on factions.
// E.g.:
// - Black Lotus is average / baseline
// - EXALT provides more intel than average
// - Red Dawn provides more money than average
// - Zombies provide:
// - zero intel
// - much less funding
// - and support rewards and penalties are amplified

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

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

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

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

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

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

// kja move these consts to Ruleset
return new MissionSiteModifiers(
fundingReward: 5,
supportReward: 20,
fundingPenalty: 1,
supportPenalty: 5
moneyReward: moneyReward,
intelReward: intelReward,
fundingReward: fundingReward,
supportReward: supportReward,
fundingPenalty: fundingPenalty,
supportPenalty: supportPenalty
);
}

Expand Down
7 changes: 4 additions & 3 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 MissionSiteDifficultyFactionPowerDivisor = 10;
public const int FactionPowerPrecision = 10;
public const int FactionPowerIncreaseAccumulationThreshold = 100;

// For more example factions data, see:
Expand Down Expand Up @@ -75,15 +75,16 @@ private static int SkillFromMissions(Agent agent)
}

public static (int difficulty, int baseDifficulty, float variationRoll) RollMissionSiteDifficulty(
IRandomGen randomGen, int factionPower)
IRandomGen randomGen,
int factionPower)
{
// Note that currently the only ways of increasing agents survivability of difficulty is:
// - by surviving missions
// - via training
// 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 / MissionSiteDifficultyFactionPowerDivisor;
int baseDifficulty = factionPower / FactionPowerPrecision;
(int difficulty, float variationRoll) = randomGen.RollVariation(
baseValue: baseDifficulty,
range: MissionSiteDifficultyVariationRange,
Expand Down

0 comments on commit 497f8a8

Please sign in to comment.