CanDoResearch? Can anyone help? Kael, TheLopez or TBA?

The function I use to return the shortest distance to the nearest city is as follows:
Code:
# Gets the distance to the nearest city
def getNearestCityDist(self, pPlot, iPlayer):
	cityList = PyPlayer(iPlayer).getCityList()
	
	lCity = []

	for city in cityList:
		cPlot = city.plot()
		iDist = self.getDistance(cPlot, pPlot)
		lCity.append(iDist)
	
	if lCity == []:
		return -1
	else:
		return min(lCity)

# Simple function to find the shortest distance between two plots
def getDistance(self, plot1, plot2):
	iX = abs(plot1.getX() - plot2.getX())
	iY = abs(plot1.getY() - plot2.getY())

	if CyMap().isWrapX():
		if iX > CyMap().getGridWidth() / 2:
			iX = CyMap().getGridWidth() - iX
	if CyMap().isWrapY():
		if iY > CyMap().getGridHeight() / 2:
			iY = CyMap().getGridHeight() - iY
		
	return max(iX, iY)
It will return the nearest distance from the given plot to the nearest city of the given player in plots. If the nearest city doesn't exist it returns -1, and you can handle this however you like.

Comparing it to Kael's method, I'd say it was probably better at handling larger distances. There are also X-Y wrapping issues with Kael's code (it won't pick up a city if it has to wrap over the edge of the map).

BTW: AI is the tough one. You'd have to fiddle with the SDK to get it to avoid distances which are too far away from a city.


Now... the other question about path blockages. You'd have to use a much cleverer funtion for finding the shortest distance to the nearest city - the best way to do it would be to use a proper path-finding algorithm. For this, I'd suggest you take a look at 12monkeys' A* Pathfinder. It might take quite a bit of work to convert it to do what you want it to though.

Oh, and Kael - I think I posted a piece of code on the Python sample code thread which is a function that is similar to CyMap().plot(), but takes wrapping into account, if you are interested.
 
Hey guys. You know that you two-and TheLopez-are sooooo on my Christmas card list now :mischief: :).

I have just a couple more things to ask you guys, though, and after that I shouldn't need to ask too much more for the time being.

1a) Thanks to you guys, I know how to use Python to get civics adding specific specialists to a city. Now what I need to know is, can I modify this code to make civics grant specific Commerce/Yield bonuses to specific specialists? If so, what extra lines would I need to add?

1b) Probably an easier way of doing what I want would be to apply the bonus to cities with the State Religion-how would I approach this in Python? I know the
Code:
i for all cities in range
bit, but how would I make it more exclusive?

2) This is a two parter, with (a) being partially dependant on (b). (a) Is it possible to use python to give Bonuses (resources) a SIZE rating-from 1 to 4? The way I would see it is that a Size 1 resource would be exactly as it is now, wheras a size 4 (Huge) resource would be equivalent to having 4 normal resources on the same plot. Perhaps this can only be done in SDK though.

(b) Can I use python to compare number of cities (+units) and compare it to the total number of a given resource-and have the difference effect 'outputs' from all cities? For instance, I want a system where if you have 6 cities but only 3 sources of corn, then the food output of all your cities drops by 1. However, if you have 4 cities and 8 sources of corn, then your food output increases by 1. Does that make sense? The actual ratio I would use would obviously depend on how do-able (a) is, but the important thing is-can (b) be done?

Once again, guys, thank you for your ENORMOUS assistance-and hopefully we will all see the fruits of your help in a future mod :).

Aussie_Lurker.
 
1)
a) You can't change the value of the specialist dynamically without the SDK. You can make it so that if you have a specialist you get extra stuff, but you won't be able to get it to show on any of the mouse-overs or anything

b) Scan all the cities, then do a check to see if they have the state religion. If they do do the bonus, if they don't, don't.

2)
a) Hmmm. May be possible. Wouldn't be easy.

b) Should be easy. At the start of each turn count how many cities you have, count how much corn you have. If you have more corn then you need give the city one extra food, if you have less, deduct one food. The interface wouldn't show your changes though.

On the finding distance to nearest city - you may want to try CyMap().findCity(...) and CyMap().calculatePathDistance(...). Find city sounds like it finds the nearest city to the plot, while the other one finds the shortest unblocked distance between two plots in plots.
 
Thanks again for all your help TGA, you are a legend. It is disappointing to have confirmed my fear that specialist yields cannot be changed dynamically-a real oversight on the part of Firaxis IMO :(. The only way I think it could be done in SDK is by taking the Schema for Angkor Wat (bonus hammers for Priests) and adding it into the civics field-unfortunately I can't modify the SDK right now because I lack the mscvprt.lib file, and can't seem to download it properly from the Microsoft site :(. I don't suppose I could be a pain, and ask either you or Kael to send me a working copy of this file?
Oh, the other disappointment, obviously, is the lack of interface support for many of these changes I want to make-it is one of the reasons I am more keen to make these changes via SDK than in Python-even though I understand how very flexible python is! So tell me, those last two ideas of mine-relating to resources-could they be done in SDK do you think? Thanks again for ALL your help.

Aussie_Lurker.
 
Oh, another thing I wanted to ask. With the nearest city function, how can I extend this to cities controlled by friends and allies? This will be important, obviously, when it comes to civs helping each other out in combat. Also, it IS possible to merge elements of your GetNearestCity function and Kael's bSafe function to get an over-riding 'Attrition' function, isn't it?

Aussie_Lurker.
 
Aussie_Lurker said:
Oh, another thing I wanted to ask. With the nearest city function, how can I extend this to cities controlled by friends and allies? This will be important, obviously, when it comes to civs helping each other out in combat. Also, it IS possible to merge elements of your GetNearestCity function and Kael's bSafe function to get an over-riding 'Attrition' function, isn't it?
Yes, though the method would depend how you define "friends and allies". Do you mean people you are not at war with, people on your team, or something more complicated.

As for how to do it - you'd have to get a list of the players, then iterate through it checking if the player is somebody whose cities count. If they are then you get their city, find the nearest one, and add the distance to the lCity list.

As for merging it with the bSafe function - think of this function as a big mysterious box, much like the functions you call from the API are. You put the plot object and the player ID in, and you get the distance to the nearest city out. You could simply do:
Code:
pPlot = pUnit.plot()
iPlayer = pUnit.getOwner()

# Finds the nearest city
minCityDist = self.getNearestCityDist(pPlot, iPlayer)

if minCityDist >= 5:
         <do attrition>

As for specialists - the trouble is that a specialist isn't an object in itself, so you can't change individual propeties. A specialist is a part of the city object. (BTW - I'm assuming you can't do what you want in XML)

Aussie_Lurker said:
I don't suppose I could be a pain, and ask either you or Kael to send me a working copy of this file?
I don't have a copy of that file with me, and can't get it for quite a while.
Aussie_Lurker said:
So tell me, those last two ideas of mine-relating to resources-could they be done in SDK do you think? Thanks again for ALL your help.
Yes. Almost certainly.

I have to warn you though that modding the SDK is not nearly as easy as modding python. To be frank, if you can't do some of the stuff you've been asking in python in this thread, I don't see that you will have much of a chance working with C++.
 
Well, TGA, to be honest all (and I use that term sparingly) I want to do is add new 'hooks' to the XML system. i.e. move schema between different areas to give me greater flexibility. I have very little interest in changing any of the core fundamentals of the game.
Also, the more you guys tell me about python, the more I am beginning to understand it-so I figure I will eventually get the hang of it. Heck, I figure that if I can learn how to set up and run-and stain-a denaturing gradient gel with PCR products on them, then SURELY I can learn how to write simple python codes. Its just practice, practice, practice ;).

Aussie_Lurker.
 
Back
Top Bottom