Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ctf_common.hpp
Go to the documentation of this file.
1 #pragma once
3 #include "inexor/shared/geom.hpp"
7 
9 #include "inexor/sound/sound.hpp"
11 
12 #define ctfteamflag(s) (!strcmp(s, "good") ? 1 : (!strcmp(s, "evil") ? 2 : 0))
13 #define ctfflagteam(i) (i==1 ? "good" : (i==2 ? "evil" : NULL))
14 
15 struct fpsent;
16 
17 struct flag
18 {
22 
24 
26  int runstart;
27 
28  fpsent *owner; // TODO this is the only hard dependency to client specific code in the gamemode code!
29  int owner_id;
30 
34  float interpangle;
36  int vistime, invistime; // one is used by the server, the other one by the client..
37 
38  flag() : id(-1) { reset(); }
39 
40  void reset()
41  {
42  version = 0;
43  spawnindex = -1;
44  droploc = spawnloc = vec(0, 0, 0);
45  team = 0;
46  droptime = owntime = 0;
47 
48  dropcount = 0;
49  owner_id = dropper = -1;
50  invistime = owntime = runstart = 0;
51  //if(id >= 0) loopv(players) players[i]->flagpickup &= ~(1<<id);
52  owner = nullptr;
53  dropangle = spawnangle = 0;
54  interploc = vec(0, 0, 0);
55  interpangle = 0;
56  interptime = 0;
57  vistime = -1000;
58  }
59 
60  vec pos() const
61  {
62  if(owner) return vec(owner->o).sub(owner->eyeheight);
63  if(droptime) return droploc;
64  return spawnloc;
65  }
66 
67 };
68 
69 struct ctfmode
70 {
71  static const int BASERADIUS = 64;
72  static const int BASEHEIGHT = 24;
73  static const int MAXFLAGS = 20;
74  static const int FLAGRADIUS = 16;
75  static const int FLAGLIMIT = 10;
76  static const int MAXHOLDSPAWNS = 100;
77  static const int HOLDSECS = 20;
78  static const int HOLDFLAGS = 1;
79  static const int RESPAWNSECS = 5;
80 
81 
82 
83  struct holdspawn
84  {
85  vec o;
87  };
88 
91  int scores[2];
92 
93  void resetflags()
94  {
95  holdspawns.shrink(0);
96  flags.shrink(0);
97  loopk(2) scores[k] = 0;
98  }
99 
100  bool addflag(int i, const vec &o, int team)
101  {
102  if(i<0 || i>=MAXFLAGS) return false;
103  while(flags.length()<=i) flags.add();
104  flag &f = flags[i];
105  f.id = i;
106  f.reset();
107  f.team = team;
108  f.spawnloc = o;
109  return true;
110  }
111 
112  bool addholdspawn(const vec &o)
113  {
114  if(holdspawns.length() >= MAXHOLDSPAWNS) return false;
115  holdspawn &h = holdspawns.add();
116  h.o = o;
117  return true;
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(ctfteamflag(team));
142  }
143 
145  {
146  loopk(2) if(scores[k]) tscores.add(teamscore(ctfflagteam(k+1), scores[k]));
147  }
148 
149  bool insidebase(const flag &f, const vec &o)
150  {
151  float dx = (f.spawnloc.x-o.x), dy = (f.spawnloc.y-o.y), dz = (f.spawnloc.z-o.z);
152  return dx*dx + dy*dy <= BASERADIUS*BASERADIUS && fabs(dz) <= BASEHEIGHT;
153  }
154 };
Definition: ents.hpp:82
int totalscore(int team)
Definition: ctf_common.hpp:120
Vector template.
Definition: cube_vector.hpp:22
vec droploc
Definition: ctf_common.hpp:20
Definition: ctf_common.hpp:83
int owner_id
Definition: ctf_common.hpp:29
bool hidefrags()
Definition: ctf_common.hpp:137
vector< holdspawn > holdspawns
Definition: ctf_common.hpp:89
int scores[2]
Definition: ctf_common.hpp:91
Definition: bomb_common.hpp:4
void shrink(int i)
shrink vector memory size AND DELETE UNUSED MEMORY
Definition: cube_vector.hpp:161
static const int HOLDSECS
Definition: ctf_common.hpp:77
int version
Definition: ctf_common.hpp:19
int dropcount
Definition: ctf_common.hpp:23
void getteamscores(vector< teamscore > &tscores)
Definition: ctf_common.hpp:144
int getteamscore(const char *team)
Definition: ctf_common.hpp:139
vec o
Definition: ctf_common.hpp:85
int dropper
Definition: ctf_common.hpp:23
vec interploc
Definition: ctf_common.hpp:33
void resetflags()
Definition: ctf_common.hpp:93
int owntime
Definition: ctf_common.hpp:21
#define ctfteamflag(s)
Definition: ctf_common.hpp:12
flag()
Definition: ctf_common.hpp:38
#define ctfflagteam(i)
Definition: ctf_common.hpp:13
ICOMMAND * f(float *a, float *b), floatret(*a **b)
Definition: ctf_common.hpp:17
static const int RESPAWNSECS
Definition: ctf_common.hpp:79
int invistime
Definition: ctf_common.hpp:36
float eyeheight
Definition: ents.hpp:135
static const int BASEHEIGHT
Definition: ctf_common.hpp:72
static const int FLAGRADIUS
Definition: ctf_common.hpp:74
int runstart
time when the flagrun was initiated
Definition: ctf_common.hpp:26
Definition: ctf_common.hpp:69
int interptime
Definition: ctf_common.hpp:35
T & add(const T &x)
Add new index to vector.
Definition: cube_vector.hpp:73
vector with 3 floats and some useful methods.
Definition: geom.hpp:110
vec & sub(const vec &o)
scalar subtraction
Definition: geom.hpp:177
bool addflag(int i, const vec &o, int team)
Definition: ctf_common.hpp:100
static const int BASERADIUS
Definition: ctf_common.hpp:71
float interpangle
Definition: ctf_common.hpp:34
entitylight light
Definition: ctf_common.hpp:32
bool addholdspawn(const vec &o)
Definition: ctf_common.hpp:112
int length() const
return size of used memory
Definition: cube_vector.hpp:146
int addscore(int team, int score)
Definition: ctf_common.hpp:131
#define loopk(m)
Definition: cube_loops.hpp:10
fpsent * owner
Definition: ctf_common.hpp:28
vec spawnloc
Definition: ctf_common.hpp:20
float dropangle
Definition: ctf_common.hpp:31
entitylight light
Definition: ctf_common.hpp:86
float spawnangle
Definition: ctf_common.hpp:31
void reset()
Definition: ctf_common.hpp:40
vec o
Definition: ents.hpp:130
bool insidebase(const flag &f, const vec &o)
Definition: ctf_common.hpp:149
int vistime
Definition: ctf_common.hpp:36
static const int MAXFLAGS
Definition: ctf_common.hpp:73
Definition: fpsent.hpp:12
int setscore(int team, int score)
Definition: ctf_common.hpp:125
static const int MAXHOLDSPAWNS
Definition: ctf_common.hpp:76
vec pos() const
Definition: ctf_common.hpp:60
int id
Definition: ctf_common.hpp:19
some team modes allow more than 2 teams allow sorting multiple teams using team scores ...
Definition: teaminfo.hpp:43
int team
Definition: ctf_common.hpp:21
mathmatics for vectors, matrices, quaterions and more
int droptime
Definition: ctf_common.hpp:21
int spawnindex
Definition: ctf_common.hpp:19
static const int HOLDFLAGS
Definition: ctf_common.hpp:78
vector< flag > flags
Definition: ctf_common.hpp:90
static const int FLAGLIMIT
Definition: ctf_common.hpp:75