Modders Guide to FfH2

finalImprovement is defined on a more global scale. You are actually calling that one against something more fundamental even than the CvPlot, as such you don't have to target it at anything at all. If you imported some of my AI upgrades it is used more often (over in CvUnitAI, and I think also CvPlayerAI) and has a new functionality of needing you to pass in a player number so you know that the final improvement is a Town and not an Enclave for all but the Kuriotates. Anyways, you don't want to use pLoopPlot->finalImprovement, you just want to use finalImprovement again using the base improvement of what is on the other plot against the base improvment of what is on this plot.

Don't forget to make sure that your function for checking range is written loose enough to allow you to specify specific improvements (other than yourself) which you must be a certain range from. Then you could do something like restrict Lion's Dens to 5 tiles away from a Wolf's Den, but allow them to be adjacent to one another, resulting in areas which build up specific types of animals if left untouched.
 
If you imported some of my AI upgrades it is used more often (over in CvUnitAI, and I think also CvPlayerAI)
I probably missed something, but I could not find a single instance of finalimprovement in FF CvUnitAI.cpp (tried both patch B and source in modmodders guide). :(
So I will bother you a bit more then:
Anyways, you don't want to use pLoopPlot->finalImprovement, you just want to use finalImprovement again using the base improvement of what is on the other plot against the base improvment of what is on this plot.
Ok, now I am lost again and I just recently started to feel quite comfortable editing dll ;)
So, what should I use here to actually make finalimprovement part work? (part of the code posted here)
Spoiler :
Code:
	for (iDX = -iRange; iDX <= iRange; iDX++)
	{
		for (iDY = -iRange; iDY <= iRange; iDY++)
		{
			if (iDX == 0 && iDY == 0)
			{
				continue;
			}
			pLoopPlot = plotXY(getX_INLINE(), getY_INLINE(), iDX, iDY);
			if (pLoopPlot != NULL)
			{
				if (pLoopPlot->getImprovementType() == eImprovement)
				{
					bInvalid = true;
					break;
				}
				ImprovementTypes eFinalImprovementType;
				eFinalImprovementType = finalImprovementUpgrade(eImprovement);

				if (eFinalImprovementType != NO_IMPROVEMENT)
				{
					if (pLoopPlot->getImprovementType() == eFinalImprovementType)
					{
						bInvalid = true;
						break;
					}
				}
Then you could do something like restrict Lion's Dens to 5 tiles away from a Wolf's Den, but allow them to be adjacent to one another, resulting in areas which build up specific types of animals if left untouched.
I did not thought about it, good idea :) But first, I have to get it running for finalImprovements before trying to extend its functionality, and as you can see, it does not go particullary well...
 
Hrm, sorry I was remembering how the code worked wrong. The uses are all in CvPlot, CvPlayerAI and CvCityAI. Also they aren't quite as perfect as they could be, so will be somewhat re-written for next patch release.

But anyway:

Code:
				ImprovementTypes eFinalImprovementType = finalImprovementUpgrade(eImprovement);

				if (finalImprovementUpgrade(pLoopPlot->getImprovementType()) == eFinalImprovementType)
				{
					bInvalid = true;
					break;
				}

That ought to work. Though you shouldn't need to check for NO_IMPROVEMENT, as EVERY improvement will return SOME improvement as their final improvement upgrade type (you already stopped this function long ago if there is no improvement on the tile)
 
That ought to work. Though you shouldn't need to check for NO_IMPROVEMENT, as EVERY improvement will return SOME improvement as their final improvement upgrade type (you already stopped this function long ago if there is no improvement on the tile)
Tried that - both when Opera suggested and now. Compiled fine, but game crashes on city founding. If I just try a worker, I get attached error connected with drawing improvement build order I linked to invalid range function :confused:
 

Attachments

  • Civ4ScreenShot0012.jpg
    Civ4ScreenShot0012.jpg
    69 KB · Views: 75
Comment out this chunk of your code and run again to be certain that the error is here and not in something else. If the error is in this location then I can't help you much without knowing precisely where you linked this new function in the main code. Basically there is some function which tells the unit "You are capable of building 12 different things" and then this function comes in later and says "You want to know about your 7th possible build? Are you F'ing Crazy? You can only build 6 things!" And thus you are out of range (here) because you have a different expected range (elsewhere)
 
Comment out this chunk of your code and run again to be certain that the error is here and not in something else.
I did. It even runs fine (except actually working) with the code I have posted above. Only after the change it crashes.
If the error is in this location then I can't help you much without knowing precisely where you linked this new function in the main code.
Thanks for help anyway, will try to find a way to fix it. But as I do not have much hope for myself, if anyone has too much time I would be obliged for any suggestions regerding my code. Just in case, I am attaching all source files containing MinimumDistance function - just look for it and you will get all of it save for the code posted here. Also, all changes (including the above code) are marked by "Improvements Limit Mod"
Basically there is some function which tells the unit "You are capable of building 12 different things" and then this function comes in later and says "You want to know about your 7th possible build? Are you F'ing Crazy? You can only build 6 things!" And thus you are out of range (here) because you have a different expected range (elsewhere)
That is what I thought. Unfortunatelly, I still do not know where is the source of this conflict...
 
how about this?

Code:
				ImprovementTypes eFinalImprovementType;
				eFinalImprovementType = finalImprovementUpgrade(eImprovement);

				if (eFinalImprovementType != NO_IMPROVEMENT)
				{
					if (pLoopPlot->getImprovementType() == eFinalImprovementType)
					{
						bInvalid = true;
						break;
					}
				}

				if (pLoopPlot->getImprovementType() == eImprovement)
				{
					bInvalid = true;
					break;
				}
				else if (bCheckBuildProgress && eBuild != NO_BUILD)
				{
					if (pLoopPlot->getBuildProgress(eBuild) > 0)
					{
						bInvalid = true;
						break;
					}
				}
you added an if block before an elif block which can cause problems.
 
how about this?

you added an if block before an elif block which can cause problems.

That was it, works fine now :) Thanks!

But...
I have now fort building blocked by other forts and castles (final upgrade in Orbis). But unfortunatelly, keep (middle upgrade) does not count. Is there any way to check for intermediate upgrades? :mischief:
 
change
if (pLoopPlot->getImprovementType() == eFinalImprovementType)

to
if (finalImprovementUpgrade(pLoopPlot->getImprovementType()) == eFinalImprovementType)
 
Unfortunatelly, the crash is back with this change.

Tried every possible configuration, even removal of other causes...
Only reverting this change fixes things.
 
That did it!
Although I feel a bit stupid for doing such mistakes...

Anyway, thanks a lot! :)
I can finally get rid of canbuild callback
 
Hey, I saw you use this saying elsewhere recently. Got it by a wheel or something? :lol:

So, you're working in the DLL now? Good news :)
 
Any chance you can post the source code so I can nab it now, while I'm working on my own DLL? No need to reinvent the wheel. :lol:
Give me some time, I need do one more adjustment and you will get both culturecontrol and improvementlimit in one nice, easy to import package.
I need some time, but will post it here today

Hey, I saw you use this saying elsewhere recently. Got it by a wheel or something? :lol:
Do you think he is researching horseback riding now? And then stirrups. You better have one foot in one, Valkrionn, if you are going to tell the truth...
So, you're working in the DLL now? Good news :)
Great :mischief: One more source for my source :)
 
Give me some time, I need do one more adjustment and you will get both culturecontrol and improvementlimit in one nice, easy to import package.
I need some time, but will post it here today

Sounds good. :goodjob:

Do you think he is researching horseback riding now? And then stirrups. You better have one foot in one, Valkrionn, if you are going to tell the truth...

:lol:
 
Ok, I did most of the fixes I wanted, corrected a few bugs (including some of the original code) and if you want, Improvements mods by Jeckel are attached. Look for the "Improvements Mods" name in source files to get what you need.
MinimumDistance component is smaller and I think with no bugs. It includes only IMinimumDistance tag and bool CvPlot::isImprovementInRange

Regarding culture control, I still have one problem. I have added code marked in green and red to make some improvements overwrite cultural borders (non-existent in Jeckel's version). It works, but the part in red does not - all owned improvements overwrite borders. Any ideas how to change the code to make it work?

Also, is there a better place to add such code?

Code:
void CvPlot::updateCulture(bool bBumpUnits, bool bUpdatePlotGroups)
{
	if (!isCity())
	{
[COLOR="SeaGreen"]/*************************************************************************************************/
/**	Improvements Mods	Improvements will sometimes overwrite cultural border	expanded by Ahwaric	21.09.09	**/
/*************************************************************************************************/
/**				---- Start Original Code ----					**
		setOwner(calculateCulturalOwner(), bBumpUnits, bUpdatePlotGroups);
/**				----  End Original Code  ----					**/
		if (getImprovementOwner() != NO_PLAYER && getImprovementType() != NO_IMPROVEMENT)
		{[/COLOR]
[COLOR="Red"]			if (GC.getImprovementInfo(getImprovementType()).isOutsideBorders())
			[/COLOR][COLOR="SeaGreen"]{
				setOwner(getImprovementOwner(), bBumpUnits, bUpdatePlotGroups);
			}
		}
		else
		{[/COLOR]
			setOwner(calculateCulturalOwner(), bBumpUnits, bUpdatePlotGroups);[COLOR="SeaGreen"]
		}
/*************************************************************************************************/
/**	Improvements Mods	END								**/
/*************************************************************************************************/[/COLOR]
	}
}
 

Attachments

Back
Top Bottom