4
// Structure for storing traceresults
11
long RandomLong(long from, long to);
12
float RandomFloat(float from, float to);
13
void lsrand(unsigned long initial_seed);
15
void AnglesToVectors(vec angles, vec &forward, vec &right, vec &up);
16
float WrapXAngle(float angle);
17
float WrapYZAngle(float angle);
18
void TraceLine(vec from, vec to, dynent *pTracer, bool CheckPlayers, traceresult_s *tr,
20
float GetDistance(vec v1, vec v2);
21
float Get2DDistance(vec v1, vec v2);
22
bool IsVisible(vec v1, vec v2, dynent *tracer = NULL, bool SkipTags=false);
23
bool IsValidFile(const char *szFileName);
24
bool FileIsOlder(const char *szFileName1, const char *szFileName2);
25
vec PredictPos(vec pos, vec vel, float Time);
27
inline void makevec(vec *v, float x, float y, float z) { v->x=x; v->y=y; v->z=z; }
28
inline bool UnderWater(const vec &o) { return hdr.waterlevel>o.z-0.5f; }
29
inline bool InWater(const vec &o) { return hdr.waterlevel>=o.z; }
30
float GetYawDiff(float curyaw, vec v1, vec v2);
31
vec CrossProduct(const vec &a, const vec &b);
32
int GetDirection(const vec &angles, const vec &v1, const vec &v2);
33
float GetCubeFloor(int x, int y);
34
float GetCubeHeight(int x, int y);
35
const char *SkillNrToSkillName(short skillnr);
36
bool IsInGame(dynent *d);
38
// ==================================================================
39
// Code of TLinkedList - Start
40
// ==================================================================
42
template <class C> class TLinkedList
51
node_s(void) : next(NULL), prev(NULL)
53
//memset(&Entry, 0, sizeof(Entry));
63
pNodeList = new node_s;
64
pNodeList->Entry = entry;
65
pNodeList->next = NULL;
66
pNodeList->prev = NULL;
67
pLastNode = pNodeList;
72
pLastNode->next = new node_s;
73
pLastNode->next->prev = pLastNode;
74
pLastNode = pLastNode->next;
75
pLastNode->Entry = entry;
76
pLastNode->next = NULL;
81
void PushNode(C Entry)
85
pNodeList = new node_s;
86
pNodeList->Entry = Entry;
87
pNodeList->next = NULL;
88
pNodeList->prev = NULL;
89
pLastNode = pNodeList;
94
node_s *pNew = new node_s;
97
pNew->next = pNodeList;
98
pNodeList->prev = pNew;
104
void DeleteEntry(C Entry)
106
node_s *pNode = pNodeList;
110
if (pNode->Entry == Entry) // first node
112
if (pNodeList == pLastNode)
115
pNodeList = pNodeList->next;
117
pNodeList->prev = NULL;
125
if (Entry == pLastNode->Entry) // last node
128
pLastNode = pLastNode->prev;
129
pLastNode->next = NULL;
139
// node is somewhere in the middle
140
pNode = SearchNode(Entry);
145
node_s *pPrevNode = pNode->prev;
151
pNode->next->prev = pPrevNode;
152
pPrevNode->next = pNode->next;
161
void DeleteNode(node_s *pNode)
166
if (pNodeList == pNode) // first node
168
if (pNodeList == pLastNode)
169
pLastNode = pNodeList->next;
171
pNodeList = pNodeList->next;
173
pNodeList->prev = NULL;
181
if (pNode == pLastNode) // last node
184
pLastNode = pLastNode->prev;
185
pLastNode->next = NULL;
195
// node is somewhere in the middle
197
node_s *pPrevNode = pNode->prev;
203
pNode->next->prev = pPrevNode;
204
pPrevNode->next = pNode->next;
213
void DeleteAllNodes(void)
215
node_s *pNode = pNodeList;
217
while (pNode != NULL)
225
pNodeList = pLastNode = NULL;
229
void Reset(void) // Special case, doesn't delete existing nodes
231
pNodeList = pLastNode = NULL;
235
node_s *SearchNode(C Entry)
237
node_s *pNode = pNodeList;
240
if (pNode->Entry == Entry)
250
return static_cast<C>(NULL);
252
C Entry = pNodeList->Entry;
253
DeleteNode(pNodeList);
257
node_s *GetFirst(void) {
260
node_s *GetLast(void) { return pLastNode; };
262
void EditEntry(C OrigEntry, C NewVal)
264
node_s *pNode = SearchNode(OrigEntry);
267
pNode->Entry = NewVal;
270
bool IsInList(C Entry)
272
return (SearchNode(Entry) != NULL);
275
bool Empty(void) { return (pNodeList == NULL); };
276
int NodeCount(void) { return iNodeCount; };
279
// construction/destruction
299
// ==================================================================
300
// Code of TLinkedList - End
301
// ==================================================================
303
// ==================================================================
304
// Code of TPriorList - Begin
305
// ==================================================================
307
template <class C, class D=int> class TPriorList
316
node_s(C Ent, D Prior) : Entry(Ent), Priority(Prior), next(NULL) {};
319
TPriorList(void) : pHeadNode(NULL), pLastNode(NULL) {};
320
~TPriorList(void) { Clear(); };
322
void AddEntry(C Entry, D Prior)
326
pHeadNode = new node_s(Entry, Prior);
327
pLastNode = pHeadNode;
333
node_s *pNew = new node_s(Entry, Prior);
334
node_s *pNode = pHeadNode;
335
node_s *pPrev = NULL;
339
if (Prior < pNode->Priority)
369
return static_cast<C>(NULL);
371
C Entry = pHeadNode->Entry;
372
DeleteNode(pHeadNode);
382
pHeadNode = pHeadNode->next;
386
pHeadNode = pLastNode = NULL;
389
bool IsInList(C Entry, D Prior)
391
node_s *pNode = pHeadNode;
394
if (pNode->Entry == Entry)
397
if (Prior < pNode->Priority)
406
bool Empty(void) { return (pHeadNode == NULL); }
407
node_s *GetFirst(void) { return pHeadNode; }
413
node_s *GetPrevNode(node_s *pNode)
415
node_s *pTemp = pHeadNode;
418
if (pTemp->next == pNode)
426
void DeleteNode(node_s *pNode)
431
if (pHeadNode == pNode) // first node
433
if (pHeadNode == pLastNode)
434
pLastNode = pHeadNode->next;
436
pHeadNode = pHeadNode->next;
444
if (pNode == pLastNode) // last node
447
pLastNode->next = NULL;
456
// node is somewhere in the middle
458
node_s *pPrevNode = GetPrevNode(pNode);
463
pPrevNode->next = pNode->next;
471
// ==================================================================
472
// Code of TPriorList - End
473
// ==================================================================
476
// ==================================================================
477
// Code of TMultiChoice - Begin
478
// ==================================================================
480
template <class C> class TMultiChoice
487
SMultiChoice(void) : MinVal(0), MaxVal(0){};
491
TLinkedList<SMultiChoice*> *pChoiceList;
494
TMultiChoice(void) : TotalVal(0) // Constructor
496
pChoiceList = new TLinkedList<SMultiChoice*>;
499
~TMultiChoice(void) // Destructor
501
while(pChoiceList->Empty() == false)
503
SMultiChoice *pEntry = pChoiceList->Pop();
513
void Insert(C Choice, short Percent = 50)
518
SMultiChoice *pChoiceEntry = new SMultiChoice;
520
pChoiceEntry->MinVal = TotalVal;
521
pChoiceEntry->MaxVal = TotalVal + Percent;
522
pChoiceEntry->Choice = Choice;
524
pChoiceList->AddNode(pChoiceEntry);
529
bool FindSelection(SMultiChoice *MS, int Choice)
531
if ((Choice >= MS->MinVal) && (Choice < MS->MaxVal))
538
void ClearChoices(void)
541
while(pChoiceList->Empty() == false)
542
delete pChoiceList->Pop();
545
bool GetSelection(C &Var)
547
int Choice = RandomLong(0, (TotalVal - 1));
548
typename TLinkedList<SMultiChoice*>::node_s *pNode = pChoiceList->GetFirst();
552
if ((Choice >= pNode->Entry->MinVal) && (Choice < pNode->Entry->MaxVal))
554
Var = pNode->Entry->Choice;
564
// ==================================================================
565
// Code of TMutiChoice - End
566
// ==================================================================