Requesting following features

would be better?
Yeah, its an improvement. :goodjob:

Or can I use isPlotNotOwned anyway or will it not work?
I didn't look too closely at it but its basically unnecessary. Also note that since you're implicitly checking the return values of the functions against the value True, you could also check the opposite with False. Like:
Code:
if isPlotOwner(tCoords, 1) == False:
Note however that the this an example of an "over-expression":
Code:
if [COLOR="DimGray"]( isPlotOwner(tCoords, 1) == True )[/COLOR]:
Because the expression inside the outer parenthesis is in itself a
Code:
boolean expression
- either True or False. And since the function call will either return True or False, we actually have these two possible outcomes (now without the parenthesis and rest of the if statement:
True == True
and
True == False
If the first outcome is true, then the whole expression equates to the value True. So in English it would be "if True is True, then its True". Pretty redundant, not? This is why you can get away with just this if statement:
Code:
if isPlotOwner(tCoords, 1):
Because the two possible outcomes are really:
Code:
if True:
and
Code:
if False:
And the way to check for a False return value is to use the not command, as I explained earlier:
Code:
if not isPlotOwner(tCoords, 1):
Your explicit checking against the True/False value is of course valid and might even be clearer. But its not strictly necessary. (Its somewhat ridiculous if you really think about it. If True is True, then its True. :rolleyes:)

will this code work?
It seems about right, but most of the time you wind up with exceptions anyway. So I guess there is only one way to make sure... (Syntax errors are easy enough to catch if you're using IDLE - just go Run -> Check Module in the menu bar. So there is basically no good excuse to wind up with syntax errors in-game.)
 
well at least I finished this code quickly! will probably test this event tomorrow! I am using the and statement right arent I?
 
well at least I finished this code quickly! will probably test this event tomorrow!
Good luck! :goodjob:

I am using the and statement right arent I?
Yes. :)

You realize that you don't need to supply any of the helper function I wrote up for you with any of the optional arguments, right? Like iSize for spawnCity() and iDistance for checkCityProximity - because those already have default values on the function definition line. So you only need to supply the argument if it is something else than the default value.

The variable eCityName is misleading, by the way, because the e usually indicates that the value is inherited from the SDK as an enumerated index number of some sort. (Like a PlayerType, a UnitType or a TechType.) But you're using it for a string value, so I guess you could use a s-prefix then, or something. (I didn't use any prefix for the name variable however. I never do with string variables...)

Also, you might wanna call the constant something else than "city name", because other events might well include names for cities, so it would become confusing. Why not call it sMacedoniaCityName or something less ambiguous?

Or you could simply not use any constants but rather put all the values directly into the eventMacedonia() function directly. ;)
 
ok condition 3 works perfectly but I believe there might be a small problem with your code again :(

the city took no name and was just rebellia (default rebel city name) the exception I was given was:
file "CvEventInterface", line 23, in onEvent
file "CvEventManager", line 187, in handleEvent
file "CvEventManager", line 378, in onBeginGameTurn
file "ModEvents", line 39, in eventMacedonia
file "CustomFunctions", line 71, in spawnCity

ArgumentError: Python arguement types in
CyCity.setName(CyCity, str)
did not match C++ signature:
setName(classCyCity[lvalue}, class std::basic_string.class
std::allocator >. bool)



also when the city spawn (maybe due to the problem) there were no units spawning and the city had no culture (just 1 square) so we need to be able to add culture to the spawn city code

the code currently in customfunctions is:
Code:
##use if required/wanted!##
##Currently contains: showPopup, isDate, spawnUnits, isPlotOwner, isPlotNotOwned, checkCityProximity, spawnCity and getPlot!##
from Popup import PyPopup
from CvPythonExtensions import *
from PyHelpers import *
from CivPlayer import *
from Utils import *

def save():
    print "Save"

def showPopup(popupHeader, popupMessage):
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()

def isDate(iDate):
    return CyGame().getTurnYear(CyGame().getGameTurn() +1) > iDate and CyGame().getGameTurnYear() <= iDate <= iDate

def spawnUnits(ePlayer, eUnitType, tCoords, iNum):
	iX, iY = tCoords
	CivPlayer(ePlayer).get(PyPlayer).initUnit(eUnitType, iX, iY, iNum)

Map = CyMap() 

def isPlotOwner(tCoords, ePlayer): 
    """ 
    Returns True if ePlayer is the owner of the plot at tCoords.  
    Otherwise returns False. 
    """ 
    pPlot = getPlot(tCoords) 
    eOwner = pPlot.getOwner() 
    return eOwner == ePlayer

def isPlotNotOwned(tCoords):
    """
    Returns True if Plot is not owned by anybody (made by J_mie6)
    if plot is owned returns False
    """
    pPlot = getPlot(tCoords)
    eOwner = pPlot.getOwner()
    return eOwner != eHellenicRebels or eRome or eGreece or eGaul or eBrittania or eCarthage or eEgypt or eGermania or ePictia or eItalianRebels or eNubianRebels or eNumidianRebels or eGallicRebels or eBrythonRebels or eGermanicRebels or ePictishRebels or eIberia or eGreekColonies

def checkCityProximity(tCoords, iDistance): 
    """ 
    Returns False if any city is within iDistance from the plot at  
    tCoords. Otherwise returns True. 
    """ 
    pPlot = getPlot(tCoords) 
    iX = pPlot.getX() 
    iY = pPlot.getY() 
    for iCurrentX in range(iX - iDistance, iX + iDistance + 1): 
        for iCurrentY in range(iY - iDistance, iY + iDistance + 1): 
            pCurrentPlot = Map.plot(iCurrentX, iCurrentY) 
            if pCurrentPlot.isCity(): 
                return False 
    return True 

def spawnCity(tCoords, ePlayer, name, iSize): 
    """ 
    Creates a new CyCity instance at tCoords belonging to ePlayer,  
    of iSize and with the optional name. (Returns None.) 
    """ 
    iX, iY = tCoords 
    pPlayer = pPlayer = gc.getPlayer(ePlayer) # alt instance(ePlayer).get(CyPlayer) 
    pCity = pPlayer.initCity(iX, iY) 
    pCity.setPopulation(iSize) 
    if name != None: 
        pCity.setName(name) 

def getPlot(tCoords): 
    """ 
    Returns the CyPlot instance of the plot at tCoords. 
    """ 
    iX, iY = tCoords 
    return Map.plot(iX, iY)

bear in mind that I had removed your = signs in your parameters (I don't really know why though) so it that the problem?

any ideas?
 
Yeah, the exception is because I didn't do my homework and check every method I used in the API. This is what the entry for CyCity.setName() reads:
VOID setName (STRING szNewValue, BOOL bFound)
So there is a second parameter required, which is a boolean value referred to as bFound. I'm not sure what it does, but maybe you could try adding a True value?

Make a habit of using the API actively, and you will avoid these issues yourself.

If you put back the assignments in the function definitions you get the optional arguments I mentioned in my last post. Its actually pretty handy!
 
so how should I change the city spawn code? (also the game brought up a new exception when I conquored byzantium 9which was barbarian and I guess it tried to make a rebellion and said, once again something about the index being out of range (is this just because the city spawn didn't work?)

what about the culture issue and unit issue (so far I pressume the units are not working because the code in front is broken...)
 
so how should I change the city spawn code? (also the game brought up a new exception when I conquored byzantium 9which was barbarian and I guess it tried to make a rebellion and said, once again something about the index being out of range (is this just because the city spawn didn't work?)
Add one parameter:
Code:
pCity.setName(name[COLOR="Red"], True[/COLOR])
And if you're not gonna use the default value for name, then you can skip the if statement on the previous line. (It checks if the default value is none other than the default - None.)

Can you post the new exception? (The full traceback.)

what about the culture issue and unit issue (so far I pressume the units are not working because the code in front is broken...)
Yeah, that is correct. Once the exception occurs, the whole function call (and more!) is exited. The exception itself is actually a good thing, because otherwise the game would crash! :eek:
 
exception: didn't record it but with a little luck I can recreate it again :D (shouldn't be a prblem anyway should it? you are using a completly different setup)

when removing my iCityDistance from the code do I have to put iDistance back into it? or just put one parameter instead of 2 (the 2nd being the iDistance)
 
So there is a second parameter required, which is a boolean value referred to as bFound. I'm not sure what it does, but maybe you could try adding a True value?

It marks that the city is just being founded (as opposed to renaming the city later on).
Its only effect is the 'city has been founded' message.
 
right ok everything works perfectly (in turn 6 when you meet a city with a good sized army in it with troops over 150 turns more advanced than you it makes you scared, so need to change that date, speaking of which, the axemen that spawn in spartacus would hold nothing against the troops in turn 111 so I either must make more of them or simply hope they pillage tarrentum :lol:)

The only problem is that culture :( the rebels have a 1 tile culture radius and I would like to know how to expand it...

EDIT: culture doesn't last long and soon gets big :D
 
when removing my iCityDistance from the code do I have to put iDistance back into it? or just put one parameter instead of 2 (the 2nd being the iDistance)
I'm not quite following but you could either test whatever it is you have, or you could post the actual code you have for advice.
 
ok exception randomly poped up (I guess those maruading Advanced spearmen have tried taking Byzantium!)

File "CvEventInterface", line 23, in onEvent
File "CvEventManager", line 187, in handleEvent
File "CvEventManager", line 374, in onBeginGameTurn
File "Rebels", line 28, in initEvent
File "CivPlayer", line 45, in instance
IndexError: list index out of range

what does it mean exactly?
 
Oh, its the barbarians bug with CivPlayer, again. I think I'll just fix that and get it over with for good. :p

But we're gonna replace the Rebels module with the new Rebellion module anyway, so I'll make sure to fix it in CivPlayer. I'll post the new version when I get around to it.
 
ok have fun fixing it!

Asaf, when will you be done extending the WBs civ limit in the DLL to 25? because I would really like to get all of the stuff to baldyr soon :D (no rush though)

Baldyr, make sure when you receive my Utils edit move the stuff I added into yours just in case it is needed (mostly will be civ names, archer, Advanced Spearman and axeman)

will you be using my Custom Functions module (and adding to it for that matter)? Because that would make me feel like I contributed to the project :D
 
ok have fun fixing it!
Yeah, the "fun" is testing that it works. :p

But the issue is basically that since I developed CivPlayer with your mod as the benchmark, I didn't simply create CivPlayer instances for all players up the Barbarians. Because there were unused slots in the WBS. Instead I only included all the actual players - meaning that the Barbarians were left out of the loop. I'll fix it simply by adding all players - including the Barbarians and any unused player slots.

Baldyr, make sure when you receive my Utils edit move the stuff I added into yours just in case it is needed (mostly will be civ names, archer, Advanced Spearman and axeman)
Yeah... But shouldn't you try to fix those XML entries instead? It would be worth the while, not?

will you be using my Custom Functions module (and adding to it for that matter)? Because that would make me feel like I contributed to the project :D
Oh, its me who is contributing to your project. :lol: But I think we'll just keep working on our separate utilities modules for now - and merge them later. Because as far as I'm concerned CustomFunctions and Utils basically do the same thing - they provide helper functions to other modules.

Perhaps we should make a Constants module and put all those assigned values in there? Since the Utils/CustomFunctions module will be filled with function definitions.

edit: This is actually the setup Rhye used in RFC. The Consts module contains all the constant variables, while all helper function are located in the RFCUtils module. All the other modules (RiseAndFall, Stability, Congresses, and so on) import these modules to access the values and functions (actually classes containing methods).
 
If you wanna be the test pilot, you could try this hot-fix in CivPlayer (line #201, in my copy, at least):
Code:
def setup():
        iLanguage = setDefaultLanguage()
        for ePlayer in [B]range(eBarbarian + 1)[/B]:
                setupCivPlayer(ePlayer)
        resetLanguage(iLanguage)
I don't know what it will do with any remaining empty player slots in the WBS, but chances are that the different player values will simply be None or -1.

edit: Chances are that you will get exceptions on initialization and that it will cause CivPlayer not to work. So I might have to do more to clear this issue right off the map.
 
Asaf, when will you be done extending the WBs civ limit in the DLL to 25? because I would really like to get all of the stuff to baldyr soon :D (no rush though)

I changed it to 28, actually, since you said you already reached 25 and might need a couple more...
I was adding some features to the DLL (from this thread) and I actually enhanced some of yours: All the extra yields per terrain/plot type (and now - per feature as well) can be added to leader traits in the XML (no need to call them from Python anymore).

So as I have just posted there - I hope to release it tomorrow.
 
I prefer them in python but thanks anyway! may be useful for future mods...

@Baldyr: When I changed the XML files as you described and put things as they were meant to be... It died (ironically the only problem I have EVER had with the XML) and I cannot face trying it again only to have to edit umpteen files and for no perticular cause (as little editing will be done unit wise now)... Of course this was ages ago (at the VERY start of Jamie'sRomeMod) but the system is fine as it is.... in Fact this reminds me that I should in fact put the irregular namings for units into the Utils (at the moment it only contains the ones I need).

I wonder if we should merge the Utils and CustomFunctions together or just leave them apart? Because most likely the CustomFunctions will be carried into my future mods and it would then be a problem to just move seeing though it then contains your variables for JRM (which would not be present in JMM for example) and plus I kinda like having my own homemade file which is completly and utterly mine :p

But it seems like a good idea to have a variable and civ/unit defines put in aswell to co-exist with CustomFunctions and Utils with the only problem being more to import (but that isn't much of a problem :lol:)

of course this is me just being difficult :satan::lol:
 
btw in case of merging required in the EventManager... I added a comment next to all I have edited in the file (aside from the very bottom). This comment reads: #Hi Baldyr! and in Utils, everything that is irregular unitwise has #Irregular next to it!

(seeing though my Functions has more functions then Utils maybee Utils should become the variable Module and leave all functions to CustomFunctions :p)

don't forget to read my previous post's edits!

EDIT: btw I had a quick look in the event XML and found these in the eventinfos (which define the options you get when a trigger is met ie: in the event forestfire you get 3 options, replant, lose etc) <PythonCallback/><PythonExpireCheck/><PythonCanDo/><PythonHelp/> and in the event trigger infos (defines what makes the event happen, like an if statement, but you probably already guessed that)<PythonCanDo/><PythonCanDoCity/><PythonCanDoUnit/><PythonCallback/>

is that anything like what you wanted before?
 
Back
Top Bottom