Non city culture borders

Primax

CivPlayers Modder
Joined
Jul 31, 2006
Messages
73
Location
Australia
I made forts able to get resources outside cities by making forts own land and add culture to the plot. I thought maybe some people would be interested in the code so I am posting it here.

this is the python code and simply adds culture and land ownership to the plot
pretty self explanatory:
Code:
	def onImprovementBuilt(self, argsList):
		'Improvement Built'
		iImprovement, iX, iY = argsList
		pPlot = gc.getMap().plot(iX,iY)
		pPlayer = gc.getPlayer(pPlot.getUnit(1).getOwner())

		if (iImprovement == gc.getInfoTypeForString("IMPROVEMENT_FORT")):
			CyInterface().addImmediateMessage("onImprovementBuilt called FORT","")
			CyMap().plot(iX, iY).setOwner(pPlayer.getID())
			CyMap().plot(iX, iY).changeCulture(pPlayer.getID(), 10, False)

The following was added to CvPlot::CalculateCulturalOwner() im not sure if its needed tho:

Code:
	if (isForceUnowned() && getImprovementType() != GC.getInfoTypeForString("IMPROVEMENT_FORT")) //Primax 0.1 Forts Culture
	//if (isForceUnowned())
	{
		return NO_PLAYER;
	}

this was added to CvPlot::isWithinCultureRange()

Code:
bool CvPlot::isWithinCultureRange(PlayerTypes ePlayer) const
{
	int iI;

	for (iI = 0; iI < GC.getNumCultureLevelInfos(); ++iI)
	{
		if (isCultureRangeCity(ePlayer, iI) || getImprovementType() == GC.getInfoTypeForString("IMPROVEMENT_FORT")) // Primax 0.1 FORT
		//if (isCultureRangeCity(ePlayer, iI))
		{
			return true;
		}
	}

	return false;
}

That should be it. Hopefully someone can find this usefull I know there were alot people interested in any threads I could find on the subject.
 
Very cool.

Would you be willing to zip your files and upload them? I am know almost nothing about python, but this would be extremely cool to have.

Thanks,

-GM
 
Great idea! I noticed one possible bug and had some nitpicks on the Python code.

You grab the first unit on the plot to determine who built the fort and thus owns the land, but what happens if there are units from another civ on the same plot? My guess is that it's possible that you building a fort could cause the other civ to own the land.

Wait, now I'm confused. Can't you only build forts within your cultural borders? I never build forts, but that seems familiar to me.

Anyway, you can use the pPlot variable you've already created on the last two lines of the code to avoid confusion and possible errors if you change it in the future.

Code:
pPlot.setOwner(pPlayer.getID())
pPlot.changeCulture(pPlayer.getID(), 10, False)
 
Great idea! I noticed one possible bug and had some nitpicks on the Python code.
Thanks for the feedback. This is just a little part of the my mod I thought people might be interested in.

You grab the first unit on the plot to determine who built the fort and thus owns the land, but what happens if there are units from another civ on the same plot? My guess is that it's possible that you building a fort could cause the other civ to own the land.

hmm I couldn't think of any ways to get around this at the time I coded it and planned to go back and change it if it caused a major headache. It is a part of the code I was watching closely. Can you think of a better way to determine who should own the plot?

is there a way to get the unit which actually built the improvement? I was thinking I might add in a check which cycles through units on the plot untill it finds a worker with no movement.
Wait, now I'm confused. Can't you only build forts within your cultural borders? I never build forts, but that seems familiar to me.

Yup, this is true. I am also using build outside borders code. or if you use this for BTS forts are buildable outside borders by default. I actually made new improvements called colonies. But again didnt think this code would be important.

Anyway, you can use the pPlot variable you've already created on the last two lines of the code to avoid confusion and possible errors if you change it in the future.

Code:
pPlot.setOwner(pPlayer.getID())
pPlot.changeCulture(pPlayer.getID(), 10, False)

thats a good question.. why didn't I just use pPlot haha. oh well does the same job. Thanks alot for you suggestions and critics I appreciate them
 
Very cool.

Would you be willing to zip your files and upload them? I am know almost nothing about python, but this would be extremely cool to have.

Thanks,

-GM

Sure, I can upload code for it. But you would need alot of other stuff to make it work such as Improvements Outside Borders by The Lopez.

Are you after colonies in particular? I ask because I can release a mod with just the code required to get this to work if you like and upload that code. Or you can wait till BTS is released and I will release the code for that :)
 
I was thinking I might add in a check which cycles through units on the plot untill it finds a worker with no movement.

That sounds like a great idea. You'll need to test, but assuming all other civs' units are reset to full movement points, you just need to look for the first unit with 0 points, regardless of worker or not. Now, hopefully the worker's MPs are removed before the function is called. ;)

If it ever became a problem, you could make it check for the civ with the most units on the plot, most workers, whatever. I bet what you have is probably sufficient for now, but I like the movement points idea.

One part I didn't understand, does the fort continue to add culture and expand borders? I ask because you use this to grab resoures, but if the fort doesn't extend borders, how do you gain the resource? Oh, do you build a fort (gaining ownership) and then build a farm/mine/whatever over the fort?
 
That sounds like a great idea. You'll need to test, but assuming all other civs' units are reset to full movement points, you just need to look for the first unit with 0 points, regardless of worker or not. Now, hopefully the worker's MPs are removed before the function is called. ;)

If it ever became a problem, you could make it check for the civ with the most units on the plot, most workers, whatever. I bet what you have is probably sufficient for now, but I like the movement points idea.

One part I didn't understand, does the fort continue to add culture and expand borders? I ask because you use this to grab resoures, but if the fort doesn't extend borders, how do you gain the resource? Oh, do you build a fort (gaining ownership) and then build a farm/mine/whatever over the fort?

Well this code is only a part of a larger mod I designed. I just threw this up so people could use it in anyway they see fit. eg. in my warlords mod I didn't use the fort I added my own Improvement called a colony which gained the resource it was planted on.

In BTS tho forts are actually able to gain resources if built on a plot you own.
 
Ah okay, so it functions like the colony from Civ3 IIRC. Nice, as it is annoying to have to build a city to get a single resource sometimes.

I'd love to be able to build a true "fishing village" as a colony. You'd place the colony on the land and would be able to acquire sea food within 2 tiles (same as fat cross). You'd need to still build work boats elsewhere perhaps. That might be too powerful though, but that's usually the worst (most expensive) type of city.
 
That sounds like a great idea. You'll need to test, but assuming all other civs' units are reset to full movement points, you just need to look for the first unit with 0 points, regardless of worker or not. Now, hopefully the worker's MPs are removed before the function is called. ;)

It's not, the movement is reduced after the function is called.


Personally I'd put the code in the SDK function CvUnit::build under the check for if it's finished.
 
Sure, I can upload code for it. But you would need alot of other stuff to make it work such as Improvements Outside Borders by The Lopez.

Are you after colonies in particular? I ask because I can release a mod with just the code required to get this to work if you like and upload that code. Or you can wait till BTS is released and I will release the code for that :)

Yep, that is what I am after, would you be willing?

I have to add it together with something else Dom Pedro II has done for my Naval Mod, but colonies would be cool, seeing as now (In my modifications) you have to have water routes actually on the map and defined.

There is no real hurry, but I would love to try it out!

Thank your time,

GM
 
Instead of using the onImprovementBuilt I decide to use the onUnitBuildImprovements. This eliminates the need for any horrible hacks :)

I test if bFinished == true other wise it gets called every turn the worker is building the improvement.


Code:
	def onUnitBuildImprovement(self, argsList):
		'Unit begins enacting a Build (building an Improvement or Route)'
		pUnit, iBuild, bFinished = argsList
		pPlayer = gc.getPlayer(pUnit.getOwner())
		pPlot = gc.getMap().plot(pUnit.getX(),pUnit.getY())

		if (bFinished == true):
			if ((iBuild == gc.getInfoTypeForString("IMPROVEMENT_FORT")) or (iBuild == gc.getInfoTypeForString("IMPROVEMENT_AIRBASE"))):
				pPlot.setOwner(pPlayer.getID())
				pPlot.changeCulture(pPlayer.getID(), 100, False)


GeneralMatt: Yup, no problem. I will get onto it once I get some spare time :)
 
Thanx, I've been wondering on just this topic and couldn't figure out where I would have to change the SDK to do this. This page is going into my bookmarks right now. :)
 
I'm very much interested in your fort development (for Warlords).

I started a thread on that topic last week (see here). I do have questions though:
  • Is it possible to setup your coding so the fort ONLY controls the space in which it is built? (and it never grows beyond that space, ever).
  • Can the fort be used to exploit any resource bonus in its space?
  • And finally, is that fort subject to "revolts" like a city when it is completely enclosed within another Civ's cultural borders? (...hope not).
All this is very exciting and would fit perfectly in my mod. I'm looking forward to developments on this issue. I wish I could help, but unfortunately I don't know anything about Python coding.

Cheers! :goodjob:
 
  • Is it possible to setup your coding so the fort ONLY controls the space in which it is built? (and it never grows beyond that space, ever).
  • Can the fort be used to exploit any resource bonus in its space?
  • And finally, is that fort subject to "revolts" like a city when it is completely enclosed within another Civ's cultural borders? (...hope not).

1) yup, by default the fort will not take any extra land besides the square it occupies.

2) Yep, the fort can be used to provide the resource it is under.

3) This one I have only played around with a little bit. But basically if you give the square only 2% culture and it is surrounded it will be owned by the opposing civ 98%. You should be able to get around this by giving the square 100% culture.

as you know its sometimes hard to get the time to write something up for the community. But I will definetly get some source code up in this thread before the week is over. (hopefully tomorrow night)
 
Having just tried to implement this sort of stuff in vanilla civ4, I think I've discovered another bug in Primax's original code - Python uses zero-based lists and so the line to get the player should really be:

pPlayer = gc.getPlayer(pPlot.getUnit(0).getOwner())
 
So, Primax, where's the code? :)
 
Back
Top Bottom