- some initial work for pathfinder changes (nothing enabled yet)
- added savegame info for network games to start thinking about how to allow players to reconnect to a network game.
This commit is contained in:
parent
c83cfc6e03
commit
7f0b439d5d
|
@ -90,6 +90,8 @@ PathFinder::~PathFinder() {
|
|||
void PathFinder::clearUnitPrecache(Unit *unit) {
|
||||
factions[unit->getFactionIndex()].precachedTravelState[unit->getId()] = tsImpossible;
|
||||
factions[unit->getFactionIndex()].precachedPath[unit->getId()].clear();
|
||||
|
||||
factions[unit->getFactionIndex()].badCellList.clear();
|
||||
}
|
||||
|
||||
void PathFinder::removeUnitPrecache(Unit *unit) {
|
||||
|
@ -427,7 +429,7 @@ bool PathFinder::processNode(Unit *unit, Node *node,const Vec2i finalPos, int i,
|
|||
//bool canUnitMoveToCell = map->aproxCanMove(unit, node->pos, sucPos);
|
||||
//bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, node->pos, sucPos);
|
||||
if(openPos(sucPos, factions[unit->getFactionIndex()]) == false &&
|
||||
map->aproxCanMoveSoon(unit, node->pos, sucPos) == true) {
|
||||
canUnitMoveSoon(unit, node->pos, sucPos) == true) {
|
||||
//if node is not open and canMove then generate another node
|
||||
Node *sucNode= newNode(factions[unit->getFactionIndex()],maxNodeCount);
|
||||
if(sucNode != NULL) {
|
||||
|
@ -459,7 +461,7 @@ bool PathFinder::addToOpenSet(Unit *unit, Node *node,const Vec2i finalPos, Vec2i
|
|||
*newNodeAdded=NULL;
|
||||
//Vec2i sucPos= node->pos + Vec2i(i, j);
|
||||
if(bypassChecks == true ||
|
||||
(map->aproxCanMoveSoon(unit, node->pos, sucPos) == true && openPos(sucPos, factions[unit->getFactionIndex()]) == false)) {
|
||||
(canUnitMoveSoon(unit, node->pos, sucPos) == true && openPos(sucPos, factions[unit->getFactionIndex()]) == false)) {
|
||||
//if node is not open and canMove then generate another node
|
||||
Node *sucNode= newNode(factions[unit->getFactionIndex()],maxNodeCount);
|
||||
if(sucNode != NULL) {
|
||||
|
@ -710,7 +712,7 @@ void PathFinder::astarJPS(std::map<Vec2i,Vec2i> cameFrom, Node *& node,
|
|||
for(unsigned int x = 1; x < path.size(); ++x) {
|
||||
Vec2i futureNode = path[x];
|
||||
|
||||
bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, newNode->pos, futureNode);
|
||||
bool canUnitMoveToCell = canUnitMoveSoon(unit, newNode->pos, futureNode);
|
||||
if(canUnitMoveToCell != true || openPos(futureNode, factions[unit->getFactionIndex()]) == true) {
|
||||
canAddEntirePath = false;
|
||||
canAddNode[make_pair(node->pos,futureNode)]=false;
|
||||
|
@ -835,7 +837,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
(factions[unitFactionIndex].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
|
||||
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
|
||||
//!!! Test MV
|
||||
if(map->aproxCanMoveSoon(unit, lastPos, nodePos) == false) {
|
||||
if(canUnitMoveSoon(unit, lastPos, nodePos) == false) {
|
||||
canMoveToCells = false;
|
||||
break;
|
||||
}
|
||||
|
@ -1073,7 +1075,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
Vec2i pos = unitPos + Vec2i(i, j);
|
||||
if(pos != unitPos) {
|
||||
//!!! Test MV
|
||||
bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, unitPos, pos);
|
||||
bool canUnitMoveToCell = canUnitMoveSoon(unit, unitPos, pos);
|
||||
if(canUnitMoveToCell == false) {
|
||||
failureCount++;
|
||||
}
|
||||
|
@ -1100,7 +1102,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
Vec2i pos = finalPos + Vec2i(i, j);
|
||||
if(pos != finalPos) {
|
||||
//!!! Test MV
|
||||
bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, pos, finalPos);
|
||||
bool canUnitMoveToCell = canUnitMoveSoon(unit, pos, finalPos);
|
||||
if(canUnitMoveToCell == false) {
|
||||
failureCount++;
|
||||
}
|
||||
|
@ -1529,6 +1531,32 @@ int PathFinder::findNodeIndex(Node *node, std::vector<Node> &nodeList) {
|
|||
return index;
|
||||
}
|
||||
|
||||
bool PathFinder::canUnitMoveSoon(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) {
|
||||
bool result = true;
|
||||
|
||||
// std::map<int,std::map<Field,BadUnitNodeList> > &badCellList = factions[unit->getFactionIndex()].badCellList;
|
||||
// if(badCellList.find(unit->getType()->getSize()) != badCellList.end()) {
|
||||
// std::map<Field,BadUnitNodeList> &badFieldList = badCellList[unit->getType()->getSize()];
|
||||
// if(badFieldList.find(unit->getCurrField()) != badFieldList.end()) {
|
||||
// BadUnitNodeList &badList = badFieldList[unit->getCurrField()];
|
||||
// if(badList.isPosBad(pos1,pos2) == true) {
|
||||
// result = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(result == true) {
|
||||
// //bool canUnitMoveToCell = map->canMove(unit, unitPos, pos);
|
||||
// //bool canUnitMoveToCell = map->aproxCanMove(unit, unitPos, pos);
|
||||
// result = map->aproxCanMoveSoon(unit, pos1, pos2);
|
||||
// if(result == false) {
|
||||
// badCellList[unit->getType()->getSize()][unit->getCurrField()].badPosList[pos1][pos2]=false;
|
||||
// }
|
||||
// }
|
||||
|
||||
result = map->aproxCanMoveSoon(unit, pos1, pos2);
|
||||
return result;
|
||||
}
|
||||
|
||||
void PathFinder::saveGame(XmlNode *rootNode) {
|
||||
std::map<string,string> mapTagReplacements;
|
||||
XmlNode *pathfinderNode = rootNode->addChild("PathFinder");
|
||||
|
@ -1698,5 +1726,4 @@ void PathFinder::loadGame(const XmlNode *rootNode) {
|
|||
// const Map *map;
|
||||
}
|
||||
|
||||
|
||||
}} //end namespace
|
||||
|
|
|
@ -42,6 +42,33 @@ typedef unsigned char directionset;
|
|||
|
||||
class PathFinder {
|
||||
public:
|
||||
class BadUnitNodeList {
|
||||
public:
|
||||
BadUnitNodeList() {
|
||||
unitSize = -1;
|
||||
//teamIndex = -1;
|
||||
field = fLand;
|
||||
}
|
||||
int unitSize;
|
||||
//int teamIndex;
|
||||
Field field;
|
||||
std::map<Vec2i, std::map<Vec2i,bool> > badPosList;
|
||||
|
||||
inline bool isPosBad(const Vec2i &pos1,const Vec2i &pos2) {
|
||||
bool result = false;
|
||||
|
||||
std::map<Vec2i, std::map<Vec2i,bool> >::iterator iterFind = badPosList.find(pos1);
|
||||
if(iterFind != badPosList.end()) {
|
||||
std::map<Vec2i,bool>::iterator iterFind2 = iterFind->second.find(pos2);
|
||||
if(iterFind2 != iterFind->second.end()) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
class Node {
|
||||
public:
|
||||
Node() {
|
||||
|
@ -76,6 +103,7 @@ public:
|
|||
precachedPath.clear();
|
||||
//mapFromToNodeList.clear();
|
||||
//lastFromToNodeListFrame = -100;
|
||||
badCellList.clear();
|
||||
}
|
||||
std::map<Vec2i, bool> openPosList;
|
||||
std::map<float, Nodes> openNodesList;
|
||||
|
@ -90,6 +118,8 @@ public:
|
|||
|
||||
//int lastFromToNodeListFrame;
|
||||
//std::map<int, std::map<Vec2i,std::map<Vec2i, bool> > > mapFromToNodeList;
|
||||
|
||||
std::map<int,std::map<Field,BadUnitNodeList> > badCellList;
|
||||
};
|
||||
typedef vector<FactionState> FactionStateList;
|
||||
|
||||
|
@ -156,6 +186,8 @@ private:
|
|||
direction nextDirectionInSet(directionset *dirs) const;
|
||||
Vec2i jump(Vec2i dest, direction dir, Vec2i start,std::vector<Vec2i> &path,int pathLength);
|
||||
bool addToOpenSet(Unit *unit, Node *node,const Vec2i finalPos, Vec2i sucPos, bool &nodeLimitReached,int maxNodeCount,Node **newNodeAdded,bool bypassChecks);
|
||||
|
||||
bool canUnitMoveSoon(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -129,6 +129,8 @@ public:
|
|||
|
||||
virtual void simpleTask(BaseThread *callingThread);
|
||||
|
||||
virtual void saveGame(XmlNode *rootNode) {};
|
||||
|
||||
protected:
|
||||
|
||||
Mutex * getServerSynchAccessor() { return NULL; }
|
||||
|
|
|
@ -202,6 +202,8 @@ public:
|
|||
void setCanAcceptConnections(bool value) { canAcceptConnections = value; }
|
||||
bool getCanAcceptConnections() const { return canAcceptConnections; }
|
||||
|
||||
virtual void saveGame(XmlNode *rootNode) {};
|
||||
|
||||
protected:
|
||||
|
||||
Mutex * getServerSynchAccessor();
|
||||
|
|
|
@ -161,6 +161,10 @@ public:
|
|||
|
||||
bool getReceivedDataSynchCheck() const {return receivedDataSynchCheck;}
|
||||
void setReceivedDataSynchCheck(bool value) { receivedDataSynchCheck = value; }
|
||||
|
||||
virtual void saveGame(XmlNode *rootNode) = 0;
|
||||
//static void loadGame(string name);
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
|
|
@ -2296,4 +2296,28 @@ void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) {
|
|||
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
void ServerInterface::saveGame(XmlNode *rootNode) {
|
||||
std::map<string,string> mapTagReplacements;
|
||||
XmlNode *serverInterfaceNode = rootNode->addChild("ServerInterface");
|
||||
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
if(slots[i] != NULL) {
|
||||
MutexSafeWrapper safeMutex(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
|
||||
XmlNode *slotNode = serverInterfaceNode->addChild("Slot");
|
||||
|
||||
ConnectionSlot *slot = slots[i];
|
||||
if(slot != NULL) {
|
||||
slotNode->addAttribute("isconnected",intToStr(slot->isConnected()), mapTagReplacements);
|
||||
slotNode->addAttribute("sessionkey",intToStr(slot->getSessionKey()), mapTagReplacements);
|
||||
slotNode->addAttribute("ipaddress",slot->getSocket(false)->getIpAddress(), mapTagReplacements);
|
||||
slotNode->addAttribute("name",slot->getName(), mapTagReplacements);
|
||||
}
|
||||
else {
|
||||
slotNode->addAttribute("isconnected",intToStr(false), mapTagReplacements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -201,6 +201,8 @@ public:
|
|||
void notifyBadClientConnectAttempt(string ipAddress);
|
||||
std::string DumpStatsToLog(bool dumpToStringOnly) const;
|
||||
|
||||
virtual void saveGame(XmlNode *rootNode);
|
||||
|
||||
private:
|
||||
void broadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1, int lockedSlotIndex = -1);
|
||||
void broadcastMessageToConnectedClients(const NetworkMessage *networkMessage, int excludeSlot = -1);
|
||||
|
|
Loading…
Reference in New Issue