- 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) {
|
void PathFinder::clearUnitPrecache(Unit *unit) {
|
||||||
factions[unit->getFactionIndex()].precachedTravelState[unit->getId()] = tsImpossible;
|
factions[unit->getFactionIndex()].precachedTravelState[unit->getId()] = tsImpossible;
|
||||||
factions[unit->getFactionIndex()].precachedPath[unit->getId()].clear();
|
factions[unit->getFactionIndex()].precachedPath[unit->getId()].clear();
|
||||||
|
|
||||||
|
factions[unit->getFactionIndex()].badCellList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathFinder::removeUnitPrecache(Unit *unit) {
|
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->aproxCanMove(unit, node->pos, sucPos);
|
||||||
//bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, node->pos, sucPos);
|
//bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, node->pos, sucPos);
|
||||||
if(openPos(sucPos, factions[unit->getFactionIndex()]) == false &&
|
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
|
//if node is not open and canMove then generate another node
|
||||||
Node *sucNode= newNode(factions[unit->getFactionIndex()],maxNodeCount);
|
Node *sucNode= newNode(factions[unit->getFactionIndex()],maxNodeCount);
|
||||||
if(sucNode != NULL) {
|
if(sucNode != NULL) {
|
||||||
|
@ -459,7 +461,7 @@ bool PathFinder::addToOpenSet(Unit *unit, Node *node,const Vec2i finalPos, Vec2i
|
||||||
*newNodeAdded=NULL;
|
*newNodeAdded=NULL;
|
||||||
//Vec2i sucPos= node->pos + Vec2i(i, j);
|
//Vec2i sucPos= node->pos + Vec2i(i, j);
|
||||||
if(bypassChecks == true ||
|
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
|
//if node is not open and canMove then generate another node
|
||||||
Node *sucNode= newNode(factions[unit->getFactionIndex()],maxNodeCount);
|
Node *sucNode= newNode(factions[unit->getFactionIndex()],maxNodeCount);
|
||||||
if(sucNode != NULL) {
|
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) {
|
for(unsigned int x = 1; x < path.size(); ++x) {
|
||||||
Vec2i futureNode = path[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) {
|
if(canUnitMoveToCell != true || openPos(futureNode, factions[unit->getFactionIndex()]) == true) {
|
||||||
canAddEntirePath = false;
|
canAddEntirePath = false;
|
||||||
canAddNode[make_pair(node->pos,futureNode)]=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 &&
|
(factions[unitFactionIndex].precachedPath[unit->getId()].size() >= pathFindExtendRefreshForNodeCount &&
|
||||||
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
|
i < getPathFindExtendRefreshNodeCount(unitFactionIndex))) {
|
||||||
//!!! Test MV
|
//!!! Test MV
|
||||||
if(map->aproxCanMoveSoon(unit, lastPos, nodePos) == false) {
|
if(canUnitMoveSoon(unit, lastPos, nodePos) == false) {
|
||||||
canMoveToCells = false;
|
canMoveToCells = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1073,7 +1075,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
Vec2i pos = unitPos + Vec2i(i, j);
|
Vec2i pos = unitPos + Vec2i(i, j);
|
||||||
if(pos != unitPos) {
|
if(pos != unitPos) {
|
||||||
//!!! Test MV
|
//!!! Test MV
|
||||||
bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, unitPos, pos);
|
bool canUnitMoveToCell = canUnitMoveSoon(unit, unitPos, pos);
|
||||||
if(canUnitMoveToCell == false) {
|
if(canUnitMoveToCell == false) {
|
||||||
failureCount++;
|
failureCount++;
|
||||||
}
|
}
|
||||||
|
@ -1100,7 +1102,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||||
Vec2i pos = finalPos + Vec2i(i, j);
|
Vec2i pos = finalPos + Vec2i(i, j);
|
||||||
if(pos != finalPos) {
|
if(pos != finalPos) {
|
||||||
//!!! Test MV
|
//!!! Test MV
|
||||||
bool canUnitMoveToCell = map->aproxCanMoveSoon(unit, pos, finalPos);
|
bool canUnitMoveToCell = canUnitMoveSoon(unit, pos, finalPos);
|
||||||
if(canUnitMoveToCell == false) {
|
if(canUnitMoveToCell == false) {
|
||||||
failureCount++;
|
failureCount++;
|
||||||
}
|
}
|
||||||
|
@ -1529,6 +1531,32 @@ int PathFinder::findNodeIndex(Node *node, std::vector<Node> &nodeList) {
|
||||||
return index;
|
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) {
|
void PathFinder::saveGame(XmlNode *rootNode) {
|
||||||
std::map<string,string> mapTagReplacements;
|
std::map<string,string> mapTagReplacements;
|
||||||
XmlNode *pathfinderNode = rootNode->addChild("PathFinder");
|
XmlNode *pathfinderNode = rootNode->addChild("PathFinder");
|
||||||
|
@ -1698,5 +1726,4 @@ void PathFinder::loadGame(const XmlNode *rootNode) {
|
||||||
// const Map *map;
|
// const Map *map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}} //end namespace
|
}} //end namespace
|
||||||
|
|
|
@ -42,6 +42,33 @@ typedef unsigned char directionset;
|
||||||
|
|
||||||
class PathFinder {
|
class PathFinder {
|
||||||
public:
|
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 {
|
class Node {
|
||||||
public:
|
public:
|
||||||
Node() {
|
Node() {
|
||||||
|
@ -76,6 +103,7 @@ public:
|
||||||
precachedPath.clear();
|
precachedPath.clear();
|
||||||
//mapFromToNodeList.clear();
|
//mapFromToNodeList.clear();
|
||||||
//lastFromToNodeListFrame = -100;
|
//lastFromToNodeListFrame = -100;
|
||||||
|
badCellList.clear();
|
||||||
}
|
}
|
||||||
std::map<Vec2i, bool> openPosList;
|
std::map<Vec2i, bool> openPosList;
|
||||||
std::map<float, Nodes> openNodesList;
|
std::map<float, Nodes> openNodesList;
|
||||||
|
@ -90,6 +118,8 @@ public:
|
||||||
|
|
||||||
//int lastFromToNodeListFrame;
|
//int lastFromToNodeListFrame;
|
||||||
//std::map<int, std::map<Vec2i,std::map<Vec2i, bool> > > mapFromToNodeList;
|
//std::map<int, std::map<Vec2i,std::map<Vec2i, bool> > > mapFromToNodeList;
|
||||||
|
|
||||||
|
std::map<int,std::map<Field,BadUnitNodeList> > badCellList;
|
||||||
};
|
};
|
||||||
typedef vector<FactionState> FactionStateList;
|
typedef vector<FactionState> FactionStateList;
|
||||||
|
|
||||||
|
@ -156,6 +186,8 @@ private:
|
||||||
direction nextDirectionInSet(directionset *dirs) const;
|
direction nextDirectionInSet(directionset *dirs) const;
|
||||||
Vec2i jump(Vec2i dest, direction dir, Vec2i start,std::vector<Vec2i> &path,int pathLength);
|
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 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
|
}}//end namespace
|
||||||
|
|
|
@ -129,6 +129,8 @@ public:
|
||||||
|
|
||||||
virtual void simpleTask(BaseThread *callingThread);
|
virtual void simpleTask(BaseThread *callingThread);
|
||||||
|
|
||||||
|
virtual void saveGame(XmlNode *rootNode) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Mutex * getServerSynchAccessor() { return NULL; }
|
Mutex * getServerSynchAccessor() { return NULL; }
|
||||||
|
|
|
@ -202,6 +202,8 @@ public:
|
||||||
void setCanAcceptConnections(bool value) { canAcceptConnections = value; }
|
void setCanAcceptConnections(bool value) { canAcceptConnections = value; }
|
||||||
bool getCanAcceptConnections() const { return canAcceptConnections; }
|
bool getCanAcceptConnections() const { return canAcceptConnections; }
|
||||||
|
|
||||||
|
virtual void saveGame(XmlNode *rootNode) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Mutex * getServerSynchAccessor();
|
Mutex * getServerSynchAccessor();
|
||||||
|
|
|
@ -161,6 +161,10 @@ public:
|
||||||
|
|
||||||
bool getReceivedDataSynchCheck() const {return receivedDataSynchCheck;}
|
bool getReceivedDataSynchCheck() const {return receivedDataSynchCheck;}
|
||||||
void setReceivedDataSynchCheck(bool value) { receivedDataSynchCheck = value; }
|
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__);
|
//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
|
}}//end namespace
|
||||||
|
|
|
@ -201,6 +201,8 @@ public:
|
||||||
void notifyBadClientConnectAttempt(string ipAddress);
|
void notifyBadClientConnectAttempt(string ipAddress);
|
||||||
std::string DumpStatsToLog(bool dumpToStringOnly) const;
|
std::string DumpStatsToLog(bool dumpToStringOnly) const;
|
||||||
|
|
||||||
|
virtual void saveGame(XmlNode *rootNode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void broadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1, int lockedSlotIndex = -1);
|
void broadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1, int lockedSlotIndex = -1);
|
||||||
void broadcastMessageToConnectedClients(const NetworkMessage *networkMessage, int excludeSlot = -1);
|
void broadcastMessageToConnectedClients(const NetworkMessage *networkMessage, int excludeSlot = -1);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user