trying to use a minimalist mod to do big things

I also think that once I get the HolyCity thing done I'll use the same 2x2 search-and-assign code to assign a palace on the regular spawns rather than using that nukem killbox method...
 
Good to hear about your progress, but looking at the code there is of course enormous potential for improvement. Not necessarily for functionality, but rather on the technical and practical side of things... Like make functions for making peace with everyone (with iteration instead of manually calling on the same method repeatedly) and then calling that instead. Or making a general function that assigns all techs per era. And so on.

Of course just about everything could be generalized so that the whole thing would be so much easier to modify, but you already know this. Its actually about the worst example of repeating code I've yet to see, but as long as its working, I guess... :p

Just to show you what I mean:
Code:
def makePeace(eTeam):
    pTeam = gc.getTeam(eTeam)
    for eRival in range(18): # creates a list with integers from 0 to 17
        pRivalPlayer = gc.getPlayer(ePlayer)
        if pRivalPlayer.isAlive():
            eRivalTeam = pRivalTeam.getTeam()
            pTeam.makePeace(eRivalTeam)
Now, all you have to repeat is:
Code:
makePeace(eTeam)
And if you generalize the function calling on makePeace() you wont need to repeat anything!

But I am very impressed with you solving you problems yourself - and how fast you're learning. :king: You should probably be starting to think about the state of your code instead of only getting results. Because if you push yourself you'll learn that much more!
 
Its actually about the worst example of repeating code I've yet to see

Just wait until you see the rest! I've literally just this moment gotten through doing all the peace and all the techs for all the spawns (I discovered that I can't start the workboat civs with their techs because then the religions will spawn immediately upon the first barbarian city founding).

So, yeah...literally just got through with that...up to 2107 lines right now :mischief:

also went in and started civs capitals with buildings and greater population/numbers (needed for balance)...will have to start certain civs with better units as well...

but other than that, I just need to do the tech related colony thing and the tech related holycity thing and I'm done.

So riddle me this...what is the best way to see if a particular tech has been discovered by anybody? I think that's what I'm going to use to determine whether or not a religion has been founded. I'm going to have the code run onCityBuilt and use an if statement regarding the tech. If both are satisfied, I'll use the loop to assign the holycity status.

I think I'm just going to use adjacentSquare...the worst thing that'll happen is that it'll move twice in the same turn, but honestly, the AI doesn't like taking advantage of the minimum city distance (I guess it crunches the resources too much), so I don't think it would happen but rarely.
 
Just out of curiosity...is there a way to enable autoplay when in single player mode, but nix it in multiplayer? It's fine if I can't, it just means you've got to hold down the <return> key for awhile...a long while...
 
So riddle me this...what is the best way to see if a particular tech has been discovered by anybody? I think that's what I'm going to use to determine whether or not a religion has been founded. I'm going to have the code run onCityBuilt and use an if statement regarding the tech. If both are satisfied, I'll use the loop to assign the holycity status.
Use the onTechAcquired call in the Event Manager and fire the code once anyone discovers the required Tech. But then you need a way to stop the code from being run ever again, and you can use a global variable for this. Firstly you set the default value at module level (= outside of any function):
Code:
bNotTriggered = True
Then you have a conditional statement where ever it is your defining the event (= inside the function):
Code:
    if bNotTriggered:
        bNotTriggered = False
This simple action will prevent the condition from ever being met more than once.

Lets see if you can figure out how to put together the rest...

Just out of curiosity...is there a way to enable autoplay when in single player mode, but nix it in multiplayer? It's fine if I can't, it just means you've got to hold down the <return> key for awhile...a long while...
I actually have no idea... Why do you need the Wworkboat thing, again? Can't the Civs just be dead until they spawn?
 
If the civs are dead until they spawn, there will be no way for a human player to play a later civ on single player mode. It's a necessary evil...
 
Unless you make one WBS for each Civ/starting date.
 
I'm thinking about doing that...but I'm not sure if I really want to include ten wbs files. Meh...I'm sure I'll do a few of them, maybe not one for every single civ.

I'm thinking of splitting up that holycity thing into two functions. One that runs on tech acquired and changes the value of bNotTriggered (do I need one of them for each religious tech? I'd think so...) and a second function that runs on city found and moves the city if that religion's bNotTriggered == False

no?
 
hmmmm...may be overcomplicating things here...there is this, after all:

BOOL isReligionSlotTaken (ReligionType eIndex)
bool (ReligionID) - is religion in that tech slot founded?
 
could I not just run this onCityBuilt?
Spoiler :

Code:
#moves holycity status to a city with the proper geographical location: run on city found
def holyCityNorm():
		if getGame().isReligionSlotTaken(0):
				for tCoords in getAdjacentList((73, 40)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									pCity.setHolyCity(0, true, true)

yeah, it encompasses the wider area, but as I've said before...on reflection I don't think it'll be an issue
 
I'm thinking of splitting up that holycity thing into two functions. One that runs on tech acquired and changes the value of bNotTriggered (do I need one of them for each religious tech? I'd think so...) and a second function that runs on city found and moves the city if that religion's bNotTriggered == False

no?
This is actually where it gets interesting. If I'm reading you correctly you're definitely on to something. :goodjob: Run with it and see where it gets you!

I would personally, of course, create one single general function for each task that can handle all religions. Then the data would be read - and set - from data structures. As an example I would have a tReligions tuple:
Code:
tReligions = (False,) * 7
This assignment statement creates a tuple with seven False entries - one for each religion - and assigns it to the name without me having to type the whole damned thing. (Copy-pasting is not programming, so I try to never do that myself. It keeps me thinking instead of... copying.) Its the equivalent as assigning this to the variable:
Code:
(False, False, False, False, False, False, False)
Then, onReligionFound I'd include the ReligionTypes value as an argument to my generic function:
Code:
MyModule.religionFounded(eReligion)
And in my religionFounded() function I'd access the global tuple variable and fetch the boolean value for the religion concerned:
Code:
if not tReligions[eReligion]:
    tReligions[eReligion] = True
And I'd store the coordinates of the holy sites in another data structure, and so on. Its not much harder than to copy-paste the same code and edit each copy, but once I need to change something the extra work that went into my program design has already paid off, counting minutes and seconds. And time matters. Also I don't have to debug several thousand lines of code once something is awry...

But still, you probably need to get Judaism working first. Then, if you want to, we can generalize the setup and you'd have all the other religions already done. All that is needed is to populate the various data structures with values. And those would be very convenient to edit later also, once you realize something needs to be tweaked.

I'm not twisting your arm here. Just almost. :p
 
BOOL isReligionSlotTaken (ReligionType eIndex)
bool (ReligionID) - is religion in that tech slot founded?
I don't know what that method checks actually, so you'd just have to test it.
 
This code works well. The religion is founded wherever it would be according to the regular rules of the game, and it then checks every time someone builds a city to see if there are any cities on the "right" plots - if there is, it moves them. The religion's presence is left in its original location, but it is no longer the holy city.

I'm cool with that.

Alright...so...now for tech-related colony spawns, as well as code to kill the workboat and conceal the tiles on new civ spawn, and I can then call it done and start playing around with advanced start wbs files (maybe)

Spoiler :
Code:
#moves holycity status to a city with the proper geographical location: run on city found
def holyCityNorm():
		if gc.getGame().isReligionSlotTaken(0):
				for tCoords in getAdjacentList((73, 40)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									gc.getGame().setHolyCity(0, pCity, false)
		if gc.getGame().isReligionSlotTaken(1):
				for tCoords in getAdjacentList((61, 46)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									gc.getGame().setHolyCity(1, pCity, false)
		if gc.getGame().isReligionSlotTaken(2):
				for tCoords in getAdjacentList((75, 35)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									gc.getGame().setHolyCity(2, pCity, false)
		if gc.getGame().isReligionSlotTaken(3):
				for tCoords in getAdjacentList((89, 39)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									gc.getGame().setHolyCity(3, pCity, false)
		if gc.getGame().isReligionSlotTaken(4):
				for tCoords in getAdjacentList((95, 43)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									gc.getGame().setHolyCity(4, pCity, false)
		if gc.getGame().isReligionSlotTaken(5):
				for tCoords in getAdjacentList((102, 45)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									gc.getGame().setHolyCity(5, pCity, false)
		if gc.getGame().isReligionSlotTaken(6):
				for tCoords in getAdjacentList((102, 32)):
							x, y = tCoords
							pCurrentPlot = cyMap.plot(x, y)
							if pCurrentPlot.isCity():
									pCity = pCurrentPlot.getPlotCity()
									gc.getGame().setHolyCity(6, pCity, false)
 
About killing the Workboat and covering the revealed tiles, I have this in PyScenario for a similar purpose:
Code:
        def hideSpawn(self):
                getPlot((0, 0)).getUnit(0).kill(False, self.Context.player)
                for tCoords in getSquareList((0, 0), 2):
                        getPlot(tCoords).setRevealed(getPlayer(self.Context.player).getTeam(), False, True, -1)
Note that this is a class method and not a regular function, but you should be able to see what I've done. getPlot() and getPlayers() are helper functions that return a CyPlot and a CyPlayer instance respectively, so there is no real mystery there. The name self.Context.player refers to a PlayerTypes (player ID) reference (integer).

This is basically the same code from the RiseAndFall module in RFC:
Code:
                        plotZero = gc.getMap().plot( 0, 0 )                        
                        if (plotZero.getNumUnits()):
                                catapult = plotZero.getUnit(0)
                                catapult.kill(False, iCiv)
                        gc.getMap().plot(0, 0).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(0, 1).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(1, 1).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(1, 0).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(123, 0).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(123, 1).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(2, 0).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(2, 1).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(2, 2).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(1, 2).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(0, 2).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(122, 0).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(122, 1).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(122, 2).setRevealed(iCiv, False, True, -1);
                        gc.getMap().plot(123, 2).setRevealed(iCiv, False, True, -1);
I guess I don't have to point out why I prefer my own instead of using Rhye's code directly? :rolleyes: (By the way, what are those semi-colons doing at the end of each setRevealed() invocation? :confused:)

If you have several Workboast on the same tile you can use:
Code:
pPlot = cyMap.plot(x, y)
iNumUnits = pPlot.getNumUnits()
for i in range(iNumUnits):
    pCurrentUnit = pPlot.getUnit(i)
    eOwner = pCurrentUnit.getOwner()
    pCurrentUnit.kill(False, eOwner)
Once again, you could (should) only define one function that takes the target plot as a argument for all your killing and covering purposes - not copy-paste some code over and over again... But its your program.
 
no, they're all on separate plots so the civs don't make contact with each other while waiting.

I need to go back after I do the colony spawns and see if it's even necessary. I just remembered that later civs start with partially revealed maps (each one custom), and their boat locations are designed to be in or near to that, so it may not be necessary at all...

but I'll definitely take a cruise thru the code when I get back from my trip to Connecticut this weekend.

Next week is going to be a busy week for me...not much time to play around with civ. If I can get the colonies done on Sunday when I get back, that might be just they way to have it done this week!
 
also, I would not be averse to including "signs" to mark the future spawn points of later civs, provided there was a way within python to remove those signs after the spawn. I'll be looking into that, too, but if anyone knows how offhand and wants to give some hints it'd be appreciated.
 
oh, one more thing...as I spawn the colonies, I'd like to spawn a missionary of whatever the civ's religion is. I think I can reasonably predict what they'd be, but I'd rather allow for a human player to pick something wildly different. How can I determine a player's religion and then spawn the appropriate unit? I have an idea, but (as ususal) it won't be pretty...
 
alright, I've defined these with the mod constants:

#triggers for colony spawns tied to Astronomy
bArabiaTriggered = True
bEnglandTriggered = True
bFranceTriggered = True
bSpainTriggered = True
bRussiaTriggered = True


but it complains that bEnglandTriggered is referenced before assignment. I need to make sure that each of these only triggers for each of these civs once. What am I doing wrong?


Spoiler :
Code:
#colony spawns tied to discovery of Astronomy, run onTechAcquired
def colonySpawn():
		pNewYork = cyMap.plot(30, 47)
		pPhiladelphia = cyMap.plot(28, 46)
		pBoston = cyMap.plot(31, 48)
#Arabs
		if gc.getTeam(11).isHasTech(42):
				if bArabiaTriggered:
						bArabiaTriggered = False
						PyPlayer(11).initUnit(4, 99, 27, 1)
						PyPlayer(11).initUnit(5, 99, 27, 2)
						PyPlayer(11).initUnit(42, 99, 27, 5)
						PyPlayer(11).initUnit(4, 104, 27, 1)
						PyPlayer(11).initUnit(5, 104, 27, 2)
						PyPlayer(11).initUnit(42, 104, 27, 5)
						PyPlayer(11).initUnit(4, 71, 25, 1)
						PyPlayer(11).initUnit(5, 71, 25, 2)
						PyPlayer(11).initUnit(42, 71, 25, 5)
#English or Celts
		if gc.getTeam(12).isHasTech(42):
				if bEnglandTriggered:
						bEnglandTriggered = False
						for tCoords in getAdjacentList((30, 47)):
								x, y = tCoords
								pCurrentPlot = cyMap.plot(x, y)
								if pCurrentPlot.isCity():
										pCity = pCurrentPlot.getPlotCity()
										pCity.kill()
						for tCoords in getAdjacentList((28, 46)):
								x, y = tCoords
								pCurrentPlot = cyMap.plot(x, y)
								if pCurrentPlot.isCity():
										pCity = pCurrentPlot.getPlotCity()
										pCity.kill()
						for tCoords in getAdjacentList((31, 48)):
								x, y = tCoords
								pCurrentPlot = cyMap.plot(x, y)
								if pCurrentPlot.isCity():
										pCity = pCurrentPlot.getPlotCity()
										pCity.kill()
						PyPlayer(12).initCity(30, 47)
						pNewYork.getPlotCity().setName("New York", 1)
						PyPlayer(12).initUnit(5, 30, 47, 2)
						PyPlayer(12).initUnit(47, 30, 47, 5)
						PyPlayer(12).initCity(28, 46)
						pPhiladelphia.getPlotCity().setName("Philadelphia", 1)
						PyPlayer(12).initUnit(5, 28, 46, 2)
						PyPlayer(12).initUnit(47, 28, 46, 5)
						PyPlayer(12).initCity(31, 48)
						pBoston.getPlotCity().setName("Boston", 1)
						PyPlayer(12).initUnit(5, 31, 48, 2)
						PyPlayer(12).initUnit(47, 31, 48, 5)
						PyPlayer(12).initUnit(4, 28, 51, 1)
						PyPlayer(12).initUnit(5, 28, 51, 2)
						PyPlayer(12).initUnit(47, 28, 51, 5)
						PyPlayer(12).initUnit(4, 64, 12, 1)
						PyPlayer(12).initUnit(5, 64, 12, 2)
						PyPlayer(12).initUnit(47, 64, 12, 5)
						PyPlayer(12).initUnit(4, 118, 13, 1)
						PyPlayer(12).initUnit(5, 118, 13, 2)
						PyPlayer(12).initUnit(47, 118, 13, 5)
						if PyPlayer(12).getStateReligion() == 0:
								PyPlayer(12).initUnit(17, 30, 47, 1)
								PyPlayer(12).initUnit(17, 28, 46, 1)
								PyPlayer(12).initUnit(17, 31, 48, 1)
								PyPlayer(12).initUnit(17, 28, 51, 1)
								PyPlayer(12).initUnit(17, 64, 12, 1)
								PyPlayer(12).initUnit(17, 118, 13, 1)
						if PyPlayer(12).getStateReligion() == 1:
								PyPlayer(12).initUnit(18, 30, 47, 1)
								PyPlayer(12).initUnit(18, 28, 46, 1)
								PyPlayer(12).initUnit(18, 31, 48, 1)
								PyPlayer(12).initUnit(18, 28, 51, 1)
								PyPlayer(12).initUnit(18, 64, 12, 1)
								PyPlayer(12).initUnit(18, 118, 13, 1)
						if PyPlayer(12).getStateReligion() == 2:
								PyPlayer(12).initUnit(19, 30, 47, 1)
								PyPlayer(12).initUnit(19, 28, 46, 1)
								PyPlayer(12).initUnit(19, 31, 48, 1)
								PyPlayer(12).initUnit(19, 28, 51, 1)
								PyPlayer(12).initUnit(19, 64, 12, 1)
								PyPlayer(12).initUnit(19, 118, 13, 1)
						if PyPlayer(12).getStateReligion() == 3:
								PyPlayer(12).initUnit(20, 30, 47, 1)
								PyPlayer(12).initUnit(20, 28, 46, 1)
								PyPlayer(12).initUnit(20, 31, 48, 1)
								PyPlayer(12).initUnit(20, 28, 51, 1)
								PyPlayer(12).initUnit(20, 64, 12, 1)
								PyPlayer(12).initUnit(20, 118, 13, 1)
						if PyPlayer(12).getStateReligion() == 4:
								PyPlayer(12).initUnit(21, 30, 47, 1)
								PyPlayer(12).initUnit(21, 28, 46, 1)
								PyPlayer(12).initUnit(21, 31, 48, 1)
								PyPlayer(12).initUnit(21, 28, 51, 1)
								PyPlayer(12).initUnit(21, 64, 12, 1)
								PyPlayer(12).initUnit(21, 118, 13, 1)
						if PyPlayer(12).getStateReligion() == 5:
								PyPlayer(12).initUnit(22, 30, 47, 1)
								PyPlayer(12).initUnit(22, 28, 46, 1)
								PyPlayer(12).initUnit(22, 31, 48, 1)
								PyPlayer(12).initUnit(22, 28, 51, 1)
								PyPlayer(12).initUnit(22, 64, 12, 1)
								PyPlayer(12).initUnit(22, 118, 13, 1)
						if PyPlayer(12).getStateReligion() == 6:
								PyPlayer(12).initUnit(23, 30, 47, 1)
								PyPlayer(12).initUnit(23, 28, 46, 1)
								PyPlayer(12).initUnit(23, 31, 48, 1)
								PyPlayer(12).initUnit(23, 28, 51, 1)
								PyPlayer(12).initUnit(23, 64, 12, 1)
								PyPlayer(12).initUnit(23, 118, 13, 1)
#French
		if gc.getTeam(13).isHasTech(42):
				if bFranceTriggered:
						bFranceTriggered = False
						PyPlayer(13).initUnit(4, 31, 37, 1)
						PyPlayer(13).initUnit(5, 31, 37, 2)
						PyPlayer(13).initUnit(43, 31, 37, 5)
						PyPlayer(13).initUnit(4, 31, 53, 1)
						PyPlayer(13).initUnit(5, 31, 53, 2)
						PyPlayer(13).initUnit(43, 31, 53, 5)
						PyPlayer(13).initUnit(4, 33, 32, 1)
						PyPlayer(13).initUnit(5, 33, 32, 2)
						PyPlayer(13).initUnit(43, 33, 32, 5)
						PyPlayer(13).initUnit(4, 57, 30, 1)
						PyPlayer(13).initUnit(5, 57, 30, 2)
						PyPlayer(13).initUnit(43, 57, 30, 5)
#Spanish
		if gc.getTeam(14).isHasTech(42):
				if bSpainTriggered:
						bSpainTriggered = False
						PyPlayer(14).initUnit(4, 27, 38, 1)
						PyPlayer(14).initUnit(5, 27, 38, 2)
						PyPlayer(14).initUnit(42, 27, 38, 5)
						PyPlayer(14).initUnit(4, 18, 39, 1)
						PyPlayer(14).initUnit(5, 18, 39, 2)
						PyPlayer(14).initUnit(42, 18, 39, 5)
						PyPlayer(14).initUnit(4, 42, 18, 1)
						PyPlayer(14).initUnit(5, 42, 18, 2)
						PyPlayer(14).initUnit(42, 42, 18, 5)
						PyPlayer(14).initUnit(4, 36, 13, 1)
						PyPlayer(14).initUnit(5, 36, 13, 2)
						PyPlayer(14).initUnit(42, 36, 13, 5)
#Russia
		if gc.getTeam(16).isHasTech(42):
				if bRussiaTriggered:
						bRussiaTriggered = False
						for tCoords in getPlotList((66, 48), (1, 64)):
								x, y = tCoords
								pCurrentPlot = cyMap.plot(x,y)
								pPotentialCity = pCurrentPlot.getPlotCity()
								iUnhappy = pPotentialCity.unhappyLevel(0)
								if pPotentialCity != None:
										iPopulation = pPotentialCity.getPopulation()
										if iUnhappy * 3 >= iPopulation:
												pCurrentPlot.setOwner(16)
						PyPlayer(16).initUnit(4, 110, 52, 1)
						PyPlayer(16).initUnit(5, 110, 52, 2)
						PyPlayer(16).initUnit(42, 110, 52, 5)
						PyPlayer(16).initUnit(4, 80, 53, 1)
						PyPlayer(16).initUnit(5, 80, 53, 2)
						PyPlayer(16).initUnit(42, 80, 53, 5)
						PyPlayer(16).initUnit(4, 96, 58, 1)
						PyPlayer(16).initUnit(5, 96, 58, 2)
						PyPlayer(16).initUnit(42, 96, 58, 5)
 
should I open with

if gc.getTeam(12).isHasTech(42):
if bEnglandTriggered == True:
bEnglandTriggered = False

or do I need to say
set bEnglandTriggered = False?
 
hm...none of this is working. I think I have the wrong idea with looking to see if they have the tech as well. I just can't figure out how to get the game to look and see onTechAcquired which tech was acquired. I mean, if I could get it to look onTechAcquired and see if tech=astronomy AND activeplayer=england that would do it, and it could only be done once per game per named civ.

But I don't see anything like that in the api
 
Back
Top Bottom