Skip to content

Commit adc3ab6

Browse files
committed
Add unit support costs
This isn't perfect, as we don't track whether a unit was captured (and is therefore free) but it's a start.
1 parent 6e55f34 commit adc3ab6

6 files changed

Lines changed: 131 additions & 8 deletions

File tree

C7/Game.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ public override void _Process(double delta) {
298298
if (Input.IsKeyPressed(Godot.Key.F1)) {
299299
EmitSignal(SignalName.ShowSpecificAdvisor, "F1");
300300
}
301+
if (Input.IsKeyPressed(Godot.Key.F3)) {
302+
EmitSignal(SignalName.ShowSpecificAdvisor, "F3");
303+
}
301304
if (Input.IsKeyPressed(Godot.Key.F6)) {
302305
EmitSignal(SignalName.ShowSpecificAdvisor, "F6");
303306
}

C7/UIElements/Advisors/Advisors.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public partial class Advisors : CenterContainer {
1212
private ILogger log = LogManager.ForContext<Advisors>();
1313

1414
private DomesticAdvisor domesticAdvisor;
15+
private MilitaryAdvisor militaryAdvisor;
1516
private ScienceAdvisor scienceAdvisor;
1617

1718
// A list of all the non-null advisors, so we can hide them whenever we
@@ -33,10 +34,6 @@ private void ShowLatestAdvisor() {
3334
this.Show();
3435
}
3536

36-
private void _on_Advisor_hide() {
37-
this.Hide();
38-
}
39-
4037
private void OnShowSpecificAdvisor(string advisorType) {
4138
// Hide any existing advisors so we can draw the requested one.
4239
foreach (TextureRect tr in advisors) {
@@ -54,6 +51,17 @@ private void OnShowSpecificAdvisor(string advisorType) {
5451
AddChild(domesticAdvisor);
5552
this.Show();
5653
}
54+
if (advisorType.Equals("F3")) {
55+
if (militaryAdvisor != null) {
56+
RemoveChild(militaryAdvisor);
57+
militaryAdvisor = null;
58+
}
59+
60+
militaryAdvisor = new MilitaryAdvisor();
61+
advisors.Add(militaryAdvisor);
62+
AddChild(militaryAdvisor);
63+
this.Show();
64+
}
5765
if (advisorType.Equals("F6")) {
5866
// TODO: What's the best way to refresh the tech tree UI without
5967
// adding too many children?
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using C7Engine;
2+
using C7GameData;
3+
using Godot;
4+
using System;
5+
6+
public partial class MilitaryAdvisor : TextureRect {
7+
Label totalUnitsLabel = new();
8+
Label allowedUnitsLabel = new();
9+
Label unitSupportCostLabel = new();
10+
11+
public override void _Ready() {
12+
this.CreateUI();
13+
}
14+
15+
private void CreateUI() {
16+
this.Texture = Util.LoadTextureFromPCX("Art/Advisors/military.pcx");
17+
18+
//TODO: Age-based background. Only use Ancient for now.
19+
ImageTexture AdvisorHappy = Util.LoadTextureFromPCX("Art/SmallHeads/popupMILITARY.pcx", 1, 40, 149, 110);
20+
ImageTexture AdvisorAngry = Util.LoadTextureFromPCX("Art/SmallHeads/popupMILITARY.pcx", 151, 40, 149, 110);
21+
ImageTexture AdvisorSad = Util.LoadTextureFromPCX("Art/SmallHeads/popupMILITARY.pcx", 301, 40, 149, 110);
22+
ImageTexture AdvisorSurprised = Util.LoadTextureFromPCX("Art/SmallHeads/popupMILITARY.pcx", 451, 40, 149, 110);
23+
24+
TextureRect AdvisorHead = new TextureRect();
25+
//TODO: Randomize or set logically
26+
AdvisorHead.Texture = AdvisorSurprised;
27+
AdvisorHead.SetPosition(new Vector2(851, 0));
28+
AddChild(AdvisorHead);
29+
30+
ImageTexture DialogBoxTexture = Util.LoadTextureFromPCX("Art/Advisors/dialogbox.pcx");
31+
TextureButton DialogBox = new TextureButton();
32+
DialogBox.TextureNormal = DialogBoxTexture;
33+
DialogBox.SetPosition(new Vector2(806, 110));
34+
AddChild(DialogBox);
35+
36+
//TODO: Multi-line capabilities
37+
Label DialogBoxAdvise = new Label();
38+
DialogBoxAdvise.Text = "You are running C7!";
39+
DialogBoxAdvise.SetPosition(new Vector2(815, 119));
40+
AddChild(DialogBoxAdvise);
41+
42+
ImageTexture GoBackTexture = Util.LoadTextureFromPCX("Art/exitBox-backgroundStates.pcx", 0, 0, 72, 48);
43+
TextureButton GoBackButton = new TextureButton();
44+
GoBackButton.TextureNormal = GoBackTexture;
45+
GoBackButton.SetPosition(new Vector2(952, 720));
46+
AddChild(GoBackButton);
47+
GoBackButton.Pressed += ReturnToMenu;
48+
49+
using (UIGameDataAccess gameDataAccess = new()) {
50+
Player player = gameDataAccess.gameData.GetHumanPlayers()[0];
51+
var (totalUnits, allowedUnits, unitSupportCost) = player.TotalUnitsAllowedUnitsAndSupportCost();
52+
53+
AddChild(totalUnitsLabel);
54+
totalUnitsLabel.SetPosition(new Vector2(0, 90));
55+
totalUnitsLabel.SetTextAndCenterLabel($"Total Units\n{totalUnits}");
56+
totalUnitsLabel.Position += new Vector2(-50, 0);
57+
58+
AddChild(allowedUnitsLabel);
59+
allowedUnitsLabel.SetPosition(new Vector2(0, 139));
60+
allowedUnitsLabel.SetTextAndCenterLabel($"Allowed Units\n{allowedUnits}");
61+
allowedUnitsLabel.Position += new Vector2(-50, 0);
62+
63+
AddChild(unitSupportCostLabel);
64+
unitSupportCostLabel.SetPosition(new Vector2(0, 188));
65+
unitSupportCostLabel.SetTextAndCenterLabel($"Unit Support Cost\n{unitSupportCost} gold/turn");
66+
unitSupportCostLabel.Position += new Vector2(-50, 0);
67+
}
68+
69+
}
70+
71+
private void ReturnToMenu() {
72+
GetParent<Advisors>().Hide();
73+
}
74+
}

C7/UIElements/GameStatus/LowerRightInfoBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public override void _Process(double delta) {
178178
if (goldPerTurn >= 0) {
179179
yearAndGold.Text = $"Turn {turnNumber} {gold} Gold (+{goldPerTurn} per turn)";
180180
} else {
181-
yearAndGold.Text = $"Turn {turnNumber} {gold} Gold (-{goldPerTurn} per turn)";
181+
yearAndGold.Text = $"Turn {turnNumber} {gold} Gold ({goldPerTurn} per turn)";
182182
}
183183
}
184184

C7Engine/EntryPoints/TurnHandling.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ internal static void AdvanceTurn() {
4545
gameData.turn++;
4646
foreach (Player player in gameData.players) {
4747
HandleCityResults(gameData, player);
48+
player.DoPerTurnFinanceUpdates(gameData);
4849

4950
// TODO: This isn't quite accurate. This should only be
5051
// incremented if the player is actually spending money on
@@ -184,9 +185,6 @@ private static void HandleCityResults(GameData gameData, Player player) {
184185

185186
city.SetItemBeingProduced(CityProductionAI.GetNextItemToBeProduced(city, producedItem));
186187
}
187-
188-
city.owner.gold += city.CurrentCommerceYield().taxes;
189-
city.owner.beakers += city.CurrentCommerceYield().beakers;
190188
}
191189
}
192190

C7GameData/Player.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ public int CalculateGoldPerTurn() {
218218
foreach (City city in cities) {
219219
result += city.CurrentCommerceYield().taxes;
220220
}
221+
222+
// Subtract unit support costs, if any.
223+
var (_, _, unitSupportCost) = TotalUnitsAllowedUnitsAndSupportCost();
224+
result -= unitSupportCost;
225+
221226
return result;
222227
}
223228

@@ -282,6 +287,41 @@ public int EstimateTurnsToResearch(Tech tech) {
282287
}
283288
return result;
284289
}
290+
291+
public void DoPerTurnFinanceUpdates(GameData gameData) {
292+
// Process per-city contributions.
293+
//
294+
// TODO: consider making this return a tuple too. Or maybe return all
295+
// the gold accounting stuff in a struct, for one pass over the cities.
296+
foreach (City city in cities) {
297+
beakers += city.CurrentCommerceYield().beakers;
298+
}
299+
gold += CalculateGoldPerTurn();
300+
}
301+
302+
public (int, int, int) TotalUnitsAllowedUnitsAndSupportCost() {
303+
int freeUnits = 0;
304+
305+
foreach (City city in cities) {
306+
// TODO: Import these sizes from Rule.cs in the biq. Maybe have
307+
// them live in the city class?
308+
if (city.size <= 6) {
309+
freeUnits += government.freeUnitsPerTown;
310+
} else if (city.size <= 12) {
311+
freeUnits += government.freeUnitsPerCity;
312+
} else {
313+
freeUnits += government.freeUnitsPerMetropolis;
314+
}
315+
}
316+
if (government.allUnitsFree) {
317+
freeUnits = units.Count;
318+
}
319+
320+
int totalUnits = units.Count;
321+
int allowedUnits = freeUnits;
322+
int unitSupportCost = Math.Max(0, (totalUnits - allowedUnits) * government.unitCost);
323+
return (totalUnits, allowedUnits, unitSupportCost);
324+
}
285325
}
286326

287327
}

0 commit comments

Comments
 (0)