SaibotLieh
Emperor
- Joined
- Sep 25, 2009
- Messages
- 1,576
I'm trying to write a mod that gives the possibility to modify the output of beakers, gold, culture and espionage through the combination of certain resources and buildings. To say it in other words, I would like to add a "BonusCommerceModifiers" option for buildings. For this purpose, I basically copied each "BonusYieldModifier" entry in the CvInfo.cpp, CvInfo.h and CvGameTextMgr.cpp files and replaced the Yield with Commerce. The .dll could be created successfully this way, the mod starts with no errors and the bonus through the resource is displayed as it should be, but it has no effect on the output of the city at all.
I have no clue what is still missing now, any help is highly appreciate. My modifications in the files are all marked with "BCM:", the mod version in the attachment has the palace modified to add 100% to anything if supplied with wheat.
CvInfo.cpp modifications:
m_ppaiBonusCommerceModifier(NULL),
(...)
if (m_ppaiBonusCommerceModifier != NULL)
{
for(int i=0;i<GC.getNumBonusInfos();i++)
{
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
(...)
int CvBuildingInfo::getBonusCommerceModifier(int i, int j) const
{
FAssertMsg(i < GC.getNumBonusInfos(), "Index out of bounds");
FAssertMsg(i > -1, "Index out of bounds");
FAssertMsg(j < NUM_COMMERCE_TYPES, "Index out of bounds");
FAssertMsg(j > -1, "Index out of bounds");
return m_ppaiBonusCommerceModifier ? m_ppaiBonusCommerceModifier[j] : -1;
}
int* CvBuildingInfo::getBonusCommerceModifierArray(int i) const
{
FAssertMsg(i < GC.getNumBonusInfos(), "Index out of bounds");
FAssertMsg(i > -1, "Index out of bounds");
return m_ppaiBonusCommerceModifier;
}
(...)
if (m_ppaiBonusCommerceModifier != NULL)
{
for(i=0;i<GC.getNumBonusInfos();i++)
{
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
m_ppaiBonusCommerceModifier = new int*[GC.getNumBonusInfos()];
for(i=0;i<GC.getNumBonusInfos();i++)
{
m_ppaiBonusCommerceModifier = new int[NUM_COMMERCE_TYPES];
stream->Read(NUM_COMMERCE_TYPES, m_ppaiBonusCommerceModifier);
}
(...)
for(i=0;i<GC.getNumBonusInfos();i++)
{
stream->Write(NUM_COMMERCE_TYPES, m_ppaiBonusCommerceModifier);
}
(...)
pXML->Init2DIntList(&m_ppaiBonusCommerceModifier, GC.getNumBonusInfos(), NUM_COMMERCE_TYPES);
if (gDLL->getXMLIFace()->SetToChildByTagName(pXML->GetXML(),"BonusCommerceModifiers"))
{
iNumChildren = gDLL->getXMLIFace()->GetNumChildren(pXML->GetXML());
if (gDLL->getXMLIFace()->SetToChildByTagName(pXML->GetXML(),"BonusCommerceModifier"))
{
for(j=0;j<iNumChildren;j++)
{
pXML->GetChildXmlValByName(szTextVal, "BonusType");
k = pXML->FindInInfoClass(szTextVal);
if (k > -1)
{
// delete the array since it will be reallocated
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier[k]);
if (gDLL->getXMLIFace()->SetToChildByTagName(pXML->GetXML(),"CommerceModifiers"))
{
// call the function that sets the commerce change variable
pXML->SetCommerce(&m_ppaiBonusCommerceModifier[k]);
gDLL->getXMLIFace()->SetToParent(pXML->GetXML());
}
else
{
pXML->InitList(&m_ppaiBonusCommerceModifier[k], NUM_COMMERCE_TYPES);
}
}
if (!gDLL->getXMLIFace()->NextSibling(pXML->GetXML()))
{
break;
}
}
// set the current xml node to it's parent node
gDLL->getXMLIFace()->SetToParent(pXML->GetXML());
}
// set the current xml node to it's parent node
gDLL->getXMLIFace()->SetToParent(pXML->GetXML());
}
(...)
CvInfo.h modifications:
DllExport int getBonusCommerceModifier(int i, int j) const; // Exposed to Python
int* getBonusCommerceModifierArray(int i) const;
(...)
int** m_ppaiBonusCommerceModifier;
CvGameTextMgr.cpp modifications:
for (iI = 0; iI < GC.getNumBonusInfos(); ++iI)
{
szFirstBuffer = gDLL->getText("TXT_KEY_BUILDING_WITH_BONUS", GC.getBonusInfo((BonusTypes) iI).getTextKeyWide());
setCommerceChangeHelp(szBuffer, L"", L"", szFirstBuffer, kBuilding.getBonusCommerceModifierArray(iI), true);
}
I have no clue what is still missing now, any help is highly appreciate. My modifications in the files are all marked with "BCM:", the mod version in the attachment has the palace modified to add 100% to anything if supplied with wheat.
CvInfo.cpp modifications:
Spoiler :
m_ppaiBonusCommerceModifier(NULL),
(...)
if (m_ppaiBonusCommerceModifier != NULL)
{
for(int i=0;i<GC.getNumBonusInfos();i++)
{
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
(...)
int CvBuildingInfo::getBonusCommerceModifier(int i, int j) const
{
FAssertMsg(i < GC.getNumBonusInfos(), "Index out of bounds");
FAssertMsg(i > -1, "Index out of bounds");
FAssertMsg(j < NUM_COMMERCE_TYPES, "Index out of bounds");
FAssertMsg(j > -1, "Index out of bounds");
return m_ppaiBonusCommerceModifier ? m_ppaiBonusCommerceModifier[j] : -1;
}
int* CvBuildingInfo::getBonusCommerceModifierArray(int i) const
{
FAssertMsg(i < GC.getNumBonusInfos(), "Index out of bounds");
FAssertMsg(i > -1, "Index out of bounds");
return m_ppaiBonusCommerceModifier;
}
(...)
if (m_ppaiBonusCommerceModifier != NULL)
{
for(i=0;i<GC.getNumBonusInfos();i++)
{
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier);
}
m_ppaiBonusCommerceModifier = new int*[GC.getNumBonusInfos()];
for(i=0;i<GC.getNumBonusInfos();i++)
{
m_ppaiBonusCommerceModifier = new int[NUM_COMMERCE_TYPES];
stream->Read(NUM_COMMERCE_TYPES, m_ppaiBonusCommerceModifier);
}
(...)
for(i=0;i<GC.getNumBonusInfos();i++)
{
stream->Write(NUM_COMMERCE_TYPES, m_ppaiBonusCommerceModifier);
}
(...)
pXML->Init2DIntList(&m_ppaiBonusCommerceModifier, GC.getNumBonusInfos(), NUM_COMMERCE_TYPES);
if (gDLL->getXMLIFace()->SetToChildByTagName(pXML->GetXML(),"BonusCommerceModifiers"))
{
iNumChildren = gDLL->getXMLIFace()->GetNumChildren(pXML->GetXML());
if (gDLL->getXMLIFace()->SetToChildByTagName(pXML->GetXML(),"BonusCommerceModifier"))
{
for(j=0;j<iNumChildren;j++)
{
pXML->GetChildXmlValByName(szTextVal, "BonusType");
k = pXML->FindInInfoClass(szTextVal);
if (k > -1)
{
// delete the array since it will be reallocated
SAFE_DELETE_ARRAY(m_ppaiBonusCommerceModifier[k]);
if (gDLL->getXMLIFace()->SetToChildByTagName(pXML->GetXML(),"CommerceModifiers"))
{
// call the function that sets the commerce change variable
pXML->SetCommerce(&m_ppaiBonusCommerceModifier[k]);
gDLL->getXMLIFace()->SetToParent(pXML->GetXML());
}
else
{
pXML->InitList(&m_ppaiBonusCommerceModifier[k], NUM_COMMERCE_TYPES);
}
}
if (!gDLL->getXMLIFace()->NextSibling(pXML->GetXML()))
{
break;
}
}
// set the current xml node to it's parent node
gDLL->getXMLIFace()->SetToParent(pXML->GetXML());
}
// set the current xml node to it's parent node
gDLL->getXMLIFace()->SetToParent(pXML->GetXML());
}
(...)
CvInfo.h modifications:
Spoiler :
DllExport int getBonusCommerceModifier(int i, int j) const; // Exposed to Python
int* getBonusCommerceModifierArray(int i) const;
(...)
int** m_ppaiBonusCommerceModifier;
CvGameTextMgr.cpp modifications:
Spoiler :
for (iI = 0; iI < GC.getNumBonusInfos(); ++iI)
{
szFirstBuffer = gDLL->getText("TXT_KEY_BUILDING_WITH_BONUS", GC.getBonusInfo((BonusTypes) iI).getTextKeyWide());
setCommerceChangeHelp(szBuffer, L"", L"", szFirstBuffer, kBuilding.getBonusCommerceModifierArray(iI), true);
}