Skip to content

Commit

Permalink
Track each player's beakers and turns researched
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWerner committed Jan 26, 2025
1 parent 136dbbe commit 41f4e6a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
32 changes: 24 additions & 8 deletions C7/Text/c7-static-map-save.json
Original file line number Diff line number Diff line change
Expand Up @@ -61528,7 +61528,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
},
{
"id": "player-2",
Expand Down Expand Up @@ -61601,7 +61603,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
},
{
"id": "player-3",
Expand Down Expand Up @@ -61674,7 +61678,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
},
{
"id": "player-4",
Expand Down Expand Up @@ -61743,7 +61749,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
},
{
"id": "player-5",
Expand Down Expand Up @@ -61816,7 +61824,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
},
{
"id": "player-6",
Expand Down Expand Up @@ -61893,7 +61903,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
},
{
"id": "player-7",
Expand Down Expand Up @@ -61966,7 +61978,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
},
{
"id": "player-8",
Expand Down Expand Up @@ -62035,7 +62049,9 @@
"luxuryRate": 0,
"scienceRate": 5,
"taxRate": 5,
"gold": 10
"gold": 10,
"beakers": 0,
"turnsResearched": 0
}
],
"barbarianInfo": {
Expand Down
2 changes: 1 addition & 1 deletion C7Engine/EntryPoints/MessageToEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public override void process() {
}

// Start researching this tech and update the UI.
player.currentlyResearchedTech = requestedTech.id;
player.SetCurrentlyResearchedTech(requestedTech.id);
new MsgUpdateUiAfterTechSelection().send();
}
}
Expand Down
7 changes: 6 additions & 1 deletion C7Engine/EntryPoints/TurnHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Serilog;

namespace C7Engine {
using System;
using C7GameData;

public class TurnHandling {
Expand Down Expand Up @@ -44,6 +45,9 @@ internal static void AdvanceTurn() {
gameData.UpdateTileOwners();

gameData.turn++;
foreach (Player player in gameData.players) {
player.turnsResearched++;
}
OnBeginTurn();
}
}
Expand Down Expand Up @@ -160,7 +164,8 @@ private static void HandleCityResults(GameData gameData) {
city.SetItemBeingProduced(CityProductionAI.GetNextItemToBeProduced(city, producedItem));
}

city.owner.gold += city.CurrentCommerceYield();
city.owner.gold += (int)Math.Floor(city.CurrentCommerceYield() * city.owner.taxRate / 10.0);
city.owner.beakers += (int)Math.Floor(city.CurrentCommerceYield() * city.owner.scienceRate / 10.0);
}
}

Expand Down
2 changes: 2 additions & 0 deletions C7GameData/ImportCiv3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ private void ImportSavLeaders() {
}

player.gold = leader.Gold;
player.beakers = leader.Beakers;
player.turnsResearched = leader.TurnsResearched;
player.scienceRate = leader.ScienceRate;
player.luxuryRate = leader.LuxuryRate;
player.taxRate = leader.TaxRate;
Expand Down
17 changes: 16 additions & 1 deletion C7GameData/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Player {
public HashSet<ID> knownTechs = new();

// The tech the player is currently researching.
public ID currentlyResearchedTech;
public ID currentlyResearchedTech { get; private set; }

// The civilopedia name of the era this player is in.
//
Expand All @@ -48,10 +48,25 @@ public class Player {
// The amount of gold this player has.
public int gold = 0;

// The number of "beakers" (gold) spent on the currently researched
// tech.
public int beakers = 0;

// The number of turns the player has been researching the current tech.
public int turnsResearched = 0;

public void AddUnit(MapUnit unit) {
this.units.Add(unit);
}

public void SetCurrentlyResearchedTech(ID id) {
currentlyResearchedTech = id;

// Clear out previous progress.
beakers = 0;
turnsResearched = 0;
}

public string GetNextCityName() {
string name = civilization.cityNames[cityNameIndex % civilization.cityNames.Count];
int bonusLoops = cityNameIndex / civilization.cityNames.Count;
Expand Down
18 changes: 17 additions & 1 deletion C7GameData/Save/SavePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public class SavePlayer {
// The amount of gold this player has.
public int gold = 0;

// The number of "beakers" (gold) spent on the currently researched
// tech.
public int beakers = 0;

// The number of turns the player has been researching the current tech.
public int turnsResearched = 0;

public Player ToPlayer(GameMap map, List<Civilization> civilizations) {
Player player = new Player{
id = id,
Expand All @@ -50,7 +57,6 @@ public Player ToPlayer(GameMap map, List<Civilization> civilizations) {
cityNameIndex = cityNameIndex,
tileKnowledge = new TileKnowledge(),
knownTechs = knownTechs,
currentlyResearchedTech = currentlyResearchedTech,
eraCivilopediaName = eraCivilopediaName,
luxuryRate = luxuryRate,
scienceRate = scienceRate,
Expand All @@ -65,6 +71,14 @@ public Player ToPlayer(GameMap map, List<Civilization> civilizations) {
player.knownTechs.Add(techId);
}
}

// Because of the custom setter we need to set the researched tech
// and then set the beakers and turns researched - otherwise they'd
// be reset by the setter.
player.SetCurrentlyResearchedTech(currentlyResearchedTech);
player.beakers = beakers;
player.turnsResearched = turnsResearched;

return player;
}

Expand All @@ -89,6 +103,8 @@ public SavePlayer(Player player) {
scienceRate = player.scienceRate;
taxRate = player.taxRate;
gold = player.gold;
beakers = player.beakers;
turnsResearched = player.turnsResearched;
}
}
}

0 comments on commit 41f4e6a

Please sign in to comment.