[MODCOMP] Multiple Yields Consumed

To answer your question, yes they are needed both CvCityAI.cpp and CvPlayerAI.cpp. I merged this mod with the Inventors mod and you need those two files even though they are not commented.

Also, there is a bug that prevents the Professions Pedia screens from showing up correctly. If you open the CvPediaProfession.py and go to line 186.. change it to look like so:

Code:
iYieldConsumed = gc.getProfessionInfo(self.iProfession).getYield[COLOR="Red"]s[/COLOR]Consumed([COLOR="Red"]0[/COLOR])

Hi Kailric,

Those were all fixed in version 0.6...

Here's the download link... http://www.filefront.com/15422167/MultipleYieldsConsumed_v0.06.zip/
 
Hi Kailric,

Those were all fixed in version 0.6...

Here's the download link... http://www.filefront.com/15422167/MultipleYieldsConsumed_v0.06.zip/

Cool, and thanks for this mod. I was trying to sipher through the code to figure out how to add multple yields when I remembered hearing about this mod. I was able to piggy back on it to do what I needed to do:goodjob:

Edit: One question, is there any other changes from .5 to .6 I need should know about cause I merged .5 already?
 
Cool, and thanks for this mod. I was trying to sipher through the code to figure out how to add multple yields when I remembered hearing about this mod. I was able to piggy back on it to do what I needed to do:goodjob:

Edit: One question, is there any other changes from .5 to .6 I need should know about cause I merged .5 already?

Glad it ends up being usefull because it was kinda hard to get it to work properly... :crazyeye:

Yes, version 0.6 also adds "MultipleYieldsProduced" so you can produce like 2 yields from one source... For exemple, sheeps could be transformed into wool and food...
 
I just come across a potential show stopper if you don't have your Yields set up correctly.. which I apprently didn't or I would not be posting this.

But for the AI to use YieldsConsumed you have to make sure that if a Yield is not considered a final product in CvPlayerAI code "AI_isYieldFinalProduct" then its needs be set as the First Yield consumed for at least one profession Profession. Cause after 50 turns the AI does a check for MaintainLevel in CvPlayer::AI_doTradeRoutes and if there is no Profession Consuming the yield... Crash, Booom, bam... wtf!#@$?#$??

And make sure you have your Yield placed correctly in the CvPlayerAI::AI_isYieldFinalProduct. If its not a final product like Cotton or Ore there needs to be a check to see if a City needs the Yield as in the code below where I added in Coal. Lumber is ok not being checked cause you always produce one lumber.

Code:
bool CvPlayerAI::AI_isYieldFinalProduct(YieldTypes eYield) const
{
	if (!GC.getYieldInfo(eYield).isCargo())
	{
		return false;
	}

	bool bFinal = true;

	switch (eYield)
	{
		case YIELD_FOOD:
		case YIELD_LUMBER:
			bFinal = false;
			break;

		case YIELD_SILVER:
			bFinal = true;
			break;

		case YIELD_COTTON:
		case YIELD_FUR:
		case YIELD_SUGAR:
		case YIELD_TOBACCO:
		case YIELD_ORE:
		///TKs
                         case YIELD_COAL:
                          ///TKe
			{
				int iLoop;
				CvCity* pLoopCity = NULL;
				for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
				{
					if (pLoopCity->AI_getNeededYield(eYield) > 0)
					{
						bFinal = false;
						break;
					}
				}
			}
			break;
 
I just come across a potential show stopper if you don't have your Yields set up correctly.. which I apprently didn't or I would not be posting this.

But for the AI to use YieldsConsumed you have to make sure that if a Yield is not considered a final product in CvPlayerAI code "AI_isYieldFinalProduct" then its needs be set as the First Yield consumed for at least one profession Profession. Cause after 50 turns the AI does a check for MaintainLevel in CvPlayer::AI_doTradeRoutes and if there is no Profession Consuming the yield... Crash, Booom, bam... wtf!#@$?#$??

And make sure you have your Yield placed correctly in the CvPlayerAI::AI_isYieldFinalProduct. If its not a final product like Cotton or Ore there needs to be a check to see if a City needs the Yield as in the code below where I added in Coal. Lumber is ok not being checked cause you always produce one lumber.
It looks as the problem that I found in my mod. I also had CTD on turn 53. The description and solution is here.
 
I just come across a potential show stopper if you don't have your Yields set up correctly.. which I apprently didn't or I would not be posting this.

But for the AI to use YieldsConsumed you have to make sure that if a Yield is not considered a final product in CvPlayerAI code "AI_isYieldFinalProduct" then its needs be set as the First Yield consumed for at least one profession Profession. Cause after 50 turns the AI does a check for MaintainLevel in CvPlayer::AI_doTradeRoutes and if there is no Profession Consuming the yield... Crash, Booom, bam... wtf!#@$?#$??

And make sure you have your Yield placed correctly in the CvPlayerAI::AI_isYieldFinalProduct. If its not a final product like Cotton or Ore there needs to be a check to see if a City needs the Yield as in the code below where I added in Coal. Lumber is ok not being checked cause you always produce one lumber.

Code:
bool CvPlayerAI::AI_isYieldFinalProduct(YieldTypes eYield) const
{
	if (!GC.getYieldInfo(eYield).isCargo())
	{
		return false;
	}

	bool bFinal = true;

	switch (eYield)
	{
		case YIELD_FOOD:
		case YIELD_LUMBER:
			bFinal = false;
			break;

		case YIELD_SILVER:
			bFinal = true;
			break;

		case YIELD_COTTON:
		case YIELD_FUR:
		case YIELD_SUGAR:
		case YIELD_TOBACCO:
		case YIELD_ORE:
		///TKs
                         case YIELD_COAL:
                          ///TKe
			{
				int iLoop;
				CvCity* pLoopCity = NULL;
				for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
				{
					if (pLoopCity->AI_getNeededYield(eYield) > 0)
					{
						bFinal = false;
						break;
					}
				}
			}
			break;

Haha, yes! I was plagued with this problem for a lot of time (always crashing just after turn 50), until through debugging I found out the problem. Anyway, the way I fixed the problem was by, in CvPlayerAI.cpp::AI_doTradeRoutes changing this line:

Code:
				if (GC.getGameINLINE().getGameTurn() > 50)
				{
					pBestYieldCity->setMaintainLevel(eLoopYield, pBestYieldCity->getMaxYieldCapacity() / 2);
				}

to this:

Code:
				if (GC.getGameINLINE().getGameTurn() > 50 && pBestYieldCity != NULL)
				{
					pBestYieldCity->setMaintainLevel(eLoopYield, pBestYieldCity->getMaxYieldCapacity() / 2);
				}
 
Haha, yes! I was plagued with this problem for a lot of time (always crashing just after turn 50), until through debugging I found out the problem. Anyway, the way I fixed the problem was by, in CvPlayerAI.cpp::AI_doTradeRoutes changing this line:

Code:
				if (GC.getGameINLINE().getGameTurn() > 50)
				{
					pBestYieldCity->setMaintainLevel(eLoopYield, pBestYieldCity->getMaxYieldCapacity() / 2);
				}

to this:

Code:
				if (GC.getGameINLINE().getGameTurn() > 50 && pBestYieldCity != NULL)
				{
					pBestYieldCity->setMaintainLevel(eLoopYield, pBestYieldCity->getMaxYieldCapacity() / 2);
				}

Yeah, it was a huge over site by the programmer not to add in a "&& pBestYieldCity != NULL". The only thing that kept me from spending even more time on finding this bug is when you turn a game into a Scenerio it saves what turn you was on. So that and using "Breaks" in debug I was able to pin point the problem with not a whole lot of difficulty.

But, If you don't add your new Yield to the CvPlayerAI by defualt it is considered a "Final Product" and this paticular crash bug want ever happen, there may be other problems not sure though.
 
Yeah, it was a huge over site by the programmer not to add in a "&& pBestYieldCity != NULL". The only thing that kept me from spending even more time on finding this bug is when you turn a game into a Scenerio it saves what turn you was on. So that and using "Breaks" in debug I was able to pin point the problem with not a whole lot of difficulty.

But, If you don't add your new Yield to the CvPlayerAI by defualt it is considered a "Final Product" and this paticular crash bug want ever happen, there may be other problems not sure though.

I may be wrong but this issue seams to be about adding new yields in general. I may be wrong but I don't think it's linked to the modcomp itself...

As for other problems, I know there are many functions that calls "getYieldConsumed()" and/or "getYieldProduced()" and in most case I've simply made them check for the first one in the list. Maybe adding a xml boolean tag for each yield like "bIsBaseYieldConsumed" or something...

Otherwise, just make sure your primary yield comes first in the list...

Aymerick
 
I may be wrong but this issue seams to be about adding new yields in general. I may be wrong but I don't think it's linked to the modcomp itself...

As for other problems, I know there are many functions that calls "getYieldConsumed()" and/or "getYieldProduced()" and in most case I've simply made them check for the first one in the list. Maybe adding a xml boolean tag for each yield like "bIsBaseYieldConsumed" or something...

Otherwise, just make sure your primary yield comes first in the list...

Aymerick

Right, I ment "Firaxis" programmers:) Still, for those who try to add new yields this is a must know as to keep for having crashes.

I finally got me a Makefile and Debug build going. I haven't found any bugs because of this mod. One thing though I intend to fix for my mods is that when you have multiple yields consumed and one of the yields is missing both yields show up as missing in the help text when you mouse over the Building. But this is only a minor issue.
 
Hallo Aymerick, hallo Kailric,

my name is ray (German modder from www.civforum.de).

I am very interested in this ModComp, especially the part "Multiple Yields Produced on Plot Tile".
Problem is, that the last download-link seems to be broken.

Could you please post a download-link to the latest version of this ModComp ?

Best regards,
ray
 
Hey, just now seeing this. Here is a link to his version 0.06 I believe it is the latest. Also, I found one bug in the code. If you have say a Gunsmith producing 6 guns and a Blacksmith producing 6 tools and no tools in the warehouse the game will store 6 of both Guns and Tools in the warehouse when it should only be storing 6 Guns. I fixed this in my Medieval mod. Either this evening or tomorrow I'll post an updated version of this mod with the above code fixed.
 

Attachments

  • MultipleYieldsConsumed_v0.06.zip
    1.6 MB · Views: 179
I fixed this in my Medieval mod. Either this evening or tomorrow I'll post an updated version of this mod with the above code fixed.

Ah ok, thank you. :)
Then I will take the source-code out of Medieval mod.
 
Ah ok, thank you. :)
Then I will take the source-code out of Medieval mod.

Well, that may be a big pain. There was only one function that I edited to fix this error and it was the "void CvCity::calculateNetYields". I have made several other adjustments to this function in relation to my Medieval mod so you will have to remove those as well. It may be hard to figure out what was done to fix this and what I added for the Medieval mod. The ///TKs Med tags in that function are dealing with my new Armorsmith building. The check for "SpecialBuildingTypes eSpecialBuilding" was added by me so all references to that can be removed. And also the code between the ///TKs Med Update 1.1h and ///TKe can be removed as well.

If you can't figure it out let me know and I'll fix it up for you.
 
Top Bottom