telling the ai where to go?

hmm I will look in CvPlot then... Asaf what is "->" is it an object like . in python?

In C++ you can have a variable of a primitive type (int, float, char, ...), a complex type (any class or struct), or a pointer to any of those (there are more, such as reference and some modifiers, but I won't get into this).

A pointer is a variable which holds an address in memory to a certain type.
A pointer variable is defined like this:
Code:
int* pNumber;
CvArea* pArea;

And as you can see, a pointer is actually to data of a certain type.

When you have a non-pointer variable, the access to the members are done the same way you know - with a dot ('.').

When you want to access a member of a pointer, you use the -> operator:
Code:
pArea->getTargetCity();

On a general note, I suggest you learn some of the basics of C++ before, or during reading the code.

Try this site.

Btw, not really sure what to do... Ideally:

each player is given a different value of wanting for each area, areas being cutomly defined (if possible in anyway by 2 sets of coords or something along those lines, if not, then I need someway of defining the areas I need)

...

but currently I am thinking it will not happen like that... though, the Med and Agean, England and America would be the easiest as they would probs be an area anyway :p
SO... how would I actually get any code to work (not like I have the EventManager.py handy :lol:) and how would the above be done using the functions that we know of...

Baldyr's right - you have setArea() for each plot. You can find how it's used in the code.

The initial spreading of areas is not done in the DLL AFAIK - there's CvMap::calculateAreas() which goes over all the plots and calls an exposed method from the exe to do that.

You can add additional code to this function to replace this, if you want.

Apart from Byzantium it doesn't matter much about what city it wants just what areas it wants the most... will it pick the area with the city that it wants the most as it's next target?

I'm not sure, but I think that for each unit it will select the most important city in the area it's in. I don't know where the code is for moving units between areas.
 
thanks for the -> me and my friend were stumped on that :p

so, what additional code would be needed to be added to function?
 
Depends on what you want to do exactly.
You should probably first define to yourself exactly what it is that you're trying to achieve, then see how you can accomplish that using the areas mechanism, and then go for the code.

It'll be easier for others to help you then.
 
wel RIGHT now I am thinking that I define a list of points and then use the set area to give them an area value (different value for each area and work off of that)
maybee this function could be adjusted and translated to work as a way out getting the points we need:

Code:
def findAreaCities(tCoords1, tCoords2):
	"""
	Used for looping. When supplied with the map coordinates of a area defined 
	by its lower left corner (tCoords1) and its upper right corner (tCoords2), 
	the function yields all cities (CyCity instances) in order.
	"""
	iX1, iY1 = tCoords1
	iX2, iY2 = tCoords2
	for iX in range(iX1, iX2 + 1):
		for iY in range(iY1, iY2 + 1):
			pPlot = Map.plot(iX, iY)
			pCity = pPlot.getPlotCity()
			if pCity != None:			
				yield pCity

so instead of yeilding pCity it would yeild pPlot or something...

also in this function:
CvPlot::setArea(int iNewValue) would you remove CvPlot when you use it and just use setArea()?
if so the function above could be modified to include this so (in python as C++ is probably different in this respect):
Code:
for iX in range(iX1, iX2 + 1):
	for iY in range(iY1, iY2 + 1):
		pPlot = Map.plot(iX, iY)
		pPlot.setArea(1)

or something like that :D
 
You might want to consider assigning a specific plot to an existing area.
In this case you can call getArea() for a plot you know is in the area you need, and use the return value in setArea() for the plot you want to change.

All that remains is to tell the AI this is an area it wants to attack. Not sure exactly if there are limitations, but basically each area holds an 'AI strategy' for each player (I don't remember the exact function names, and can't look for them right now).

You could also create new areas (CvMap::addArea(), I think) - but look for places it's used to make sure it's correct.

Sorry for the short answer. I might have more time in a few days. Try progressing by then and post questions if you have them.
 
ok I will check this. One question, how can I get the area ingame (or using debug logs) because, I will probably want to make sure that areas are different for example while defining spain I use an area from a plot in spain... Then while defining France I set them to the same area....


Also what will happen to plots I don't set?
what are the difference between these?:

Code:
int CvPlot::getArea() const
{
	return m_iArea;
}
Code:
CvArea* CvMap::getArea(int iID)																
{
	return m_areas.getAt(iID);
}

?
 
The area in spain and france is probably the same area.
You'd need to create a new area (I think using addArea()) and assign it to some of the plots.

CvPlot holds the area index, CvMap returns the actual area class instance according to the index.
 
is the for loop in C++ usable for a replacement for the python forloop? As far as I can tell it is different

if yes I am soon going to start working on this code
 
You have for loops in C++ if that's the question. I'm not sure exactly what you mean by replacement.

You can read about for loops here (it's part of the link I already sent you. You should really read a little there), but you should probably read the entire 'control flow' chapter.
 
but from my current understanding of the for loop, It is not like the python for loop... I guess I will just have to see :D
 
I would expect only the syntax to be different, but I really wouldn't know.
 
I think I understand the question now.
For loops in C++ are different than the ones in Python in more than just syntax.

In Python, a for loop is actually of going over all items in a collection.

In C++, a for loop is just a while loop with 3 statements: Initialization, condition checking and advancement.
So you could use it to go over all items in a collection, but the most common use of a for loop is this:

Code:
for (int i=0; i<10; i++)
{
   // Do something
}

which means that the code in it will be executed 10 times, and each time the value of i will be different (starting from 0 until it's 9).
The variable i can be defined before the loop, and then you don't need the 'int' in the loop statement.

It's similar to the Python code:

Code:
for i in xrange(10):
 
so how would the python for loop be acheived in C++?
 
That depends on the collection you're trying to go over, but a simple access using [] should be enough in most cases. For example:

Code:
for (int i=0; i<10; i++)
{
   Do something with data[i]
}

Of course, that depends on data...
 
well I would want it to reutrn all coordinates between a top right hand coord and a bottom left coord (of course these two coords together form a sqaure and it is that which I want all the coords from) therefore each area will be defined as a sqaure...
 
You know, typically the place I want to tell the AI to go to is that well known location explored in Dante's Inferno marked with a sign that end with "Abandon all hope, ye who enter here", usually right when it does something particularly irritating or just plain stupid.

But I'm pretty sure there is no code, C++ or Python, that will do that.

There is, however, plenty of code that can make the programmer, or user, feel a bit like they have gone there.
 
You know, typically the place I want to tell the AI to go to is that well known location explored in Dante's Inferno marked with a sign that end with "Abandon all hope, ye who enter here", usually right when it does something particularly irritating or just plain stupid.

But I'm pretty sure there is no code, C++ or Python, that will do that.

You know, if you divide by zero, you get "#inf", which can be short for inferno ;)

@jamie: I don't really understand what you're trying to do - what do you mean by "return all coordinates" in this square? where do you want to return them to? what do you want to do with them?
 
when the loop reutrns all the coordinates in the sqaure it then uses the set area function to mkae them into for example area 1... so if italy is a square italy would be area 1 and the spains square would be area 2 etc....
@god emperor: What?! :lol:

anyway, for example:

the topright hand coord is 2,2 and bottom left is 0,0

in a python for loop that reuturns all coordinates iside the square formed by these two coords this would inturn return the following coords and set them to an area which we will call: N

(0,0), (1,0), (2,0), (0,1), (1,1), (2,1), (0,2), (1, 2) and finally: (2,2)

the for loop reutnrs the first coordinate, sets it to an area and continues with the next one. In python all this would be:

Code:
tCoords = (I forget what this is but never mind)
for iX in tCoords:
       for iY in tCoords:
              tCoords2 = (iX, iY)
              tCoords2.setArea(1)

or something simmilar

understand now?
 
This function doesn't return the coordinates, but rather receives a range of plots and sets them all to the same area.

So how about something like that:

Code:
for (int iX = x1; iX<x2; iX++)
{
   for (int iY = y1; iY<y2; iY++)
   {
      GC.getMapINLINE().plotINLINE(iX, iY).setArea(iArea);
   }
}
 
ok so how would I use this? Because if I am thinking correctly this is what I need
 
Back
Top Bottom