Trying to fix Assimilation bug, please help

Ninja2

Great Engineer
Joined
Nov 17, 2005
Messages
1,142
Location
Denmarkia
Hi all,

So I am using one of Kael's modcomps, Assimilation.

There is a bug in the component, since when I conquer a city I am still able to build my unique building in it, even though it already has the normal version of the same building. Playing e.g. Romans, this allows me to build the Forum in conquered cities that already have a marketplace, and I thus get the benefit of both buildings.

I am trying to figure out how to fix this, as Kael doesn't seem to have time to look into this. What I'd like to do in this specific situation is to disallow my own unique building in the conquered city, although I am open to other (easier) solutions. I *think* I need to add a condition in the pasted code below (like: if the city has foo building, disallow the unique foo building), but I don't know how to syntax it properly. Help! :)

This is from CvCity.cpp:
Code:
bool CvCity::canConstruct(BuildingTypes eBuilding, bool bContinue, bool bTestVisible, bool bIgnoreCost) const

[...]

//Ass: Added by Kael 07/02/2008
	if (GC.getGameINLINE().isOption(GAMEOPTION_ASSIMILATION))
	{
        BuildingClassTypes eBuildingClass = ((BuildingClassTypes)(GC.getBuildingInfo(eBuilding).getBuildingClassType()));
        if (GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) != eBuilding)
        {
            return false;
        }
	}
//Ass: End Add

And from CvPlayer.cpp
Code:
bool CvPlayer::canConstruct(BuildingTypes eBuilding, bool bContinue, bool bTestVisible, bool bIgnoreCost) const

[...]

//Ass: Modified by Kael 07/02/2008
//	FAssert(GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) == eBuilding);
//	if (GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) != eBuilding)
//	{
//		return false;
//	}
	if (!GC.getGameINLINE().isOption(GAMEOPTION_ASSIMILATION))
	{
	FAssert(GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) == eBuilding);
	if (GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) != eBuilding)
	{
		return false;
	}
	}
//Ass: End Modify
 
Hi all,

So I am using one of Kael's modcomps, Assimilation.

There is a bug in the component, since when I conquer a city I am still able to build my unique building in it, even though it already has the normal version of the same building. Playing e.g. Romans, this allows me to build the Forum in conquered cities that already have a marketplace, and I thus get the benefit of both buildings.

I am trying to figure out how to fix this, as Kael doesn't seem to have time to look into this. What I'd like to do in this specific situation is to disallow my own unique building in the conquered city, although I am open to other (easier) solutions. I *think* I need to add a condition in the pasted code below (like: if the city has foo building, disallow the unique foo building), but I don't know how to syntax it properly. Help! :)

This is from CvCity.cpp:
Code:
bool CvCity::canConstruct(BuildingTypes eBuilding, bool bContinue, bool bTestVisible, bool bIgnoreCost) const

[...]

//Ass: Added by Kael 07/02/2008
	if (GC.getGameINLINE().isOption(GAMEOPTION_ASSIMILATION))
	{
        BuildingClassTypes eBuildingClass = ((BuildingClassTypes)(GC.getBuildingInfo(eBuilding).getBuildingClassType()));
        if (GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) != eBuilding)
        {
            return false;
        }
	}
//Ass: End Add

And from CvPlayer.cpp
Code:
bool CvPlayer::canConstruct(BuildingTypes eBuilding, bool bContinue, bool bTestVisible, bool bIgnoreCost) const

[...]

//Ass: Modified by Kael 07/02/2008
//	FAssert(GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) == eBuilding);
//	if (GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) != eBuilding)
//	{
//		return false;
//	}
	if (!GC.getGameINLINE().isOption(GAMEOPTION_ASSIMILATION))
	{
	FAssert(GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) == eBuilding);
	if (GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) != eBuilding)
	{
		return false;
	}
	}
//Ass: End Modify

I don't know how but I do know one thing. Afforess solved it in his latest beta of AND 1.6. You should ask Afforess. :)
 
There are two solutions here. You need to decide what you want to happen:

With Assimilation, should I be able to build MY civilization's UB and the OTHER civilization's unique building in the same city?

OR should I ONLY be able to build the UB for the civilization who founded the city.

The latter method is, what I believe Kael Intended, and what I chose.

If you choose the latter method, here's what you do to fix it:

in CvPlayer::acquireCity(...)

A ways down, right here where it begins checking if buildings are destroyed or not, the red section is the problem section.

Code:
for (iI = 0; iI < GC.getNumBuildingInfos(); iI++)
	{
		int iNum = 0;

		if (paiNumRealBuilding[iI] > 0)
		{
			BuildingClassTypes eBuildingClass = (BuildingClassTypes)GC.getBuildingInfo((BuildingTypes)iI).getBuildingClassType();
[COLOR="Red"]			if (::isWorldWonderClass(eBuildingClass))
			{
				eBuilding = (BuildingTypes)iI;
			}
			else
			{			
				eBuilding = eBuilding = (BuildingTypes)GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass);
			}[/COLOR]

			if (eBuilding != NO_BUILDING)
			{
				if (bTrade || !(GC.getBuildingInfo((BuildingTypes)iI).isNeverCapture()))
				{
					if (!isProductionMaxedBuildingClass(((BuildingClassTypes)(GC.getBuildingInfo(eBuilding).getBuildingClassType())), true))
					{

Here's what you tweak it to:

Code:
	for (iI = 0; iI < GC.getNumBuildingInfos(); iI++)
	{
		int iNum = 0;

		if (paiNumRealBuilding[iI] > 0)
		{
			BuildingClassTypes eBuildingClass = (BuildingClassTypes)GC.getBuildingInfo((BuildingTypes)iI).getBuildingClassType();
[COLOR="Blue"]/************************************************************************************************/
/* Afforess	                  Start		 02/03/10                                              */
/*                                                                                              */
/*   Assimilation Bug Fix                                                                       */
/************************************************************************************************/
			if ((::isWorldWonderClass(eBuildingClass)) || (GC.getGameINLINE().isOption(GAMEOPTION_ASSIMILATION)))
			{
				eBuilding = (BuildingTypes)iI;
/************************************************************************************************/
/* Afforess	                     END                                                            */
/************************************************************************************************/[/COLOR]
			}
			else
			{			
				eBuilding = eBuilding = (BuildingTypes)GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass);
			}

			if (eBuilding != NO_BUILDING)
			{
				if (bTrade || !(GC.getBuildingInfo((BuildingTypes)iI).isNeverCapture()))
				{
					if (!isProductionMaxedBuildingClass(((BuildingClassTypes)(GC.getBuildingInfo(eBuilding).getBuildingClassType())), true))
					{
						if (pNewCity->isValidBuildingLocation(eBuilding))
						{
							if (!bConquest || bRecapture || GC.getGameINLINE().getSorenRandNum(100, "Capture Probability") < GC.getBuildingInfo((BuildingTypes)iI).getConquestProbability())
							{
								iNum += paiNumRealBuilding[iI];
							}
						}
					}
				}

That will make it so the other civilizations buildings, including UB's, will stay as their UB, and won't convert to your UB.
 
Thanks for helping out, Afforess! :)

I don't understand your solution. Are you saying that Kael's mod replaces buildings in conquered cities currently? This is news to me. The bug I'm hunting is the one where you can have two buildings of the same type in a conquered city - one being the original vanilla building, the other being my own unique building I can build after conquest. Like having a Lighthouse and a Trading Post (Viking unique building), for a net +2:food: in each sea tile, which is obviously overpowered.

Please read the bolded part in the first post. :)
 
I don't understand your solution. Are you saying that Kael's mod replaces buildings in conquered cities currently? This is news to me. The bug I'm hunting is the one where you can have two buildings of the same type in a conquered city - one being the original vanilla building, the other being my own unique building I can build after conquest. Like having a Lighthouse and a Trading Post (Viking unique building), for a net +2:food: in each sea tile, which is obviously overpowered.

You don't understand how UB work from a SDK perspective.

Let me try to explain.

Every Building is a Unique Building. All of them. It's just that most of the Unique Buildings match the default building (set in the buildingClassInfos.xml) and so don't show up as UB's.

Now, when I capture a city as the vikings, it converts every building, except for wonders, to my UB. So let's pretend the city has a walls, terrace (the city is Incan), and lighthouse. The walls get converted back to my UB, but as vikings, my UB is the walls, so nothing changes. The terrace get's converted back to my UB, and my UB is the granary, so it changes to the granary. The lighthouse get's converted to my UB, and my UB is the Trading Post, so the building magically changes into a trading post.

Above is a description of BTS standard behavior.

Here's the problem with this & Assimilation.

With Assimilation, my UB doesn't matter, the original player's does. You don't want the game to convert the lighthouse to the Trading Post. You don't want the Terrace to change into a Granary, because it would allow us to build a terrace again. That's why my post changes, so that buildings won't convert to your UB when they get captured.
 
Aha, that explains it! :) I must say, you've really come a long way in a short time in respect of handling the dll! :goodjob: I'll implement the fix you suggested, and again, thanks for the help.
 
there are many more problems... civic building happiness changes do not work for foreign ub, neither building health changes. i im currently trying to fix it, but had no luck yet.
 
Top Bottom