BonusCommerceModifier for Buildings

SaibotLieh

Emperor
Joined
Sep 25, 2009
Messages
1,576
This modcomp allows to modify the output of beakers, gold, culture and espionage of buildings relatively by certain resources, similiar to the already existing BonusYieldModifiers, that does this for food, production and commerce. All changes in the code are marked with "BCM". As examples the market, grocer and bank have their gold output increase modified by some resources.

Many thanks to Afforess for showing me how things had to be done.

Download: http://forums.civfanatics.com/downloads.php?do=file&id=13599
 

Attachments

  • BonusCommerceModifier.jpg
    BonusCommerceModifier.jpg
    113.5 KB · Views: 906
:slowly reach up and very carefully touch the area around my mouth:

OMG!

:feel along the edge of something curved:

Oh, that...

:comes to the end of the curve:

That is a hook!

:notices there are bumbs on the flat side and goes on to trace them out:

YOU ARE ADDICTED TO CIVILIZATION 4! YOU ARE MINE FOREVER!
 
:slowly reach up and very carefully touch the area around my mouth:

OMG!

:feel along the edge of something curved:

Oh, that...

:comes to the end of the curve:

That is a hook!

:notices there are bumbs on the flat side and goes on to trace them out:

YOU ARE ADDICTED TO CIVILIZATION 4! YOU ARE MINE FOREVER!

What? :confused: :confused: :confused:
 

Oh, that's right. You are merely a hearing guy :).

You need to know American Sign Language to understand this. The sign for ADDICTION is a hooked index finger to the side of a mouth. Hence an imagery above.
 
Hey SaibotLieh,

This modcomp is great, and very nicely documented. I've merged it into our Rhye's and Fall of Europe mod. Everything works great... except for the AI logic. I have a bunch of buildings that give +5%:gold:/:science:/:culture:/:espionage: based on resources. If the building provides some other benefit as well, the AI will build it (and get the benefits), but if the building only gives bonus commerce from resources the AI never builds it. This leads me to suspect that the AI is valuing this incorrectly.

Of course, it is also possible that I merged something in wrong or there is some other strange interaction going on. Can anyone who has used this modcomp verify that the AI actually builds buildings which only give +X%:gold:/:science:/:culture:/:espionage: from resources? That would help me tremendously in figuring out what is going on.
 
Of course, it is also possible that I merged something in wrong or there is some other strange interaction going on. Can anyone who has used this modcomp verify that the AI actually builds buildings which only give +X%:gold:/:science:/:culture:/:espionage: from resources? That would help me tremendously in figuring out what is going on.

Are you giving the building a big enough value? If you give a building 5% science with Iron, or any small value, the AI will only value it as 1.05 * current science rate. Either that or the AI doesn't have the resource, and so it won't benefit from the building.

Try setting the building to a high rate, like 500% gold with wheat, and make sure the AI has access to wheat. See what happens. If the AI doesn't build it quickly, we know there is a problem.
 
Are you giving the building a big enough value? If you give a building 5% science with Iron, or any small value, the AI will only value it as 1.05 * current science rate. Either that or the AI doesn't have the resource, and so it won't benefit from the building.

Try setting the building to a high rate, like 500% gold with wheat, and make sure the AI has access to wheat. See what happens. If the AI doesn't build it quickly, we know there is a problem.

I think that's a good idea to test the modcomp. If it turns out that the AI still doesn't build the buildings I'm afraid I might be not of much help, because this is the only SDK work I've done so far. To make the AI regonize the bonus I've basically searched the whole CvCityAI for 'getCommerceModifier' and added the same code with 'getBonusCommerceModifier' and a loop for all bonuses. For example, this

Spoiler :

Code:
iTempValue = ((kBuilding.getCommerceModifier(COMMERCE_RESEARCH) * getBaseCommerceRate(COMMERCE_RESEARCH)) / 40);


becomes this:

Spoiler :

Code:
					iTempValue = ((kBuilding.getCommerceModifier(COMMERCE_RESEARCH) * getBaseCommerceRate(COMMERCE_RESEARCH)) / 40);
					
//BCM:Added 27.9.09					

					for (iJ = 0; iJ < GC.getNumBonusInfos(); iJ++)
					{
						iTempValue += ((kBuilding.getBonusCommerceModifier(iJ,COMMERCE_RESEARCH) * getBaseCommerceRate(COMMERCE_RESEARCH)) / 40);
					}
					
//BCM:End


Now looking at the code again I see two things that could explain wrong behavior of the AI. The first part of the new code was completely excluded by me:

Spoiler :

Code:
							if (bCulturalVictory1)
							{
								BuildingTypes eLoopBuilding = (BuildingTypes) iI;
								CvBuildingInfo& kLoopBuilding = GC.getBuildingInfo(eLoopBuilding);
								int iLoopBuildingCultureModifier = kLoopBuilding.getCommerceModifier(COMMERCE_CULTURE);

//BCM:Added 27.9.09
								
//								for (iJ = 0; iJ < GC.getNumBonusInfos(); iJ++)
//								{
//									iLoopBuildingCultureModifier += kLoopBuilding.getBonusCommerceModifier(iJ,COMMERCE_CULTURE);
//								}
								
//BCM:End


I think the problem here was that the loop didn't worked and I had no clue how to correct it. However, I think this part is only important if the AI is looking for buildings to build in oder to reach a cultural victory, so this might not be that important.

The second thing is that I haven't put the information in the code that the last part is a replacement of the original code, not an addition.

Spoiler :

Code:
//BCM:Added 27.9.09
					
					iValue += ((kBuilding.getCommerceModifier(COMMERCE_CULTURE) * getBaseCommerceRate(COMMERCE_CULTURE)) / 15);
					
					for (iJ = 0; iJ < GC.getNumBonusInfos(); iJ++)
					{
						iValue += ((kBuilding.getBonusCommerceModifier(iJ,COMMERCE_CULTURE) * getBaseCommerceRate(COMMERCE_CULTURE)) / 15);
					}
					
					if (GC.getGameINLINE().isOption(GAMEOPTION_NO_ESPIONAGE))
					{
						iValue += ((kBuilding.getCommerceModifier(COMMERCE_ESPIONAGE) * getBaseCommerceRate(COMMERCE_ESPIONAGE)) / 15);
						
						for (iJ = 0; iJ < GC.getNumBonusInfos(); iJ++)
						{
							iValue += ((kBuilding.getBonusCommerceModifier(iJ,COMMERCE_ESPIONAGE) * getBaseCommerceRate(COMMERCE_ESPIONAGE)) / 15);
						}
					}
					
				}
				
                if (iFocusFlags & BUILDINGFOCUS_BIGCULTURE)
				{
					iTempValue = (kBuilding.getCommerceModifier(COMMERCE_CULTURE) / 5);
					
					for (iJ = 0; iJ < GC.getNumBonusInfos(); iJ++)
					{
						iTempValue += (kBuilding.getBonusCommerceModifier(iJ,COMMERCE_CULTURE) / 5);
					}
					
					if (iTempValue != 0)
					{
						if (MAX_INT == aiCommerceRank[COMMERCE_CULTURE])
						{
							aiCommerceRank[COMMERCE_CULTURE] = findCommerceRateRank(COMMERCE_CULTURE);
						}

						// if this is a limited wonder, and we are not one of the top 4 in this category, 
						// do not count the culture value
						// we probably do not want to build this here (but we might)
						if (bIsLimitedWonder && (aiCommerceRank[COMMERCE_CULTURE] > (3 + iLimitedWonderLimit)))
						{
							iTempValue  = 0;
						}

						iValue += iTempValue;
					}
				}
				
				if (iFocusFlags & BUILDINGFOCUS_ESPIONAGE || (GC.getGameINLINE().isOption(GAMEOPTION_NO_ESPIONAGE) && (iFocusFlags & BUILDINGFOCUS_CULTURE)))
				{
					iTempValue = ((kBuilding.getCommerceModifier(COMMERCE_ESPIONAGE) * getBaseCommerceRate(COMMERCE_ESPIONAGE)) / 60);
					
					for (iJ = 0; iJ < GC.getNumBonusInfos(); iJ++)
					{
						iTempValue += ((kBuilding.getBonusCommerceModifier(iJ,COMMERCE_ESPIONAGE) * getBaseCommerceRate(COMMERCE_ESPIONAGE)) / 60);
					}
					
					if (iTempValue != 0)
					{
						if (MAX_INT == aiCommerceRank[COMMERCE_ESPIONAGE])
						{
							aiCommerceRank[COMMERCE_ESPIONAGE] = findCommerceRateRank(COMMERCE_ESPIONAGE);
						}

						// if this is a limited wonder, and we are not one of the top 4 in this category, subtract the value
						// we do _not_ want to build this here (unless the value was small anyway)
						if (bIsLimitedWonder && (aiCommerceRank[COMMERCE_ESPIONAGE] > (3 + iLimitedWonderLimit)))
						{
							iTempValue *= -1;
						}

						iValue += iTempValue;
					}
					iTempValue = (kBuilding.getCommerceChange(COMMERCE_ESPIONAGE) * 3);
					iTempValue += (kBuilding.getObsoleteSafeCommerceChange(COMMERCE_ESPIONAGE) * 3);
					iTempValue *= 100 + kBuilding.getCommerceModifier(COMMERCE_ESPIONAGE);
					
					for (iJ = 0; iJ < GC.getNumBonusInfos(); iJ++)
					{
						iTempValue *= 100 + kBuilding.getBonusCommerceModifier(iJ,COMMERCE_ESPIONAGE);
					}
					
					iValue += iTempValue / 100;
				}
			}
			
//BCM:End


(At least I'm pretty sure it is, really should have added a comment here :wallbash:)

I hope this helps in some way, and I'm really happy that my modcomp is of some use. :thumbsup:
 
Thanks for the suggestion Afforess -- an obvious thing I should have tried before posting here complaining. Indeed, we I crank the bonus up to 100%, the AI does build my buildings. So there's nothing fundamentally wrong with the AI code, though I may tweak the weights a little bit because I think my buildings were still good choices at their cost.

SaibotLieh: I'm not too concerned if the AI values culture correctly (it really doesn't make that much of a difference). Anyway, thanks again for this modcomp.
 
Thanks for the suggestion Afforess -- an obvious thing I should have tried before posting here complaining. Indeed, we I crank the bonus up to 100%, the AI does build my buildings. So there's nothing fundamentally wrong with the AI code, though I may tweak the weights a little bit because I think my buildings were still good choices at their cost.

No Worries, just glad it works for you too. ;)
 
The city interface tooltip is displaying wrong commerce (the commerce itself works correctly). The bonus from a building with bonus commerce gets multiplied with the rest (however).

Example:

72 raw commerce

10% gold slider = 7.2 gold
+5 gold by corporation
+331 gold by buildings
+140% by ressources
+325% by buildings

= +3500.64 total gets displayed which must be incorrect. should be (7.2 + 5 + 331) * (1 + 1.4 + 3.25) = 1939.08 right?

 
Damn, you are right, thanks for noticing. I made an error in the CvGameTextMgr file. Did not pay enough attention to it that time. The second entry must be corrected. The corretly working file is attached to the post. :)
 

Attachments

  • CvGameTextMgr.zip
    68.3 KB · Views: 290
Edit: I got it, I believe. :D

PHP:
//BCM:Added 11.6.10
	
	int iBonusCommerce = city.getBonusCommerceRateModifier(eCommerceType);
	if (0 != iBonusCommerce)
	{
		szBuffer.append(gDLL->getText("TXT_KEY_MISC_HELP_BONUS_COMMERCE", iBonusCommerce, info.getChar()));
		szBuffer.append(NEWLINE);
		iModifier += iBonusCommerce;
	}
	
//BCM:End
 
Edit: I got it, I believe. :D

Aye, that's the new second entry. Of course the old one should be deleted, otherwise there will be even more income displayed. ;)
 
Why isn't the +10% with gold appearing in my mod? I have seen it in the XML, but it doesn't appear neather in the Civilopedia, nor ingame. It's making me sad. :sad:
 
Top Bottom