Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
collect_common.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include "inexor/shared/geom.hpp"
9 
10 #define collectteambase(s) (!strcmp(s, "good") ? 1 : (!strcmp(s, "evil") ? 2 : 0))
11 #define collectbaseteam(i) (i==1 ? "good" : (i==2 ? "evil" : NULL))
12 
13 // TODO: Split into .cpp and .hpp
15 {
16  static const int BASERADIUS = 16;
17  static const int BASEHEIGHT = 16;
18  static const int MAXBASES = 20;
19  static const int TOKENRADIUS = 16;
20  static const int TOKENLIMIT = 5;
21  static const int UNOWNEDTOKENLIMIT = 15;
22  static const int TOKENDIST = 16;
23  static const int SCORELIMIT = 50;
24  static const int RESPAWNSECS = 5;
25  static const int EXPIRETOKENTIME = 10000;
26  static const int STEALTOKENTIME = 5000;
27 
28 
29 
30  struct base
31  {
32  int id, team;
33  vec o;
34  int laststeal;
35 
36  // client only
38  string info;
40 
41  base() { reset(); }
42 
43  void reset()
44  {
45  o = vec(0, 0, 0);
46  team = 0;
47  laststeal = 0;
48  }
49  };
50 
51  struct token
52  {
53  int id, team, droptime;
54  vec o;
55  int yaw, dropper;
57 
58  token() { reset(); }
59 
60  void reset()
61  {
62  o = vec(0, 0, 0);
63  team = 0;
64  dropper = -1;
65  droptime = 0;
66  }
67  };
68 
70  int scores[2];
72  int nexttoken; // server only
73 
74  void resetbases()
75  {
76  bases.shrink(0);
77  tokens.shrink(0);
78  loopk(2) scores[k] = 0;
79  tokens.shrink(0);
80  nexttoken = 0;
81  }
82 
83  bool addbase(int i, const vec &o, int team)
84  {
85  if(i<0 || i>=MAXBASES) return false;
86  while(bases.length()<=i) bases.add();
87  base &b = bases[i];
88  b.reset();
89  b.id = i;
90  b.team = team;
91  b.o = o;
92  return true;
93  }
94 
95  token *findtoken(int id)
96  {
97  loopv(tokens) if(tokens[i].id == id) return &tokens[i];
98  return nullptr;
99  }
100 
101  token &droptoken(const vec &o, int team, int droptime)
102  {
103  token &t = tokens.add();
104  t.o = o;
105  t.team = team;
106  t.droptime = droptime;
107  return t;
108  }
109 
110  bool removetoken(int id)
111  {
112  loopv(tokens) if(tokens[i].id == id)
113  {
114  tokens.removeunordered(i);
115  return true;
116  }
117  return false;
118  }
119 
120  int totalscore(int team)
121  {
122  return team >= 1 && team <= 2 ? scores[team-1] : 0;
123  }
124 
125  int setscore(int team, int score)
126  {
127  if(team >= 1 && team <= 2) return scores[team-1] = score;
128  return 0;
129  }
130 
131  int addscore(int team, int score)
132  {
133  if(team >= 1 && team <= 2) return scores[team-1] += score;
134  return 0;
135  }
136 
137  bool hidefrags() { return true; }
138 
139  int getteamscore(const char *team)
140  {
141  return totalscore(collectteambase(team));
142  }
143 
145  {
146  loopk(2) if(scores[k]) tscores.add(teamscore(collectbaseteam(k+1), scores[k]));
147  }
148 
149  bool insidebase(const base &b, const vec &o)
150  {
151  float dx = (b.o.x-o.x), dy = (b.o.y-o.y), dz = (b.o.z-o.z);
152  return dx*dx + dy*dy <= BASERADIUS*BASERADIUS && fabs(dz) <= BASEHEIGHT;
153  }
154 };
Definition: ents.hpp:82
void reset()
Definition: collect_common.hpp:43
int id
Definition: collect_common.hpp:53
Vector template.
Definition: cube_vector.hpp:22
static const int MAXBASES
Definition: collect_common.hpp:18
static const int BASEHEIGHT
Definition: collect_common.hpp:17
int totalscore(int team)
Definition: collect_common.hpp:120
int nexttoken
Definition: collect_common.hpp:72
int addscore(int team, int score)
Definition: collect_common.hpp:131
token * findtoken(int id)
Definition: collect_common.hpp:95
int droptime
Definition: collect_common.hpp:53
int dropper
Definition: collect_common.hpp:55
void reset()
Definition: collect_common.hpp:60
Definition: collect_common.hpp:30
static const int UNOWNEDTOKENLIMIT
Definition: collect_common.hpp:21
static const int TOKENRADIUS
Definition: collect_common.hpp:19
int id
Definition: collect_common.hpp:32
base()
Definition: collect_common.hpp:41
#define collectteambase(s)
Definition: collect_common.hpp:10
bool hidefrags()
Definition: collect_common.hpp:137
static const int TOKENLIMIT
Definition: collect_common.hpp:20
int team
Definition: collect_common.hpp:32
int laststeal
Definition: collect_common.hpp:34
bool removetoken(int id)
Definition: collect_common.hpp:110
#define collectbaseteam(i)
Definition: collect_common.hpp:11
T & add(const T &x)
Add new index to vector.
Definition: cube_vector.hpp:73
bool addbase(int i, const vec &o, int team)
Definition: collect_common.hpp:83
vector with 3 floats and some useful methods.
Definition: geom.hpp:110
int team
Definition: collect_common.hpp:53
token & droptoken(const vec &o, int team, int droptime)
Definition: collect_common.hpp:101
static const int STEALTOKENTIME
Definition: collect_common.hpp:26
vec o
Definition: collect_common.hpp:54
int scores[2]
Definition: collect_common.hpp:70
static const int EXPIRETOKENTIME
Definition: collect_common.hpp:25
static const int RESPAWNSECS
Definition: collect_common.hpp:24
vector< token > tokens
Definition: collect_common.hpp:71
void t(T x, const char *cmp)
Definition: utilTest.cpp:52
vec tokenpos
Definition: collect_common.hpp:37
int setscore(int team, int score)
Definition: collect_common.hpp:125
#define loopk(m)
Definition: cube_loops.hpp:10
string info
Definition: collect_common.hpp:38
static const int TOKENDIST
Definition: collect_common.hpp:22
static const int BASERADIUS
Definition: collect_common.hpp:16
vector< base > bases
Definition: collect_common.hpp:69
int yaw
Definition: collect_common.hpp:55
vec o
Definition: collect_common.hpp:33
some team modes allow more than 2 teams allow sorting multiple teams using team scores ...
Definition: teaminfo.hpp:43
static const int SCORELIMIT
Definition: collect_common.hpp:23
mathmatics for vectors, matrices, quaterions and more
void getteamscores(vector< teamscore > &tscores)
Definition: collect_common.hpp:144
void resetbases()
Definition: collect_common.hpp:74
int getteamscore(const char *team)
Definition: collect_common.hpp:139
bool insidebase(const base &b, const vec &o)
Definition: collect_common.hpp:149
#define loopv(v)
Definition: cube_loops.hpp:21
entitylight light
Definition: collect_common.hpp:39
token()
Definition: collect_common.hpp:58
entitylight light
Definition: collect_common.hpp:56
Definition: collect_common.hpp:14
Definition: collect_common.hpp:51