BuildingInfo- PrereqCiv(Help with code not working)

Castor_Troy

Warlord
Joined
Jun 4, 2007
Messages
145
Location
Romania
Hello, I`ve busted my head trying to find the problem, i am inexperienced in C++ so possibly/hopefully the solution is really simple: the code is from FFH2(thought i should have no problems with that just a simple identify and merge job). But here goes this is what i have put in my source code:
Notes:
Spoiler :
1. The compiling gives no errors, all the tags are at their specific place( i use K-Mod source files as a basis).
2.Tried to compile without the readPass3 since i had no ideea what it does, it compiles but still doesnt work.
3.The function doesnt work properly nor display the civ requirement anywhere.
4.The XML gives also no errors the tag is where it is supposed to be. The game doesnt crash ran on AIAutoPlay hundreds of turns no crash

CvInfos.cpp:
Spoiler :
m_iPrereqReligion(NO_RELIGION),
m_iPrereqCiv(NO_CIVILIZATION), // Separatio
m_iPrereqCorporation(NO_CORPORATION),
__________________________________________
int CvBuildingInfo::getPrereqReligion() const
{
return m_iPrereqReligion;
}
// Separatio START
int CvBuildingInfo::getPrereqCiv() const
{
return m_iPrereqCiv;
}
// Separatio END

int CvBuildingInfo::getPrereqCorporation() const
{
return m_iPrereqCorporation;
}
___________________________________________
stream->Read(&m_iPrereqReligion);
stream->Read(&m_iPrereqCiv); // Separatio
stream->Read(&m_iPrereqCorporation);
___________________________________________
stream->Write(m_iPrereqReligion);
stream->Write(m_iPrereqCiv); // Separatio
stream->Write(m_iPrereqCorporation);
___________________________________________
pXML->GetChildXmlValByName(szTextVal, "PrereqReligion");
m_iPrereqReligion = pXML->FindInInfoClass(szTextVal);

pXML->GetChildXmlValByName(szTextVal, "PrereqCiv"); // Separatio
m_aszExtraXMLforPass3.push_back(szTextVal);

pXML->GetChildXmlValByName(szTextVal, "PrereqCorporation");
m_iPrereqCorporation = pXML->FindInInfoClass(szTextVal);
___________________________________________
// Separatio START
bool CvBuildingInfo::readPass3()
{
if (m_aszExtraXMLforPass3.size() < 1)
{
FAssert(false);
return false;
}
m_iPrereqCiv = GC.getInfoTypeForString(m_aszExtraXMLforPass3[0]);
m_aszExtraXMLforPass3.clear();
return true;
}
// Separatio END

CvInfos.h:
Spoiler :
int getPrereqReligion() const;
int getPrereqCiv() const; // Separatio
int getPrereqCorporation() const;
___________________________________________
int m_iPrereqReligion;
int m_iPrereqCiv; // Separatio
int m_iPrereqCorporation;
___________________________________________
bool readPass3(); // Separatio

CvCity.cpp:
Spoiler :
in CvCity::canConstruct
if (GC.getBuildingInfo(eBuilding).getPrereqReligion() != NO_RELIGION)
{
if (!(isHasReligion((ReligionTypes)(GC.getBuildingInfo(eBuilding).getPrereqReligion()))))
{
return false;
}
}
// Separatio START
if (GC.getBuildingInfo(eBuilding).getPrereqCiv() != NO_CIVILIZATION)
{
if (GC.getBuildingInfo(eBuilding).getPrereqCiv() != getCivilizationType())
{
return false;
}
}
// Separatio END

CvGameTextMsg.cpp:
Spoiler :
// Separatio START
// if ((eDefaultBuilding != NO_BUILDING) && (eUniqueBuilding != NO_BUILDING))
if (eDefaultBuilding != NO_BUILDING
&& (eUniqueBuilding != NO_BUILDING
|| GC.getBuildingInfo(eDefaultBuilding).getPrereqCiv() == eCivilization))
// Separatio END
___________________________________________
// Separatio START
// szBuffer.Format((bLinks ? L"<link=literal>%s</link> - (<link=literal>%s</link>)" : L"%s - (%s)"),
// GC.getBuildingInfo(eDefaultBuilding).getDescription(),
// GC.getBuildingInfo(eUniqueBuilding).getDescription());
if (GC.getBuildingInfo(eDefaultBuilding).getPrereqCiv() != eCivilization)
{
szBuffer.Format((bLinks ? L"<link=literal>%s</link> - (<link=literal>%s</link>)" : L"%s - (%s)"),
GC.getBuildingInfo(eDefaultBuilding).getDescription(),
GC.getBuildingInfo(eUniqueBuilding).getDescription());
}
else
{
szBuffer.Format((bLinks ? L"<link=literal>%s</link>" : L"%s"),
GC.getBuildingInfo(eDefaultBuilding).getDescription());
}
// Separatio END

XML tags:
Spoiler :
<PrereqReligion>NONE</PrereqReligion>
<PrereqCiv>CIVILIZATION_CORDUBA</PrereqCiv> //Separatio
<PrereqCorporation>NONE</PrereqCorporation>

CyInfoInterface1.cpp:
Spoiler :
.def("getPrereqReligion", &CvBuildingInfo::getPrereqReligion, "int ()")
.def("getPrereqCiv", &CvBuildingInfo::getPrereqCiv, "int ()") // Separatio
.def("getPrereqCorporation", &CvBuildingInfo::getPrereqCorporation, "int ()")


P.S.
Could i be missing some codes from the FFH2 regarding the effect ? Although possible i checked it three times and excluded all the prereqCiv they had for Civic, Events, Projects, Improvements
 
Yes like i specified in the Notes: there are absolutely no errors XML, DLL compiler and the game is playable. I even tried messing around more with the messaging part to make it display, but it seems the values never gets read for some reasons, i am pressuming smth from CvCity.cpp is missing or incorrect but i cant understand what.
 
i'm pretty sure you need to indicate manually in the xml loading part of the code that you want the ReadPass3 method to be called for buildings

look for that line in cvXMLLoadUtilitySet.cpp
Code:
	LoadGlobalClassInfo(GC.getBuildingInfo(), "CIV4BuildingInfos", "Buildings", "Civ4BuildingInfos/BuildingInfos/BuildingInfo", false, &CvDLLUtilityIFaceBase::createBuildingInfoCacheObject);

and add after it something like that :
Code:
	for (int i=0; i < GC.getNumBuildingInfos(); ++i)
	{
		GC.getBuildingInfo((BuildingTypes)i).readPass3();
	}
 
i'm pretty sure you need to indicate manually in the xml loading part of the code that you want the ReadPass3 method to be called for buildings
Yeah, that is required. However order is important here because using data before the are read from xml is a real issue. BuildingInfo need info from CivilizationInfo. This mean the order is as follows in
CvXMLLoadUtility::LoadPreMenuGlobals() in CvXMLLoadUtilitySet.cpp.

PHP:
LoadGlobalClassInfo(GC.getCivilizationInfo()
LoadGlobalClassInfo(GC.getBuildingInfo()
for (int i=0; i < GC.getNumBuildingInfos(); ++i)
{
	GC.getBuildingInfo((BuildingTypes)i).readPass3();
}
There can be other lines in between those lines and copy paste is not the right way to do this. It just shows the order relative to each other to get the job done. Also I didn't copy paste the rather long load lines.

Personally I would place the loop near the end of the function together with the other loops already placed there. However that is not strictly needed.

I don't have the FFT2 source with me right now. What I wrote is based on vanilla and AFAIK I'm the only one who altered this part of the code in any mod. This mean either it's FTTW, M:C or vanilla code when it comes to reading xml files. Please correct me if I'm wrong. I would be very interested if somebody else did some interesting work in this part of the code.
 
EDITED:
Working at night takes it toll a bad copy/paste.
It works but i got a bunch of errors from moving the LoadGlobalClassInfo(GC.getCivilizationInfo()...) so i instead ported the for (int i=0; i < GC.getNumBuildingInfos(); ++i)..... after its official place like you suggested Nightinggale. Now works like a charm tested it out.

Basically for adding it you will need two searches in the FFH2 code:
PrereqCiv (and put everything related to BuildingInfo) and ReadPass3 (Which has 3 parts 1 in Info.cpp 1 in Info.h(this one caused me a problem cause i pasted it wrong from start) 1 in CvXMLLoadUtilitySet.cpp
 
Top Bottom