Trait for Diplomatic Bonus

deanej

Deity
Joined
Apr 8, 2006
Messages
4,859
Location
New York State
I'm hoping to have a trait in my mod that would give a leader with the trait a diplo bonus with other civs. I've found this code in RFC in CvPlayerAI::AI_getAttitudeVal:
Code:
	if (ePlayer == FRANCE) {
		if ((getID() != ROME) && (getID() != GREECE)
			&& (getID() != SPAIN) && (getID() != ENGLAND) && (getID() != GERMANY) && (getID() != RUSSIA)
			&& (getID() != VIKING)
			&& (getID() != NETHERLANDS) && (getID() != PORTUGAL))
			iAttitude += 8;
	}
However, I'm not sure how to convert it to a trait. I was hoping to add something like iDiploBonus in Civ4TraitInfos so that the value wouldn't be hardcoded in the DLL. It would also be nice to implement a trait that makes the leader not affected by this bonus.
 
I'm hoping to have a trait in my mod that would give a leader with the trait a diplo bonus with other civs.

I have recently learned about the memory fields, basicinfo/civ4memoryinfos.xml, and the matching attitude percent and decay rates in leaderheadinfos. Each memory corresponds to one different text in the diplo screen, like "You razed a holy city!". You could define one new memory type and associate a text string with it so that would show in the diplo screen. I assume you would want to have the decay set to infinity so the value never changes. Different leaders could have a different attitude percent; in particular I am pretty sure a zero value means that leader would ignore the memory.

You would have to add an xml field in the sdk, where a civ would have a list of civ/value pairs, and then during game start you would need to add a loop which populated the memory values from this xml data.
 
If you want a new string to show up in the diplomacy screen, you will have to use memories. For something simpler, you may want the python call CvPlayer.AI_setAttitudeExtra(iPlayer, iValue). This changes the diplomacy value like you want, but it shows up in the diplomacy screen with a generic text "Past events have been good to us".
 
You can write some python code in onGameStart to search for individual civs and call AI_setAttitudeExtra. That should be all you need. Dune Wars uses this technique and it works fine for what you want.
 
Hello

I have some difficulties to implement a new xml tag relative to the leader’s traits.
My problem concerns the SDK step, particularly how to make this tag have some effects in the game.
My aim is to add a tag that would give a bonus/malus in diplomacy with other players. This tag would be used for a new Diplomatic trait, but also for other existing traits like Charismatic or Aggressive.

I have followed the steps given by Kael’s walkthrough
http://forums.civfanatics.com/showthread.php?t=166935
and I looked through Total War’s mod files to have a model, as there is also an iDiplomacy tag.

First, I created in XML (TraitsInfos.xml) a new tag called iDiplomacy and I changed the CivilisationsSchemas to add some new entries. I loaded the game, no problem.
Then, I created in CvInfos.h and CvInfos.cpp a new variable named m_iDiplomacy and a new function named getDiplomacy() in CvTrait. This one simply returns the int m_iDIplomacy.

Spoiler :

//------------------------------------------------------------------------------------------------------
//
// FUNCTION: CvTraitInfo()
//
// PURPOSE : Default constructor
//
//------------------------------------------------------------------------------------------------------
CvTraitInfo::CvTraitInfo() :
m_iHealth(0),
m_iHappiness(0),
m_iDiplomacy(0),


Spoiler :

int CvTraitInfo::getHealth() const
{
return m_iHealth;
}

int CvTraitInfo::getHappiness() const
{
return m_iHappiness;
}

int CvTraitInfo::getDiplomacy() const
{
return m_iDiplomacy;
}


Then I added a line in bool CvTraitInfo::read(CvXMLLoadUtility* pXML).

Spoiler :

bool CvTraitInfo::read(CvXMLLoadUtility* pXML)
{
CvString szTextVal;
if (!CvInfoBase::read(pXML))
{
return false;
}

pXML->GetChildXmlValByName(szTextVal, "ShortDescription");
setShortDescription(szTextVal);

pXML->GetChildXmlValByName(&m_iHealth, "iHealth");
pXML->GetChildXmlValByName(&m_iHappiness, "iHappiness");
pXML->GetChildXmlValByName(&m_iDiplomacy, "iDiplomacy");


At this point I compiled, no errors, and I launched the game, no bug.
So, step 3, now I have to make this new tag do something.
I have been in CvPlayerAI and identified the AI_GetAttitudeVal function. For me, this function is used to calculate the relationship level of AI player with all other ones (the value that appears in the diplomacy table during the game).

Spoiler :

int CvPlayerAI::AI_getAttitudeVal(PlayerTypes ePlayer, bool bForced) const
{
PROFILE_FUNC();

int iRankDifference;
int iAttitude;
int iI;

FAssertMsg(ePlayer != getID(), "shouldn't call this function on ourselves");

if (bForced)
{
if (getTeam() == GET_PLAYER(ePlayer).getTeam() || (GET_TEAM(getTeam()).isVassal(GET_PLAYER(ePlayer).getTeam()) && !GET_TEAM(getTeam()).isCapitulated()))
{
return 100;
}

if (isBarbarian() || GET_PLAYER(ePlayer).isBarbarian())
{
return -100;
}
}

iAttitude = GC.getLeaderHeadInfo(getPersonalityType()).getBaseAttitude();

iAttitude += GC.getHandicapInfo(GET_PLAYER(ePlayer).getHandicapType()).getAttitudeChange();


This function adds a lot of parameters to find out a number which is translated into an attitude of the AI towards another player (AI of human)
I think I have to get the value of my XML tag and then add it to the algorithm. But I don’t know how to do this :confused: … so if somebody could help me it would be great
 
Hello

I still try to fix my problem of creating a new diplomatic trait.

I have added a line (copied from TotalWar mod) in the CvPlayerAI.cpp, into the GetAttitudeVal function

Spoiler :

iAttitude = GC.getLeaderHeadInfo(getPersonalityType()).getBaseAttitude();

iAttitude += GC.getHandicapInfo(GET_PLAYER(ePlayer).getHandicapType()).getAttitudeChange();
// Ajout bonus diplomatique
iAttitude += GC.getTraitInfo((TraitTypes)iI).getDiplomacy();


Then I compiled without errors (but a warning because I did'nt declare the iI variable)
It should have added a relation bonus of 3 for the diplomatic leaders, but nothing happens during the game.

I try to understand C++ and the way the game is coded.
GC means a class right ? Where can I find it ? And where can I find the GET_PLAYER function ?
Thanks by advance
 
Back
Top Bottom