Davinci Fan
Chieftain
- Joined
- Jun 6, 2007
- Messages
- 86
This began as a problem I'd had with my mod, but since it has been solved, I thought I'd share it with everyone:
Follow Kael's tutorial on adding XML tags in the tutorials forum. Specifically:
Civ4TerrainSchema.XML:
In CIV4BonusInfos.XML (every entry):
CvInfos.cpp:
CvInfos.h:
To add functionality, modify CvMapGenerator.cpp:
Remember: the 'i' in isRequiresWater is lower-case...
Below is the original post:
I'm working on a comp for my mod that adds a tag to BonusInfos that allow me to restrict a resource to coasts and rivers.
I've followed Kael's tutorial to great success in the setup department (thanks for that), but while programming the functionality, I've hit a road block, and my relatively limited experience is unequipped to solve this problem.
There does not appear to be any problem with anything from the tutorial, since everything compiled just fine after that, so for the moment I'd like to hope that the problem here is in my programming.
Here is what I've added thus far:
IsRequiresWater is a function I modeled according to the tutorial, exactly copying IsNoRiverside (except for the name obviously) with respect to the'get' function.
When I compile, I get three errors:
Error 2039: 'IsRequiresWater' : is not a member of 'CvBonusInfo'
Error 2228: left of '.IsCoastalLand' must have class/struct/union type
Error 2228: left of '.IsFreshWater' must have class/struct/union type
Can someone more literate than I help me out here?
Thanks,
Follow Kael's tutorial on adding XML tags in the tutorials forum. Specifically:
Civ4TerrainSchema.XML:
Code:
<ElementType name="bNoRiverSide" content="textOnly" dt:type="boolean"/>
[B]<ElementType name="bRequiresWater" content="textOnly" dt:type="boolean"/>[/B] //line 216 in the unmodified version
<ElementType name="bNormalize" content="textOnly" dt:type="boolean"/>
...
<element type="bNoRiverSide"/>
[B]<element type="bRequiresWater"/>[/B] //line 265
<element type="bNormalize"/>
In CIV4BonusInfos.XML (every entry):
Code:
<bNoRiverSide>0</bNoRiverSide>
[B]<bRequiresWater>0</bRequiresWater>[/B] //change to 1 to restrict this resource
<bNormalize>0</bNormalize>
CvInfos.cpp:
Code:
//------------------------------------------------------------------------------------------------------
//
// FUNCTION: CvBonusInfo()
//
// PURPOSE : Default constructor
//
//------------------------------------------------------------------------------------------------------
CvBonusInfo::CvBonusInfo() :
...
m_bNoRiverSide(false),
[B]m_bRequiresWater(false),[/B]
m_bNormalize(false),
[CENTER]...[/CENTER]
//------------------------------------------------------------------------------------------------------
//
// FUNCTION: ~CvBonusInfo()
//
// PURPOSE : Default destructor
//
//------------------------------------------------------------------------------------------------------
CvBonusInfo::~CvBonusInfo()
...
bool CvBonusInfo::[B]isRequiresWater()[/B] const
{
return m_bRequiresWater;
}
[CENTER]...[/CENTER]
void CvBonusInfo::read(FDataStreamBase* stream)
{
...
stream->Read(&m_bNoRiverSide);
[B]stream->Read(&m_bRequiresWater);[/B]
stream->Read(&m_bNormalize);
[CENTER]...[/CENTER]
void CvBonusInfo::write(FDataStreamBase* stream)
...
stream->Write(m_bNoRiverSide);
[B]stream->Write(m_bRequiresWater);[/B]
stream->Write(m_bNormalize);
[CENTER]...[/CENTER]
pXML->GetChildXmlValByName(&m_bNoRiverSide, "bNoRiverSide");
[B]pXML->GetChildXmlValByName(&m_bRequiresWater, "bRequiresWater");[/B]
pXML->GetChildXmlValByName(&m_bNormalize, "bNormalize");
CvInfos.h:
Code:
DllExport bool isNoRiverSide() const; // Exposed to Python
[B]DllExport bool isRequiresWater() const; [/B] // Exposed to Python
DllExport bool isNormalize() const; // Exposed to Python
[CENTER]...[/CENTER]
bool m_bNoRiverSide;
[B]bool m_bRequiresWater;[/B]
bool m_bNormalize;
To add functionality, modify CvMapGenerator.cpp:
Code:
bool CvMapGenerator::canPlaceBonusAt(BonusTypes eBonus, int iX, int iY, bool bIgnoreLatitude)
{
...
if (pPlot->isWater())
{
if (((GC.getMapINLINE().getNumBonusesOnLand(eBonus) * 100) / (GC.getMapINLINE().getNumBonuses(eBonus) + 1)) < pInfo.getMinLandPercent())
{
return false;
}
}
[B] if (GC.getBonusInfo(eBonus).isRequiresWater())
{
if (!(pPlot->isCoastalLand(0) || pPlot->isFreshWater()))
{
return false;
}
}[/B]
// Make sure there are no bonuses of the same class (but a different type) nearby:
iRange = pClassInfo.getUniqueRange();
...
return true;
}
Remember: the 'i' in isRequiresWater is lower-case...
Below is the original post:
I'm working on a comp for my mod that adds a tag to BonusInfos that allow me to restrict a resource to coasts and rivers.
I've followed Kael's tutorial to great success in the setup department (thanks for that), but while programming the functionality, I've hit a road block, and my relatively limited experience is unequipped to solve this problem.
There does not appear to be any problem with anything from the tutorial, since everything compiled just fine after that, so for the moment I'd like to hope that the problem here is in my programming.
Here is what I've added thus far:
Code:
bool CvMapGenerator::canPlaceBonusAt(BonusTypes eBonus, int iX, int iY, bool bIgnoreLatitude)
{
PROFILE_FUNC();
CvArea* pArea;
CvPlot* pPlot;
CvPlot* pLoopPlot;
int iRange;
int iDX, iDY;
int iI;
pPlot = GC.getMapINLINE().plotINLINE(iX, iY);
pArea = pPlot->area();
...
CvBonusInfo& pInfo = GC.getBonusInfo(eBonus);
CvBonusClassInfo& pClassInfo = GC.getBonusClassInfo((BonusClassTypes) pInfo.getBonusClassType());
if (pPlot->isWater())
{
if (((GC.getMapINLINE().getNumBonusesOnLand(eBonus) * 100) / (GC.getMapINLINE().getNumBonuses(eBonus) + 1)) < pInfo.getMinLandPercent())
{
return false;
}
}
[B] if (pInfo.IsRequiresWater)
{
if (!(pPlot.IsCoastalLand || pPlot.IsFreshWater))
{
return false;
}
}[/B]
...
return true;
}
When I compile, I get three errors:
Error 2039: 'IsRequiresWater' : is not a member of 'CvBonusInfo'
Error 2228: left of '.IsCoastalLand' must have class/struct/union type
Error 2228: left of '.IsFreshWater' must have class/struct/union type
Can someone more literate than I help me out here?
Thanks,