Requesting following features

Soon, hopefully. I look forward to coding it, also.
 
well I am going to be away untill friday so if you are going to start within the next 3 days I won't be able to find out :p
 
Ok, here it is. I tried to do some testing but its difficult since you changed the scenario map. :rolleyes:

Firstly the code that goes into the HistoricalNames module (before/after the data):
Spoiler :
PHP:
### Historical City Names Manager, by Baldyr and J_mie6

from Helpers import *
from eNums import *

# constants
lDirectionTypes = list()
for eDirection in xrange(DirectionTypes.NUM_DIRECTION_TYPES):
        lDirectionTypes.append(DirectionTypes(eDirection))

# main functions

def nameCity(pCity):
        """
        Handles incoming calls from CvEventManager.onCityBuilt().
        Firstly checks if the city plot is a special case by calling renameCity(). If so, the function exits.
        Secondly checks the city name dictionary by calling getSite().
        If a valid historical site is found the value is used as the city name, by calling setName().
        """
        if renameCity(pCity.getOwner(), pCity): return
        tCoords = getSite(pCity)
        if tCoords:
                setName(pCity, cityNameDict[tCoords])

def renameCity(ePlayer, pCity):
        """
        Called from CvEventManager.onCityAcquiredAndKept().
        Checks plots by coordinates and city ownership; sets the name accordingly.
        """
        tCoords = getCoords(pCity)
        name = ""
        if tCoords == (46, 27):
                if ePlayer == CivPlayer.playerID("Byzantium"):
                        name = "Constantinople"
                elif ePlayer == CivPlayer.playerID("Rome"):
                        name = "Byzantion" 
        elif tCoords == (71, 15):
                if ePlayer == CivPlayer.playerID("Egypt"):
                        name = "Damascus"
                elif ePlayer == CivPlayer.playerID("Rome"):
                        name = "Damasci"
        if name:
                setName(pCity, name)
                return True

def isInvalidSite(ePlayer, tCoords):
        """
        Called from CvGameUtils.cannotFoundCity().
        Returns False if the city plot or any adjacent plot is found in the city name dictionary.
        Also always returns False if the call concerns the human player.
        Returns True by default if no conditions are met.
        """
        if ( instance(ePlayer) == human()
             or isHistoric(tCoords)
             or isHistoric(checkAdjacent(tCoords)) ):
                return False
        return True

# helper functions

def setName(pCity, name):
        """
        Changes the city name.
        """
        pCity.setName(name, False)

def getSite(pCity):
        """
        Returns a tuple containing map coordinates if a match is found in the city name dictionary.
        Firstly checks the city plot, secondly all adjacent plots, and finally all plots within city's radius.
        """
        tCoords = getCoords(pCity)
        if isHistoric(tCoords):
                return tCoords
        else:
                tAlternateSite = checkAdjacent(tCoords)
                if tAlternateSite:
                        return tAlternateSite
                else:
                        tAlternateSite = checkBFC(pCity)
                        if tAlternateSite:
                                return tAlternateSite

def isHistoric(tCoords):
        """
        Returns True if the plot coordinate tuple is a valid key in the city name dictonary. Else returns False.
        """
        return cityNameDict.has_key(tCoords)
                        
def checkAdjacent(tCoords):
        """
        Returns the map coordinates of the first found historical city site on an adjacent tile.
        """
        for eDirection in lDirectionTypes:
                tAlternateSite = getCoords(plotDirection(tCoords[0], tCoords[1], eDirection))
                if isHistoric(tAlternateSite):
                        return tAlternateSite
                                          
def checkBFC(pCity):
        """
        Returns the map coordinates of the first found historical city site within the city's radius.
        """
        for iIndex in xrange(19):
                tAlternateSite = getCoords(pCity.getCityIndexPlot(iIndex))
                if isHistoric(tAlternateSite):
                        return tAlternateSite
                
# data

cityNameDict = {
(...)
Secondly you add these lines into CvEventManager:
Spoiler :
Code:
	def onCityBuilt(self, argsList):
		'City Built'
		city = argsList[0]

		Powers.gaul(city, city.getOwner())
[COLOR="Red"]		Cities.nameCity(city)[/COLOR]

[COLOR="Red"]##[/COLOR]		if (city.getOwner() == gc.getGame().getActivePlayer()):
[COLOR="Red"]##[/COLOR]			self.__eventEditCityNameBegin(city, False)	
		CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
(Note that I commented out those lines for testing - you may wanna do the same!)
Code:
	def onCityAcquiredAndKept(self, argsList):
		'City Acquired and Kept'
		iOwner,pCity = argsList

[COLOR="Red"]		Cities.renameCity(*argsList)[/COLOR]
And in order to enable the HistoricalCities module you add the red bits:
Code:
def initiateCustomPython():
	if gc.getGame().isFinalInitialized():
		global Powers, Rebellion, Custom, CC[COLOR="Red"], Cities[/COLOR]
		import Powers, Rebellion, CustomFeatures as Custom, CatapultConstruction as CC[COLOR="Red"], HistoricalCities as Cities[/COLOR]
		if not Rebellion.getGlobalScriptDict():
			Rebellion.setup()
		CC.load()
		from CvGameUtils import CvGameUtils
		CvGameUtils.powers = Powers
		CvGameUtils.custom = Custom
[COLOR="Red"]		CvGameUtils.cities = Cities[/COLOR]
		Custom.gameTurn()
Finally, you need to edit CvGameUtils:
Code:
	def cannotFoundCity(self,argsList):
		iPlayer, iPlotX, iPlotY = argsList
		return [COLOR="Red"]self.cities.isInvalidSite(iPlayer, (iPlotX, iPlotY))[/COLOR]
Note however that you also need to enable the cannotFoundCity callback in PythonCallbackDefines.xml:
Code:
	<Define>
		<DefineName>USE_CANNOT_FOUND_CITY_CALLBACK</DefineName>
		<iDefineIntVal>[COLOR="Red"]1[/COLOR]</iDefineIntVal>
	</Define>
There are bound to be bugs and issues, but you wanted to get your hands dirty, right? ;) I'm confident that you can clear up any exceptions and whatnot on your own. :p I documented the code for you, after all. :D
 
If you mean the
Code:
##		if (city.getOwner() == gc.getGame().getActivePlayer()):
##			self.__eventEditCityNameBegin(city, False)
lines, it's to disable the name city popup when you found a city.
 
It dawned on me that I forgot about something potentially vital:
Code:
def checkAdjacent(tCoords):
        """
        Returns the map coordinates of the first found historical city site on an adjacent tile.
        """
        for eDirection in lDirectionTypes:
[COLOR="Red"]                pPlot = plotDirection(tCoords[0], tCoords[1], eDirection)
                if pPlot.isNone(): continue
                tAlternateSite = getCoords(pPlot)[/COLOR]
                if isHistoric(tAlternateSite):
                        return tAlternateSite
Hopefully you'll experience a few less crashes... :p
 
wait a minute, how is the module imported? :confused:

edit: right missed that :p
 
All of the custom Python in your mod has to be imported only after the game has already initialized, because otherwise any XML settings won't show, and my code breaks down. There is nothing standard fare about the code I've done, and it was never intended to be looked at by anyone else than me. The priority has instead been to make it easy for you to add function calls to the event manager, without having to add anything but one single line for each new feature.
 
right ok, no exceptions :p however,

When the ere takes byzantium off anybody the name isn't changed (can't test the romans :p, because the city has the same name anyway!) the Damascus/Damasci link works perfectly!

the historical names work perfectly! (had trouble finding invalid spots! :p everywhere gave me a name :p well not everywhere)

so Byzantium to find problem (does it have to take off rome?) also something wierd happens when byzantium takes Constaniople :p it gives the message that happens when a rebel civ becomes the reborn civ :p (probs as I resurrected it :D) but that won't happen in game I think...

So things to do:
Byzantium - Constantinople link fix
got to make it so the players founding is restricted within certain coords... I will try this myself, can't be to hard (he says)

also if a historical city is razed and re founded will the name still be used? and what about if some silly player founds a city and renames it to say: Toletum and then the AI founds the real Toletum... What happens :p?
 
Eh, did you request any further work from me?

Good luck with testing and further development anyway!

Regarding map restrictions; if there are lots of areas to be defined we could do it with data structures also, instead of hardcoding coordinates. Tell me if you wanna explore this further.
 
Well I did ask you to do player restriction but you must have overlooked it! I will work on it later and will get back to you (count this as my work :p), also I was thinking about the dire situation of the ERE last night and how it basically required the human to be the roman civ... So... I am going to attempt 2 new events, the first only occurs if Rome is under AI control, They will get an army outside of byzantium and 2 turns before the ERE flip if rome doesn't control it then it gets fliped to them (The idea is they take the city and some surrounding cities) and then the second happens regardless (provided the ERE has less than x amount of cities) where the ere flips everything within a box (small, probably northern greece and some of the eastern surroundings) maybee 3 turns after they spawn with a message saying a number of cities have joined the cause of the mighty Eastern Roman empire! So... These 2 events secure the life of the ERE if Rome is the AI or if the player fails to make a big enough empire in the east :p

Will take a lot of work to code these 2 events and the player restriction (which I will do in utils surely?) I will get back to you on the results! Congratulations on your error free code! (kind of unnerving, makes me think something really wrong will happen soon :p)
 
Well I did ask you to do player restriction but you must have overlooked it!
I have no recollection of this, but if you need help with it please explain. If you have the design all done (coordinates and specifics on the players concerned), then it would be easy enough to fix it for you.

Congratulations on your error free code! (kind of unnerving, makes me think something really wrong will happen soon :p)
Oh, there is bound to be some issue with it, eventually. I did test things and made sure everything loaded alright and that there were no exceptions in-game, but nothing more.
 
I will only ask for help when I am well and truely stuck :p
 
Fair enough, but I imagine what you propose could be done in a somewhat efficient manner, rather than just hard-coding a huge number of coordinates or ranges. There is also the issue of avoiding lag by using the callbacks in CvGameUtils...

But as a scripting exercise I'm sure its a good project for you to cut you teeth on. :D
 
ok, what do you suggest I base the restriction code on? What are the disadvantages of the Utils? you used it didn't you?

I will try and make this as efficient as possible (most likely with a dictionary, I love dictionaries)
 
It depends on what you intend to do - what the design of this feature will look like.

The problem with using the Game Utils call-backs is that those are called hundreds and thousands of times in-between any game turn, and together those micro-seconds add up to milli-seconds, that add up to seconds - and in the course of a whole game you're looking at minutes - and even hours of lag.

This is why any code you add in these call-backs needs to be as efficient as possible. You basically need to find the simplest logic possible, expressed in the least amount of expressions. I'm not even sure if a gigantic if-tree is more efficient than to index some data-structure, but you wanna scale down any unnecessary scripting.

But go ahead, give it a try. With any luck I will only have some minor pointers to hand out after you're done with it. Its not like its rocket science - its only computer science. ;)

As a side-note, I could add that I never added any actual lines of code into the CvGameUtils module. This is because its not importing any of the new modules I've made for you! (Not directly, at least.) So all the tools I've made for your mod aren't even available. Instead I've restricted all the call-backs to calling other modules for the actual logic on the return lines. Take a look and see if you can make any sense of it all...

As stated before; the work I did for this mod was never intended to be looked at by anyone else... :p
 
but you did edit it for the historical city names :p why did you have to there?
 
I only added a function call from CvGameUtils to CustomFeatures. I'm using the return value from that function as the return value of the call back to the DLL.

Its technical, is what it is.
 
also, map restrictions are only really for one box, the flip code regards one box so thats 4 coords in total, not enough for a data structure :p (Well unless you think differently?) I guess will work on this tommorrow! What are your thoughts on why the Byzantium -> constaninople code doesn't work? I checked the coords for it and they are all fine... I'm stumped, I guess tommorrow I will make a debug for that part :p It's not like it has any excuse! The damasci code works fine (a question about that, if egypt founds Damasci will it be named the eygptian variant? I guess not as it is on the CityAcquiredAndKept callback Should be easy to hard code that in somewhere though!)

I will make some code for the Restrictions and you can pick it to pieces later (and give suggestions on it's effciency) :p
 
Back
Top Bottom