Subsystem: Technology - Adam-Poppenheimer/Civ-Clone GitHub Wiki
Technologies are the ways by which Civilization 5 represents advancements in knowledge and culture. The game consists of a single tech tree, the same for all civilizations, that civs can advance through by spending Science. Technologies belong to a particular era (neolithic era, classical era, medieval era, etc) and have a cost in Science needed to unlock them. Most techs have prerequisite technologies that must be discovered first. Once a civilization has discovered a tech, it gains access to any units, buildings, abilities, improvements, or policy trees that tech enables. It can also increase Improvement yield, reveal Resources, or provide free Great People when discovered. Civ Clone currently has all techs up to the end of the Medieval Era, since that was the subset of the game it was trying to implement.
Individual techs are defined through the ITechDefinition interface and its standard implementation, which occurs at design time. In addition to its various game-mechanical elements, ITechDefinition includes row and column indices for its placement in the tech tree, something consumed by the relatively complex UI for displaying a tech tree. TechDefinition, ITechDefinition's standard implementation, is a ScriptableObject that provides read-only access to its properties by backing them with private fields tagged with the [SerializeField] attribute.
The bulk of this subsystem's behavior happens in ITechCanon and its standard implementation, TechCanon. ITechCanon does a lot of things. It sets techs as discovered or undiscovered for civs and records the progress each civ has for each tech (how close they are to researching it). It can get all techs from a given era, all techs in the era before a current area, and all entry techs for an era (techs whose prerequisites are exclusively in previous eras). ITechCanon can produce a prerequisite chain leading to a given tech for a given civilization: a list of all the techs a civ needs to discover, in a discoverable order, in order to research the given tech. ITechCanon keeps track of the number of free techs a civilization has. It provides a number of query methods to determine what units, buildings, abilities, visible resources, and policy trees are available to a particular civ given the technologies it's discovered. And lastly, it provides queries to determine what improvements, buildings, and resources would be available from a particular collection of techs, which is used for yield estimation in the Map Generation subsystem.
There is perhaps an argument to be made that ITechCanon has too many responsibilities. However, these responsibilities seem fairly closely linked together, all of which emerge directly from the techs a civilization has discovered. It made organizational sense to let ITechCanon be large for this reason.
The last component of Technology is IUnitUpgradeLogic/UnitUpgradeLogic. This class exists to determine upgrade lines and to find the most technologically sophisticated units available to a civ. Certain units can upgrade into more advanced versions of themselves (Archers into Composite Bowmen into Crossbowmen, for example). UnitUpgradeLogic finds the IUnitUpgradeLine a unit is in, and fines the most advanced units in each IUnitUpgrade line discovered by a particular civilization.