Ramkhamhaeng
Warlord
- Joined
- Feb 24, 2014
- Messages
- 209
Hello,
does anybody know if other modders already implemented an own A*-Star algorithm for the unit path search?
This fundamental part is not implemented in the DLL source code, just parts, see
FAStarNode.h, CvGameCoreUtils.cpp
I know that Caveman2Cosmos successfully extended the game by its own path search, but the code basis of this mod is so complex that it is extremely hard to pick one single feature. They changed almost everything…
Some more thoughts about the problem:
• It is no easy problem because the we just had access to a few function handlers, which will be called during the path search, hidden in the Civ4 binary.
• I've already learned that it not possible to define new path finders similar to the existing ones. The EXE contains some hard coded calls to 'GeneratePath(...)' with a fixed pointer (GC.getPathFinder()). It is not possible to made getPathFinder() non-constant.
(from CvMap.cpp)
=> So, the new code had to be hooked into the existing unit path finder(s).
• My targeting search algorithm needs a search from the target plot to the unit plot.
This is inverse to Civ4's search order!
I was able to swap both plots during the search
(By writing setter-function for the existing 'GetDestX(FAStar*)', etc functions)
This approached failed because CvDLLFAStarIFaceBase.GeneratePath(...) then runs the A*-Star search, but the result (chain of nodes/plots) is unuseable because it just contain the ending plot (I can not flip the generated path back.)
does anybody know if other modders already implemented an own A*-Star algorithm for the unit path search?
This fundamental part is not implemented in the DLL source code, just parts, see
FAStarNode.h, CvGameCoreUtils.cpp
I know that Caveman2Cosmos successfully extended the game by its own path search, but the code basis of this mod is so complex that it is extremely hard to pick one single feature. They changed almost everything…
Some more thoughts about the problem:
Spoiler :
• It is no easy problem because the we just had access to a few function handlers, which will be called during the path search, hidden in the Civ4 binary.
• I've already learned that it not possible to define new path finders similar to the existing ones. The EXE contains some hard coded calls to 'GeneratePath(...)' with a fixed pointer (GC.getPathFinder()). It is not possible to made getPathFinder() non-constant.
(from CvMap.cpp)
Code:
gDLL->getFAStarIFace()->Initialize(&GC.getPathFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), pathDestValid, pathHeuristic, pathCost, pathValid, pathAdd, NULL, NULL);
gDLL->getFAStarIFace()->Initialize(&GC.getInterfacePathFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), pathDestValid, pathHeuristic, pathCost, pathValid, pathAdd, NULL, NULL);
// adding new finders here...
• My targeting search algorithm needs a search from the target plot to the unit plot.
This is inverse to Civ4's search order!
I was able to swap both plots during the search
(By writing setter-function for the existing 'GetDestX(FAStar*)', etc functions)
This approached failed because CvDLLFAStarIFaceBase.GeneratePath(...) then runs the A*-Star search, but the result (chain of nodes/plots) is unuseable because it just contain the ending plot (I can not flip the generated path back.)