Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add AutomaticallyUpgradesInProduction Unique #10654

Conversation

dHannasch
Copy link
Contributor

Obsolete units in production will automatically upgrade without losing any invested Production, provided this will not create a deficit in the civilization's strategic resources.
-- https://civilization.fandom.com/wiki/Obsolete#Civilization_V

That is to say, when a unit goes "obsolete", this has two effects: the unit can no longer be built, and any in-production units automatically upgrade for free if they have an upgrade and the upgrade is currently available to build.

These two effects are separable. Indeed they are separated, since not all units have an upgrade available at the time they go obsolete. (Notably, the Scout.)

There is not currently any case of the opposite in the base game, but it doesn't seem unreasonable for some mod to have that. In Civ V, Cavalry is no longer available after you research Combustion, and if you don't have Oil, well then you shouldn't have researched Combustion. But some mod might allow you to continue to build Cavalry. (In point of fact, horses were still used in war alongside combustion vehicles for quite some time.)

We might call a unit "presumptively obsolete" in this situation: continuing to build them isn't necessarily a good idea, and units that happen to be in-production will upgrade automatically if possible, but you can continue to build the old unit. But it's more explicit to skip terms like "presumptively obsolete" and spell out exactly what we mean: in-production units automatically upgrade for free, but there are no other direct effects.

This branch attempts to keep all new functionality in Uniques from the start. This branch is rough and inefficient (and will obviously need to change in light of forthcoming changes to obsoleteTech to support multiple obsoleting techs), but this gives you the basic idea.

I'm thinking of shaping the rework of obsoleteTech to actually split into two functions, one for the part where you can't build the unit anymore, one for the part where the unit automatically upgrades. The legacy field obsoleteTech of course implies both.

@SomeTroglodyte
Copy link
Collaborator

What about https://github.com/yairm210/Unciv/blob/master/core/src/com/unciv/logic/city/CityConstructions.kt#L415 ?

@dHannasch
Copy link
Contributor Author

dHannasch commented Dec 3, 2023

What about https://github.com/yairm210/Unciv/blob/master/core/src/com/unciv/logic/city/CityConstructions.kt#L415 ?

...huh.

...maybe I'm missing something obvious, but why do we have both https://github.com/yairm210/Unciv/blob/master/core/src/com/unciv/logic/city/CityConstructions.kt#L416

                    if (rejectionReasons.all { it.type == RejectionReasonType.Obsoleted }...

and https://github.com/yairm210/Unciv/blob/master/core/src/com/unciv/logic/civilization/managers/TechManager.kt#L327

        obsoleteOldUnits(techName)

?

As I understand it, TechManager.addTechnology() is called when a new tech is added. It calls TechManager.obsoleteOldUnits() to upgrade in-progress constructions.

Meanwhile, separately, CityConstructions.validateInProgressConstructions() is called at the end of every turn. It also upgrades in-progress constructions, without using any of the obsoleteOldUnits() code.

Aren't they redundant?

https://github.com/yairm210/Unciv/blob/master/core/src/com/unciv/logic/civilization/managers/TurnManager.kt#L277

            civInfo.tech.endTurn(nextTurnStats.science.toInt())

        for (city in civInfo.cities.sortedByDescending { it.isBeingRazed }) {
            progressBar?.increment()
            CityTurnManager(city).endTurn()
        }

Right before CityConstructions.endTurn() is called, TechManager.endTurn() is called. Which upgrades in-progress constructions. I guess CityConstructions.validateConstructionQueue() is also called when something is bought, and in principle a building might have a Unique that gives a free tech. But the free tech would still be added by TechManager.addTechnology(). Unless there's a bug in the TechManager, it seems impossible for the RejectionReasonType.Obsoleted to ever fire.

Though, this does kind of make me wonder...this is getting way off into the weeds, but in principle the automatic-upgrade-in-production business could happen for other reasons, like acquiring Oil, not just because a tech is discovered. It could take a conditional. In which case validateInProgressConstructions() would be the place, since that's called before every construction, not just when a tech is discovered.

Actually...hmm. They don't do quite the same thing. TechManager.addTechnology() adds a tech once. validateInProgressConstructions() checks every time, so it would never actually be possible to build the old unit if that was running the checks. I think for the first pass, to just imitate what happens to obsolete units, TechManager.addTechnology() is the one we want for this Unique. So it's fortunate that there's already stuff happening there, even if maybe before this Unique is was redundant.

Copy link

github-actions bot commented Dec 3, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the Conflicts label Dec 3, 2023
Copy link

github-actions bot commented Dec 3, 2023

Conflicts have been resolved.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Mar 14, 2024
@SeventhM SeventhM mentioned this pull request Mar 16, 2024
2 tasks
Copy link

This PR was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions bot closed this Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants