summaryrefslogtreecommitdiff
path: root/src/fpsgame/fps.cpp
diff options
context:
space:
mode:
authorxolatile2025-08-06 22:54:55 +0200
committerxolatile2025-08-06 22:54:55 +0200
commit0a1172b75f571685c264a8b9d8ee224bbf11381f (patch)
treed041fdc68a60f0ebb48a3852bbcce6d9432f83d5 /src/fpsgame/fps.cpp
parentaffde05dc07a94643f1fd2751b2b441f57f73d7d (diff)
downloadxolatile-badassbug-0a1172b75f571685c264a8b9d8ee224bbf11381f.tar.xz
xolatile-badassbug-0a1172b75f571685c264a8b9d8ee224bbf11381f.tar.zst
Please do not hate me, it makes sense...
Diffstat (limited to 'src/fpsgame/fps.cpp')
-rw-r--r--src/fpsgame/fps.cpp654
1 files changed, 154 insertions, 500 deletions
diff --git a/src/fpsgame/fps.cpp b/src/fpsgame/fps.cpp
index da678f6..c74f5f4 100644
--- a/src/fpsgame/fps.cpp
+++ b/src/fpsgame/fps.cpp
@@ -1,39 +1,28 @@
#include "game.h"
-namespace game
-{
+namespace game {
bool intermission = false;
int maptime = 0, maprealtime = 0, maplimit = -1;
int respawnent = -1;
int lasthit = 0, lastspawnattempt = 0;
-
int following = -1, followdir = 0;
-
fpsent *player1 = NULL; // our client
vector<fpsent *> players; // other clients
int savedammo[NUMGUNS];
-
bool clientoption(const char *arg) { return false; }
-
- void taunt()
- {
+ void taunt() {
if(player1->state!=CS_ALIVE || player1->physstate<PHYS_SLOPE) return;
if(lastmillis-player1->lasttaunt<1000) return;
player1->lasttaunt = lastmillis;
addmsg(N_TAUNT, "rc", player1);
}
COMMAND(taunt, "");
-
- ICOMMAND(getfollow, "", (),
- {
+ ICOMMAND(getfollow, "", (), {
fpsent *f = followingplayer();
intret(f ? f->clientnum : -1);
});
-
- void follow(char *arg)
- {
- if(arg[0] ? player1->state==CS_SPECTATOR : following>=0)
- {
+ void follow(char *arg) {
+ if(arg[0] ? player1->state==CS_SPECTATOR : following>=0) {
following = arg[0] ? parseplayer(arg) : -1;
if(following==player1->clientnum) following = -1;
followdir = 0;
@@ -41,20 +30,15 @@ namespace game
}
}
COMMAND(follow, "s");
-
- void nextfollow(int dir)
- {
- if(player1->state!=CS_SPECTATOR || clients.empty())
- {
+ void nextfollow(int dir) {
+ if(player1->state!=CS_SPECTATOR || clients.empty()) {
stopfollowing();
return;
}
int cur = following >= 0 ? following : (dir < 0 ? clients.length() - 1 : 0);
- loopv(clients)
- {
+ loopv(clients) {
cur = (cur + dir + clients.length()) % clients.length();
- if(clients[cur] && clients[cur]->state!=CS_SPECTATOR)
- {
+ if(clients[cur] && clients[cur]->state!=CS_SPECTATOR) {
if(following<0) conoutf("follow on");
following = cur;
followdir = dir;
@@ -65,117 +49,85 @@ namespace game
}
ICOMMAND(nextfollow, "i", (int *dir), nextfollow(*dir < 0 ? -1 : 1));
-
const char *getclientmap() { return clientmap; }
-
- void resetgamestate()
- {
+ void resetgamestate() {
clearprojectiles();
clearbouncers();
}
-
- fpsent *spawnstate(fpsent *d) // reset player state not persistent accross spawns
- {
+ fpsent *spawnstate(fpsent *d) { // reset player state not persistent accross spawns {
d->respawn();
d->spawnstate(gamemode);
return d;
}
-
- void respawnself()
- {
+ void respawnself() {
if(ispaused()) return;
- if(m_mp(gamemode))
- {
+ if(m_mp(gamemode)) {
int seq = (player1->lifesequence<<16)|((lastmillis/1000)&0xFFFF);
if(player1->respawned!=seq) { addmsg(N_TRYSPAWN, "rc", player1); player1->respawned = seq; }
}
- else
- {
+ else {
spawnplayer(player1);
showscores(false);
lasthit = 0;
}
}
-
- fpsent *pointatplayer()
- {
+ fpsent *pointatplayer() {
loopv(players) if(players[i] != player1 && intersect(players[i], player1->o, worldpos)) return players[i];
return NULL;
}
-
- void stopfollowing()
- {
+ void stopfollowing() {
if(following<0) return;
following = -1;
followdir = 0;
conoutf("follow off");
}
-
- fpsent *followingplayer(fpsent *fallback)
- {
+ fpsent *followingplayer(fpsent *fallback) {
if(player1->state!=CS_SPECTATOR || following<0) return fallback;
fpsent *target = getclient(following);
if(target && target->state!=CS_SPECTATOR) return target;
return fallback;
}
-
- fpsent *hudplayer()
- {
+ fpsent *hudplayer() {
if(thirdperson && allowthirdperson()) return player1;
return followingplayer(player1);
}
-
- void setupcamera()
- {
+ void setupcamera() {
fpsent *target = followingplayer();
- if(target)
- {
+ if(target) {
player1->yaw = target->yaw;
player1->pitch = target->state==CS_DEAD ? 0 : target->pitch;
player1->o = target->o;
player1->resetinterp();
}
}
-
- bool allowthirdperson(bool msg)
- {
+ bool allowthirdperson(bool msg) {
return player1->state==CS_SPECTATOR || player1->state==CS_EDITING || m_edit || !multiplayer(msg);
}
ICOMMAND(allowthirdperson, "b", (int *msg), intret(allowthirdperson(*msg!=0) ? 1 : 0));
-
- bool detachcamera()
- {
+ bool detachcamera() {
fpsent *d = hudplayer();
return d->state==CS_DEAD;
}
-
- bool collidecamera()
- {
- switch(player1->state)
- {
+ bool collidecamera() {
+ switch(player1->state) {
case CS_EDITING: return false;
case CS_SPECTATOR: return followingplayer()!=NULL;
}
return true;
}
-
VARP(smoothmove, 0, 75, 100);
VARP(smoothdist, 0, 32, 64);
-
- void predictplayer(fpsent *d, bool move)
- {
+ void predictplayer(fpsent *d, bool move) {
d->o = d->newpos;
d->yaw = d->newyaw;
d->pitch = d->newpitch;
d->roll = d->newroll;
- if(move)
- {
+ if(move) {
moveplayer(d, 1, false);
d->newpos = d->o;
}
float k = 1.0f - float(lastmillis - d->smoothmillis)/smoothmove;
- if(k>0)
- {
+ if(k>0) {
d->o.add(vec(d->deltapos).mul(k));
d->yaw += d->deltayaw*k;
if(d->yaw<0) d->yaw += 360;
@@ -184,57 +136,42 @@ namespace game
d->roll += d->deltaroll*k;
}
}
-
- void otherplayers(int curtime)
- {
- loopv(players)
- {
+ void otherplayers(int curtime) {
+ loopv(players) {
fpsent *d = players[i];
if(d == player1 || d->ai) continue;
-
if(d->state==CS_DEAD && d->ragdoll) moveragdoll(d);
- else if(!intermission)
- {
+ else if(!intermission) {
if(lastmillis - d->lastaction >= d->gunwait) d->gunwait = 0;
if(d->quadmillis) entities::checkquad(curtime, d);
}
-
const int lagtime = totalmillis-d->lastupdate;
if(!lagtime || intermission) continue;
- else if(lagtime>1000 && d->state==CS_ALIVE)
- {
+ else if(lagtime>1000 && d->state==CS_ALIVE) {
d->state = CS_LAGGED;
continue;
}
- if(d->state==CS_ALIVE || d->state==CS_EDITING)
- {
+ if(d->state==CS_ALIVE || d->state==CS_EDITING) {
if(smoothmove && d->smoothmillis>0) predictplayer(d, true);
else moveplayer(d, 1, false);
}
else if(d->state==CS_DEAD && !d->ragdoll && lastmillis-d->lastpain<2000) moveplayer(d, 1, true);
}
}
-
- void checkslowmo()
- {
+ void checkslowmo() {
static int lastslowmohealth = 0;
server::forcegamespeed(intermission ? 100 : clamp(player1->health, 25, 200));
- if(player1->health<player1->maxhealth && lastmillis-max(maptime, lastslowmohealth)>player1->health*player1->health/2)
- {
+ if(player1->health<player1->maxhealth && lastmillis-max(maptime, lastslowmohealth)>player1->health*player1->health/2) {
lastslowmohealth = lastmillis;
player1->health++;
}
}
-
- void updateworld() // main game update loop
- {
+ void updateworld() { // main game update loop {
if(!maptime) { maptime = lastmillis; maprealtime = totalmillis; return; }
if(!curtime) { gets2c(); if(player1->clientnum>=0) c2sinfo(); return; }
-
physicsframe();
ai::navigate();
- if(player1->state != CS_DEAD && !intermission)
- {
+ if(player1->state != CS_DEAD && !intermission) {
if(player1->quadmillis) entities::checkquad(curtime, player1);
}
updateweapons(curtime);
@@ -242,19 +179,15 @@ namespace game
ai::update();
moveragdolls();
gets2c();
- if(connected)
- {
- if(player1->state == CS_DEAD)
- {
+ if(connected) {
+ if(player1->state == CS_DEAD) {
if(player1->ragdoll) moveragdoll(player1);
- else if(lastmillis-player1->lastpain<2000)
- {
+ else if(lastmillis-player1->lastpain<2000) {
player1->move = player1->strafe = 0;
moveplayer(player1, 10, true);
}
}
- else if(!intermission)
- {
+ else if(!intermission) {
if(player1->ragdoll) cleanragdoll(player1);
moveplayer(player1, 10, true);
swayhudgun(curtime);
@@ -263,139 +196,98 @@ namespace game
}
if(player1->clientnum>=0) c2sinfo(); // do this last, to reduce the effective frame lag
}
-
- float proximityscore(float x, float lower, float upper)
- {
+ float proximityscore(float x, float lower, float upper) {
if(x <= lower) return 1.0f;
if(x >= upper) return 0.0f;
float a = x - lower, b = x - upper;
return (b * b) / (a * a + b * b);
}
-
static inline float harmonicmean(float a, float b) { return a + b > 0 ? 2 * a * b / (a + b) : 0.0f; }
-
// avoid spawning near other players
- float ratespawn(dynent *d, const extentity &e)
- {
+ float ratespawn(dynent *d, const extentity &e) {
fpsent *p = (fpsent *)d;
vec loc = vec(e.o).addz(p->eyeheight);
float maxrange = !m_noitems ? 400.0f : 110.0f;
float minplayerdist = maxrange;
- loopv(players)
- {
+ loopv(players) {
const fpsent *o = players[i];
- if(o == p)
- {
+ if(o == p) {
if(m_noitems || (o->state != CS_ALIVE && lastmillis - o->lastpain > 3000)) continue;
}
else if(o->state != CS_ALIVE || isteam(o->team, p->team)) continue;
-
vec dir = vec(o->o).sub(loc);
float dist = dir.squaredlen();
if(dist >= minplayerdist*minplayerdist) continue;
dist = sqrtf(dist);
dir.mul(1/dist);
-
// scale actual distance if not in line of sight
if(raycube(loc, dir, dist) < dist) dist *= 1.5f;
minplayerdist = min(minplayerdist, dist);
}
return 1.0f - proximityscore(minplayerdist, 80.0f, maxrange);
}
-
- void pickgamespawn(fpsent *d)
- {
+ void pickgamespawn(fpsent *d) {
int ent = d == player1 && respawnent >= 0 ? respawnent : -1;
findplayerspawn(d, ent, 0);
}
-
- void spawnplayer(fpsent *d) // place at random spawn
- {
+ void spawnplayer(fpsent *d) { // place at random spawn {
pickgamespawn(d);
spawnstate(d);
- if(d==player1)
- {
+ if(d==player1) {
if(editmode) d->state = CS_EDITING;
else if(d->state != CS_SPECTATOR) d->state = CS_ALIVE;
}
else d->state = CS_ALIVE;
}
-
VARP(spawnwait, 0, 0, 1000);
-
- void respawn()
- {
- if(player1->state==CS_DEAD)
- {
+ void respawn() {
+ if(player1->state==CS_DEAD) {
player1->attacking = false;
respawnself();
}
}
COMMAND(respawn, "");
-
// inputs
-
VARP(attackspawn, 0, 1, 1);
-
- void doattack(bool on)
- {
+ void doattack(bool on) {
if(!connected || intermission) return;
if((player1->attacking = on) && attackspawn) respawn();
}
-
VARP(jumpspawn, 0, 1, 1);
-
- bool canjump()
- {
+ bool canjump() {
if(!connected || intermission) return false;
if(jumpspawn) respawn();
return player1->state!=CS_DEAD;
}
-
- bool allowmove(physent *d)
- {
+ bool allowmove(physent *d) {
if(d->type!=ENT_PLAYER) return true;
return !((fpsent *)d)->lasttaunt || lastmillis-((fpsent *)d)->lasttaunt>=1000;
}
-
VARP(hitsound, 0, 0, 1);
-
- void damaged(int damage, fpsent *d, fpsent *actor, bool local)
- {
+ void damaged(int damage, fpsent *d, fpsent *actor, bool local) {
if((d->state!=CS_ALIVE && d->state != CS_LAGGED && d->state != CS_SPAWNING) || intermission) return;
-
if(local) damage = d->dodamage(damage);
else if(actor==player1) return;
-
fpsent *h = hudplayer();
- if(h!=player1 && actor==h && d!=actor)
- {
+ if(h!=player1 && actor==h && d!=actor) {
if(hitsound && lasthit != lastmillis) playsound(S_HIT);
lasthit = lastmillis;
}
- if(d==h)
- {
+ if(d==h) {
damagecompass(damage, actor->o);
}
damageeffect(damage, d, d!=h);
-
ai::damaged(d, actor);
-
if(d->health<=0) { if(local) killed(d, actor); }
else if(d==h) playsound(S_PAIN6);
else playsound(S_PAIN1+rnd(5), &d->o);
}
-
VARP(deathscore, 0, 1, 1);
-
- void deathstate(fpsent *d, bool restore)
- {
+ void deathstate(fpsent *d, bool restore) {
d->state = CS_DEAD;
d->lastpain = lastmillis;
if(!restore) d->deaths++;
-
- if(d==player1)
- {
+ if(d==player1) {
if(deathscore) showscores(true);
disablezoom();
if(!restore) loopi(NUMGUNS) savedammo[i] = player1->ammo[i];
@@ -403,53 +295,41 @@ namespace game
d->roll = 0;
playsound(S_DIE1+rnd(2));
}
- else
- {
+ else {
d->move = d->strafe = 0;
d->resetinterp();
d->smoothmillis = 0;
playsound(S_DIE1+rnd(2), &d->o);
}
}
-
VARP(teamcolorfrags, 0, 1, 1);
-
/// xolatile: HUD frag messages
#define fragmessageduration (2000)
-
string hudfragger, hudfragged;
int hudfraggun, hudfragmillis;
-
- void sethudfragdata(char *fragger, char *fragged, int gunid)
- {
+ void sethudfragdata(char *fragger, char *fragged, int gunid) {
copystring(hudfragger, fragger ? fragger : "");
copystring(hudfragged, fragged);
hudfraggun = gunid;
hudfragmillis = lastmillis;
}
-
- void killed(fpsent *d, fpsent *actor)
- {
- if(d->state==CS_EDITING)
- {
+ void killed(fpsent *d, fpsent *actor) {
+ if(d->state==CS_EDITING) {
d->editstate = CS_DEAD;
d->deaths++;
if(d!=player1) d->resetinterp();
return;
}
else if((d->state!=CS_ALIVE && d->state != CS_LAGGED && d->state != CS_SPAWNING) || intermission) return;
-
fpsent *h = followingplayer(player1);
int contype = d==h || actor==h ? CON_FRAG_SELF : CON_FRAG_OTHER;
const char *dname = "", *aname = "";
- if(m_teammode && teamcolorfrags)
- {
+ if(m_teammode && teamcolorfrags) {
dname = teamcolorname(d, "you");
aname = teamcolorname(actor, "you");
}
- else
- {
+ else {
dname = colorname(d, NULL, "", "", "you");
aname = colorname(actor, NULL, "", "", "you");
}
@@ -457,22 +337,18 @@ namespace game
conoutf(contype, "\f2%s got killed by %s!", dname, aname);
else if(d==actor || actor->type==ENT_INANIMATE)
conoutf(contype, "\f2%s suicided%s", dname, d==player1 ? "!" : "");
- else if(isteam(d->team, actor->team))
- {
+ else if(isteam(d->team, actor->team)) {
contype |= CON_TEAMKILL;
if(actor==player1) conoutf(contype, "\f6%s fragged a teammate (%s)", aname, dname);
else if(d==player1) conoutf(contype, "\f6%s got fragged by a teammate (%s)", dname, aname);
else conoutf(contype, "\f2%s fragged a teammate (%s)", aname, dname);
}
- else
- {
- if(d==player1)
- {
+ else {
+ if(d==player1) {
conoutf(contype, "\f2%s got fragged by %s", dname, aname);
sethudfragdata(actor->name, d->name, actor->gunselect);
}
- else
- {
+ else {
conoutf(contype, "\f2%s fragged %s", aname, dname);
sethudfragdata(actor->name, d->name, actor->gunselect);
}
@@ -480,16 +356,12 @@ namespace game
deathstate(d);
ai::killed(d, actor);
}
-
- void timeupdate(int secs)
- {
+ void timeupdate(int secs) {
server::timeupdate(secs);
- if(secs > 0)
- {
+ if(secs > 0) {
maplimit = lastmillis + secs*1000;
}
- else
- {
+ else {
intermission = true;
player1->attacking = false;
conoutf(CON_GAMEINFO, "\f2intermission:");
@@ -497,36 +369,26 @@ namespace game
conoutf(CON_GAMEINFO, "\f2player frags: %d, deaths: %d", player1->frags, player1->deaths);
int accuracy = (player1->totaldamage*100)/max(player1->totalshots, 1);
conoutf(CON_GAMEINFO, "\f2player total damage dealt: %d, damage wasted: %d, accuracy(%%): %d", player1->totaldamage, player1->totalshots-player1->totaldamage, accuracy);
-
showscores(true);
disablezoom();
-
execident("intermission");
}
}
-
ICOMMAND(getfrags, "", (), intret(player1->frags));
ICOMMAND(getflags, "", (), intret(player1->flags));
ICOMMAND(getdeaths, "", (), intret(player1->deaths));
ICOMMAND(getaccuracy, "", (), intret((player1->totaldamage*100)/max(player1->totalshots, 1)));
ICOMMAND(gettotaldamage, "", (), intret(player1->totaldamage));
ICOMMAND(gettotalshots, "", (), intret(player1->totalshots));
-
vector<fpsent *> clients;
-
- fpsent *newclient(int cn) // ensure valid entity
- {
- if(cn < 0 || cn > max(0xFF, MAXCLIENTS + MAXBOTS))
- {
+ fpsent *newclient(int cn) { // ensure valid entity {
+ if(cn < 0 || cn > max(0xFF, MAXCLIENTS + MAXBOTS)) {
neterr("clientnum", false);
return NULL;
}
-
if(cn == player1->clientnum) return player1;
-
while(cn >= clients.length()) clients.add(NULL);
- if(!clients[cn])
- {
+ if(!clients[cn]) {
fpsent *d = new fpsent;
d->clientnum = cn;
clients[cn] = d;
@@ -534,18 +396,13 @@ namespace game
}
return clients[cn];
}
-
- fpsent *getclient(int cn) // ensure valid entity
- {
+ fpsent *getclient(int cn) { // ensure valid entity {
if(cn == player1->clientnum) return player1;
return clients.inrange(cn) ? clients[cn] : NULL;
}
-
- void clientdisconnected(int cn, bool notify)
- {
+ void clientdisconnected(int cn, bool notify) {
if(!clients.inrange(cn)) return;
- if(following==cn)
- {
+ if(following==cn) {
if(followdir) nextfollow(followdir);
else stopfollowing();
}
@@ -560,32 +417,22 @@ namespace game
DELETEP(clients[cn]);
cleardynentcache();
}
-
- void clearclients(bool notify)
- {
+ void clearclients(bool notify) {
loopv(clients) if(clients[i]) clientdisconnected(i, notify);
}
-
- void initclient()
- {
+ void initclient() {
player1 = spawnstate(new fpsent);
filtertext(player1->name, "Anonymous", false, false, MAXNAMELEN);
players.add(player1);
}
-
VARP(showmodeinfo, 0, 1, 1);
-
- void startgame()
- {
+ void startgame() {
clearprojectiles();
clearbouncers();
clearragdolls();
-
clearteaminfo();
-
// reset perma-state
- loopv(players)
- {
+ loopv(players) {
fpsent *d = players[i];
d->frags = d->flags = 0;
d->deaths = 0;
@@ -596,106 +443,74 @@ namespace game
d->lifesequence = -1;
d->respawned = d->suicided = -2;
}
-
intermission = false;
maptime = maprealtime = 0;
maplimit = -1;
-
conoutf(CON_GAMEINFO, "\f2game mode is %s", server::modename(gamemode));
-
const char *info = m_valid(gamemode) ? gamemodes[gamemode - STARTGAMEMODE].info : NULL;
if(showmodeinfo && info) conoutf(CON_GAMEINFO, "\f0%s", info);
-
showscores(false);
disablezoom();
lasthit = 0;
-
execident("mapstart");
}
-
- void loadingmap(const char *name)
- {
+ void loadingmap(const char *name) {
execident("playsong");
}
-
- void startmap(const char *name) // called just after a map load
- {
+ void startmap(const char *name) { // called just after a map load {
pwreset();
ai::savewaypoints();
ai::clearwaypoints(true);
-
respawnent = -1; // so we don't respawn at an old spot
if(!m_mp(gamemode)) spawnplayer(player1);
else findplayerspawn(player1, -1);
entities::resetspawns();
copystring(clientmap, name ? name : "");
-
sendmapinfo();
}
-
- const char *getmapinfo()
- {
+ const char *getmapinfo() {
return showmodeinfo && m_valid(gamemode) ? gamemodes[gamemode - STARTGAMEMODE].info : NULL;
}
-
- const char *getscreenshotinfo()
- {
+ const char *getscreenshotinfo() {
return server::modename(gamemode, NULL);
}
-
- void physicstrigger(physent *d, bool local, int floorlevel, int material)
- {
+ void physicstrigger(physent *d, bool local, int floorlevel, int material) {
if(d->type==ENT_INANIMATE) return;
if (floorlevel>0) { if(d==player1 || d->type!=ENT_PLAYER || ((fpsent *)d)->ai) msgsound(S_JUMP, d); }
else if(floorlevel<0) { if(d==player1 || d->type!=ENT_PLAYER || ((fpsent *)d)->ai) msgsound(S_LAND, d); }
}
-
- void dynentcollide(physent *d, physent *o, const vec &dir)
- {
+ void dynentcollide(physent *d, physent *o, const vec &dir) {
return;
}
-
- void msgsound(int n, physent *d)
- {
- if(!d || d==player1)
- {
+ void msgsound(int n, physent *d) {
+ if(!d || d==player1) {
addmsg(N_SOUND, "ci", d, n);
playsound(n);
}
- else
- {
+ else {
if(d->type==ENT_PLAYER && ((fpsent *)d)->ai)
addmsg(N_SOUND, "ci", d, n);
playsound(n, &d->o);
}
}
-
int numdynents() { return players.length(); }
-
- dynent *iterdynents(int i)
- {
+ dynent *iterdynents(int i) {
if(i<players.length()) return players[i];
i -= players.length();
return NULL;
}
-
- bool duplicatename(fpsent *d, const char *name = NULL, const char *alt = NULL)
- {
+ bool duplicatename(fpsent *d, const char *name = NULL, const char *alt = NULL) {
if(!name) name = d->name;
if(alt && d != player1 && !strcmp(name, alt)) return true;
loopv(players) if(d!=players[i] && !strcmp(name, players[i]->name)) return true;
return false;
}
-
static string cname[3];
static int cidx = 0;
-
- const char *colorname(fpsent *d, const char *name, const char *prefix, const char *suffix, const char *alt)
- {
+ const char *colorname(fpsent *d, const char *name, const char *prefix, const char *suffix, const char *alt) {
if(!name) name = alt && d == player1 ? alt : d->name;
bool dup = !name[0] || duplicatename(d, name, alt) || d->aitype != AI_NONE;
- if(dup || prefix[0] || suffix[0])
- {
+ if(dup || prefix[0] || suffix[0]) {
cidx = (cidx+1)%3;
if(dup) formatstring(cname[cidx], d->aitype == AI_NONE ? "%s%s \fs\f5(%d)\fr%s" : "%s%s \fs\f5[%d]\fr%s", prefix, name, d->clientnum, suffix);
else formatstring(cname[cidx], "%s%s%s", prefix, name, suffix);
@@ -703,58 +518,40 @@ namespace game
}
return name;
}
-
VARP(teamcolortext, 0, 1, 1);
-
- const char *teamcolorname(fpsent *d, const char *alt)
- {
+ const char *teamcolorname(fpsent *d, const char *alt) {
if(!teamcolortext || !m_teammode || d->state==CS_SPECTATOR) return colorname(d, NULL, "", "", alt);
return colorname(d, NULL, isteam(d->team, player1->team) ? "\fs\f1" : "\fs\f3", "\fr", alt);
}
-
- const char *teamcolor(const char *name, bool sameteam, const char *alt)
- {
+ const char *teamcolor(const char *name, bool sameteam, const char *alt) {
if(!teamcolortext || !m_teammode) return sameteam || !alt ? name : alt;
cidx = (cidx+1)%3;
formatstring(cname[cidx], sameteam ? "\fs\f1%s\fr" : "\fs\f3%s\fr", sameteam || !alt ? name : alt);
return cname[cidx];
}
-
- const char *teamcolor(const char *name, const char *team, const char *alt)
- {
+ const char *teamcolor(const char *name, const char *team, const char *alt) {
return teamcolor(name, team && isteam(team, player1->team), alt);
}
-
VARP(teamsounds, 0, 1, 1);
-
- void teamsound(bool sameteam, int n, const vec *loc)
- {
+ void teamsound(bool sameteam, int n, const vec *loc) {
playsound(n, loc, NULL, teamsounds ? (m_teammode && sameteam ? SND_USE_ALT : SND_NO_ALT) : 0);
}
-
- void teamsound(fpsent *d, int n, const vec *loc)
- {
+ void teamsound(fpsent *d, int n, const vec *loc) {
teamsound(isteam(d->team, player1->team), n, loc);
}
-
- void suicide(physent *d)
- {
- if(d==player1 || (d->type==ENT_PLAYER && ((fpsent *)d)->ai))
- {
+ void suicide(physent *d) {
+ if(d==player1 || (d->type==ENT_PLAYER && ((fpsent *)d)->ai)) {
if(d->state!=CS_ALIVE) return;
fpsent *pl = (fpsent *)d;
if(!m_mp(gamemode)) killed(pl, pl);
- else
- {
+ else {
int seq = (pl->lifesequence<<16)|((lastmillis/1000)&0xFFFF);
if(pl->suicided!=seq) { addmsg(N_SUICIDE, "rc", pl); pl->suicided = seq; }
}
}
}
ICOMMAND(suicide, "", (), suicide(player1));
-
- void drawicon(int icon, float x, float y, float sz)
- {
+ void drawicon(int icon, float x, float y, float sz) {
settexture("packages/hud/items.png");
float tsz = 0.25f, tx = tsz*(icon%4), ty = tsz*(icon/4);
gle::defvertex(2);
@@ -766,11 +563,8 @@ namespace game
gle::attribf(x+sz, y+sz); gle::attribf(tx+tsz, ty+tsz);
gle::end();
}
-
- float abovegameplayhud(int w, int h)
- {
- switch(hudplayer()->state)
- {
+ float abovegameplayhud(int w, int h) {
+ switch(hudplayer()->state) {
case CS_EDITING:
case CS_SPECTATOR:
return 1;
@@ -778,61 +572,47 @@ namespace game
return 1650.0f/1800.0f;
}
}
-
int ammohudup[3] = { GUN_CG, GUN_RL, GUN_GL },
ammohuddown[3] = { GUN_RIFLE, GUN_SG, GUN_PISTOL },
ammohudcycle[7] = { -1, -1, -1, -1, -1, -1, -1 };
-
- ICOMMAND(ammohudup, "V", (tagval *args, int numargs),
- {
+ ICOMMAND(ammohudup, "V", (tagval *args, int numargs), {
loopi(3) ammohudup[i] = i < numargs ? getweapon(args[i].getstr()) : -1;
});
-
- ICOMMAND(ammohuddown, "V", (tagval *args, int numargs),
- {
+ ICOMMAND(ammohuddown, "V", (tagval *args, int numargs), {
loopi(3) ammohuddown[i] = i < numargs ? getweapon(args[i].getstr()) : -1;
});
-
- ICOMMAND(ammohudcycle, "V", (tagval *args, int numargs),
- {
+ ICOMMAND(ammohudcycle, "V", (tagval *args, int numargs), {
loopi(7) ammohudcycle[i] = i < numargs ? getweapon(args[i].getstr()) : -1;
});
-
VARP(ammohud, 0, 1, 1);
-
- void drawammohud(fpsent *d)
- {
+ void drawammohud(fpsent *d) {
float x = HICON_X + 2*HICON_STEP, y = HICON_Y, sz = HICON_SIZE;
pushhudmatrix();
hudmatrix.scale(1/3.2f, 1/3.2f, 1);
flushhudmatrix();
float xup = (x+sz)*3.2f, yup = y*3.2f + 0.1f*sz;
- loopi(3)
- {
+ loopi(3) {
int gun = ammohudup[i];
if(gun < GUN_FIST || gun > GUN_PISTOL || gun == d->gunselect || !d->ammo[gun]) continue;
drawicon(HICON_FIST+gun, xup, yup, sz);
yup += sz;
}
float xdown = x*3.2f - sz, ydown = (y+sz)*3.2f - 0.1f*sz;
- loopi(3)
- {
+ loopi(3) {
int gun = ammohuddown[3-i-1];
if(gun < GUN_FIST || gun > GUN_PISTOL || gun == d->gunselect || !d->ammo[gun]) continue;
ydown -= sz;
drawicon(HICON_FIST+gun, xdown, ydown, sz);
}
int offset = 0, num = 0;
- loopi(7)
- {
+ loopi(7) {
int gun = ammohudcycle[i];
if(gun < GUN_FIST || gun > GUN_PISTOL) continue;
if(gun == d->gunselect) offset = i + 1;
else if(d->ammo[gun]) num++;
}
float xcycle = (x+sz/2)*3.2f + 0.5f*num*sz, ycycle = y*3.2f-sz;
- loopi(7)
- {
+ loopi(7) {
int gun = ammohudcycle[(i + offset)%7];
if(gun < GUN_FIST || gun > GUN_PISTOL || gun == d->gunselect || !d->ammo[gun]) continue;
xcycle -= sz;
@@ -840,9 +620,7 @@ namespace game
}
pophudmatrix();
}
-
- void hudquad(float x, float y, float w, float h, float r = 1, float g = 1, float b = 1, float tx = 0, float ty = 0, float tw = 1, float th = 1)
- {
+ void hudquad(float x, float y, float w, float h, float r = 1, float g = 1, float b = 1, float tx = 0, float ty = 0, float tw = 1, float th = 1) {
gle::defvertex(2);
gle::deftexcoord0();
gle::colorf(r, g, b);
@@ -853,20 +631,15 @@ namespace game
gle::attribf(x+w, y+h); gle::attribf(tx + tw, ty + th);
gle::end();
}
-
VARP(healthcolors, 0, 1, 1);
-
VARP(hudhealth, 0, 1, 1);
FVARP(hudhealthx, 0, 0, 1);
FVARP(hudhealthy, 0, 1, 1);
FVARP(hudhealthscale, 0.1, 1.0, 1.0);
-
- void drawhudhealth(fpsent *d, int w, int h)
- {
+ void drawhudhealth(fpsent *d, int w, int h) {
pushhudmatrix();
hudmatrix.scale(hudhealthscale, hudhealthscale, 1);
flushhudmatrix();
-
bvec healthcolor = bvec::hexcolor(healthcolors && !m_insta ?
(d->state==CS_DEAD ? 0x808080 :
(d->health<=25 ? 0xc02020 :
@@ -889,21 +662,16 @@ namespace game
defformatstring(health, "%d", d->state==CS_DEAD ? 0 : d->health);
float tw=0, th=0; text_boundsf(health, tw, th);
draw_text(health, offset.x+(125*proportion-tw)/2, offset.y+(healthbarh-th)/2, healthcolor.r, healthcolor.g, healthcolor.b);
-
pophudmatrix();
}
-
VARP(hudmaxhealth, 0, 1, 1);
FVARP(hudmaxhealthx, 0, 0.207, 1);
FVARP(hudmaxhealthy, 0, 0.97, 1);
FVARP(hudmaxhealthscale, 0.1, 1.0, 1.0);
-
- void drawhudmaxhealth(fpsent *d, int w, int h)
- {
+ void drawhudmaxhealth(fpsent *d, int w, int h) {
pushhudmatrix();
hudmatrix.scale(hudmaxhealthscale, hudmaxhealthscale, 1);
flushhudmatrix();
-
const float proportion = (w/15.0f)/160.0f;
const float healthboostw = 160*proportion;
const float healthboosth = 78*proportion;
@@ -917,23 +685,17 @@ namespace game
settexture("packages/hud/health_boost_quad.png");
hudquad(offset.x, offset.y, healthboostw, healthboosth);
}
-
pophudmatrix();
}
-
VARP(armourcolors, 0, 1, 1);
-
VARP(hudarmour, 0, 1, 1);
FVARP(hudarmourx, 0, 1, 1);
FVARP(hudarmoury, 0, 1, 1);
FVARP(hudarmourscale, 0.1, 1.0, 1.0);
-
- void drawhudarmour(fpsent *d, int w, int h)
- {
+ void drawhudarmour(fpsent *d, int w, int h) {
pushhudmatrix();
hudmatrix.scale(hudarmourscale, hudarmourscale, 1);
flushhudmatrix();
-
bvec armourcolor = bvec::hexcolor(d->armourtype == A_BLUE ? 0x83ade5 : (d->armourtype == A_GREEN ? 0x77f29e : (d->armourtype == A_YELLOW ? 0xf5f19b : 0xffffff)));
const float proportion = (w/4.0f)/600.0f;
const float armourbarw = 600*proportion;
@@ -951,25 +713,19 @@ namespace game
defformatstring(armour, "%d", d->state==CS_DEAD ? 0 : d->armour);
float tw=0, th=0; text_boundsf(armour, tw, th);
draw_text(armour, offset.x+(2*(600-63)*proportion-tw)/2, offset.y+(armourbarh-th)/2, armourcolor.r, armourcolor.g, armourcolor.b);
-
pophudmatrix();
}
-
- void drawhudicons(fpsent *d, int w, int h)
- {
+ void drawhudicons(fpsent *d, int w, int h) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
-
if(hudhealth) drawhudhealth(d, w, h);
if(hudmaxhealth) drawhudmaxhealth(d, w, h);
if(hudarmour) drawhudarmour(d, w, h);
-
if(d->state!=CS_DEAD) {
drawicon(HICON_FIST+d->gunselect, HICON_X + 2*HICON_STEP, HICON_Y);
if(ammohud) drawammohud(d);
}
}
-
VARP(gameclock, 0, 0, 1);
FVARP(gameclockscale, 1e-3f, 0.75f, 1e3f);
HVARP(gameclockcolour, 0, 0xFFFFFF, 0xFFFFFF);
@@ -978,34 +734,25 @@ namespace game
VARP(gameclockalign, -1, 0, 1);
FVARP(gameclockx, 0, 0.50f, 1);
FVARP(gameclocky, 0, 0.03f, 1);
-
- void drawgameclock(int w, int h)
- {
+ void drawgameclock(int w, int h) {
int secs = max(maplimit-lastmillis + 999, 0)/1000, mins = secs/60;
secs %= 60;
-
defformatstring(buf, "%d:%02d", mins, secs);
int tw = 0, th = 0;
text_bounds(buf, tw, th);
-
vec2 offset = vec2(gameclockx, gameclocky).mul(vec2(w, h).div(gameclockscale));
if(gameclockalign == 1) offset.x -= tw;
else if(gameclockalign == 0) offset.x -= tw/2.0f;
offset.y -= th/2.0f;
-
pushhudmatrix();
hudmatrix.scale(gameclockscale, gameclockscale, 1);
flushhudmatrix();
-
int color = mins < 1 ? gameclocklowcolour : gameclockcolour;
draw_text(buf, int(offset.x), int(offset.y), (color>>16)&0xFF, (color>>8)&0xFF, color&0xFF, gameclockalpha);
-
pophudmatrix();
}
-
extern int hudscore;
extern void drawhudscore(int w, int h);
-
VARP(ammobar, 0, 0, 1);
VARP(ammobaralign, -1, 0, 1);
VARP(ammobarhorizontal, 0, 0, 1);
@@ -1017,77 +764,58 @@ namespace game
FVARP(ammobarx, 0, 0.025f, 1.0f);
FVARP(ammobary, 0, 0.5f, 1.0f);
FVARP(ammobarscale, 0.1f, 0.5f, 1.0f);
-
- void drawammobarcounter(const vec2 &center, const fpsent *p, int gun)
- {
+ void drawammobarcounter(const vec2 &center, const fpsent *p, int gun) {
vec2 icondrawpos = vec2(center).sub(HICON_SIZE / 2);
int alpha = p->ammo[gun] ? 0xFF : 0x7F;
gle::color(bvec(0xFF, 0xFF, 0xFF), alpha);
drawicon(HICON_FIST + gun, icondrawpos.x, icondrawpos.y);
-
int fw, fh; text_bounds("000", fw, fh);
float labeloffset = HICON_SIZE / 2.0f + ammobarcountsep + ammobarcountscale * (ammobarhorizontal ? fh : fw) / 2.0f;
vec2 offsetdir = (ammobarhorizontal ? vec2(0, 1) : vec2(1, 0)).mul(ammobarflip ? -1 : 1);
vec2 labelorigin = vec2(offsetdir).mul(labeloffset).add(center);
-
pushhudmatrix();
hudmatrix.translate(labelorigin.x, labelorigin.y, 0);
hudmatrix.scale(ammobarcountscale, ammobarcountscale, 1);
flushhudmatrix();
-
defformatstring(label, "%d", p->ammo[gun]);
int tw, th; text_bounds(label, tw, th);
vec2 textdrawpos = vec2(-tw, -th).div(2);
float ammoratio = (float)p->ammo[gun] / itemstats[gun-GUN_SG].add;
bvec color = bvec::hexcolor(p->ammo[gun] == 0 || ammoratio >= 1.0f ? 0xFFFFFF : (ammoratio >= 0.5f ? 0xFFC040 : 0xFF0000));
draw_text(label, textdrawpos.x, textdrawpos.y, color.r, color.g, color.b, alpha);
-
pophudmatrix();
}
-
- static inline bool ammobargunvisible(const fpsent *d, int gun)
- {
+ static inline bool ammobargunvisible(const fpsent *d, int gun) {
return d->ammo[gun] > 0 || d->gunselect == gun;
}
-
- void drawammobar(int w, int h, fpsent *p)
- {
+ void drawammobar(int w, int h, fpsent *p) {
if(m_insta) return;
-
int NUMPLAYERGUNS = GUN_PISTOL - GUN_SG + 1;
int numvisibleguns = NUMPLAYERGUNS;
if(ammobarhideempty) loopi(NUMPLAYERGUNS) if(!ammobargunvisible(p, GUN_SG + i)) numvisibleguns--;
-
vec2 origin = vec2(ammobarx, ammobary).mul(vec2(w, h).div(ammobarscale));
vec2 offsetdir = ammobarhorizontal ? vec2(1, 0) : vec2(0, 1);
float stepsize = HICON_SIZE + ammobarsep;
float initialoffset = (ammobaralign - 1) * (numvisibleguns - 1) * stepsize / 2;
-
pushhudmatrix();
hudmatrix.scale(ammobarscale, ammobarscale, 1);
flushhudmatrix();
-
int numskippedguns = 0;
- loopi(NUMPLAYERGUNS) if(ammobargunvisible(p, GUN_SG + i) || !ammobarhideempty)
- {
+ loopi(NUMPLAYERGUNS) if(ammobargunvisible(p, GUN_SG + i) || !ammobarhideempty) {
float offset = initialoffset + (i - numskippedguns) * stepsize;
vec2 drawpos = vec2(offsetdir).mul(offset).add(origin);
drawammobarcounter(drawpos, p, GUN_SG + i);
}
else numskippedguns++;
-
pophudmatrix();
}
-
VARP(speedometer, 0, 1, 1);
FVARP(speedometerx, 0.0, 0.5, 1.0);
FVARP(speedometery, 0.0, 0.6, 1.0);
FVARP(speedometerscale, 0.1, 0.5, 1.0);
VARP(speedometercolor, 0, 1, 1);
FVARP(speedometeralpha, 0.0, 0.5, 1.0);
-
- void drawspeedometer(fpsent *d, int w, int h)
- {
+ void drawspeedometer(fpsent *d, int w, int h) {
int speedforreal = (int) (sqrtf(d->vel.squaredlen()) + 1.0f);
speedforreal = (speedforreal == 1) ? 0 : speedforreal;
vec colour = vec(255, 255, 255);
@@ -1101,35 +829,26 @@ namespace game
else if (speedforreal>180 && speedforreal<=240) colour = vec(90, 180, 60);
else colour = vec(30, 240, 30);
}
-
defformatstring(speedstring, "%d", speedforreal);
text_boundsf(speedstring, realw, realh);
vec2 offset = vec2(speedometerx, speedometery).mul(vec2(w, h).div(speedometerscale));
offset.x -= realw/2.0f;
offset.y -= realh/2.0f;
-
pushhudmatrix();
hudmatrix.scale(speedometerscale, speedometerscale, 1);
flushhudmatrix();
-
const int speedow = 220;
const int speedoh = 101;
settexture("packages/hud/speedometer.png");
hudquad(offset.x+realw/2.0f-speedow/2, offset.y+realh/2.0f-speedoh/2, speedow, speedoh);
-
draw_text(speedstring, int(offset.x), int(offset.y), colour.x, colour.y, colour.z, (int)(speedometeralpha*255.0f));
-
pophudmatrix();
}
-
- void gameplayhud(int w, int h)
- {
+ void gameplayhud(int w, int h) {
pushhudmatrix();
hudmatrix.scale(h/1800.0f, h/1800.0f, 1);
flushhudmatrix();
-
- if(player1->state==CS_SPECTATOR)
- {
+ if(player1->state==CS_SPECTATOR) {
int pw, ph, tw, th, fw, fh;
text_bounds(" ", pw, ph);
text_bounds("SPECTATOR", tw, th);
@@ -1138,36 +857,25 @@ namespace game
text_bounds(f ? colorname(f) : " ", fw, fh);
fh = max(fh, ph);
draw_text("SPECTATOR", w*1800/h - tw - pw, 1650 - th - fh);
- if(f)
- {
+ if(f) {
int color = statuscolor(f, 0xFFFFFF);
draw_text(colorname(f), w*1800/h - fw - pw, 1650 - fh, (color>>16)&0xFF, (color>>8)&0xFF, color&0xFF);
}
}
-
fpsent *d = hudplayer();
-
pophudmatrix();
-
if(d->state!=CS_EDITING && d->state!=CS_SPECTATOR) drawhudicons(d, w, h);
-
- if(d->state!=CS_EDITING && d->state!=CS_SPECTATOR && d->state!=CS_DEAD)
- {
+ if(d->state!=CS_EDITING && d->state!=CS_SPECTATOR && d->state!=CS_DEAD) {
if(ammobar) drawammobar(w, h, d);
if(speedometer) drawspeedometer(d, w, h);
}
-
- if(!m_edit)
- {
+ if(!m_edit) {
if(gameclock) drawgameclock(w, h);
if(hudscore) drawhudscore(w, h);
}
-
/// Frag message.
-
- if((hudfragmillis+fragmessageduration > lastmillis) && (lastmillis>fragmessageduration))
- {
+ if((hudfragmillis+fragmessageduration > lastmillis) && (lastmillis>fragmessageduration)) {
vec2 center = vec2(0.5*w, 0.2*h);
float width = 0, height = 0;
pushhudmatrix();
@@ -1180,69 +888,49 @@ namespace game
pophudmatrix();
}
}
-
- int clipconsole(int w, int h)
- {
+ int clipconsole(int w, int h) {
return 0;
}
-
VARP(teamcrosshair, 0, 1, 1);
VARP(hitcrosshair, 0, 425, 1000);
-
- const char *defaultcrosshair(int index)
- {
- switch(index)
- {
+ const char *defaultcrosshair(int index) {
+ switch(index) {
case 2: return "data/hit.png";
case 1: return "data/teammate.png";
default: return "data/crosshair.png";
}
}
-
- int selectcrosshair(vec &color)
- {
+ int selectcrosshair(vec &color) {
fpsent *d = hudplayer();
if(d->state==CS_SPECTATOR || d->state==CS_DEAD) return -1;
-
if(d->state!=CS_ALIVE) return 0;
-
int crosshair = 0;
if(lasthit && lastmillis - lasthit < hitcrosshair) crosshair = 2;
- else if(teamcrosshair)
- {
+ else if(teamcrosshair) {
dynent *o = intersectclosest(d->o, worldpos, d);
- if(o && o->type==ENT_PLAYER && isteam(((fpsent *)o)->team, d->team))
- {
+ if(o && o->type==ENT_PLAYER && isteam(((fpsent *)o)->team, d->team)) {
crosshair = 1;
color = vec(0, 0, 1);
}
}
-
- if(crosshair!=1 && !editmode && !m_insta)
- {
+ if(crosshair!=1 && !editmode && !m_insta) {
if(d->health<=25) color = vec(1, 0, 0);
else if(d->health<=50) color = vec(1, 0.5f, 0);
}
if(d->gunwait) color.mul(0.5f);
return crosshair;
}
-
- void lighteffects(dynent *e, vec &color, vec &dir)
- {
+ void lighteffects(dynent *e, vec &color, vec &dir) {
#if 0
fpsent *d = (fpsent *)e;
- if(d->state!=CS_DEAD && d->quadmillis)
- {
+ if(d->state!=CS_DEAD && d->quadmillis) {
float t = 0.5f + 0.5f*sinf(2*M_PI*lastmillis/1000.0f);
color.y = color.y*(1-t) + t;
}
#endif
}
-
- int maxsoundradius(int n)
- {
- switch(n)
- {
+ int maxsoundradius(int n) {
+ switch(n) {
case S_JUMP:
case S_LAND:
case S_WEAPLOAD:
@@ -1258,11 +946,9 @@ namespace game
return 500;
}
}
-
- bool serverinfostartcolumn(g3d_gui *g, int i)
- {
+ bool serverinfostartcolumn(g3d_gui *g, int i) {
static const char * const names[] = { "ping ", "players ", "mode ", "map ", "time ", "master ", "host ", "port ", "description " };
- static const float struts[] = { 7, 7, 12.5f, 14, 7, 8, 14, 7, 24.5f };
+ static const float struts[] = { 7, 7, 12.5f, 14, 7, 8, 14, 7, 24.5f };
if(size_t(i) >= sizeof(names)/sizeof(names[0])) return false;
g->pushlist();
g->text(names[i], 0xFFFF80, !i ? " " : NULL);
@@ -1270,34 +956,23 @@ namespace game
g->mergehits(true);
return true;
}
-
- void serverinfoendcolumn(g3d_gui *g, int i)
- {
+ void serverinfoendcolumn(g3d_gui *g, int i) {
g->mergehits(false);
g->column(i);
g->poplist();
}
-
- const char *mastermodecolor(int n, const char *unknown)
- {
+ const char *mastermodecolor(int n, const char *unknown) {
return (n>=MM_START && size_t(n-MM_START)<sizeof(mastermodecolors)/sizeof(mastermodecolors[0])) ? mastermodecolors[n-MM_START] : unknown;
}
-
- const char *mastermodeicon(int n, const char *unknown)
- {
+ const char *mastermodeicon(int n, const char *unknown) {
return (n>=MM_START && size_t(n-MM_START)<sizeof(mastermodeicons)/sizeof(mastermodeicons[0])) ? mastermodeicons[n-MM_START] : unknown;
}
-
- bool serverinfoentry(g3d_gui *g, int i, const char *name, int port, const char *sdesc, const char *map, int ping, const vector<int> &attr, int np)
- {
- if(ping < 0 || attr.empty() || attr[0]!=PROTOCOL_VERSION)
- {
- switch(i)
- {
+ bool serverinfoentry(g3d_gui *g, int i, const char *name, int port, const char *sdesc, const char *map, int ping, const vector<int> &attr, int np) {
+ if(ping < 0 || attr.empty() || attr[0]!=PROTOCOL_VERSION) {
+ switch(i) {
case 0:
if(g->button(" ", 0xFFFFDD, "serverunk")&G3D_UP) return true;
break;
-
case 1:
case 2:
case 3:
@@ -1305,18 +980,14 @@ namespace game
case 5:
if(g->button(" ", 0xFFFFDD)&G3D_UP) return true;
break;
-
case 6:
if(g->buttonf("%s ", 0xFFFFDD, NULL, name)&G3D_UP) return true;
break;
-
case 7:
if(g->buttonf("%d ", 0xFFFFDD, NULL, port)&G3D_UP) return true;
break;
-
case 8:
- if(ping < 0)
- {
+ if(ping < 0) {
if(g->button(sdesc, 0xFFFFDD)&G3D_UP) return true;
}
else if(g->buttonf("[%s protocol] ", 0xFFFFDD, NULL, attr.empty() ? "unknown" : (attr[0] < PROTOCOL_VERSION ? "older" : "newer"))&G3D_UP) return true;
@@ -1324,35 +995,26 @@ namespace game
}
return false;
}
-
- switch(i)
- {
- case 0:
- {
+ switch(i) {
+ case 0: {
const char *icon = attr.inrange(3) && np >= attr[3] ? "serverfull" : (attr.inrange(4) ? mastermodeicon(attr[4], "serverunk") : "serverunk");
if(g->buttonf("%d ", 0xFFFFDD, icon, ping)&G3D_UP) return true;
break;
}
-
case 1:
- if(attr.length()>=4)
- {
+ if(attr.length()>=4) {
if(g->buttonf(np >= attr[3] ? "\f3%d/%d " : "%d/%d ", 0xFFFFDD, NULL, np, attr[3])&G3D_UP) return true;
}
else if(g->buttonf("%d ", 0xFFFFDD, NULL, np)&G3D_UP) return true;
break;
-
case 2:
if(g->buttonf("%s ", 0xFFFFDD, NULL, attr.length()>=2 ? server::modename(attr[1], "") : "")&G3D_UP) return true;
break;
-
case 3:
if(g->buttonf("%.25s ", 0xFFFFDD, NULL, map)&G3D_UP) return true;
break;
-
case 4:
- if(attr.length()>=3 && attr[2] > 0)
- {
+ if(attr.length()>=3 && attr[2] > 0) {
int secs = clamp(attr[2], 0, 59*60+59),
mins = secs/60;
secs %= 60;
@@ -1363,36 +1025,28 @@ namespace game
case 5:
if(g->buttonf("%s%s ", 0xFFFFDD, NULL, attr.length()>=5 ? mastermodecolor(attr[4], "") : "", attr.length()>=5 ? server::mastermodename(attr[4], "") : "")&G3D_UP) return true;
break;
-
case 6:
if(g->buttonf("%s ", 0xFFFFDD, NULL, name)&G3D_UP) return true;
break;
-
case 7:
if(g->buttonf("%d ", 0xFFFFDD, NULL, port)&G3D_UP) return true;
break;
-
case 8:
if(g->buttonf("%.25s", 0xFFFFDD, NULL, sdesc)&G3D_UP) return true;
break;
}
return false;
}
-
// any data written into this vector will get saved with the map data. Must take care to do own versioning, and endianess if applicable. Will not get called when loading maps from other games, so provide defaults.
void writegamedata(vector<char> &extras) {}
void readgamedata(vector<char> &extras) {}
-
const char *savedconfig() { return "config.cfg"; }
const char *restoreconfig() { return "restore.cfg"; }
const char *defaultconfig() { return "data/defaults.cfg"; }
const char *autoexec() { return "autoexec.cfg"; }
const char *savedservers() { return "servers.cfg"; }
-
- void loadconfigs()
- {
+ void loadconfigs() {
execident("playsong");
-
execfile("auth.cfg", false);
}
}