Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fpsstate.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 
5 #include "inexor/shared/ents.hpp"
8 #include "inexor/util/random.hpp"
9 
10 #include <algorithm>
11 
12 
13 enum { AI_NONE = 0, AI_BOT, AI_MAX };
14 #define isaitype(a) (a >= 0 && a <= AI_MAX-1)
15 
18 struct fpsstate
19 {
24  int ammo[NUMGUNS];
25  int aitype, skill;
26  int backupweapon; //no ammo - weapon
28  int bombdelay;
29 
31 
33  void baseammo(int gun, int k = 2, int scale = 1)
34  {
35  ammo[gun] = (itemstats[gun-GUN_SG].add*k)/scale;
36  }
37 
39  void addammo(int gun, int k = 1, int scale = 1)
40  {
41  const itemstat &is = itemstats[gun-GUN_SG];
42  ammo[gun] = std::min(ammo[gun] + (is.add*k)/scale, is.max);
43  }
44 
46  bool hasmaxammo(int type)
47  {
48  const itemstat &is = itemstats[type-I_SHELLS];
49  return ammo[type-I_SHELLS+GUN_SG]>=is.max;
50  }
51 
53  bool canpickup(int type)
54  {
55  if(type<I_SHELLS || type>I_QUAD) return false;
56  const itemstat &is = itemstats[type-I_SHELLS];
57  switch(type)
58  {
59  case I_BOOST: return maxhealth<is.max;
60  case I_HEALTH: return health<maxhealth;
61  case I_GREENARMOUR:
62  // (100h/100g only absorbs 200 damage)
63  if(armourtype==A_YELLOW && armour>=100) return false;
64  case I_YELLOWARMOUR: return !armourtype || armour<is.max;
65  case I_QUAD: return quadmillis<is.max;
66  case I_BOMBRADIUS:
67  return bombradius<is.max;
68  break;
69  case I_BOMBDELAY:
70  return bombdelay<is.max;
71  break;
72  default: return ammo[is.info]<is.max;
73  }
74  }
75 
77  void pickup(int type)
78  {
79  if(type<I_SHELLS || type>I_QUAD) return;
80  const itemstat &is = itemstats[type-I_SHELLS];
81  switch(type)
82  {
83  case I_BOOST:
85  case I_HEALTH: // boost also adds to health
87  break;
88  case I_GREENARMOUR:
89  case I_YELLOWARMOUR:
90  armour = std::min(armour+is.add, is.max);
91  armourtype = is.info;
92  break;
93  case I_QUAD:
95  break;
96  case I_BOMBRADIUS:
98  break;
99  case I_BOMBDELAY:
100  bombdelay = std::min(bombdelay+is.add, is.max);
101  break;
102  default:
103  ammo[is.info] = std::min(ammo[is.info]+is.add, is.max);
104  break;
105  }
106  }
107 
109  void respawn()
110  {
111  health = maxhealth;
112  armour = 0;
113  armourtype = A_BLUE;
114  quadmillis = 0;
116  gunwait = 0;
117  bombradius = 1;
118  bombdelay = 1;
119  loopi(NUMGUNS) ammo[i] = 0;
120  ammo[backupweapon] = 1;
121  }
122 
125  {
126  if(m_demo)
127  {
130  } else if(m_insta)
131  {
132  armour = 0;
133  health = 1;
135  ammo[GUN_RIFLE] = 100;
137  } else if(m_regencapture)
138  {
139  armourtype = A_BLUE;
140  armour = 25;
142  ammo[GUN_PISTOL] = 40;
143  ammo[GUN_GL] = 1;
145  } else if(m_tactics)
146  {
148  armour = 100;
149  ammo[GUN_PISTOL] = 40;
151  int spawngun1 = inexor::util::random::rnd(5)+1, spawngun2;
152  gunselect = spawngun1;
153  baseammo(spawngun1, m_noitems ? 2 : 1);
154  do spawngun2 = inexor::util::random::rnd(5)+1; while(spawngun1==spawngun2);
155  baseammo(spawngun2, m_noitems ? 2 : 1);
156  if(m_noitems) ammo[GUN_GL] += 1;
157  } else if(m_efficiency)
158  {
160  armour = 100;
161  loopi(5) baseammo(i+1);
162  gunselect = GUN_CG;
163  ammo[GUN_CG] /= 2;
165  } else if(m_ctf || m_collect)
166  {
167  armourtype = A_BLUE;
168  armour = 50;
169  ammo[GUN_PISTOL] = 40;
170  ammo[GUN_GL] = 1;
172  } else if(m_bomb)
173  {
174  health = 1;
176  armour = 0;
179  } else if(m_hideandseek)
180  {
181  health = 100;
182  armour = 0;
183  gunselect = GUN_RL;
184  ammo[GUN_RL] = 10;
185  ammo[GUN_PISTOL] = 0;
186  ammo[GUN_GL] = 0;
188  } else
189  {
190  armourtype = A_BLUE;
191  armour = 25;
192  ammo[GUN_PISTOL] = 40;
193  ammo[GUN_GL] = 1;
195  }
196  }
197 
199  int dodamage(int damage)
200  {
201  int ad = damage*(armourtype+1)*25/100; // let armour absorb when possible
202  if(ad>armour) ad = armour;
203  armour -= ad;
204  damage -= ad;
205  health -= damage;
206  return damage;
207  }
208 
210  int hasammo(int gun, int exclude = -1)
211  {
212  return gun >= 0 && gun <= NUMGUNS && gun != exclude && ammo[gun] > 0;
213  }
214 };
fpsstate()
Definition: fpsstate.hpp:30
void addammo(int gun, int k=1, int scale=1)
add ammo
Definition: fpsstate.hpp:39
#define m_efficiency
Definition: gamemode.hpp:96
int skill
Definition: fpsstate.hpp:25
Definition: fpsstate.hpp:13
bool canpickup(int type)
check if I can pick up this item depending on the radius
Definition: fpsstate.hpp:53
int hasammo(int gun, int exclude=-1)
is there ammo left for this gun
Definition: fpsstate.hpp:210
int dodamage(int damage)
just subtract damage here, we can set death, etc. later in code calling this
Definition: fpsstate.hpp:199
void baseammo(int gun, int k=2, int scale=1)
set initial ammo
Definition: fpsstate.hpp:33
Definition: guns.hpp:38
Definition: ents.hpp:47
void pickup(int type)
pick up this item
Definition: fpsstate.hpp:77
int armour
Definition: fpsstate.hpp:21
int backupweapon
Definition: fpsstate.hpp:26
bool hasmaxammo(int type)
ammo limitation reached/exceeded?
Definition: fpsstate.hpp:46
#define m_regencapture
Definition: gamemode.hpp:98
int gunselect
Definition: fpsstate.hpp:23
int bombradius
Definition: fpsstate.hpp:27
int quadmillis
Definition: fpsstate.hpp:22
Definition: guns.hpp:39
Definition: ents.hpp:45
bomb radius (see bomberman game mode)
Definition: ents.hpp:44
int gunwait
Definition: fpsstate.hpp:23
Definition: guns.hpp:40
bomberman game mode
Definition: ents.hpp:43
grenade launcher
Definition: guns.hpp:22
int gamemode
The currently set gamemode.
Definition: gamemode.cpp:11
void spawnstate(int gamemode)
configure spawn settings (weapons, ammo, health...) depending on game mode
Definition: fpsstate.hpp:124
#define m_demo
Definition: gamemode.hpp:114
pickup description structure
Definition: guns.hpp:46
bomberman game mode
Definition: ents.hpp:45
#define m_insta
Definition: gamemode.hpp:94
cone-shaped spotlights
Definition: ents.hpp:41
else loopi(numargs)
Definition: command.cpp:3019
static const itemstat itemstats[]
create an array of itemstat instances ('pickups')
Definition: guns.hpp:56
int health
Definition: fpsstate.hpp:20
#define m_tactics
Definition: gamemode.hpp:95
#define m_ctf
Definition: gamemode.hpp:99
Definition: guns.hpp:30
#define m_noitems
those game mode check macros are built on top of the layer above
Definition: gamemode.hpp:92
int armourtype
Definition: fpsstate.hpp:21
#define m_collect
Definition: gamemode.hpp:102
int max
Definition: guns.hpp:48
int info
Definition: guns.hpp:52
Definition: ents.hpp:46
const T & min(const inexor::rpc::SharedVar< T > &a, const T &b)
Definition: SharedVar.hpp:210
Definition: guns.hpp:16
int ammo[NUMGUNS]
Definition: fpsstate.hpp:24
int bombdelay
Definition: fpsstate.hpp:28
int add
Definition: guns.hpp:48
int maxhealth
Definition: fpsstate.hpp:20
rocket launcher
Definition: guns.hpp:20
T rnd(const T Rmin, const T Rmax)
Generate a random number between Rmin and Rmax.
Definition: random.hpp:88
int aitype
Definition: fpsstate.hpp:25
void respawn()
reset all members when spawning
Definition: fpsstate.hpp:109
#define m_hideandseek
Definition: gamemode.hpp:109
#define m_bomb
Definition: gamemode.hpp:108
Definition: fpsstate.hpp:13
Definition: fpsstate.hpp:13
static map entities ("entity") and dynamic entities (players/monsters, "dynent") the gamecode extends...
shotgun
Definition: guns.hpp:18
chaingun
Definition: guns.hpp:19
Definition: guns.hpp:21
Definition: guns.hpp:23
Definition: guns.hpp:17
First person state.
Definition: fpsstate.hpp:18
Definition: ents.hpp:46