JDHalfrack
Chieftain
- Joined
- Mar 18, 2009
- Messages
- 35
First off, let me say how excellent this site is. There are some really smart cookies that post on this site. Anyway... a little about me before I ask my question so you know a little about where I'm coming from (I'll hide it under a "spoiler" tag so if you don't want to read it, you don't have to... ).
Okay, so my idea was to make a trait that gives happines to all your cities when you are at war. Basically, +1/city per civilization you are at war with. Making the trait is easy enough (once again... spoilers so you don't have to read it):
Basically, the idea behind this trait is that any leader with this trait wants to be at war, and thrives on war. So, I did what I could with XML, and moved onto the CvCity.h and CvCity.cpp.
In the CvCity.h file, I added the following code under the 'public:' section:
I added the following code under the 'protective:' section:
In the CvCity.cpp file I added the following code in the 'void CvCity::reset' function:
I made the following edit (the bold) in the in the 'int CvCity::happyLevel()' function:
I added the following code in the 'CvCity::read(FDataStreamBase* pStream)' function:
I added the following code in the 'CvCity::write(FDataStreamBase* pStream)' function:
I added the following two functions at the very end of cvCity.cpp:
At this point, I think I have added all the right coding to add "warhappiness" to a city. The DLL compiles with no errors (takes about 15 - 20 mins). And I copy it to my Assets folder.
So, in the CvEventManager.py file, I editted the following code:
I know this will find every city owned by the player declaring war because I have tested it with other functions (like pCity.change Population). But, when it gets to this point in when I declare war, I get this error:
"AttributeError: 'CyCity' object has no attribute 'changeWarHappiness'
ERR: Python function onEvent failed, module CvEventInterface"
Am I "calling" my function wrong? Or is there a LOT more to this than even I thought?
Thanks ahead for the help guys. If you need more info from me, let me know.
JD
Spoiler :
I've been programming for about 5 years (self taught), so I am not a complete novice. In fact, if any of you ever play Madden and head over to football-freaks.com, you can find a lot of my work over there. Ususally I do my programming in Basic (Visual Studio 9.0) but I have messed around with C, C++ and C# enough to figure out the basic coding of the CvGameCoreDLL. Long story short, I am not a complete idiot, and I really did try this on my own before posting.
Okay, so my idea was to make a trait that gives happines to all your cities when you are at war. Basically, +1/city per civilization you are at war with. Making the trait is easy enough (once again... spoilers so you don't have to read it):
Spoiler :
Code:
<TraitInfo>
<Type>TRAIT_GENECIDAL</Type>
<Description>TXT_KEY_TRAIT_GENECIDAL</Description>
<ShortDescription>TXT_KEY_TRAIT_GENECIDAL_SHORT</ShortDescription>
<Help>TXT_KEY_TRAIT_GENECIDAL_HELP</Help>
<iHealth>0</iHealth>
<iHappiness>0</iHappiness>
<iMaxAnarchy>-1</iMaxAnarchy>
<iUpkeepModifier>0</iUpkeepModifier>
<iLevelExperienceModifier>-10</iLevelExperienceModifier>
<iGreatPeopleRateModifier>0</iGreatPeopleRateModifier>
<iGreatGeneralRateModifier>25</iGreatGeneralRateModifier>
<iDomesticGreatGeneralRateModifier>0</iDomesticGreatGeneralRateModifier>
<iMaxGlobalBuildingProductionModifier>0</iMaxGlobalBuildingProductionModifier>
<iMaxTeamBuildingProductionModifier>0</iMaxTeamBuildingProductionModifier>
<iMaxPlayerBuildingProductionModifier>0</iMaxPlayerBuildingProductionModifier>
<ExtraYieldThresholds/>
<TradeYieldModifiers/>
<CommerceChanges/>
<CommerceModifiers/>
<FreePromotions>
<FreePromotion>
<PromotionType>PROMOTION_CITY_RAIDER1</PromotionType>
<bFreePromotion>1</bFreePromotion>
</FreePromotion>
</FreePromotions>
<FreePromotionUnitCombats>
<FreePromotionUnitCombat>
<UnitCombatType>UNITCOMBAT_MELEE</UnitCombatType>
<bFreePromotionUnitCombat>1</bFreePromotionUnitCombat>
</FreePromotionUnitCombat>
<FreePromotionUnitCombat>
<UnitCombatType>UNITCOMBAT_SIEGE</UnitCombatType>
<bFreePromotionUnitCombat>1</bFreePromotionUnitCombat>
</FreePromotionUnitCombat>
<FreePromotionUnitCombat>
<UnitCombatType>UNITCOMBAT_ARMOR</UnitCombatType>
<bFreePromotionUnitCombat>1</bFreePromotionUnitCombat>
</FreePromotionUnitCombat>
</FreePromotionUnitCombats>
</TraitInfo>
In the CvCity.h file, I added the following code under the 'public:' section:
Code:
DllExport int getWarHappiness() const;
DllExport void changeWarHappiness(int iChange);
Code:
int m_iWarHappiness;
In the CvCity.cpp file I added the following code in the 'void CvCity::reset' function:
Code:
m_iWarHappiness = 0;
Spoiler :
Code:
int CvCity::happyLevel() const
{
int iHappiness;
iHappiness = 0;
iHappiness += std::max(0, getLargestCityHappiness());
iHappiness += std::max(0, getMilitaryHappiness());
iHappiness += std::max(0, getCurrentStateReligionHappiness());
iHappiness += std::max(0, getBuildingGoodHappiness());
iHappiness += std::max(0, getExtraBuildingGoodHappiness());
iHappiness += std::max(0, getFeatureGoodHappiness());
iHappiness += std::max(0, getBonusGoodHappiness());
iHappiness += std::max(0, getReligionGoodHappiness());
iHappiness += std::max(0, getCommerceHappiness());
iHappiness += std::max(0, area()->getBuildingHappiness(getOwnerINLINE()));
iHappiness += std::max(0, GET_PLAYER(getOwnerINLINE()).getBuildingHappiness());
iHappiness += std::max(0, (getExtraHappiness() + GET_PLAYER(getOwnerINLINE()).getExtraHappiness()));
iHappiness += std::max(0, GC.getHandicapInfo(getHandicapType()).getHappyBonus());
iHappiness += std::max(0, getVassalHappiness());
[SIZE="4"][B]iHappiness += std::max(0, getWarHappiness());[/B][/SIZE]
if (getHappinessTimer() > 0)
{
iHappiness += GC.getDefineINT("TEMP_HAPPY");
}
return std::max(0, iHappiness);
}
Code:
pStream->Read(&m_iWarHappiness);
Code:
pStream->Write(&m_iWarHappiness);
Code:
int CvCity::getWarHappiness() const
{
return m_iWarHappiness;
}
void CvCity::changeWarHappiness(int iChange)
{
m_iWarHappiness += iChange;
}
At this point, I think I have added all the right coding to add "warhappiness" to a city. The DLL compiles with no errors (takes about 15 - 20 mins). And I copy it to my Assets folder.
So, in the CvEventManager.py file, I editted the following code:
Spoiler :
Code:
def onChangeWar(self, argsList):
'War Status Changes'
bIsWar = argsList[0]
iTeam = argsList[1]
iRivalTeam = argsList[2]
[B][SIZE="4"]##### Gen Trait Start #####
if (CyGame().isFinalInitialized()):
pTeam = gc.getTeam(iTeam)
pRivalTeam = gc.getTeam(iRivalTeam)
iPlayer = pTeam.getLeaderID()
iRivalPlayer = pRivalTeam.getLeaderID()
pPlayer = gc.getPlayer(iPlayer)
iTrait = CvUtil.findInfoTypeNum(gc.getTraitInfo,gc.getNumTraitInfos(),'TRAIT_GENECIDAL')
if (pPlayer.hasTrait(iTrait)) and (bIsWar):
for iCity in range(pPlayer.getNumCities()):
pCity = pPlayer.getCity(iCity)
pCity.changeWarHappiness(+1)
##### Gen Trait End #####[/SIZE][/B]
"AttributeError: 'CyCity' object has no attribute 'changeWarHappiness'
ERR: Python function onEvent failed, module CvEventInterface"
Am I "calling" my function wrong? Or is there a LOT more to this than even I thought?
Thanks ahead for the help guys. If you need more info from me, let me know.
JD