unit movement

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I am attempting to develop a patrol function for a naval unit. The following function can search through adjacent plots:

Code:
for (iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
{
	pLoopPlot = plotDirection(pPlot->getX_INLINE(), pPlot->getY_INLINE(), ((DirectionTypes)iI));


-1 = NO_DIRECTION
0 = DIRECTION_NORTH
1 = DIRECTION_NORTHEAST
2 = DIRECTION_EAST
3 = DIRECTION_SOUTHEAST
4 = DIRECTION_SOUTH
5 = DIRECTION_SOUTHWEST
6 = DIRECTION_WEST
7 = DIRECTION_NORTHWEST
8 = NUM_DIRECTION_TYPES

Lets say I wanted to move 6 spaces due north (not just one plot). How do I tell the unit to move 6 spaces using direction type "DIRECTION_NORTH" ?
 
Can it be done like this?

Code:
for (iDX = -(iMaxRange); iDX <= iMaxRange; iDX++)
{
	for (iDY = -(iMaxRange); iDY <= iMaxRange; iDY++)
	{
		pLoopPlot = plotXY(getX_INLINE(), getY_INLINE(), iDX, iDY);
			
		if (pLoopPlot != NULL)
		{
			DirectionTypes directionType = directionXY(pUnitPlot, pLoopPlot);
			
			if (directionType == DIRECTION_NORTH)
 
Generally movement is done by giving the unit a destination plot and letting the pathfinder figure out the best way to get there. Is there a particular reason you want to hardcode it to move in a specific path? Seems like trying to make units in that manner would present a number of potential problems, such as, what if an enemy unit is in the way?
 
Generally movement is done by giving the unit a destination plot and letting the pathfinder figure out the best way to get there. Is there a particular reason you want to hardcode it to move in a specific path? Seems like trying to make units in that manner would present a number of potential problems, such as, what if an enemy unit is in the way?

Yes. Note: Mine Sweepers are invisible and can pass through plots with enemy units. Only a plot with an armed enemy mine will set off the sweeper/detonation code. I was attempting to create a patrol of a 3 plot range from a plot that is 6 plots away from a coastal city. I realize that some of these coastal cities will have just a few water plots surrounding them, in which case a patrol would not be possible. For example: I might want to send a mine sweeper 6 plots north and do a scan for any mines that may exist within 3 plots surrounding that northern plot. If it detects an enemy mine, move the sweeper to that plot and attempt to remove it. Detonation occurs if the sweeper code fails to remove the mine.

I'm open to any ideas that you may have for setting up a patrol.
 
I would think the logic for minesweepers should be something along the lines of this:

1) Do a starting scan from whatever plot they are currently on
1a) If we find an enemy mine, break the loop and set that plot as the destination plot
2) If we dont find any mines in range, pick a new plot to scan from and move there, start over. (dont have any bright ideas about how to find a new destination plot. Perhaps check AI_attackSeaMove() and see what they do there. You might also want to try putting in some code to have minesweepers join up with attacking/assault fleets to help clear any defensive mines)
 
I would think the logic for minesweepers should be something along the lines of this:

1) Do a starting scan from whatever plot they are currently on
1a) If we find an enemy mine, break the loop and set that plot as the destination plot
2) If we dont find any mines in range, pick a new plot to scan from and move there, start over. (dont have any bright ideas about how to find a new destination plot. Perhaps check AI_attackSeaMove() and see what they do there. You might also want to try putting in some code to have minesweepers join up with attacking/assault fleets to help clear any defensive mines)

Yup. The key is selecting the next plot to scan from. The join up code could be useful. More research...
 
Top Bottom