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 26, 2025
1 parent 1630c5a commit 0b49693
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 16 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
8 changes: 6 additions & 2 deletions C7/UIElements/GameStatus/LowerRightInfoBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ 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) {
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
5 changes: 5 additions & 0 deletions C7GameData/ImportCiv3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ private void ImportBicLeaders() {
// 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 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 = gold;
}
}
}

0 comments on commit 0b49693

Please sign in to comment.