Then you're doing something wrong, because it works for me. Can you post the exact file you're testing with?
I took the popup code and added it in a bunch of different places: onCityDoTurn, onPlayerEndTurn, OnCultureExpansion... But they never showed up, which suggests that even a changefood command wouldn't process.You can't just change the value of YieldTypes.YIELD_FOOD though, that's just the index of the food value, not the actual food value. You can't manipulate in-game variables such as food, hitpoints, etc directly, you have to do so through functions. The onCityDoTurn event gives you a city argument, so the second line in your example would have to be something like:
Code:pCity.changeFood(Pycity.getFoodRate() * (getGoodHealth() - getBadHealth()) * 0.05)
Thanks for the reply Locutus!Originally posted by Locutus
You have to use attachMultilineText instead of setText or whatever is currently used. The civilopedia file (CvPedia*) have a number of examples of this.
What I mean is I'm writing text to a panel and it's clipping vertically, not horizontally... It's a list of text (in the Civolopedia actually) but it's too long to show all at once so it goes off the bottom edge...
I'm taking the entire CvEventManager.py file and adding the popup to it inside one of the functions:
I can't say I'm experienced with Python or object oriented language for that matter, so I don't know how to properly initialize a file, so I just used an already existing one. I also added the same popup code to other functions in the same file, such as OnEndTurn, OnCityDoTurn, ect... Just as a kind of troubleshooting to see if the commands are being processed.Code:def onCultureExpansion(self, argsList): 'City Culture Expansion' popup = PyPopup.PyPopup() popup.setBodyString( 'Hello World' ) popup.launch() pCity = argsList iPlayer = argsList CvUtil.pyPrint("City %s's culture has expanded" %(pCity.getName(),))
Okay, it seems that the problem is that the python files weren't updating. The cache needed to be cleared.
Are you modifying the main game files or using a Mod folder?
I'm using a mod folder, but I'm also launching the game directly into the mod using the command line. Still, even before I did that I wasn't getting any error messages.
Error messages are something I'm familiar and comfortable with. Changing files and seeing no result at all is not.
Okay, on another note, I'm having a hard time changing the food rate of the city. I believe it's a type-casting error: My formula mixes integers and a float, and passes the result of this formula to a function expecting an integer. Typecasting really bugged the heck out of me in C, so could I get some help on this?
The code I'm using now is:
If I use pCity.changeFood(10) it works just fine.Code:HealthyFood = getFoodRate(pCity) * (getGoodHealth(pCity) - getBadHealth(pCity)) * 0.1 pCity.changeFood(HealthyFood)
Neither does pCity.changeFood(getGoodHealth(pCity)) or pCity.changeFood(pCity.getGoodHealth()) oddly enough.
Last edited by Mylon; November 6, 2005 at 10:36.
You can just cast HealthyFood to an int as you pass it into that function.
For the onUnitMove() function... Is there any way to get both the original and destination plot locations? Obviously the destination is the value of pPlot (or pUnit.pPlot()). But I can't see any way to figure out where the unit came from.
Alternatively, is there any event trigger that can be called before the unit is moved (but after the move order has been issued)?
Hi Trip, is there a way of switching the Health and food values-such that Health dictates population growth and Food surplus/deficit dictates the health bonus/penalty? If so, where will I find it in the scripts?
Thanks a bunch !
P.S. In combination with that, how do I add/subtract the things which contribute to health/unhealth?
Another question - it's possible to add new Promotion types, yes? I haven't been able to successfully do so at this point, just want to make sure I'm not banging my head against the wall pointlessly.
edit: nm, got it working. Apparently if you add a new promotion type and try and load an old savegame, it'll die, but if you start a new one, it works fine.
Last edited by Bhruic; November 8, 2005 at 23:56.
Actually, I'm about 99% sure pPlot is the original plot and pUnit.plot() the destination.Originally posted by Bhruic
Obviously the destination is the value of pPlot (or pUnit.pPlot()).
No, we'll have to add that ourselves when the SDK comes out.Alternatively, is there any event trigger that can be called before the unit is moved (but after the move order has been issued)?
I'd hate to argue with you, but I'm pretty sure it's not.Originally posted by Locutus
Actually, I'm about 99% sure pPlot is the original plot and pUnit.plot() the destination.
I did a popup that displayed the getX/getY values for both, and they were always identical.
I'm trying to see if I can add an option to the diplo screen, namely:
Allow the player to offer declare war on opponent in exchange of whatever. Currently, I can declare war on Cyrus when Peter asks me to, but I can't barter and agree in exchange of this or that tech (but I can get Alex to fight Mansa Musa in exchang of Biology). This is asymetrical, the player cannot do what the ai can (and vice versa).
So I tried to do it, but don't know where to find CyDiplomacy?
I'll probably try to simplify the accept trade/neogtiate etc which I find really clunky to work with but for the moment I can't find where the screen class really is and that bothers me. Any ideas?
Clash of Civilization team member
(a civ-like game whose goal is low micromanagement and good AI)
web site http://clash.apolyton.net/frame/index.shtml and forum here on apolyton)
Question. This here event:
What are the parameters exactly? 'owner' - is that the person that lost the city or that got the city? Same for 'playerType'? And for 'city.getOwner()', has that already been set to the new owner, or is it at this point still for the original owner?Originally posted by Locutus
A couple of (I hope) easy questions:
1. In the reportEvent function of CvEventManager.py there is a reference to Events.log. Where is this file? Does CvUtil.PyPrint() print to it?
2. Can I get more detail about the arguments to CyInterface().addMessage()? The API reference is kind of vague.
Thanks a lot for the class reference, Locutus. You own. I detected an error in the api if you want to fix the master:
CvCity::getProduction() does return an int, and it is the base production of that city at that moment, not a boolean.
I'm now trying to figure out how to change that base :]
i looked through this and other threads and some things are not yet very clear to me:
* what if i only want to overwrite parts of the things. for instance i want to add my own additional keyboard shortcuts for my notebook. eg. ALT-right moves the unit right.
how could i make sure that that works but keeps everything else the same? is that possible?
* is there a "safe" way to add such stuff to the normal game (not a special mod) without fiddling around with the game's own "asset" folder? please note: this should be UI only
- Artificial Intelligence usually beats real stupidity
- Atheism is a nonprophet organization.
I'm trying to lear a thing or two here and I tried using your code.
I replaced this lines in the CvEventManager.py file
The popup box shows but no unit is spwned in the city, I have tried the documentation and I can't find whats wrong here.PHP Code:
def onCityBuilt(self, argsList):
city = argsList
if (city.getOwner() == CyGame().getActivePlayer()):
CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
popup = PyPopup.PyPopup()
popup.setBodyString( 'Hello World' )
city.getOwner().initUnit(17, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)
I also tried your original code, no luck there either, the popup box shows but no unit is spawned. What is wrong???
Hummm, ok i reply to my self here.
I inserted this Row..
Instead of this...
city.getOwner().initUnit(17, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)
Seemed to work, now could anyone explain to me if there was something wrong with the original code or have I forgot to import a module into the CvEventManager.py file???
I'm lost here!?!?
Enable python error messages in the civ .ini file and enable logging. They will tell you what's wrong.
My guess would be that either city.getOwner() doesn't exists or it returns an integer so you should wrap it with gc.getPlayer(...) like you did in the new line you used. (I couldn't find it in the python api, but maybe city here is not of the CyCity type)
the city.(getowner()) works even better than CyGame().getActivePlayer() because the latter give me a unit for all cities created the first only the owner.
city is a variable containing the newly created city defined in the line...
city = argsList
Now i have bin able to make this work, but I can't figure out how to add promotions. I have looked around in other mods that adds them but it does not see, to work.
I try to add the "combat I" promotion but it will simply not be attached.
I added the line setHasPromotion(0,TRUE) so the last line would be then...
gc.getPlayer(city.(getowner()).initUnit(17,city.ge tX(),city.getY(),UnitAITypes.NO_UNITAI).setHasProm otion(0,TRUE)
this should add a promotion type Combat I
Does any one know if it's posibble to force the Technology Discovered popup dialog appear.
I want to use the setHasTech api call and display the popup, i have the call working but no popup appears.
how do I pass a null-pointer to a function ?
eg: for the argument "CyCity* pSkipCity = NULL" in CyMap.findCity( ... )
When I tried this in the in-game python console, I got errors about Null, NULL, null being unknown. Just passing a 0 got me the error "arguments "..., ..., int" don't match "..., ..., CyCity* ". Passing an empty list  didn't work either.
Oh, and btw: could it be that "onUnitLost" has more arguments than only pUnit ? With this code:
I always get the error getUnitClassType() can't be executed on a tuple.Code:def onUnitLost(self, pUnit): if pUnit.getUnitClassType() == self.iUnitClassHarvester : self.hu.lostHarvester(pUnit)
Last edited by PJayTycy; November 17, 2005 at 20:51.
i try to implement a wonder which provides a unit/or a certain tech (no free tech like in the xml file).
the 'onCityBuilt' example combined with the 'onBuildingBuilt' command is maybe a ?good idea to make this work - but i'm too stupid (learning python in a few days is a hard job) - the game don't do i want them to do.
can some1 help me?
Last edited by GIR; November 26, 2005 at 07:57.
I don't feel like looking up the API, so double check this code before you use it!
if iBuilding == gc.getInfoTypeForString('BUILDING_YOURWONDER')
(tab) iPlayer = pCity.getOwner()
(tab) gc.setPlayerHasTech(iPlayer, gc.getInfoTypeForString('TECH_YOURTECH').
And there ya go.
big thx Mylon for you help, the whole day i am trying to get it running!
this looks like a simple way but i think i make something wrong, because the game says:
Failed to load python module CvEventInterface.
her is the part i includet to the onbuildingbuilt:
if iBuilding == gc.getInfoTypeForString( 'BUILDING_STONEHENGE' ):
iPlayer = pCity.getOwner()
gc.setPlayerHasTech(iPlayer, gc.getInfoTypeForString( 'TECH_ROCKETRY' )
Last edited by GIR; November 26, 2005 at 17:05.
The code you added should look like:
edit: Made slight changePHP Code:
if iBuildingType == gc.getInfoTypeForString( 'BUILDING_STONEHENGE' ):
pPlayer = gc.getPlayer(pCity.plot().getOwner())
gc.getTeam(pPlayer.getTeam()).setHasTech(gc.getInfoTypeForString( 'TECH_ROCKETRY' ), true, pPlayer.getID(), false, false)
Last edited by Bhruic; November 26, 2005 at 14:57.