Skip to content

Added Golden Ages - #1134

Open
zack-the-coding-actuary wants to merge 12 commits into
C7-Game:Developmentfrom
zack-the-coding-actuary:golden_age
Open

zack-the-coding-actuary wants to merge 12 commits into
C7-Game:Developmentfrom
zack-the-coding-actuary:golden_age

Conversation

@zack-the-coding-actuary

@zack-the-coding-actuary zack-the-coding-actuary commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Ready for review.

Addressing issue #1119

Done:

  • Added fields/properties/methods in the Player class to support golden ages
  • Added yield increase logic in Tile_Yield class
  • Added rules in the Rules class for Golden Age duration and bonus yields (configurable from Lua)
  • Golden Age properly starts when winning combat with a unit with the "Starts Golden Age" flag against a non-barbarian combat unit
  • Logic to scan player's Great Wonders when a Wonder is built to see if player qualifies for a Golden Age
  • Mark units that trigger golden ages as never obsolete until a player has had a golden age
  • Track duration of Golden Age in UI
  • Add Domestic Advisor pop-ups for Golden Age start and end. Does not fire when golden age duration is set to 0 in existing SAV/BIQ file, if ruleset.json has a duration of 0 (for Civ 3 games), or if golden_age.lua has a duration of 0 or less (clamped to 0, for standalone games)

- Took away 100% saturation from minimap colors, which causes similarly hued colors to collide visually on the map
- Slightly increased opacity of civ colors on the minimap, so less of the base terrain colors show through
Add golden age duration and tile bonuses to Rules, and track each
player's golden age end turn through save/load.

- Rules: add GoldenAgeDuration (default 20) and GoldenAgeBonuses, a new GoldenAgeBonus struct (Shields, Commerce; default 1, 1)
- ImportCiv3: read GoldenAgeDuration from the BIQ RULE section. The bonuses are not in the BIQ, so they are always set to 1, 1
- ImportCiv3: read each player's golden age end turn from LEAD.GoldenAgeEndTurn when importing a SAV
- Player/SavePlayer: make goldenAgeEnds public and round-trip it through OpenCiv3 saves
- civ3/ruleset.json: add goldenAgeDuration and goldenAgeBonuses
- standalone: add golden_age.lua and apply it from ruleset.lua. It is required at the top of the file because the module loader path is unset by the time the addon function runs
Units with the "starts golden age" flag now start their owner's golden
age when they kill a unit belonging to another civ, if the owner has not
yet had one.

- SaveUnitPrototype.Flag/UnitPrototype: add StartsGoldenAge flag and startsGoldenAge property
- ImportCiv3: set the flag from the BIQ PRTO StartsGoldenAge field
- civ3/ruleset.json: add the flag to the 31 units that have it in conquests.biq
- Player: add TryStartGoldenAge(), which sets goldenAgeEnds to the current turn plus Rules.GoldenAgeDuration. It does nothing for barbarians or for a player who has already had a golden age
- MapUnit.Fight: call StartGoldenAgeIfEarned on kills only, for either the attacker or the defender. Retreats do not count, and neither do fights against barbarians. AI combat counts
- Add GoldenAgeTriggerTest
- Fixed whitespace
- Golden Age check only runs when enemy unit is a combat unit
- Added unit test to ensure GA does not trigger off killing non-combat unit
Completing a great wonder now starts the owner's golden age if the traits of all great wonders the owner currently has, including the new one, cover all of the owner's civ traits. Only great wonders the player owns at that moment count, so a wonder in a lost city no longer helps. Small wonders and regular buildings never trigger or contribute. A player who has already had a golden age does not get another.

- City.HandleCityProduction: after a great wonder is built, collect the traits of the owner's great wonders and call Player.TryStartGoldenAge() when they cover the civ's traits. Obsolete wonders are included
- Add a TODO noting that a civ with no traits gets a golden age on its first great wonder. No edge case handling implemented at this time.
- Add wonder trigger tests to GoldenAgeTriggerTest, driving the real HandleCityProduction: all traits in one wonder, traits covered by owned wonders (including in another city), traits not covered, regular buildings and small wonders never triggering or counting, and no second golden age
… golden age

A unit with the starts-golden-age flag is no longer treated as obsolete by UnitPrototype.IsUnitObsolete while its owner has not yet had a golden age, even if the unit it upgrades to can be built. Once the owner has had a golden age (HasHadGA stays true after it ends), normal obsolescence applies again.

- UnitPrototype.IsUnitObsolete: return false for units with startsGoldenAge when the owner has not had a golden age. The check comes before the AllowLesserUnitProduction check.
- GoldenAgeTriggerTest: add tests confirming an obsolete golden age unit stays producible before the owner's first golden age, and becomes (and stays) obsolete afterwards.
- UnitPrototypeTest: give each player in the Conquests unit availability test a prior golden age, because Swiss Mercenary starts golden ages and would otherwise no longer be obsolete in the SAV case. The JSON case is covered by the same change.

Note: the remote JSON save used by UnitAvailability_JSON predates the golden age flag, so its prototypes do not carry it and behave as before. Older JSON saves may not get the combat trigger or this obsolescence exemption until their prototypes are regenerated.
While the human player is in a golden age, the research progress line in the lower right info box is prefixed with the number of turns remaining, for example "Golden Age (12) - Writing (4 turns)". Outside a golden age the line is unchanged.

- LowerRightInfoBox._Process: when player.IsInGA is true, prefix the SummarizeScience text with "Golden Age (N) - ", where N is player.goldenAgeEnds minus the current turn. A golden age ends on the turn goldenAgeEnds, so that turn is not counted.
The human player now sees a domestic advisor pop-up when their golden age begins ("Our civilization has entered a Golden Age!", happy advisor) and on the turn it ends ("Our Golden Age has ended, so says our analysis", sad advisor). Golden ages are disabled when the rules specify a duration of 0.

- MessageToUI: add MsgGoldenAgeStarted and MsgGoldenAgeEnded, each carrying the controller id so the UI only shows them to the player they belong to.
- Player.TryStartGoldenAge: return false without changing any state when GoldenAgeDuration is 0, so a disabled golden age sends no message and does not use up the player's one golden age. Send MsgGoldenAgeStarted when the golden age begins, which covers both the combat and wonder triggers.
- TurnHandling.AdvanceTurn: after the turn advances, send MsgGoldenAgeEnded for each player whose golden age ends on that turn.
- Game.cs / Game_EmitMessages.cs: handle both messages for the UI controller and show an InformationPopup with the Domestic Advisor, following the EmitScienceGuidanceSignal pattern.
- standalone/golden_age.lua: clamp the golden age duration to a minimum of 0 so a negative value cannot be loaded.

Note: the clamp only covers the standalone Lua path. Civ3 mode reads the duration from ruleset.json and BIQ/SAV imports copy it from the BIQ, so a hand-edited negative value there is not clamped. A save loaded exactly on the turn a golden age ends does not show the end pop-up, because the check only runs when the turn advances.
@zack-the-coding-actuary
zack-the-coding-actuary marked this pull request as ready for review November 24, 2026 20:02
New games started from inside OpenCiv3 now take their golden age duration and tile bonuses from Lua, in both the base civ3 and standalone modes. Loaded OpenCiv3 saves, SAV imports, BIQ imports and scenarios are unaffected and keep their own values.

- gameplay.lua: add golden_age_config (duration 20, shields 1, commerce 1) and gameplay.golden_age.duration/shields/commerce functions, each clamped with math.max(0, value) so a negative value cannot be loaded.
- GameMode.GetSave: after cloning the ruleset, set Rules.GoldenAgeDuration and Rules.GoldenAgeBonuses from those functions. GetSave is only used when starting a new game, so loads and imports never go through it.
- ruleset.json: remove the goldenAgeDuration and goldenAgeBonuses entries from the rules block, since Lua now supplies them. The startsGoldenAge unit flags stay, because they are static unit data.
- standalone: delete golden_age.lua and remove its require and call from ruleset.lua, since GetSave overwrites those values anyway.

The defaults on Rules (20 turns, bonuses of 1 and 1) are unchanged and remain the fallback for older OpenCiv3 saves that lack the fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant