-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: new mission site creation logic, dependend on factions. WIP beca…
…use need to iron out some known bugs.
- Loading branch information
Konrad Jamrozik
committed
Jun 13, 2024
1 parent
f96fec9
commit d421673
Showing
11 changed files
with
108 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,100 @@ | ||
using System.Text.Json.Serialization; | ||
using Lib.Contracts; | ||
using Lib.Json; | ||
using UfoGameLib.Lib; | ||
using UfoGameLib.State; | ||
|
||
namespace UfoGameLib.Model; | ||
|
||
// kja integrate Faction class with the rest of codebase | ||
public class Faction : IIdentifiable | ||
{ | ||
public int Id { get; } | ||
public readonly string Name; | ||
public readonly int Power; | ||
public int MissionSiteCountdown; | ||
public readonly int PowerIncrease; | ||
public readonly int PowerAcceleration; | ||
public readonly int IntelInvested; | ||
|
||
|
||
[JsonConstructor] | ||
public Faction(int id, string name, int power, int powerIncrease, int powerAcceleration, int intelInvested) | ||
public Faction( | ||
int id, | ||
string name, | ||
int power, | ||
int missionSiteCountdown, | ||
int powerIncrease, | ||
int powerAcceleration, | ||
int intelInvested) | ||
{ | ||
Id = id; | ||
Name = name; | ||
Power = power; | ||
MissionSiteCountdown = missionSiteCountdown; | ||
PowerIncrease = powerIncrease; | ||
PowerAcceleration = powerAcceleration; | ||
IntelInvested = intelInvested; | ||
} | ||
|
||
public static Faction Init( | ||
RandomGen randomGen, | ||
int id, | ||
string name, | ||
int power, | ||
int? powerIncrease = null, | ||
int? powerAcceleration = null) | ||
=> new( | ||
id, | ||
name, | ||
power, | ||
RandomizeMissionSiteCountdown(randomGen), | ||
powerIncrease ?? 0, | ||
powerAcceleration ?? 0, | ||
0); | ||
|
||
public Faction DeepClone() | ||
=> new(Id, Name, Power, MissionSiteCountdown, PowerIncrease, PowerAcceleration, IntelInvested); | ||
|
||
public List<MissionSite> CreateMissionSites(ILog log, RandomGen randomGen, GameState state) | ||
{ | ||
return new Faction(Id, Name, Power, PowerIncrease, PowerAcceleration, IntelInvested); | ||
Contract.Assert(MissionSiteCountdown >= 1); | ||
|
||
MissionSiteCountdown--; | ||
if (MissionSiteCountdown > 0) | ||
return []; | ||
|
||
Contract.Assert(MissionSiteCountdown == 0); | ||
MissionSiteCountdown = RandomizeMissionSiteCountdown(randomGen); | ||
|
||
// kja2-simul-feat to make simulation more interesting: create easier missions from time to time and | ||
// make AI player send less experienced soldiers on it. | ||
List<MissionSite> sites = []; | ||
// kja BUG ROOT CAUSE: this must increase the ID, right now it does not. | ||
int siteId = state.NextMissionSiteId; | ||
(int difficulty, int difficultyFromTurn, int roll) = | ||
Ruleset.RollMissionSiteDifficulty(state.Timeline.CurrentTurn, randomGen); | ||
|
||
var site = new MissionSite( | ||
siteId, | ||
this, | ||
difficulty, | ||
turnAppeared: state.Timeline.CurrentTurn, | ||
expiresIn: Ruleset.MissionSiteTurnsUntilExpiration); | ||
|
||
// Note: currently returning only one mission site even though this method supports | ||
// returning a list. | ||
sites.Add(site); | ||
|
||
log.Info( | ||
$"Add {site.LogString} : " + | ||
$"Faction: {Name}, " + | ||
$"difficulty: {difficulty,3}, " + | ||
$"difficultyFromTurn: {difficultyFromTurn,3}, " + | ||
$"difficultyRoll: {roll,2}."); | ||
|
||
return sites; | ||
} | ||
|
||
private static int RandomizeMissionSiteCountdown(RandomGen randomGen) | ||
=> randomGen.Roll(Ruleset.FactionMissionSiteCountdown); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters