First and foremost, I'm going to state that I'm incredibly new to C++ (In the sense that I understand coding languages in general but don't know this one at all). For my mod, I needed to be able to prevent Barbarians from entering a specific civ's territory. After tracking down code from handicapinfos (that determines if the difficulty setting will allow Barbarians to enter the civ's territory), I found two pieces of code that, ultimately, references this and gave Barbarian units permission.
In CivTacticsAi there is:
Etc, and then in CvUnit, there is
Well, I knew what I wanted to do. I wanted to add another check in there. First, to detect who the owner of the targeted plot was, and if it was my civilization (and if the unit was a barbarian), to throw false, much like the check does for the EarliestBarbarianReleaseTurn setting.
I looked through the code and in posts and in the wiki to try and figure out the exact way to manipulate the variables to achieve this result. Again, I don't know C++, but I understand the concepts, so I put together this.
For CvTacticalAi, just before the bit that asks about bBarsbAllowedYet:
And then this for CvUnit:
I thought I had did pretty good (it was a mess trying to figure out how to get both the plot owner and also check the civilization info for the name, I saw how to do one or the other, but not both). But, I realized thaaaat... Apparently, I'm pretty off.
I'm hoping I've made a simple mistake, since I don't know the specific of the languages, and the entire method isn't off. Can I get some guidance on what I'm doing wrong?
In CivTacticsAi there is:
Code:
void CvTacticalAI::FindTacticalTargets()
{
int iI;
CvPlot* pLoopPlot;
CvTacticalTarget newTarget;
bool bValidPlot;
bool bEnemyDominatedPlot;
CvPlayerTrade* pPlayerTrade = m_pPlayer->GetTrade();
// Clear out target list since we rebuild it each turn
m_AllTargets.clear();
bool bBarbsAllowedYet = GC.getGame().getGameTurn() >= GC.getGame().GetBarbarianReleaseTurn();
for(iI = 0; iI < GC.getMap().numPlots(); iI++)
{
pLoopPlot = GC.getMap().plotByIndexUnchecked(iI);
bValidPlot = false;
if(pLoopPlot->isVisible(m_pPlayer->getTeam()))
{
if(!m_pPlayer->isBarbarian() || bBarbsAllowedYet)
{
bValidPlot = true;
}
Etc, and then in CvUnit, there is
Code:
bool CvUnit::canMoveInto(const CvPlot& plot, byte bMoveFlags) const
{
VALIDATE_OBJECT
TeamTypes ePlotTeam;
if(atPlot(plot))
{
return false;
}
// Cannot move around in unrevealed land freely
if(!(bMoveFlags & MOVEFLAG_PRETEND_UNEMBARKED) && isNoRevealMap() && willRevealByMove(plot))
{
return false;
}
// Barbarians have special restrictions early in the game
if(isBarbarian() && (GC.getGame().getGameTurn() < GC.getGame().GetBarbarianReleaseTurn()) && (plot.isOwned()))
{
return false;
}
Well, I knew what I wanted to do. I wanted to add another check in there. First, to detect who the owner of the targeted plot was, and if it was my civilization (and if the unit was a barbarian), to throw false, much like the check does for the EarliestBarbarianReleaseTurn setting.
I looked through the code and in posts and in the wiki to try and figure out the exact way to manipulate the variables to achieve this result. Again, I don't know C++, but I understand the concepts, so I put together this.
For CvTacticalAi, just before the bit that asks about bBarsbAllowedYet:
Code:
bool bOwnedByAlzadaal;
pOwnerOfThisPlot = pLoopPlot->getOwner();
if(strcmp(pOwnerOfThisPlot->getCivilizationInfo().GetType(), "CIVILIZATION_ALZADAAL") == 0)
{
bOwnedByAlzadaal = true;
}
// Make sure I am not a barbarian who can not move into owned territory this early in the game
if(!m_pPlayer->isBarbarian() && bOwnedByAlzadaal)
{
bValidPlot = false;
}
else
{
if(!m_pPlayer->isBarbarian() || bBarbsAllowedYet)
{
bValidPlot = true;
}
}
And then this for CvUnit:
Code:
bool bIsOwnedByAlzadaal;
pOwnerOfTargetPlot = plot.getOwner();
if(strcmp(pOwnerOfTargetPlot->getCivilizationInfo().GetType(), "CIVILIZATION_ALZADAAL") == 0)
{
bIsOwnedByAlzadaal = true;
}
if(isBarbarian() && bIsOwnedByAlzadaal)
{
return false;
}
if(isBarbarian() && (GC.getGame().getGameTurn() < GC.getGame().GetBarbarianReleaseTurn()) && (plot.isOwned()))
{
return false;
}
I thought I had did pretty good (it was a mess trying to figure out how to get both the plot owner and also check the civilization info for the name, I saw how to do one or the other, but not both). But, I realized thaaaat... Apparently, I'm pretty off.
I'm hoping I've made a simple mistake, since I don't know the specific of the languages, and the entire method isn't off. Can I get some guidance on what I'm doing wrong?