Barracks UB Issue

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I have come across a really strange issue: I have a problem creating a unit. This unit is called the MTI and it has two prerequisites:

Code:
<PrereqBuilding>BUILDING_BARRACKS</PrereqBuilding>
<PrereqTech>TECH_ORGANIZED_WARFARE</PrereqTech>

If a user plays a civ that has a Unique Building (UB) for the barracks, i.e. Zulu, Shaka, BUILDING_ZULU_IKHANDA; The icon fails to light up to add the MTI into the build cue. Both the Barracks and the Ikhanda have the same BuildingClass:

Code:
<BuildingClass>BUILDINGCLASS_BARRACKS</BuildingClass>
<Type>BUILDING_ZULU_IKHANDA</Type>

If the user plays a civ, without a UB for the barracks, the icon lights up every time, when both prerequisites are met. The failure seems to occur in the CvMainInterface.py file at the point where the code determines what the iUnitType is. In this case:

Code:
if iUnitType == gc.getInfoTypeForString("UNIT_MTI"):

I tried to replace that line with:

Code:
if iUnitClassType == gc.getInfoTypeForString("UNITCLASS_MTI"):

...but had the same result. The code failed to progress past this line. It makes no sense to me why this is happening. :crazyeye: :confused:

Update: If I take away the prerequisit for the Barracks, the icon works. So it all comes down to the building type.
 
The PrereqBuilding tag specifies a building type, not a building class so it does not work with UBs since they are not the same type.

This has come up before, including with Final Frontier Plus (and other related mods). I don't know if anybody has ever "fixed" it, but there is a workaround.

The workaround that I know of is to make all units that require the regular building of the UB's class be UUs for the civ with the UB, even if it is just so that the UU can specify the UB instead of the regular building (but is identical in every other way). So this solutions would be to make a UU version of the "MTI" for the Zulu, the XML for the UU can be identical to the original except for the unit type string (like UNIT_MTI_ZULU or something, which the player should never see) and the PrereqBuilding, which would be set to the Ikhanda. (And likewise for any other civ with a UB version of the barracks.)

The other, more complete but more difficult, solution would be to change the usage of the PrereqBuilding tag in the DLL (and Python, probably) to make it specify a building class. I don't know how many locations in the DLL you'd have to adjust for that - any place that uses it, which might only be one place, and anything that generates text for it (which is probably a couple of places in the DLL and maybe in the civilopedia too). The easy part is to then go through the unit XML and change every use of it to specify the building class of the currently specified building.
 
The PrereqBuilding tag specifies a building type, not a building class so it does not work with UBs since they are not the same type.

This has come up before, including with Final Frontier Plus (and other related mods). I don't know if anybody has ever "fixed" it, but there is a workaround.

The workaround that I know of is to make all units that require the regular building of the UB's class be UUs for the civ with the UB, even if it is just so that the UU can specify the UB instead of the regular building (but is identical in every other way). So this solutions would be to make a UU version of the "MTI" for the Zulu, the XML for the UU can be identical to the original except for the unit type string (like UNIT_MTI_ZULU or something, which the player should never see) and the PrereqBuilding, which would be set to the Ikhanda. (And likewise for any other civ with a UB version of the barracks.)

The other, more complete but more difficult, solution would be to change the usage of the PrereqBuilding tag in the DLL (and Python, probably) to make it specify a building class. I don't know how many locations in the DLL you'd have to adjust for that - any place that uses it, which might only be one place, and anything that generates text for it (which is probably a couple of places in the DLL and maybe in the civilopedia too). The easy part is to then go through the unit XML and change every use of it to specify the building class of the currently specified building.


My solution is a little different. I removed the Training Instructor unit XML requirement for the Barracks type and made a change to the CvMainInterface.py file:

Code:
FoundBarracks = False      #Placed at the beginning of this section.



# CombinedForces Mod
if GameOptionsStatus.isOC_COMBINED_FORCES():
	iBCBarracks = gc.getInfoTypeForString("BUILDINGCLASS_BARRACKS")
						
	for iBld in range(gc.getNumBuildingInfos()):
		if (g_pSelectedUnitCity.getNumActiveBuilding(iBld) > 0):
			if gc.getBuildingInfo(iBld).getBuildingClassType() == iBCBarracks:	
				FoundBarracks = True
				break
								
	if FoundBarracks:									
		if iUnitType == gc.getInfoTypeForString("UNIT_HTI"):
			if CombinedForces.showBuildCombinedUnitButton(g_pSelectedUnit):
				screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUILD_AABRIGADE").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 691, 691, False )
				screen.show("BottomButtonContainer")
				iCount = iCount + 1
									
		if iUnitType == gc.getInfoTypeForString("UNIT_MTI"):
			if CombinedForces.showBuildCombinedUnitButton(g_pSelectedUnit):
				screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUILD_ARMY").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 692, 692, False )
				screen.show("BottomButtonContainer")
				iCount = iCount + 1
									
		if iUnitType == gc.getInfoTypeForString("UNIT_NTI"):
			if CombinedForces.showBuildCombinedUnitButton(g_pSelectedUnit):
				screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUILD_FLEET").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 693, 693, False )
				screen.show("BottomButtonContainer")
				iCount = iCount + 1
									
		if iUnitType == gc.getInfoTypeForString("UNIT_TATI"):
			if CombinedForces.showBuildCombinedUnitButton(g_pSelectedUnit):
				screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUILD_TACTICAL_AIR_FORCE").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 694, 694, False )
				screen.show("BottomButtonContainer")
				iCount = iCount + 1
									
		if iUnitType == gc.getInfoTypeForString("UNIT_SATI"):
			if CombinedForces.showBuildCombinedUnitButton(g_pSelectedUnit):
				screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUILD_STRATEGIC_AIR_FORCE").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 695, 695, False )
				screen.show("BottomButtonContainer")
				iCount = iCount + 1
# End CombinedForces Mod

This change checks for the existance of the Barracks building class in the city before making the icon visible for any of the Training Instructor units. The test worked perfectly.
 
Back
Top Bottom