summaryrefslogtreecommitdiff
path: root/src/fpsgame/game.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fpsgame/game.h')
-rw-r--r--src/fpsgame/game.h216
1 files changed, 68 insertions, 148 deletions
diff --git a/src/fpsgame/game.h b/src/fpsgame/game.h
index 3cdbba3..974f1f3 100644
--- a/src/fpsgame/game.h
+++ b/src/fpsgame/game.h
@@ -5,8 +5,7 @@
// console message types
-enum
-{
+enum {
CON_CHAT = 1<<8,
CON_TEAMCHAT = 1<<9,
CON_GAMEINFO = 1<<10,
@@ -20,8 +19,7 @@ enum
#define DNF 100.0f // for normalized vectors
#define DVELF 1.0f // for playerspeed based velocity vectors
-enum // static entity types
-{
+enum { // static entity types {
NOTUSED = ET_EMPTY, // entity slot not in use in map
LIGHT = ET_LIGHT, // lightsource, attr1 = radius, attr2 = intensity
MAPMODEL = ET_MAPMODEL, // attr1 = angle, attr2 = idx
@@ -41,10 +39,9 @@ enum // static entity types
};
enum { GUN_FIST = 0, GUN_SG, GUN_CG, GUN_RL, GUN_RIFLE, GUN_GL, GUN_PISTOL, NUMGUNS };
-enum { A_BLUE, A_GREEN, A_YELLOW }; // armour types... take 20/40/60 % off
+enum { A_BLUE, A_GREEN, A_YELLOW }; // armour types... take 20/40/60 % off INCORRECT!
-enum
-{
+enum {
M_TEAM = 1<<0,
M_NOITEMS = 1<<1,
M_NOAMMO = 1<<2,
@@ -56,21 +53,20 @@ enum
M_LOBBY = 1<<15
};
-static struct gamemodeinfo
-{
+static struct gamemodeinfo {
const char *name;
int flags;
const char *info;
-} gamemodes[] =
-{
- { "demo", M_DEMO | M_LOCAL, NULL},
- { "ffa", M_LOBBY, "Free For All: Collect items for ammo. Frag everyone to score points." },
- { "coop edit", M_EDIT, "Cooperative Editing: Edit maps with multiple players simultaneously." },
- { "teamplay", M_TEAM, "Teamplay: Collect items for ammo. Frag \fs\f3the enemy team\fr to score points for \fs\f1your team\fr." },
- { "instagib", M_NOITEMS | M_INSTA, "Instagib: You spawn with full rifle ammo and die instantly from one shot. There are no items. Frag everyone to score points." },
- { "insta team", M_NOITEMS | M_INSTA | M_TEAM, "Instagib Team: You spawn with full rifle ammo and die instantly from one shot. There are no items. Frag \fs\f3the enemy team\fr to score points for \fs\f1your team\fr." },
- { "efficiency", M_NOITEMS | M_EFFICIENCY, "Efficiency: You spawn with all weapons and armour. There are no items. Frag everyone to score points." },
- { "effic team", M_NOITEMS | M_EFFICIENCY | M_TEAM, "Efficiency Team: You spawn with all weapons and armour. There are no items. Frag \fs\f3the enemy team\fr to score points for \fs\f1your team\fr." },
+} gamemodes[] = {
+ {
+ "demo", M_DEMO | M_LOCAL, NULL}, {
+ "ffa", M_LOBBY, "Free For All: Collect items for ammo. Frag everyone to score points." }, {
+ "coop edit", M_EDIT, "Cooperative Editing: Edit maps with multiple players simultaneously." }, {
+ "teamplay", M_TEAM, "Teamplay: Collect items for ammo. Frag \fs\f3the enemy team\fr to score points for \fs\f1your team\fr." }, {
+ "instagib", M_NOITEMS | M_INSTA, "Instagib: You spawn with full rifle ammo and die instantly from one shot. There are no items. Frag everyone to score points." }, {
+ "insta team", M_NOITEMS | M_INSTA | M_TEAM, "Instagib Team: You spawn with full rifle ammo and die instantly from one shot. There are no items. Frag \fs\f3the enemy team\fr to score points for \fs\f1your team\fr." }, {
+ "efficiency", M_NOITEMS | M_EFFICIENCY, "Efficiency: You spawn with all weapons and armour. There are no items. Frag everyone to score points." }, {
+ "effic team", M_NOITEMS | M_EFFICIENCY | M_TEAM, "Efficiency Team: You spawn with all weapons and armour. There are no items. Frag \fs\f3the enemy team\fr to score points for \fs\f1your team\fr." },
};
#define STARTGAMEMODE (-1)
@@ -98,13 +94,12 @@ static struct gamemodeinfo
enum { MM_AUTH = -1, MM_OPEN = 0, MM_VETO, MM_LOCKED, MM_PRIVATE, MM_PASSWORD, MM_START = MM_AUTH };
-static const char * const mastermodenames[] = { "auth", "open", "veto", "locked", "private", "password" };
+static const char * const mastermodenames[] = { "auth", "open", "veto", "locked", "private", "password" };
static const char * const mastermodecolors[] = { "", "\f0", "\f2", "\f2", "\f3", "\f3" };
-static const char * const mastermodeicons[] = { "server", "server", "serverlock", "serverlock", "serverpriv", "serverpriv" };
+static const char * const mastermodeicons[] = { "server", "server", "serverlock", "serverlock", "serverpriv", "serverpriv" };
// hardcoded sounds, defined in sounds.cfg
-enum
-{
+enum {
S_JUMP = 0, S_LAND, S_RIFLE, S_PUNCH1, S_SG, S_CG,
S_RLFIRE, S_RLHIT, S_WEAPLOAD, S_ITEMAMMO, S_ITEMHEALTH,
S_ITEMARMOUR, S_ITEMPUP, S_ITEMSPAWN, S_TELEPORT, S_NOAMMO, S_PUPOUT,
@@ -113,15 +108,12 @@ enum
S_FLAUNCH, S_FEXPLODE,
S_SPLASH1, S_SPLASH2,
S_JUMPPAD, S_PISTOL,
-
S_V_FIGHT,
S_V_BOOST, S_V_BOOST10,
S_V_QUAD, S_V_QUAD10,
-
S_BURN,
S_CHAINSAW_ATTACK,
S_CHAINSAW_IDLE,
-
S_HIT
};
@@ -129,8 +121,7 @@ enum
enum { PRIV_NONE = 0, PRIV_MASTER, PRIV_AUTH, PRIV_ADMIN };
-enum
-{
+enum {
N_CONNECT = 0, N_SERVINFO, N_WELCOME, N_INITCLIENT, N_POS, N_TEXT, N_SOUND, N_CDIS,
N_SHOOT, N_EXPLODE, N_SUICIDE,
N_DIED, N_DAMAGE, N_HITPUSH, N_SHOTFX, N_EXPLODEFX,
@@ -157,8 +148,7 @@ enum
NUMMSG
};
-static const int msgsizes[] = // size inclusive message token, 0 for variable or not-checked sizes
-{
+static const int msgsizes[] = { // size inclusive message token, 0 for variable or not-checked sizes {
N_CONNECT, 0, N_SERVINFO, 0, N_WELCOME, 1, N_INITCLIENT, 0, N_POS, 0, N_TEXT, 0, N_SOUND, 2, N_CDIS, 2,
N_SHOOT, 0, N_EXPLODE, 0, N_SUICIDE, 1,
N_DIED, 5, N_DAMAGE, 6, N_HITPUSH, 7, N_SHOTFX, 10, N_EXPLODEFX, 4,
@@ -193,8 +183,7 @@ static const int msgsizes[] = // size inclusive message token, 0 for variab
#define DEMO_VERSION 1 // bump when demo format changes
#define DEMO_MAGIC "SAUERBRATEN_DEMO"
-struct demoheader
-{
+struct demoheader {
char magic[16];
int version, protocol;
};
@@ -202,14 +191,11 @@ struct demoheader
#define MAXNAMELEN 15
#define MAXTEAMLEN 4
-enum
-{
+enum {
HICON_BLUE_ARMOUR = 0,
HICON_GREEN_ARMOUR,
HICON_YELLOW_ARMOUR,
-
HICON_HEALTH,
-
HICON_FIST,
HICON_SG,
HICON_CG,
@@ -217,11 +203,8 @@ enum
HICON_RIFLE,
HICON_GL,
HICON_PISTOL,
-
HICON_QUAD,
-
HICON_TOKEN,
-
HICON_X = 20,
HICON_Y = 1650,
HICON_TEXTY = 1644,
@@ -234,20 +217,20 @@ static struct itemstat {
int add, max, sound;
const char *name;
int icon, info;
-} itemstats[] = {
- {10, 30, S_ITEMAMMO, "SG", HICON_SG, GUN_SG},
- {20, 60, S_ITEMAMMO, "CG", HICON_CG, GUN_CG},
- {5, 15, S_ITEMAMMO, "RL", HICON_RL, GUN_RL},
- {5, 15, S_ITEMAMMO, "RI", HICON_RIFLE, GUN_RIFLE},
- {10, 30, S_ITEMAMMO, "GL", HICON_GL, GUN_GL},
- {30, 120, S_ITEMAMMO, "PI", HICON_PISTOL, GUN_PISTOL},
- {25, 100, S_ITEMHEALTH, "H", HICON_HEALTH, -1},
- {100, 200, S_ITEMHEALTH, "MH", HICON_HEALTH, 50},
- {5, 100, S_ITEMHEALTH, "TH", HICON_HEALTH, -1},
- {5, 50, S_ITEMARMOUR, "TA", HICON_BLUE_ARMOUR, A_BLUE},
- {50, 100, S_ITEMARMOUR, "GA", HICON_GREEN_ARMOUR, A_GREEN},
- {100, 200, S_ITEMARMOUR, "YA", HICON_YELLOW_ARMOUR, A_YELLOW},
- {20000, 30000, S_ITEMPUP, "Q", HICON_QUAD, -1},
+} itemstats[] = { {
+ 10, 30, S_ITEMAMMO, "SG", HICON_SG, GUN_SG}, {
+ 20, 60, S_ITEMAMMO, "CG", HICON_CG, GUN_CG}, {
+ 5, 15, S_ITEMAMMO, "RL", HICON_RL, GUN_RL}, {
+ 5, 15, S_ITEMAMMO, "RI", HICON_RIFLE, GUN_RIFLE}, {
+ 10, 30, S_ITEMAMMO, "GL", HICON_GL, GUN_GL}, {
+ 30, 120, S_ITEMAMMO, "PI", HICON_PISTOL, GUN_PISTOL}, {
+ 25, 100, S_ITEMHEALTH, "H", HICON_HEALTH, -1}, {
+ 100, 200, S_ITEMHEALTH, "MH", HICON_HEALTH, 50}, {
+ 5, 100, S_ITEMHEALTH, "TH", HICON_HEALTH, -1}, {
+ 5, 50, S_ITEMARMOUR, "TA", HICON_BLUE_ARMOUR, A_BLUE}, {
+ 50, 100, S_ITEMARMOUR, "GA", HICON_GREEN_ARMOUR, A_GREEN}, {
+ 100, 200, S_ITEMARMOUR, "YA", HICON_YELLOW_ARMOUR, A_YELLOW}, {
+ 20000, 30000, S_ITEMPUP, "Q", HICON_QUAD, -1},
};
#define MAXRAYS 12
@@ -260,7 +243,7 @@ static const struct guninfo {
const char *name, *file;
short part;
} guns[NUMGUNS] = {
- // delay| dmg| spr| spd| kck| rng| ray| pus| exp|
+ // delay| dmg| spr| spd| kck| rng| ray| pus| exp| {
{ S_PUNCH1, 100, 30, 0, 0, 0, 30, 1, 80, 0, 0, "fist", "fist", 0 },
{ S_SG, 1000, 20, 280, 0, 20, 1024, MAXRAYS, 100, 0, 0, "shotgun", "shotg", 0 },
{ S_CG, 100, 20, 70, 0, 10, 1024, 1, 80, 0, 0, "chaingun", "chaing", 0 },
@@ -287,61 +270,45 @@ extern void pwreset(void);
#include "ai.h"
// inherited by fpsent and server clients
-struct fpsstate
-{
+struct fpsstate {
int health, maxhealth;
int armour, maxarmour, armourtype;
int quadmillis;
int gunselect, gunwait;
int ammo[NUMGUNS];
int aitype, skill;
-
fpsstate() : maxhealth(100), maxarmour(50), aitype(AI_NONE), skill(0) {}
-
- void baseammo(int gun, int k = 2, int scale = 1)
- {
+ void baseammo(int gun, int k = 2, int scale = 1) {
ammo[gun] = (itemstats[gun-GUN_SG].add*k)/scale;
}
-
- void addammo(int gun, int k = 1, int scale = 1)
- {
+ void addammo(int gun, int k = 1, int scale = 1) {
itemstat &is = itemstats[gun-GUN_SG];
ammo[gun] = min(ammo[gun] + (is.add*k)/scale, is.max);
}
-
- bool hasmaxammo(int type)
- {
+ bool hasmaxammo(int type) {
const itemstat &is = itemstats[type-I_SHELLS];
return ammo[type-I_SHELLS+GUN_SG]>=is.max;
}
-
- bool canpickup(int type)
- {
+ bool canpickup(int type) {
if(type<I_SHELLS || type>I_QUAD) return false;
itemstat &is = itemstats[type-I_SHELLS];
- switch(type)
- {
+ switch(type) {
case I_BOOST: return maxhealth<is.max || health<maxhealth;
case I_TINYHEALTH: return health<maxhealth;
case I_HEALTH: return health<maxhealth;
-
case I_TINYARMOUR:
[[fallthrough]];
case I_GREENARMOUR:
[[fallthrough]];
case I_YELLOWARMOUR: return maxarmour<is.max || armour<maxarmour;
-
case I_QUAD: return quadmillis<is.max;
default: return ammo[is.info]<is.max;
}
}
-
- void pickup(int type)
- {
+ void pickup(int type) {
if(type<I_SHELLS || type>I_QUAD) return;
itemstat &is = itemstats[type-I_SHELLS];
- switch(type)
- {
+ switch(type) {
case I_TINYHEALTH:
health = min(health+is.add, maxhealth);
break;
@@ -368,9 +335,7 @@ struct fpsstate
break;
}
}
-
- void respawn()
- {
+ void respawn() {
maxhealth = 100;
health = maxhealth;
maxarmour = 50;
@@ -382,39 +347,31 @@ struct fpsstate
loopi(NUMGUNS) ammo[i] = 0;
ammo[GUN_FIST] = 1;
}
-
- void spawnstate(int gamemode)
- {
- if(m_demo)
- {
+ void spawnstate(int gamemode) {
+ if(m_demo) {
gunselect = GUN_FIST;
}
- else if(m_insta)
- {
+ else if(m_insta) {
armour = 0;
health = 1;
gunselect = GUN_RIFLE;
ammo[GUN_RIFLE] = 100;
}
- else if(m_efficiency)
- {
+ else if(m_efficiency) {
armourtype = A_GREEN;
armour = 100;
loopi(NUMGUNS-1) baseammo(i+1);
gunselect = GUN_CG;
ammo[GUN_CG] /= 2;
}
- else
- {
+ else {
armourtype = A_BLUE;
armour = 25;
ammo[GUN_PISTOL] = 40;
}
}
-
// just subtract damage here, can set death, etc. later in code calling this
- int dodamage(int damage)
- {
+ int dodamage(int damage) {
int ad = (damage*(armourtype+1)*30)/100; // let armour absorb when possible
if(ad>armour) ad = armour;
armour -= ad;
@@ -422,17 +379,14 @@ struct fpsstate
health -= damage;
return damage;
}
-
- int hasammo(int gun, int exclude = -1)
- {
+ int hasammo(int gun, int exclude = -1) {
return gun >= 0 && gun <= NUMGUNS && gun != exclude && ammo[gun] > 0;
}
};
extern int screenw, screenh;
-struct fpsent : dynent, fpsstate
-{
+struct fpsent : dynent, fpsstate {
int weight; // affects the effectiveness of hitpush
int clientnum, privilege, lastupdate, plag, ping;
int lifesequence; // sequence id for each respawn, used in damage test
@@ -448,48 +402,35 @@ struct fpsent : dynent, fpsstate
editinfo *edit;
float deltayaw, deltapitch, deltaroll, newyaw, newpitch, newroll;
int smoothmillis;
-
string name, team, info;
int playermodel;
ai::aiinfo *ai;
int ownernum, lastnode;
-
vec muzzle;
-
- fpsent() : weight(100), clientnum(-1), privilege(PRIV_NONE), lastupdate(0), plag(0), ping(0), lifesequence(0), respawned(-1), suicided(-1), lastpain(0), attacksound(-1), attackchan(-1), idlesound(-1), idlechan(-1), frags(0), flags(0), deaths(0), totaldamage(0), totalshots(0), edit(NULL), smoothmillis(-1), playermodel(-1), ai(NULL), ownernum(-1), muzzle(-1, -1, -1)
- {
+ fpsent() : weight(100), clientnum(-1), privilege(PRIV_NONE), lastupdate(0), plag(0), ping(0), lifesequence(0), respawned(-1), suicided(-1), lastpain(0), attacksound(-1), attackchan(-1), idlesound(-1), idlechan(-1), frags(0), flags(0), deaths(0), totaldamage(0), totalshots(0), edit(NULL), smoothmillis(-1), playermodel(-1), ai(NULL), ownernum(-1), muzzle(-1, -1, -1) {
name[0] = team[0] = info[0] = 0;
respawn();
}
- ~fpsent()
- {
+ ~fpsent() {
freeeditinfo(edit);
if(attackchan >= 0) stopsound(attacksound, attackchan);
if(idlechan >= 0) stopsound(idlesound, idlechan);
if(ai) delete ai;
}
-
- void hitpush(int damage, const vec &dir, fpsent *actor, int gun)
- {
+ void hitpush(int damage, const vec &dir, fpsent *actor, int gun) {
vec push(dir);
push.mul((actor==this && guns[gun].exprad ? EXP_SELFPUSH : 1.0f)*guns[gun].hitpush*damage/weight);
vel.add(push);
}
-
- void stopattacksound()
- {
+ void stopattacksound() {
if(attackchan >= 0) stopsound(attacksound, attackchan, 250);
attacksound = attackchan = -1;
}
-
- void stopidlesound()
- {
+ void stopidlesound() {
if(idlechan >= 0) stopsound(idlesound, idlechan, 100);
idlesound = idlechan = -1;
}
-
- void respawn()
- {
+ void respawn() {
dynent::reset();
fpsstate::respawn();
respawned = suicided = -1;
@@ -506,22 +447,17 @@ struct fpsent : dynent, fpsstate
stopattacksound();
lastnode = -1;
}
-
- int respawnwait(int secs, int delay = 0)
- {
+ int respawnwait(int secs, int delay = 0) {
return max(0, secs - (::lastmillis - lastpain - delay)/1000);
}
};
-struct teamscore
-{
+struct teamscore {
const char *team;
int score;
teamscore() {}
teamscore(const char *s, int n) : team(s), score(n) {}
-
- static bool compare(const teamscore &x, const teamscore &y)
- {
+ static bool compare(const teamscore &x, const teamscore &y) {
if(x.score > y.score) return true;
if(x.score < y.score) return false;
return strcmp(x.team, y.team) < 0;
@@ -533,8 +469,7 @@ static inline bool htcmp(const char *key, const teamscore &t) { return htcmp(key
#define MAXTEAMS 128
-struct teaminfo
-{
+struct teaminfo {
char team[MAXTEAMLEN+1];
int frags;
};
@@ -542,14 +477,11 @@ struct teaminfo
static inline uint hthash(const teaminfo &t) { return hthash(t.team); }
static inline bool htcmp(const char *team, const teaminfo &t) { return !strcmp(team, t.team); }
-namespace entities
-{
+namespace entities {
extern vector<extentity *> ents;
-
extern const char *entmdlname(int type);
extern const char *itemname(int i);
extern int itemicon(int i);
-
extern void preloadentities();
extern void renderentities();
extern void checkitems(fpsent *d);
@@ -562,12 +494,10 @@ namespace entities
extern void pickupeffects(int n, fpsent *d);
extern void teleporteffects(fpsent *d, int tp, int td, bool local = true);
extern void jumppadeffects(fpsent *d, int jp, bool local = true);
-
extern void repammo(fpsent *d, int type, bool local = true);
}
-namespace game
-{
+namespace game {
// fps
extern int gamemode, nextmode;
extern string clientmap;
@@ -580,7 +510,6 @@ namespace game
extern int respawnent;
extern int following;
extern int smoothmove, smoothdist;
-
extern bool clientoption(const char *arg);
extern fpsent *getclient(int cn);
extern fpsent *newclient(int cn);
@@ -608,12 +537,10 @@ namespace game
extern void drawicon(int icon, float x, float y, float sz = 120);
const char *mastermodecolor(int n, const char *unknown);
const char *mastermodeicon(int n, const char *unknown);
-
// client
extern bool connected, remote, demoplayback;
extern string servinfo;
extern vector<uchar> messages;
-
extern int parseplayer(const char *arg);
extern void ignore(int cn);
extern void unignore(int cn);
@@ -627,7 +554,6 @@ namespace game
extern void forceintermission();
extern void c2sinfo(bool force = false);
extern void sendposition(fpsent *d, bool reliable = false);
-
// weapon
extern int getweapon(const char *name);
extern void shoot(fpsent *d, const vec &targ);
@@ -652,7 +578,6 @@ namespace game
extern void gunselect(int gun, fpsent *d);
extern void weaponswitch(fpsent *d);
extern void avoidweapons(ai::avoidset &obstacles, float radius);
-
// scoreboard
extern void showscores(bool on);
extern void getbestplayers(vector<fpsent *> &best);
@@ -660,18 +585,14 @@ namespace game
extern void clearteaminfo();
extern void setteaminfo(const char *team, int frags);
extern int statuscolor(fpsent *d, int color);
-
// render
- struct playermodelinfo
- {
+ struct playermodelinfo {
const char *ffa, *blueteam, *redteam, *hudguns,
*vwep, *quad, *armour[3],
*ffaicon, *blueicon, *redicon;
bool ragdoll;
};
-
extern int playermodel, teamskins, testteam;
-
extern void saveragdoll(fpsent *d);
extern void clearragdolls();
extern void moveragdolls();
@@ -680,8 +601,7 @@ namespace game
extern vec hudgunorigin(int gun, const vec &from, const vec &to, fpsent *d);
}
-namespace server
-{
+namespace server {
extern const char *modename(int n, const char *unknown = "unknown");
extern const char *mastermodename(int n, const char *unknown = "unknown");
extern void startintermission();