Skip to content

Commit

Permalink
Keep track of player gold and display it in the lower right
Browse files Browse the repository at this point in the history
This doesn't yet accurately display gold per turn, but tracking gold is needed for research.

#392
  • Loading branch information
TomWerner committed Jan 29, 2025
1 parent 8e9ff82 commit 092a609
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 29 deletions.
10 changes: 6 additions & 4 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,13 @@ private void _onEndTurnButtonPressed() {

private void OnPlayerStartTurn() {
log.Information("Starting player turn");
int turnNumber = TurnHandling.GetTurnNumber();
EmitSignal(SignalName.TurnStarted, turnNumber);
CurrentState = GameState.PlayerTurn;

using (var gameDataAccess = new UIGameDataAccess()) {
int turnNumber = TurnHandling.GetTurnNumber();
Player player = gameDataAccess.gameData.GetHumanPlayers()[0];

EmitSignal(SignalName.TurnStarted, turnNumber, player.gold, /*goldPerTurn=*/0);
CurrentState = GameState.PlayerTurn;

GetNextAutoselectedUnit(gameDataAccess.gameData);
}
}
Expand Down
24 changes: 16 additions & 8 deletions C7/Text/c7-static-map-save.json
Original file line number Diff line number Diff line change
Expand Up @@ -61524,7 +61524,8 @@
"hasPlayedCurrentTurn": false,
"civilization": "A Barbarian Chiefdom",
"cityNameIndex": 0,
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
},
{
"id": "player-2",
Expand Down Expand Up @@ -61593,7 +61594,8 @@
"tech-2"
],
"eraCivilopediaName": "ERAS_Ancient_Times",
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
},
{
"id": "player-3",
Expand Down Expand Up @@ -61662,7 +61664,8 @@
"tech-2"
],
"eraCivilopediaName": "ERAS_Ancient_Times",
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
},
{
"id": "player-4",
Expand Down Expand Up @@ -61727,7 +61730,8 @@
"tech-4"
],
"eraCivilopediaName": "ERAS_Ancient_Times",
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
},
{
"id": "player-5",
Expand Down Expand Up @@ -61796,7 +61800,8 @@
"tech-2"
],
"eraCivilopediaName": "ERAS_Ancient_Times",
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
},
{
"id": "player-6",
Expand Down Expand Up @@ -61869,7 +61874,8 @@
"tech-2"
],
"eraCivilopediaName": "ERAS_Ancient_Times",
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
},
{
"id": "player-7",
Expand Down Expand Up @@ -61938,7 +61944,8 @@
"tech-4"
],
"eraCivilopediaName": "ERAS_Ancient_Times",
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
},
{
"id": "player-8",
Expand Down Expand Up @@ -62003,7 +62010,8 @@
"tech-3"
],
"eraCivilopediaName": "ERAS_Ancient_Times",
"turnsUntilPriorityReevaluation": 0
"turnsUntilPriorityReevaluation": 0,
"gold": 10
}
],
"barbarianInfo": {
Expand Down
4 changes: 2 additions & 2 deletions C7/UIElements/GameStatus/GameStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ private void OnTurnEnded() {
LowerRightInfoBox.StopToggling();
}

private void OnTurnStarted(int turnNumber) {
private void OnTurnStarted(int turnNumber, int gold, int goldPerTurn) {
//Oh hai, we do need this handler here!
LowerRightInfoBox.SetTurn(turnNumber);
LowerRightInfoBox.SetTurnAndGold(turnNumber, gold, goldPerTurn);
}

private void OnNoMoreAutoselectableUnits() {
Expand Down
12 changes: 8 additions & 4 deletions C7/UIElements/GameStatus/LowerRightInfoBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@ public void UpdateUnitInfo(MapUnit NewUnit, TerrainType terrain) {

///This is going to evolve a lot over time. Probably this info box will need to keep some local state.
///But for now it'll show the changing turn number, providing some interactivity
public void SetTurn(int turnNumber) {
yearAndGold.Text = $"Turn {turnNumber} 10 Gold (+0 per turn)";
public void SetTurnAndGold(int turnNumber, int gold, int goldPerTurn) {
if (goldPerTurn >= 0) {
yearAndGold.Text = $"Turn {turnNumber} {gold} Gold (+{goldPerTurn} per turn)";
} else {
yearAndGold.Text = $"Turn {turnNumber} {gold} Gold (-{goldPerTurn} per turn)";
}
}

public void UpdateTechProgress(string techName, int turnsRemaining) {
if (turnsRemaining > 0) {
SetTextAndCenterLabel(scienceProgress, $"{techName} (-- turns)");
SetTextAndCenterLabel(scienceProgress, $"{techName} (-- turns)");
} else {
SetTextAndCenterLabel(scienceProgress, $"{techName} ({turnsRemaining} turns)");
SetTextAndCenterLabel(scienceProgress, $"{techName} ({turnsRemaining} turns)");
}
}

Expand Down
2 changes: 2 additions & 0 deletions C7Engine/EntryPoints/TurnHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ private static void HandleCityResults(GameData gameData) {
}
city.SetItemBeingProduced(CityProductionAI.GetNextItemToBeProduced(city, producedItem));
}

city.owner.gold += city.CurrentCommerceYield();
}
}

Expand Down
2 changes: 2 additions & 0 deletions C7GameData/City.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public int CurrentProductionYield() {
return yield;
}
public int CurrentCommerceYield() {
// TODO: Split this into science, entertainment, etc.

int yield = 3; //city center min yield
foreach (CityResident r in residents) {
yield += r.tileWorked.commerceYield(owner);
Expand Down
27 changes: 16 additions & 11 deletions C7GameData/ImportCiv3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,24 +351,27 @@ private void ImportRaces() {
private void ImportBicLeaders() {
BiqData theBiq = biq.Race is null ? defaultBiq : biq;

// Make a player for each civ. The barbarians are always civ 0.
for (int i = 0; i < save.Civilizations.Count; ++i) {
save.Players.Add(MakeSavePlayerFromCiv(save.Civilizations[i],
/*isBarbarian=*/i == 0,
/*isHuman=*/false,
/*cityNameIndex=*/0,
/*era=*/""));
}
// Make a player for each civ. The barbarians are always civ 0.
for (int i = 0; i < save.Civilizations.Count; ++i) {
save.Players.Add(MakeSavePlayerFromCiv(save.Civilizations[i],
/*isBarbarian=*/i == 0,
/*isHuman=*/false,
/*cityNameIndex=*/0,
/*era=*/""));
}

// Now fill in the rest of the data using the leader struct.
bool foundHuman = false;
int leadIndex = 0;
foreach (LEAD lead in theBiq.Lead) {
SavePlayer player = save.Players[lead.Civ];
foreach (LEAD lead in theBiq.Lead) {
SavePlayer player = save.Players[lead.Civ];

// Put the player in the correct starting era.
player.eraCivilopediaName = theBiq.Eras[lead.InitialEra].CivilopediaEntry;

// Give the correct amount of starting gold.
player.gold = lead.StartCash;

// Add the starting techs for scenarios.
if (theBiq.LeadTech != null) {
for (int j = 0; j < theBiq.LeadTech[leadIndex].Length; ++j) {
Expand All @@ -378,7 +381,7 @@ private void ImportBicLeaders() {

// Mark the first human playable civ as the human player.
if (lead.HumanPlayer == 1 && !foundHuman) {
player.human = true;
player.human = true;
foundHuman = true;
}

Expand Down Expand Up @@ -412,6 +415,8 @@ private void ImportSavLeaders() {
}
}

player.gold = leader.Gold;

save.Players.Add(player);
i++;
}
Expand Down
3 changes: 3 additions & 0 deletions C7GameData/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class Player {

public int turnsUntilPriorityReevaluation = 0;

// The amount of gold this player has.
public int gold = 0;

public void AddUnit(MapUnit unit) {
this.units.Add(unit);
}
Expand Down
5 changes: 5 additions & 0 deletions C7GameData/Save/SavePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class SavePlayer {

public int turnsUntilPriorityReevaluation = 0;

// The amount of gold this player has.
public int gold = 0;

public Player ToPlayer(GameMap map, List<Civilization> civilizations) {
Player player = new Player{
id = id,
Expand All @@ -41,6 +44,7 @@ public Player ToPlayer(GameMap map, List<Civilization> civilizations) {
knownTechs = knownTechs,
currentlyResearchedTech = currentlyResearchedTech,
eraCivilopediaName = eraCivilopediaName,
gold = gold,
};
foreach (TileLocation tile in tileKnowledge) {
player.tileKnowledge.AddTileToKnown(map.tileAt(tile.x, tile.y));
Expand Down Expand Up @@ -70,6 +74,7 @@ public SavePlayer(Player player) {
knownTechs = player.knownTechs;
currentlyResearchedTech = player.currentlyResearchedTech;
eraCivilopediaName = player.eraCivilopediaName;
gold = player.gold;
}
}
}

0 comments on commit 092a609

Please sign in to comment.