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

Adjacent Improvements #11214

Conversation

LessRekkless
Copy link
Collaborator

@LessRekkless LessRekkless commented Aug 9, 2024

New table Improvement_YieldPerXAdjacentImprovement to replace the following VP-created tables:

  • Improvement_AdjacentImprovementYieldChanges
  • Improvement_YieldAdjacentSameType
  • Improvement_YieldAdjacentSameTwoType

Everything now gains yields from adjacent improvements, based on the number required improvements. Fractional Yields from different Improvement Types are added together (truncated down to the nearest whole number).

These tables and the corresponding (commented) SQL will be deleted during the implementation phase of next Congress, so modmods have time to switch over.

@KungCheops I didn't touch AI evaluation of this, as you asked.

please keep the two commits separate.

 - improvement Yields are increased by other, specific, adjacent Improvements
 - fractional Yields from different Improvement Types are added together
 - obsoletes Improvement_AdjacentImprovementYieldChanges, Improvement_YieldAdjacentSameType, Improvement_YieldAdjacentSameTwoType
 - obsolete tables will be removed after next Congress to give modmodders time to make the swap
 - CivilopediaScreen:
    - The relevant pages for improvements using this table now have inputs ceiling'd to the second decimal place
    - Text Frames don't automatically resize unless pushed through UpdateNarrowTextBlock.
    - The Adjacent Improvement text can be pretty long between newlines, and the wrapping function doesn't seem to have hanging indents, so I made my own

SQL Cleanup:
 - ImprovementChanges.sql should not include UIs (their presence in Improvement_TechYieldChanges and the PillageGold column will stay for now)
 - Farms on Freshwater Hills aren't a thing, so Terrace Farm doesn't need to reference them
 - clarify actual use of Improvement_AdjacentTerrainYieldChanges (the improvement boosts the adjacent terrain, not vice versa)
@KungCheops
Copy link
Contributor

Nice, I'll get to work with the CvBuilderTaskingAI support asap

@LessRekkless LessRekkless force-pushed the upstream/vpc-2.06a/adjacent_improvements branch from 75e31eb to 61383e3 Compare August 11, 2024 15:40
// Special case for culture
if (eYield == YIELD_CULTURE)
{
fYield += m_iCultureAdjacentSameType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. OtherImprovement can be anything, not just the same type of improvement. Why is this Culture exception being unconditionally added when it's labelled "CultureAdjacentSameType"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize it wasn't displaying, my bad.

Copy link
Collaborator Author

@LessRekkless LessRekkless Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed m_iCultureAdjacentSameType entirely


map<YieldTypes, map<ImprovementTypes, fraction>>::const_iterator itImprovement = m_YieldPerXAdjacentImprovement.find(eYield);

return itImprovement != m_YieldPerXAdjacentImprovement.end()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a semicolon, doesn't compile

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

pAdjacentPlot = plotDirection(getX(), getY(), static_cast<DirectionTypes>(iI));
if(pAdjacentPlot)
{
fRtnValue += kImprovement.GetYieldPerXAdjacentImprovement(eYield, pAdjacentPlot->getImprovementType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no IsImprovementPillaged check here and no verification that pAdjacentPlot->getImprovementType() doesn't return NO_IMPROVEMENT.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if (eYield == NO_YIELD)
return (!m_YieldPerXAdjacentImprovement.empty() || m_iCultureAdjacentSameType != 0);
else if (eYield == YIELD_CULTURE)
return m_iCultureAdjacentSameType != 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be:

if (eYield == YIELD_CULTURE && m_iCultureAdjacentSameType != 0)
    return true;

as it is now, normal culture adjacency yields don't work at all

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed m_iCultureAdjacentSameType entirely

@LessRekkless LessRekkless force-pushed the upstream/vpc-2.06a/adjacent_improvements branch from 61383e3 to d5edfe9 Compare August 18, 2024 22:04
@LessRekkless LessRekkless marked this pull request as draft August 18, 2024 22:04
@LessRekkless
Copy link
Collaborator Author

I've deleted m_iCultureAdjacentSameType entirely; marking as draft since the new way of inclusion needs a compile and test.

@LessRekkless
Copy link
Collaborator Author

image
image
Looks like it works!

@LessRekkless LessRekkless marked this pull request as ready for review August 20, 2024 22:03
Copy link
Contributor

@KungCheops KungCheops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

const int nRequired = pResults->GetInt(3);
CvAssert(nRequired > 0);

m_YieldPerXAdjacentImprovement[yield_idx][improvement_idx] = fraction(yield, nRequired);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LessRekkless This doesn't appear to be additive with CultureAdjacentSameType.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated using the += operator, which initializes a map to the default ( fraction(0,1) ) before adding.

Tested using C++ 98:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated using the += operator, which initializes a map to the default ( fraction(0,1) ) before adding.

Tested using C++ 98: image

Maybe a unit test suite wouldn't be the worst idea. But not sure how to set that up, should preferably be run in the CI pipeline or whatever it's called.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a future improvement perhaps

 - added YieldPerXAdjacentImprovement into the dll, along with relevant functions and its use in calculating yields, build tasker and improvement checking.
 - Adjacent Improvement yields are no longer required to be the same yield as base.
 - all improvements now GAIN benefits from adjacency, none of them will GIVE benefits. - Marked obsolete variables and functions for deletion. Improvement_YieldPerXAdjacentImprovement is replacing:
   - Improvement_YieldAdjacentSameType,
   - Improvement_YieldAdjacentTwoSameType,
   - Improvement_AdjacentImprovementYieldChanges
 - completely removed the m_iCultureAdjacentSameType member variable associated with the vanilla Improvement.CultureAdjacentSameType column.  The column now directly inserts into m_YieldPerXAdjacentImprovement

Miscellaneous:
 - Consolidated adjacent improvements during setImprovementType() and setImprovementPillaged()
 - remove adjacent plot updates for Improvement_AdjacentResourceChanges, Improvement_AdjacentFeatureChanges, as these tables are covered with this->updateYield(), not pAdjacentPlot->updateYield()
 - extended YieldTypes for-loops to CULTURE_LOCAL where I deemed it appropriate
 - combined adjacent plot for-loops where possible
@RecursiveVision RecursiveVision merged commit 9a17565 into LoneGazebo:master Sep 3, 2024
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.

3 participants