From 012d51a1068277abcde362e238b199b88e0765dc Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Mon, 6 Nov 2006 12:40:45 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@481 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/bot/bot_util.h | 1130 ++++++++++++++++----------------- source/src/bot/bot_waypoint.h | 382 +++++------ source/src/client.cpp | 367 ----------- 3 files changed, 756 insertions(+), 1123 deletions(-) delete mode 100644 source/src/client.cpp diff --git a/source/src/bot/bot_util.h b/source/src/bot/bot_util.h index 7765dd55..1b9d4dd5 100644 --- a/source/src/bot/bot_util.h +++ b/source/src/bot/bot_util.h @@ -1,565 +1,565 @@ -#ifndef BOT_UTIL_H -#define BOT_UTIL_H - -// Structure for storing traceresults -struct traceresult_s -{ - vec end; - bool collided; -}; - -long RandomLong(long from, long to); -float RandomFloat(float from, float to); -void lsrand(unsigned long initial_seed); - -void AnglesToVectors(vec angles, vec &forward, vec &right, vec &up); -float WrapXAngle(float angle); -float WrapYZAngle(float angle); -void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult_s *tr, - bool SkipTags=false); -float GetDistance(vec v1, vec v2); -float Get2DDistance(vec v1, vec v2); -bool IsVisible(vec v1, vec v2, dynent *tracer = NULL, bool SkipTags=false); -bool IsValidFile(const char *szFileName); -bool FileIsOlder(const char *szFileName1, const char *szFileName2); -vec PredictPos(vec pos, vec vel, float Time); -vec Normalize(vec v); -inline void makevec(vec *v, float x, float y, float z) { v->x=x; v->y=y; v->z=z; }; -inline bool UnderWater(const vec &o) { return hdr.waterlevel>o.z-0.5f; }; -inline bool InWater(const vec &o) { return hdr.waterlevel>=o.z; }; -float GetYawDiff(float curyaw, vec v1, vec v2); -vec CrossProduct(const vec &a, const vec &b); -int GetDirection(const vec &angles, const vec &v1, const vec &v2); -float GetCubeFloor(int x, int y); -float GetCubeHeight(int x, int y); -char *SkillNrToSkillName(short skillnr); -bool IsInGame(dynent *d); - -// ================================================================== -// Code of TLinkedList - Start -// ================================================================== - -template class TLinkedList -{ -public: - struct node_s - { - C Entry; - node_s *next; - node_s *prev; - - node_s(void) : next(NULL), prev(NULL) - { - //memset(&Entry, 0, sizeof(Entry)); - }; - }; - - // member functions - - void AddNode(C entry) - { - if (!pNodeList) - { - pNodeList = new node_s; - pNodeList->Entry = entry; - pNodeList->next = NULL; - pNodeList->prev = NULL; - pLastNode = pNodeList; - iNodeCount = 1; - } - else - { - pLastNode->next = new node_s; - pLastNode->next->prev = pLastNode; - pLastNode = pLastNode->next; - pLastNode->Entry = entry; - pLastNode->next = NULL; - iNodeCount++; - } - } - - void PushNode(C Entry) - { - if (!pNodeList) - { - pNodeList = new node_s; - pNodeList->Entry = Entry; - pNodeList->next = NULL; - pNodeList->prev = NULL; - pLastNode = pNodeList; - iNodeCount = 1; - } - else - { - node_s *pNew = new node_s; - pNew->Entry = Entry; - pNew->prev = NULL; - pNew->next = pNodeList; - pNodeList->prev = pNew; - pNodeList = pNew; - iNodeCount++; - } - } - - void DeleteEntry(C Entry) - { - node_s *pNode = pNodeList; - if (!pNode) - return; - - if (pNode->Entry == Entry) // first node - { - if (pNodeList == pLastNode) - pLastNode = NULL; - - pNodeList = pNodeList->next; - if (pNodeList) - pNodeList->prev = NULL; - pNode->next = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - return; - } - - if (Entry == pLastNode->Entry) // last node - { - pNode = pLastNode; - pLastNode = pLastNode->prev; - pLastNode->next = NULL; - - pNode->next = NULL; - pNode->prev = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - return; - } - - // node is somewhere in the middle - pNode = SearchNode(Entry); - - if (!pNode) - return; - - node_s *pPrevNode = pNode->prev; - - if (!pPrevNode) - return; - - // unlink pNode - pNode->next->prev = pPrevNode; - pPrevNode->next = pNode->next; - - pNode->next = NULL; - pNode->prev = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - } - - void DeleteNode(node_s *pNode) - { - if (!pNode) - return; - - if (pNodeList == pNode) // first node - { - if (pNodeList == pLastNode) - pLastNode = pNodeList->next; - - pNodeList = pNodeList->next; - if (pNodeList) - pNodeList->prev = NULL; - pNode->next = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - return; - } - - if (pNode == pLastNode) // last node - { - pNode = pLastNode; - pLastNode = pLastNode->prev; - pLastNode->next = NULL; - - pNode->next = NULL; - pNode->prev = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - return; - } - - // node is somewhere in the middle - - node_s *pPrevNode = pNode->prev; - - if (!pPrevNode) - return; - - // unlink pNode - pNode->next->prev = pPrevNode; - pPrevNode->next = pNode->next; - - pNode->next = NULL; - pNode->prev = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - } - - void DeleteAllNodes(void) - { - node_s *pNode = pNodeList; - node_s *pTemp; - while (pNode != NULL) - { - pTemp = pNode; - pNode = pNode->next; - pTemp->next = NULL; - pTemp->prev = NULL; - delete pTemp; - } - pNodeList = pLastNode = NULL; - iNodeCount = 0; - } - - void Reset(void) // Special case, doesn't delete existing nodes - { - pNodeList = pLastNode = NULL; - iNodeCount = 0; - } - - node_s *SearchNode(C Entry) - { - node_s *pNode = pNodeList; - while(pNode) - { - if (pNode->Entry == Entry) - return pNode; - pNode = pNode->next; - } - return NULL; - } - - C Pop(void) - { - if (!pNodeList) - return static_cast(NULL); - - C Entry = pNodeList->Entry; - DeleteNode(pNodeList); - return Entry; - } - - node_s *GetFirst(void) { return pNodeList; }; - node_s *GetLast(void) { return pLastNode; }; - - void EditEntry(C OrigEntry, C NewVal) - { - node_s *pNode = SearchNode(OrigEntry); - - if (pNode) - pNode->Entry = NewVal; - } - - bool IsInList(C Entry) - { - return (SearchNode(Entry) != NULL); - } - - bool Empty(void) { return (pNodeList == NULL); }; - int NodeCount(void) { return iNodeCount; }; - - - // construction/destruction - TLinkedList(void) - { - pNodeList = NULL; - pLastNode = NULL; - iNodeCount = 0; - }; - - ~TLinkedList(void) - { - DeleteAllNodes(); - }; - -private: - node_s *pNodeList; - node_s *pLastNode; - int iNodeCount; -}; - -// ================================================================== -// Code of TLinkedList - End -// ================================================================== - -// ================================================================== -// Code of TPriorList - Begin -// ================================================================== - -template class TPriorList -{ -public: - struct node_s - { - C Entry; - D Priority; - node_s *next; - - node_s(C Ent, D Prior) : Entry(Ent), Priority(Prior), next(NULL) {}; - }; - - TPriorList(void) : pHeadNode(NULL), pLastNode(NULL) {}; - ~TPriorList(void) { Clear(); }; - - void AddEntry(C Entry, D Prior) - { - if (!pHeadNode) - { - pHeadNode = new node_s(Entry, Prior); - pLastNode = pHeadNode; - iNodeCount=1; - } - else - { - iNodeCount++; - node_s *pNew = new node_s(Entry, Prior); - node_s *pNode = pHeadNode; - node_s *pPrev = NULL; - - while(pNode) - { - if (Prior < pNode->Priority) - { - if (!pPrev) - { - pNew->next = pNode; - pHeadNode = pNew; - } - else - { - pPrev->next = pNew; - pNew->next = pNode; - } - break; - } - pPrev = pNode; - pNode = pNode->next; - } - - if (!pNode) - { - pLastNode = pNew; - if (pPrev) - pPrev->next = pNew; - } - } - } - - C Pop(void) - { - if (!pHeadNode) - return static_cast(NULL); - - C Entry = pHeadNode->Entry; - DeleteNode(pHeadNode); - return Entry; - } - - void Clear(void) - { - node_s *pTemp; - while(pHeadNode) - { - pTemp = pHeadNode; - pHeadNode = pHeadNode->next; - delete pTemp; - } - - pHeadNode = pLastNode = NULL; - } - - bool IsInList(C Entry, D Prior) - { - node_s *pNode = pHeadNode; - while(pNode) - { - if (pNode->Entry == Entry) - return true; - - if (Prior < pNode->Priority) - return false; - - pNode = pNode->next; - } - - return false; - } - - bool Empty(void) { return (pHeadNode == NULL); } - node_s *GetFirst(void) { return pHeadNode; } -private: - node_s *pHeadNode; - node_s *pLastNode; - int iNodeCount; - - node_s *GetPrevNode(node_s *pNode) - { - node_s *pTemp = pHeadNode; - while(pTemp) - { - if (pTemp->next == pNode) - return pTemp; - pTemp = pTemp->next; - } - - return NULL; - } - - void DeleteNode(node_s *pNode) - { - if (!pNode) - return; - - if (pHeadNode == pNode) // first node - { - if (pHeadNode == pLastNode) - pLastNode = pHeadNode->next; - - pHeadNode = pHeadNode->next; - pNode->next = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - return; - } - - if (pNode == pLastNode) // last node - { - pNode = pLastNode; - pLastNode->next = NULL; - - pNode->next = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - return; - } - - // node is somewhere in the middle - - node_s *pPrevNode = GetPrevNode(pNode); - if (!pPrevNode) - return; - - // unlink pNode - pPrevNode->next = pNode->next; - pNode->next = NULL; - delete pNode; - pNode = NULL; - iNodeCount--; - } -}; - -// ================================================================== -// Code of TPriorList - End -// ================================================================== - - -// ================================================================== -// Code of TMultiChoice - Begin -// ================================================================== - -template class TMultiChoice -{ - struct SMultiChoice - { - int MinVal; - int MaxVal; - C Choice; - SMultiChoice(void) : MinVal(0), MaxVal(0){}; - }; - - int TotalVal; - TLinkedList *pChoiceList; - -public: - TMultiChoice(void) : TotalVal(0) // Constructor - { - pChoiceList = new TLinkedList; - }; - - ~TMultiChoice(void) // Destructor - { - while(pChoiceList->Empty() == false) - { - SMultiChoice *pEntry = pChoiceList->Pop(); - if (pEntry) - delete pEntry; - else - break; - } - delete pChoiceList; - pChoiceList = NULL; - } - - void Insert(C Choice, short Percent = 50) - { - if (Percent == 0) - return; - - SMultiChoice *pChoiceEntry = new SMultiChoice; - - pChoiceEntry->MinVal = TotalVal; - pChoiceEntry->MaxVal = TotalVal + Percent; - pChoiceEntry->Choice = Choice; - - pChoiceList->AddNode(pChoiceEntry); - - TotalVal += Percent; - }; - - bool FindSelection(SMultiChoice *MS, int Choice) - { - if ((Choice >= MS->MinVal) && (Choice < MS->MaxVal)) - { - return true; - } - return false; - } - - void ClearChoices(void) - { - TotalVal = 0; - while(pChoiceList->Empty() == false) - delete pChoiceList->Pop(); - } - - bool GetSelection(C &Var) - { - int Choice = RandomLong(0, (TotalVal - 1)); - typename TLinkedList::node_s *pNode = pChoiceList->GetFirst(); - - while(pNode) - { - if ((Choice >= pNode->Entry->MinVal) && (Choice < pNode->Entry->MaxVal)) - { - Var = pNode->Entry->Choice; - return true; - } - pNode = pNode->next; - } - - return false; - } -}; - -// ================================================================== -// Code of TMutiChoice - End -// ================================================================== - -#endif +#ifndef BOT_UTIL_H +#define BOT_UTIL_H + +// Structure for storing traceresults +struct traceresult_s +{ + vec end; + bool collided; +}; + +long RandomLong(long from, long to); +float RandomFloat(float from, float to); +void lsrand(unsigned long initial_seed); + +void AnglesToVectors(vec angles, vec &forward, vec &right, vec &up); +float WrapXAngle(float angle); +float WrapYZAngle(float angle); +void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult_s *tr, + bool SkipTags=false); +float GetDistance(vec v1, vec v2); +float Get2DDistance(vec v1, vec v2); +bool IsVisible(vec v1, vec v2, dynent *tracer = NULL, bool SkipTags=false); +bool IsValidFile(const char *szFileName); +bool FileIsOlder(const char *szFileName1, const char *szFileName2); +vec PredictPos(vec pos, vec vel, float Time); +vec Normalize(vec v); +inline void makevec(vec *v, float x, float y, float z) { v->x=x; v->y=y; v->z=z; }; +inline bool UnderWater(const vec &o) { return hdr.waterlevel>o.z-0.5f; }; +inline bool InWater(const vec &o) { return hdr.waterlevel>=o.z; }; +float GetYawDiff(float curyaw, vec v1, vec v2); +vec CrossProduct(const vec &a, const vec &b); +int GetDirection(const vec &angles, const vec &v1, const vec &v2); +float GetCubeFloor(int x, int y); +float GetCubeHeight(int x, int y); +char *SkillNrToSkillName(short skillnr); +bool IsInGame(dynent *d); + +// ================================================================== +// Code of TLinkedList - Start +// ================================================================== + +template class TLinkedList +{ +public: + struct node_s + { + C Entry; + node_s *next; + node_s *prev; + + node_s(void) : next(NULL), prev(NULL) + { + //memset(&Entry, 0, sizeof(Entry)); + }; + }; + + // member functions + + void AddNode(C entry) + { + if (!pNodeList) + { + pNodeList = new node_s; + pNodeList->Entry = entry; + pNodeList->next = NULL; + pNodeList->prev = NULL; + pLastNode = pNodeList; + iNodeCount = 1; + } + else + { + pLastNode->next = new node_s; + pLastNode->next->prev = pLastNode; + pLastNode = pLastNode->next; + pLastNode->Entry = entry; + pLastNode->next = NULL; + iNodeCount++; + } + } + + void PushNode(C Entry) + { + if (!pNodeList) + { + pNodeList = new node_s; + pNodeList->Entry = Entry; + pNodeList->next = NULL; + pNodeList->prev = NULL; + pLastNode = pNodeList; + iNodeCount = 1; + } + else + { + node_s *pNew = new node_s; + pNew->Entry = Entry; + pNew->prev = NULL; + pNew->next = pNodeList; + pNodeList->prev = pNew; + pNodeList = pNew; + iNodeCount++; + } + } + + void DeleteEntry(C Entry) + { + node_s *pNode = pNodeList; + if (!pNode) + return; + + if (pNode->Entry == Entry) // first node + { + if (pNodeList == pLastNode) + pLastNode = NULL; + + pNodeList = pNodeList->next; + if (pNodeList) + pNodeList->prev = NULL; + pNode->next = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + return; + } + + if (Entry == pLastNode->Entry) // last node + { + pNode = pLastNode; + pLastNode = pLastNode->prev; + pLastNode->next = NULL; + + pNode->next = NULL; + pNode->prev = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + return; + } + + // node is somewhere in the middle + pNode = SearchNode(Entry); + + if (!pNode) + return; + + node_s *pPrevNode = pNode->prev; + + if (!pPrevNode) + return; + + // unlink pNode + pNode->next->prev = pPrevNode; + pPrevNode->next = pNode->next; + + pNode->next = NULL; + pNode->prev = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + } + + void DeleteNode(node_s *pNode) + { + if (!pNode) + return; + + if (pNodeList == pNode) // first node + { + if (pNodeList == pLastNode) + pLastNode = pNodeList->next; + + pNodeList = pNodeList->next; + if (pNodeList) + pNodeList->prev = NULL; + pNode->next = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + return; + } + + if (pNode == pLastNode) // last node + { + pNode = pLastNode; + pLastNode = pLastNode->prev; + pLastNode->next = NULL; + + pNode->next = NULL; + pNode->prev = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + return; + } + + // node is somewhere in the middle + + node_s *pPrevNode = pNode->prev; + + if (!pPrevNode) + return; + + // unlink pNode + pNode->next->prev = pPrevNode; + pPrevNode->next = pNode->next; + + pNode->next = NULL; + pNode->prev = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + } + + void DeleteAllNodes(void) + { + node_s *pNode = pNodeList; + node_s *pTemp; + while (pNode != NULL) + { + pTemp = pNode; + pNode = pNode->next; + pTemp->next = NULL; + pTemp->prev = NULL; + delete pTemp; + } + pNodeList = pLastNode = NULL; + iNodeCount = 0; + } + + void Reset(void) // Special case, doesn't delete existing nodes + { + pNodeList = pLastNode = NULL; + iNodeCount = 0; + } + + node_s *SearchNode(C Entry) + { + node_s *pNode = pNodeList; + while(pNode) + { + if (pNode->Entry == Entry) + return pNode; + pNode = pNode->next; + } + return NULL; + } + + C Pop(void) + { + if (!pNodeList) + return static_cast(NULL); + + C Entry = pNodeList->Entry; + DeleteNode(pNodeList); + return Entry; + } + + node_s *GetFirst(void) { return pNodeList; }; + node_s *GetLast(void) { return pLastNode; }; + + void EditEntry(C OrigEntry, C NewVal) + { + node_s *pNode = SearchNode(OrigEntry); + + if (pNode) + pNode->Entry = NewVal; + } + + bool IsInList(C Entry) + { + return (SearchNode(Entry) != NULL); + } + + bool Empty(void) { return (pNodeList == NULL); }; + int NodeCount(void) { return iNodeCount; }; + + + // construction/destruction + TLinkedList(void) + { + pNodeList = NULL; + pLastNode = NULL; + iNodeCount = 0; + }; + + ~TLinkedList(void) + { + DeleteAllNodes(); + }; + +private: + node_s *pNodeList; + node_s *pLastNode; + int iNodeCount; +}; + +// ================================================================== +// Code of TLinkedList - End +// ================================================================== + +// ================================================================== +// Code of TPriorList - Begin +// ================================================================== + +template class TPriorList +{ +public: + struct node_s + { + C Entry; + D Priority; + node_s *next; + + node_s(C Ent, D Prior) : Entry(Ent), Priority(Prior), next(NULL) {}; + }; + + TPriorList(void) : pHeadNode(NULL), pLastNode(NULL) {}; + ~TPriorList(void) { Clear(); }; + + void AddEntry(C Entry, D Prior) + { + if (!pHeadNode) + { + pHeadNode = new node_s(Entry, Prior); + pLastNode = pHeadNode; + iNodeCount=1; + } + else + { + iNodeCount++; + node_s *pNew = new node_s(Entry, Prior); + node_s *pNode = pHeadNode; + node_s *pPrev = NULL; + + while(pNode) + { + if (Prior < pNode->Priority) + { + if (!pPrev) + { + pNew->next = pNode; + pHeadNode = pNew; + } + else + { + pPrev->next = pNew; + pNew->next = pNode; + } + break; + } + pPrev = pNode; + pNode = pNode->next; + } + + if (!pNode) + { + pLastNode = pNew; + if (pPrev) + pPrev->next = pNew; + } + } + } + + C Pop(void) + { + if (!pHeadNode) + return static_cast(NULL); + + C Entry = pHeadNode->Entry; + DeleteNode(pHeadNode); + return Entry; + } + + void Clear(void) + { + node_s *pTemp; + while(pHeadNode) + { + pTemp = pHeadNode; + pHeadNode = pHeadNode->next; + delete pTemp; + } + + pHeadNode = pLastNode = NULL; + } + + bool IsInList(C Entry, D Prior) + { + node_s *pNode = pHeadNode; + while(pNode) + { + if (pNode->Entry == Entry) + return true; + + if (Prior < pNode->Priority) + return false; + + pNode = pNode->next; + } + + return false; + } + + bool Empty(void) { return (pHeadNode == NULL); } + node_s *GetFirst(void) { return pHeadNode; } +private: + node_s *pHeadNode; + node_s *pLastNode; + int iNodeCount; + + node_s *GetPrevNode(node_s *pNode) + { + node_s *pTemp = pHeadNode; + while(pTemp) + { + if (pTemp->next == pNode) + return pTemp; + pTemp = pTemp->next; + } + + return NULL; + } + + void DeleteNode(node_s *pNode) + { + if (!pNode) + return; + + if (pHeadNode == pNode) // first node + { + if (pHeadNode == pLastNode) + pLastNode = pHeadNode->next; + + pHeadNode = pHeadNode->next; + pNode->next = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + return; + } + + if (pNode == pLastNode) // last node + { + pNode = pLastNode; + pLastNode->next = NULL; + + pNode->next = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + return; + } + + // node is somewhere in the middle + + node_s *pPrevNode = GetPrevNode(pNode); + if (!pPrevNode) + return; + + // unlink pNode + pPrevNode->next = pNode->next; + pNode->next = NULL; + delete pNode; + pNode = NULL; + iNodeCount--; + } +}; + +// ================================================================== +// Code of TPriorList - End +// ================================================================== + + +// ================================================================== +// Code of TMultiChoice - Begin +// ================================================================== + +template class TMultiChoice +{ + struct SMultiChoice + { + int MinVal; + int MaxVal; + C Choice; + SMultiChoice(void) : MinVal(0), MaxVal(0){}; + }; + + int TotalVal; + TLinkedList *pChoiceList; + +public: + TMultiChoice(void) : TotalVal(0) // Constructor + { + pChoiceList = new TLinkedList; + }; + + ~TMultiChoice(void) // Destructor + { + while(pChoiceList->Empty() == false) + { + SMultiChoice *pEntry = pChoiceList->Pop(); + if (pEntry) + delete pEntry; + else + break; + } + delete pChoiceList; + pChoiceList = NULL; + } + + void Insert(C Choice, short Percent = 50) + { + if (Percent == 0) + return; + + SMultiChoice *pChoiceEntry = new SMultiChoice; + + pChoiceEntry->MinVal = TotalVal; + pChoiceEntry->MaxVal = TotalVal + Percent; + pChoiceEntry->Choice = Choice; + + pChoiceList->AddNode(pChoiceEntry); + + TotalVal += Percent; + }; + + bool FindSelection(SMultiChoice *MS, int Choice) + { + if ((Choice >= MS->MinVal) && (Choice < MS->MaxVal)) + { + return true; + } + return false; + } + + void ClearChoices(void) + { + TotalVal = 0; + while(pChoiceList->Empty() == false) + delete pChoiceList->Pop(); + } + + bool GetSelection(C &Var) + { + int Choice = RandomLong(0, (TotalVal - 1)); + typename TLinkedList::node_s *pNode = pChoiceList->GetFirst(); + + while(pNode) + { + if ((Choice >= pNode->Entry->MinVal) && (Choice < pNode->Entry->MaxVal)) + { + Var = pNode->Entry->Choice; + return true; + } + pNode = pNode->next; + } + + return false; + } +}; + +// ================================================================== +// Code of TMutiChoice - End +// ================================================================== + +#endif diff --git a/source/src/bot/bot_waypoint.h b/source/src/bot/bot_waypoint.h index 565bf593..934e9d55 100644 --- a/source/src/bot/bot_waypoint.h +++ b/source/src/bot/bot_waypoint.h @@ -1,191 +1,191 @@ -// -// C++ Implementation: bot_waypoint.h -// -// Description: Containts all defintions for bot waypoint code -// -// -// Author: Rick Helmus -// - -// Enable this for flood support -#define WP_FLOOD - -#ifndef BOT_WAYPOINT_H -#define BOT_WAYPOINT_H - -#define WAYPOINT_VERSION 2 -#define EXP_WP_VERSION 1 -#define REACHABLE_RANGE 15.0f -#define MAX_MAP_GRIDS 64 -#define SECTOR_SIZE 18 - -#define W_FL_TELEPORT (1<<1) // used if waypoint is at a teleporter -#define W_FL_TELEPORTDEST (1<<2) // used if waypoint is at a teleporter destination -#define W_FL_FLOOD (1<<3) // used if this waypoint is made by flooding the map -#define W_FL_JUMP (1<<4) // if set, bot jumps when reached this waypoint -#define W_FL_TRIGGER (1<<5) // used if this waypoint is at a trigger -#define W_FL_INTAG (1<<6) // used if this waypoint is in a tagged cube - -#define MAX_FLOODWPCONNECTDIST 2 -#define MAX_FLOODWPDIST 4.0f - -struct waypoint_header_s -{ - char szFileType[10]; - int iFileVersion; - int iFileFlags; // not currently used - int iWPCount; - char szMapName[32]; // name of map for these waypoints -}; - -// Old waypoint structure, used for waypoint version 1 -struct waypoint_version_1_s -{ - int iFlags; - vec v_origin; - TLinkedList ConnectedWPs; - - // A* stuff - float f, g; - waypoint_version_1_s *pParent; - - // Construction - waypoint_version_1_s(void) : iFlags(0), f(0.0f), g(0.0f), pParent(NULL) { }; -}; - -struct node_s -{ - vec v_origin; - int iFlags; - short sTriggerNr; - short sYaw; - short sCost; // Base and static cost - TLinkedList ConnectedWPs; - TLinkedList ConnectedWPsWithMe; - - TLinkedList FailedGoalList; - - // Construction - node_s(void) : iFlags(0), sTriggerNr(0), sYaw(-1), sCost(10) { }; - node_s(const vec &o, const int &f, const short t=0, const short y=-1) : v_origin(o), - iFlags(f), - sTriggerNr(t), - sYaw(y), - sCost(0) { }; -}; - -struct waypoint_s -{ - node_s *pNode; - short g[2]; - waypoint_s *pParent[2]; - bool bIsOpen[2], bIsClosed[2]; - - // Construction - waypoint_s(void) : pNode(NULL) { bIsOpen[0] = bIsOpen[1] = bIsClosed[0] = - bIsClosed[1] = false; pParent[0] = pParent[1] = NULL; - g[0] = g[1] = 0; }; -}; - -class CWaypointClass -{ -protected: - bool m_bDrawWaypoints; - bool m_bDrawWPPaths; - bool m_bAutoWaypoint; - bool m_bAutoPlacePaths; - bool m_bDrawWPText; - vec m_vLastCreatedWP; - float m_fPathDrawTime; - char m_szMapName[32]; - -#ifdef WP_FLOOD - bool m_bFlooding; // True if flooding map with waypoints - bool m_bFilteringNodes; - int m_iFloodStartTime; - int m_iCurFloodX, m_iCurFloodY; - int m_iFloodSize; - int m_iFilteredNodes; -#endif - friend class CBot; - -public: - TLinkedList m_Waypoints[MAX_MAP_GRIDS][MAX_MAP_GRIDS]; - int m_iWaypointCount; // number of waypoints currently in use - - CWaypointClass(void); - virtual ~CWaypointClass(void) { Clear(); }; - - void Think(void); - void Init(void); - void Clear(void); - bool LoadWaypoints(void); - void SaveWaypoints(void); - bool LoadWPExpFile(void); - void SaveWPExpFile(void); - void SetMapName(char *map) { strcpy(m_szMapName, map); }; - - void SetWaypointsVisible(bool Visible) { m_bDrawWaypoints = Visible; }; - void SetPathsVisible(bool Visible) { m_bDrawWPPaths = Visible; }; - void SetAutoWaypoint(bool On) { m_bAutoWaypoint = On; }; - void SetWPInfo(bool on) { m_bDrawWPText = on; }; - void SetWPFlags(node_s *wp, int iFlags) { wp->iFlags |= iFlags; }; - void UnsetWPFlags(node_s *wp, int iFlags) { wp->iFlags &= ~iFlags; }; - void SetWPTriggerNr(node_s *wp, short sTriggerNr) { wp->sTriggerNr = sTriggerNr; }; - void SetWPYaw(node_s *wp, short sYaw) { wp->sYaw = sYaw; }; - bool WaypointsAreVisible(void) { return m_bDrawWaypoints; }; - node_s *AddWaypoint(vec o, bool connectwp); - void DeleteWaypoint(dynent *d); - void AddPath(node_s *pWP1, node_s *pWP2); - void DeletePath(node_s *pWP); - void DeletePath(node_s *pWP1, node_s *pWP2); - void ManuallyCreatePath(dynent *d, int iCmd, bool TwoWay); - void ManuallyDeletePath(dynent *d, int iCmd, bool TwoWay); - - bool WPIsReachable(vec from, vec to); - //node_s *GetNearestWaypoint(vec v_src, float flRange, bool CheckVisible = true, bool SkipFloodWPs = true); - node_s *GetNearestWaypoint(vec v_src, float flRange); - node_s *GetNearestWaypoint(dynent *d, float flRange) { return GetNearestWaypoint(d->o, flRange); }; - node_s *GetNearestTriggerWaypoint(vec v_src, float flRange); - node_s *GetWaypointFromVec(const vec &v_src); - void DrawNearWaypoints(); - void GetNodeIndexes(const vec &v_origin, short *i, short *j); - void CalcCost(node_s *pNode); - void ReCalcCosts(void); - - -#ifdef WP_FLOOD - // Flood functions - virtual void StartFlood(void); - void StopFlood(void); - void FloodThink(void); - bool CanPlaceNodeHere(const vec &from); - void ConnectFloodWP(node_s *pWP); - node_s *GetNearestFloodWP(vec v_origin, float flRange, node_s *pIgnore, bool SkipTags=false); - node_s *GetNearestFloodWP(dynent *d, float flRange) { return GetNearestFloodWP(d->o, flRange, NULL); }; - node_s *GetNearestTriggerFloodWP(vec v_origin, float flRange); -#endif -}; - -class CACWaypointClass: public CWaypointClass -{ -public: -#ifdef WP_FLOOD - // Flood functions - virtual void StartFlood(void); -#endif -}; - -class CCubeWaypointClass: public CWaypointClass -{ -public: - void CreateWPsAtTeleporters(void); - void CreateWPsAtTriggers(void); - -#ifdef WP_FLOOD - // Flood functions - virtual void StartFlood(void); -#endif -}; - -#endif // BOT_WAYPOINT_H +// +// C++ Implementation: bot_waypoint.h +// +// Description: Containts all defintions for bot waypoint code +// +// +// Author: Rick Helmus +// + +// Enable this for flood support +#define WP_FLOOD + +#ifndef BOT_WAYPOINT_H +#define BOT_WAYPOINT_H + +#define WAYPOINT_VERSION 2 +#define EXP_WP_VERSION 1 +#define REACHABLE_RANGE 15.0f +#define MAX_MAP_GRIDS 64 +#define SECTOR_SIZE 18 + +#define W_FL_TELEPORT (1<<1) // used if waypoint is at a teleporter +#define W_FL_TELEPORTDEST (1<<2) // used if waypoint is at a teleporter destination +#define W_FL_FLOOD (1<<3) // used if this waypoint is made by flooding the map +#define W_FL_JUMP (1<<4) // if set, bot jumps when reached this waypoint +#define W_FL_TRIGGER (1<<5) // used if this waypoint is at a trigger +#define W_FL_INTAG (1<<6) // used if this waypoint is in a tagged cube + +#define MAX_FLOODWPCONNECTDIST 2 +#define MAX_FLOODWPDIST 4.0f + +struct waypoint_header_s +{ + char szFileType[10]; + int iFileVersion; + int iFileFlags; // not currently used + int iWPCount; + char szMapName[32]; // name of map for these waypoints +}; + +// Old waypoint structure, used for waypoint version 1 +struct waypoint_version_1_s +{ + int iFlags; + vec v_origin; + TLinkedList ConnectedWPs; + + // A* stuff + float f, g; + waypoint_version_1_s *pParent; + + // Construction + waypoint_version_1_s(void) : iFlags(0), f(0.0f), g(0.0f), pParent(NULL) { }; +}; + +struct node_s +{ + vec v_origin; + int iFlags; + short sTriggerNr; + short sYaw; + short sCost; // Base and static cost + TLinkedList ConnectedWPs; + TLinkedList ConnectedWPsWithMe; + + TLinkedList FailedGoalList; + + // Construction + node_s(void) : iFlags(0), sTriggerNr(0), sYaw(-1), sCost(10) { }; + node_s(const vec &o, const int &f, const short t=0, const short y=-1) : v_origin(o), + iFlags(f), + sTriggerNr(t), + sYaw(y), + sCost(0) { }; +}; + +struct waypoint_s +{ + node_s *pNode; + short g[2]; + waypoint_s *pParent[2]; + bool bIsOpen[2], bIsClosed[2]; + + // Construction + waypoint_s(void) : pNode(NULL) { bIsOpen[0] = bIsOpen[1] = bIsClosed[0] = + bIsClosed[1] = false; pParent[0] = pParent[1] = NULL; + g[0] = g[1] = 0; }; +}; + +class CWaypointClass +{ +protected: + bool m_bDrawWaypoints; + bool m_bDrawWPPaths; + bool m_bAutoWaypoint; + bool m_bAutoPlacePaths; + bool m_bDrawWPText; + vec m_vLastCreatedWP; + float m_fPathDrawTime; + char m_szMapName[32]; + +#ifdef WP_FLOOD + bool m_bFlooding; // True if flooding map with waypoints + bool m_bFilteringNodes; + int m_iFloodStartTime; + int m_iCurFloodX, m_iCurFloodY; + int m_iFloodSize; + int m_iFilteredNodes; +#endif + friend class CBot; + +public: + TLinkedList m_Waypoints[MAX_MAP_GRIDS][MAX_MAP_GRIDS]; + int m_iWaypointCount; // number of waypoints currently in use + + CWaypointClass(void); + virtual ~CWaypointClass(void) { Clear(); }; + + void Think(void); + void Init(void); + void Clear(void); + bool LoadWaypoints(void); + void SaveWaypoints(void); + bool LoadWPExpFile(void); + void SaveWPExpFile(void); + void SetMapName(char *map) { strcpy(m_szMapName, map); }; + + void SetWaypointsVisible(bool Visible) { m_bDrawWaypoints = Visible; }; + void SetPathsVisible(bool Visible) { m_bDrawWPPaths = Visible; }; + void SetAutoWaypoint(bool On) { m_bAutoWaypoint = On; }; + void SetWPInfo(bool on) { m_bDrawWPText = on; }; + void SetWPFlags(node_s *wp, int iFlags) { wp->iFlags |= iFlags; }; + void UnsetWPFlags(node_s *wp, int iFlags) { wp->iFlags &= ~iFlags; }; + void SetWPTriggerNr(node_s *wp, short sTriggerNr) { wp->sTriggerNr = sTriggerNr; }; + void SetWPYaw(node_s *wp, short sYaw) { wp->sYaw = sYaw; }; + bool WaypointsAreVisible(void) { return m_bDrawWaypoints; }; + node_s *AddWaypoint(vec o, bool connectwp); + void DeleteWaypoint(dynent *d); + void AddPath(node_s *pWP1, node_s *pWP2); + void DeletePath(node_s *pWP); + void DeletePath(node_s *pWP1, node_s *pWP2); + void ManuallyCreatePath(dynent *d, int iCmd, bool TwoWay); + void ManuallyDeletePath(dynent *d, int iCmd, bool TwoWay); + + bool WPIsReachable(vec from, vec to); + //node_s *GetNearestWaypoint(vec v_src, float flRange, bool CheckVisible = true, bool SkipFloodWPs = true); + node_s *GetNearestWaypoint(vec v_src, float flRange); + node_s *GetNearestWaypoint(dynent *d, float flRange) { return GetNearestWaypoint(d->o, flRange); }; + node_s *GetNearestTriggerWaypoint(vec v_src, float flRange); + node_s *GetWaypointFromVec(const vec &v_src); + void DrawNearWaypoints(); + void GetNodeIndexes(const vec &v_origin, short *i, short *j); + void CalcCost(node_s *pNode); + void ReCalcCosts(void); + + +#ifdef WP_FLOOD + // Flood functions + virtual void StartFlood(void); + void StopFlood(void); + void FloodThink(void); + bool CanPlaceNodeHere(const vec &from); + void ConnectFloodWP(node_s *pWP); + node_s *GetNearestFloodWP(vec v_origin, float flRange, node_s *pIgnore, bool SkipTags=false); + node_s *GetNearestFloodWP(dynent *d, float flRange) { return GetNearestFloodWP(d->o, flRange, NULL); }; + node_s *GetNearestTriggerFloodWP(vec v_origin, float flRange); +#endif +}; + +class CACWaypointClass: public CWaypointClass +{ +public: +#ifdef WP_FLOOD + // Flood functions + virtual void StartFlood(void); +#endif +}; + +class CCubeWaypointClass: public CWaypointClass +{ +public: + void CreateWPsAtTeleporters(void); + void CreateWPsAtTriggers(void); + +#ifdef WP_FLOOD + // Flood functions + virtual void StartFlood(void); +#endif +}; + +#endif // BOT_WAYPOINT_H diff --git a/source/src/client.cpp b/source/src/client.cpp deleted file mode 100644 index 1a1bc1df..00000000 --- a/source/src/client.cpp +++ /dev/null @@ -1,367 +0,0 @@ -// client.cpp, mostly network related client game code - -#include "cube.h" - -ENetHost *clienthost = NULL; -int connecting = 0; -int connattempts = 0; -int disconnecting = 0; -int clientnum = -1; // our client id in the game -bool c2sinit = false; // whether we need to tell the other clients our stats - -int getclientnum() { return clientnum; }; - -bool multiplayer() -{ - // check not correct on listen server? - if(clienthost) conoutf("operation not available in multiplayer"); - return clienthost!=NULL; -}; - -bool allowedittoggle() -{ - bool allow = !clienthost || gamemode==1; - if(!allow) conoutf("editing in multiplayer requires coopedit mode (1)"); - return allow; -}; - -VARF(rate, 0, 0, 25000, if(clienthost && (!rate || rate>1000)) enet_host_bandwidth_limit (clienthost, rate, rate)); - -void throttle(); - -VARF(throttle_interval, 0, 5, 30, throttle()); -VARF(throttle_accel, 0, 2, 32, throttle()); -VARF(throttle_decel, 0, 2, 32, throttle()); - -void throttle() -{ - if(!clienthost || connecting) return; - ASSERT(ENET_PEER_PACKET_THROTTLE_SCALE==32); - enet_peer_throttle_configure(clienthost->peers, throttle_interval*1000, throttle_accel, throttle_decel); -}; - -void ctf_team(char *name) -{ - bool isvalidteam = strcmp(name, "RVSF") == 0 || strcmp(name, "CLA") == 0; - if(strcmp(name, player1->team) == 0 && isvalidteam) return; - c2sinit = false; - ctf_death(); - if(isvalidteam) strcpy(player1->team, name); - else strcpy(player1->team, rb_team_string(rnd(2))); - player1->lastaction = lastmillis; - player1->state = CS_DEAD; -}; - -void newname(char *name) { c2sinit = false; s_strncpy(player1->name, name, 16); }; -void newskin(int skin) { player1->nextskin = max(0, min(skin, (rb_team_int(player1->team)==TEAM_CLA ? 3 : 5))); }; -void newteam(char *name) -{ - if(m_teammode) ctf_team(name); - else { s_strncpy(player1->team, name, 5); c2sinit=false; }; -}; - -COMMANDN(team, newteam, ARG_1STR); -COMMANDN(name, newname, ARG_1STR); -COMMANDN(skin, newskin, ARG_1INT); - -void connects(char *servername) -{ - disconnect(1); // reset state - - ENetAddress address; - address.port = CUBE_SERVER_PORT; - - if(servername) - { - addserver(servername); - conoutf("attempting to connect to %s", servername); - if(!resolverwait(servername, &address)) - { - conoutf("could not resolve server %s", servername); - return; - }; - } - else - { - conoutf("attempting to connect over LAN"); - address.host = ENET_HOST_BROADCAST; - }; - - clienthost = enet_host_create(NULL, 1, rate, rate); - - if(clienthost) - { - enet_host_connect(clienthost, &address, 4); - enet_host_flush(clienthost); - connecting = lastmillis; - connattempts = 0; - } - else - { - conoutf("could not connect to server"); - disconnect(); - }; -}; - -void disconnect(int onlyclean, int async) -{ - if(clienthost) - { - if(!connecting && !disconnecting) - { - enet_peer_disconnect(clienthost->peers, DISC_NONE); - enet_host_flush(clienthost); - disconnecting = lastmillis; - }; - if(clienthost->peers->state != ENET_PEER_STATE_DISCONNECTED) - { - if(async) return; - enet_peer_reset(clienthost->peers); - }; - enet_host_destroy(clienthost); - }; - - if(clienthost && !connecting) conoutf("disconnected"); - clienthost = NULL; - connecting = 0; - connattempts = 0; - disconnecting = 0; - clientnum = -1; - c2sinit = false; - player1->lifesequence = 0; - loopv(players) zapdynent(players[i]); - - localdisconnect(); - - if(!onlyclean) { stop(); localconnect(); }; -}; - -void trydisconnect() -{ - if(!clienthost) - { - conoutf("not connected"); - return; - }; - if(connecting) - { - conoutf("aborting connection attempt"); - disconnect(); - return; - }; - conoutf("attempting to disconnect..."); - disconnect(0, !disconnecting); -}; - -void toserver(char *text) { conoutf("%s:\f %s", player1->name, text); addmsg(SV_TEXT, "rs", text); }; -void echo(char *text) { conoutf("%s", text); }; - -void lanconnect() -{ - connects(0); -}; - -COMMAND(echo, ARG_VARI); -COMMANDN(say, toserver, ARG_VARI); -COMMANDN(connect, connects, ARG_1STR); -COMMAND(lanconnect, ARG_NONE); -COMMANDN(disconnect, trydisconnect, ARG_NONE); - -// collect c2s messages conveniently - -vector messages; - -void addmsg(int type, const char *fmt, ...) -{ - if(demoplayback) return; - static uchar buf[MAXTRANS]; - ucharbuf p(buf, MAXTRANS); - putint(p, type); - int numi = 1, nums = 0; - bool reliable = false; - if(fmt) - { - va_list args; - va_start(args, fmt); - while(*fmt) switch(*fmt++) - { - case 'r': reliable = true; break; - case 'i': - { - int n = isdigit(*fmt) ? *fmt++-'0' : 1; - loopi(n) putint(p, va_arg(args, int)); - numi += n; - break; - }; - case 's': sendstring(va_arg(args, const char *), p); nums++; break; - }; - va_end(args); - }; - int num = nums?0:numi; - if(num!=msgsizelookup(type)) { s_sprintfd(s)("inconsistant msg size for %d (%d != %d)", type, num, msgsizelookup(type)); fatal(s); }; - int len = p.length(); - messages.add(len&0xFF); - messages.add((len>>8)|(reliable ? 0x80 : 0)); - loopi(len) messages.add(buf[i]); -}; - -int lastupdate = 0, lastping = 0; -bool senditemstoserver = false; // after a map change, since server doesn't have map data - -string clientpassword; -char *toserverpwd = NULL; -void password(char *p) { s_strcpy(clientpassword, p); }; -COMMAND(password, ARG_1STR); - -bool netmapstart() { senditemstoserver = true; return clienthost!=NULL; }; - -void initclientnet() -{ - clientpassword[0] = 0; - newname("unnamed"); - ctf_team("red"); -}; - -void sendpackettoserv(int chan, ENetPacket *packet) -{ - if(clienthost) { enet_host_broadcast(clienthost, chan, packet); enet_host_flush(clienthost); } - else localclienttoserver(chan, packet); -} - -void c2skeepalive() -{ - if(clientnum<0 || !clienthost) return; - if(lastmillis-lastupdate<40) return; - - ENetEvent event; - while(clienthost!=NULL && enet_host_service(clienthost, &event, 0)>0) {}; // fixme - - lastupdate = SDL_GetTicks(); -}; - -extern string masterpwd; - -void c2sinfo(dynent *d) // send update to the server -{ - if(clientnum<0) return; // we haven't had a welcome message from the server yet - if(lastmillis-lastupdate<40) return; // don't update faster than 25fps - ENetPacket *packet = enet_packet_create(NULL, 100, 0); - ucharbuf q(packet->data, packet->dataLength); - - putint(q, SV_POS); - putint(q, clientnum); - putuint(q, (int)(d->o.x*DMF)); // quantize coordinates to 1/16th of a cube, between 1 and 3 bytes - putuint(q, (int)(d->o.y*DMF)); - putuint(q, (int)(d->o.z*DMF)); - putuint(q, (int)(d->yaw*DAF)); - putint(q, (int)(d->pitch*DAF)); - putint(q, (int)(d->roll*DAF)); - putint(q, (int)(d->vel.x*DVF)); // quantize to 1/100, almost always 1 byte - putint(q, (int)(d->vel.y*DVF)); - putint(q, (int)(d->vel.z*DVF)); - // pack rest in 1 byte: strafe:2, move:2, onfloor:1, state:3 - putint(q, (d->strafe&3) | ((d->move&3)<<2) | (((int)d->onfloor)<<4) | ((editmode ? CS_EDITING : d->state)<<5) ); - - enet_packet_resize(packet, q.length()); - incomingdemodata(0, q.buf, q.length(), true); - sendpackettoserv(0, packet); - - bool serveriteminitdone = false; - if(gun_changed || senditemstoserver || !c2sinit || messages.length() || lastmillis-lastping>250) - { - packet = enet_packet_create (NULL, MAXTRANS, 0); - ucharbuf p(packet->data, packet->dataLength); - - if(gun_changed) - { - packet->flags = ENET_PACKET_FLAG_RELIABLE; - putint(p, SV_WEAPCHANGE); - putint(p, player1->gunselect); - gun_changed = false; - }; - if(senditemstoserver) - { - packet->flags = ENET_PACKET_FLAG_RELIABLE; - putint(p, SV_ITEMLIST); - if(!m_noitems) putitems(p); - putint(p, -1); - senditemstoserver = false; - serveriteminitdone = true; - }; - if(!c2sinit) // tell other clients who I am - { - packet->flags = ENET_PACKET_FLAG_RELIABLE; - c2sinit = true; - putint(p, SV_INITC2S); - sendstring(player1->name, p); - sendstring(player1->team, p); - putint(p, player1->skin); - putint(p, player1->lifesequence); - }; - int i = 0; - while(i < messages.length()) // send messages collected during the previous frames - { - int len = messages[i] | ((messages[i+1]&0x7F)<<8); - if(p.remaining() < len) break; - if(messages[i+1]&0x80) packet->flags = ENET_PACKET_FLAG_RELIABLE; - p.put(&messages[i+2], len); - i += 2 + len; - }; - messages.remove(0, i); - if(lastmillis-lastping>250) - { - putint(p, SV_PING); - putint(p, lastmillis); - lastping = lastmillis; - }; - if(!p.length()) enet_packet_destroy(packet); - else - { - enet_packet_resize(packet, p.length()); - sendpackettoserv(1, packet); - }; - }; - lastupdate = lastmillis; - if(serveriteminitdone) loadgamerest(); // hack -}; - -void gets2c() // get updates from the server -{ - ENetEvent event; - if(!clienthost) return; - if(connecting && lastmillis/3000 > connecting/3000) - { - conoutf("attempting to connect..."); - connecting = lastmillis; - ++connattempts; - if(connattempts > 3) - { - conoutf("could not connect to server"); - disconnect(); - return; - }; - }; - while(clienthost!=NULL && enet_host_service(clienthost, &event, 0)>0) - switch(event.type) - { - case ENET_EVENT_TYPE_CONNECT: - conoutf("connected to server"); - connecting = 0; - throttle(); - break; - - case ENET_EVENT_TYPE_RECEIVE: - if(disconnecting) - conoutf("attempting to disconnect..."); - else localservertoclient(event.channelID, event.packet->data, event.packet->dataLength); - enet_packet_destroy(event.packet); - break; - - case ENET_EVENT_TYPE_DISCONNECT: - extern char *disc_reasons[]; - if(event.data>DISC_MAXCLIENTS) event.data = DISC_NONE; - if(!disconnecting || event.data) conoutf("\fserver network error, disconnecting (%s) ...", disc_reasons[event.data]); - disconnect(); - return; - } -};