CvDLLFAStarIFaceBase::generatePath()

LyTning94

Dragonborn
Joined
Nov 10, 2010
Messages
397
Location
Skyrim
I am working on writing the AI for my unit, and ran across a problem telling it to go to a certain plot. I debugged it and traced the problem all the way back to CvSelectionGroup::generatePath(), which contains this code:

Code:
bSuccess = gDLL->getFAStarIFace()->GeneratePath(&GC.getPathFinder(), pFromPlot->getX_INLINE(), pFromPlot->getY_INLINE(), pToPlot->getX_INLINE(), pToPlot->getY_INLINE(), false, iFlags, bReuse);

return bSuccess;

I tried Right Mouse Button->Go To Definition on GeneratePath() in the code displayed, and I got this:

Code:
class CvDLLFAStarIFaceBase
{
public:
	virtual bool GeneratePath(FAStar*, int iXstart, int iYstart, int iXdest, int iYdest, bool bCardinalOnly = false, int iInfo = 0, bool bReuse = false) = 0;

I know the basics of C++, and read a tutorial on virtual functions, and from what I remember (correct me if I'm wrong), it basically allows a member of a certain class to call a function in another class with the same name using a pointer. It would then follow that generatePath() is in fact a function in a different class, but the only other generatePath() functions I can find are CvSelectionGroup::generatePath() (which calls this function), and CvUnit::generatePath() (which calls CvSelectionGroup::generatePath()).

I have no idea why the game would be unable to generate a path from the specific plots I was dealing with (they were all of 3x1 plots away I believe, I was at war with the owner of the unit, and the unit was supposed to move to my capital). The only reason I can think of is that I set the unit to <bNoCapture>1</bNoCapture>, and my capital was empty at the time, but I think I already made an exception for this in the DLL.

Thanks in advance for the help!
 
CvDLLFAStarIFaceBase is an interface, or an abstract class.
You'll notice the ' = 0' at the end of the method declaration. This means that this method is 'pure virtual', or abstract. This means that this method has no implementation in this class, and therefore you cannot create an instance of this class.
Any derived class must implement this virtual method if you want to create an instance of it.

Specifically in this case, the derived class of this interface is implemented in the exe, and the DLL receives a pointer to this class.

If you want to have control over this, maybe this will help you (never did it myself):
You'll notice that you send GC.getPathFinder() to the function.
This is a pointer of type FAStar (not defined in the DLL, only declared), which is initialized in CvMap::setup().
There are a few path finders like that one initialized there.
Each of them receives callback functions for certain tasks (whether destination is valid, the cost of the move, etc.)

You can find the implementation for these functions in CvGameCoreUtils.cpp.

You should be able to debug and/or modify these to see what's going on.
 
Top Bottom