remove yet another massive chunk of game/network code

This commit is contained in:
q66 2020-04-17 20:19:42 +02:00
parent b03c776b81
commit bebef4e338
17 changed files with 72 additions and 2817 deletions

View file

@ -45,7 +45,6 @@ client_src = [
'../game/game.cc',
'../game/render.cc',
'../game/server.cc',
'../game/weapon.cc'
]
threads_dep = dependency('threads')

View file

@ -1056,13 +1056,14 @@ struct animmodel : model
void setanim(int animpart, int num, int frame, int range, float speed, int priority = 0)
{
if(animpart<0 || animpart>=MAXANIMPARTS || num<0 || num>=game::numanims()) return;
const int NUM_ANIMS = 0; // FIXME
if(animpart<0 || animpart>=MAXANIMPARTS || num<0 || num>=NUM_ANIMS) return;
if(frame<0 || range<=0 || !meshes || !meshes->hasframes(frame, range))
{
conoutf("invalid frame %d, range %d in model %s", frame, range, model->name);
return;
}
if(!anims[animpart]) anims[animpart] = new vector<animspec>[game::numanims()];
if(!anims[animpart]) anims[animpart] = new vector<animspec>[NUM_ANIMS];
animspec &spec = anims[animpart][num].add();
spec.frame = frame;
spec.range = range;

View file

@ -91,12 +91,12 @@ void removetrackeddynlights(physent *owner)
void updatedynlights()
{
cleardynlights();
game::adddynlights();
//game::adddynlights();
loopv(dynlights)
{
dynlight &d = dynlights[i];
if(d.owner) game::dynlighttrack(d.owner, d.o, d.hud);
//if(d.owner) game::dynlighttrack(d.owner, d.o, d.hud);
d.calcradius();
d.calccolor();
}

View file

@ -1579,7 +1579,7 @@ bool bounce(physent *d, float secs, float elasticity, float waterfric, float gra
}
else if(collideplayer) break;
d->o = old;
game::bounced(d, collidewall);
//game::bounced(d, collidewall);
float c = collidewall.dot(d->vel),
k = 1.0f + (1.0f-elasticity)*c/d->vel.magnitude();
d->vel.mul(k);

View file

@ -1076,7 +1076,7 @@ bool matchanim(const char *name, const char *pattern)
ICOMMAND(findanims, "s", (char *name),
{
vector<int> anims;
game::findanims(name, anims);
//game::findanims(name, anims);
vector<char> buf;
string num;
loopv(anims)

View file

@ -199,7 +199,7 @@ struct partrenderer
{
o = p->o;
d = p->d;
if(type&PT_TRACK && p->owner) game::particletrack(p->owner, o, d);
//if(type&PT_TRACK && p->owner) game::particletrack(p->owner, o, d);
if(p->fade <= 5)
{
ts = 1;

View file

@ -1790,7 +1790,7 @@ template<class MDL> struct skelcommands : modelcommands<MDL, struct MDL::skelmes
if(!MDL::loading || MDL::loading->parts.empty()) { conoutf("not loading an %s", MDL::formatname()); return; }
vector<int> anims;
game::findanims(anim, anims);
//game::findanims(anim, anims);
if(anims.empty()) conoutf("could not find animation %s", anim);
else
{

View file

@ -2878,7 +2878,7 @@ namespace UI
else
{
vector<int> anims;
game::findanims(animspec, anims);
//game::findanims(animspec, anims);
if(anims.length()) anim = anims[0];
}
}
@ -2936,7 +2936,7 @@ namespace UI
int sx1, sy1, sx2, sy2;
window->calcscissor(sx, sy, sx+w, sy+h, sx1, sy1, sx2, sy2, false);
modelpreview::start(sx1, sy1, sx2-sx1, sy2-sy1, false, clipstack.length() > 0);
game::renderplayerpreview(model, color, team, weapon);
game::renderplayerpreview(model, color, weapon);
if(clipstack.length()) clipstack.last().scissor();
modelpreview::end();
}

View file

@ -501,7 +501,7 @@ template<class MDL> struct vertcommands : modelcommands<MDL, struct MDL::vertmes
{
if(!MDL::loading || MDL::loading->parts.empty()) { conoutf("not loading an %s", MDL::formatname()); return; }
vector<int> anims;
game::findanims(anim, anims);
//game::findanims(anim, anims);
if(anims.empty()) conoutf("could not find animation %s", anim);
else loopv(anims)
{

View file

@ -35,93 +35,6 @@ namespace game
settexture("media/interface/radar/radar.png", 3);
}
void drawradar(float x, float y, float s)
{
gle::defvertex(2);
gle::deftexcoord0();
gle::begin(GL_TRIANGLE_STRIP);
gle::attribf(x, y); gle::attribf(0, 0);
gle::attribf(x+s, y); gle::attribf(1, 0);
gle::attribf(x, y+s); gle::attribf(0, 1);
gle::attribf(x+s, y+s); gle::attribf(1, 1);
gle::end();
}
void drawteammate(gameent *d, float x, float y, float s, gameent *o, float scale, float blipsize = 1)
{
vec dir = d->o;
dir.sub(o->o).div(scale);
float dist = dir.magnitude2(), maxdist = 1 - 0.05f - 0.05f;
if(dist >= maxdist) dir.mul(maxdist/dist);
dir.rotate_around_z(-camera1->yaw*RAD);
float bs = 0.06f*blipsize*s,
bx = x + s*0.5f*(1.0f + dir.x),
by = y + s*0.5f*(1.0f + dir.y);
vec v(-0.5f, -0.5f, 0);
v.rotate_around_z((90+o->yaw-camera1->yaw)*RAD);
gle::attribf(bx + bs*v.x, by + bs*v.y); gle::attribf(0, 0);
gle::attribf(bx + bs*v.y, by - bs*v.x); gle::attribf(1, 0);
gle::attribf(bx - bs*v.x, by - bs*v.y); gle::attribf(1, 1);
gle::attribf(bx - bs*v.y, by + bs*v.x); gle::attribf(0, 1);
}
void setbliptex(int team, const char *type = "")
{
defformatstring(blipname, "media/interface/radar/blip%s%s.png", teamblipcolor[validteam(team) ? team : 0], type);
settexture(blipname, 3);
}
void drawplayerblip(gameent *d, float x, float y, float s, float blipsize = 1)
{
if(d->state != CS_ALIVE && d->state != CS_DEAD) return;
float scale = calcradarscale();
setbliptex(d->team, d->state == CS_DEAD ? "_dead" : "_alive");
gle::defvertex(2);
gle::deftexcoord0();
gle::begin(GL_QUADS);
drawteammate(d, x, y, s, d, scale, blipsize);
gle::end();
}
void drawteammates(gameent *d, float x, float y, float s)
{
if(!radarteammates) return;
float scale = calcradarscale();
int alive = 0, dead = 0;
loopv(players)
{
gameent *o = players[i];
if(o != d && o->state == CS_ALIVE && o->team == d->team)
{
if(!alive++)
{
setbliptex(d->team, "_alive");
gle::defvertex(2);
gle::deftexcoord0();
gle::begin(GL_QUADS);
}
drawteammate(d, x, y, s, o, scale);
}
}
if(alive) gle::end();
loopv(players)
{
gameent *o = players[i];
if(o != d && o->state == CS_DEAD && o->team == d->team)
{
if(!dead++)
{
setbliptex(d->team, "_dead");
gle::defvertex(2);
gle::deftexcoord0();
gle::begin(GL_QUADS);
}
drawteammate(d, x, y, s, o, scale);
}
}
if(dead) gle::end();
}
clientmode *cmode = NULL;
void setclientmode()
@ -166,7 +79,7 @@ namespace game
addmsg(N_EDITMODE, "ri", on ? 1 : 0);
if(player1->state==CS_DEAD) deathstate(player1, true);
disablezoom();
player1->suicided = player1->respawned = -2;
player1->respawned = -2;
checkfollow();
}
@ -508,15 +421,11 @@ namespace game
}
}
VARP(teamcolorchat, 0, 1, 1);
const char *chatcolorname(gameent *d) { return teamcolorchat ? teamcolorname(d, NULL) : colorname(d); }
const char *chatcolorname(gameent *d) { return colorname(d); }
void toserver(char *text) { conoutf(CON_CHAT, "%s:%s %s", chatcolorname(player1), teamtextcode[0], text); addmsg(N_TEXT, "rcs", player1, text); }
void toserver(char *text) { conoutf(CON_CHAT, "%s: %s", chatcolorname(player1), text); addmsg(N_TEXT, "rcs", player1, text); }
COMMANDN(say, toserver, "C");
void sayteam(char *text) { if(!m_teammode || !validteam(player1->team)) return; conoutf(CON_TEAMCHAT, "%s:%s %s", chatcolorname(player1), teamtextcode[player1->team], text); addmsg(N_SAYTEAM, "rcs", player1, text); }
COMMAND(sayteam, "C");
ICOMMAND(servcmd, "C", (char *cmd), addmsg(N_SERVCMD, "rs", cmd));
static void sendposition(gameent *d, packetbuf &q)
@ -761,24 +670,6 @@ namespace game
break;
}
case N_TELEPORT:
{
int cn = getint(p), tp = getint(p), td = getint(p);
gameent *d = getclient(cn);
if(!d || d->lifesequence < 0 || d->state==CS_DEAD) continue;
entities::teleporteffects(d, tp, td, false);
break;
}
case N_JUMPPAD:
{
int cn = getint(p), jp = getint(p);
gameent *d = getclient(cn);
if(!d || d->lifesequence < 0 || d->state==CS_DEAD) continue;
entities::jumppadeffects(d, jp, false);
break;
}
default:
neterr("type");
return;
@ -792,24 +683,8 @@ namespace game
{
if(d==player1) getint(p);
else d->state = getint(p);
d->frags = getint(p);
d->flags = getint(p);
d->deaths = getint(p);
}
d->lifesequence = getint(p);
d->health = getint(p);
d->maxhealth = getint(p);
if(resume && d==player1)
{
getint(p);
loopi(NUMGUNS) getint(p);
}
else
{
int gun = getint(p);
d->gunselect = clamp(gun, 0, NUMGUNS-1);
loopi(NUMGUNS) d->ammo[i] = getint(p);
}
}
void parsemessages(int cn, gameent *d, ucharbuf &p)
@ -847,7 +722,6 @@ namespace game
int cn = getint(p);
gameent *a = cn >= 0 ? getclient(cn) : NULL;
gamepaused = val;
player1->attacking = ACT_IDLE;
if(a) conoutf("%s %s the game", colorname(a), val ? "paused" : "resumed");
else conoutf("game is %s", val ? "paused" : "resumed");
break;
@ -883,21 +757,7 @@ namespace game
filtertext(text, text, true, true);
if(d->state!=CS_DEAD && d->state!=CS_SPECTATOR)
particle_textcopy(d->abovehead(), text, PART_TEXT, 2000, 0x32FF64, 4.0f, -8);
conoutf(CON_CHAT, "%s:%s %s", chatcolorname(d), teamtextcode[0], text);
break;
}
case N_SAYTEAM:
{
int tcn = getint(p);
gameent *t = getclient(tcn);
getstring(text, p);
filtertext(text, text, true, true);
if(!t) break;
int team = validteam(t->team) ? t->team : 0;
if(t->state!=CS_DEAD && t->state!=CS_SPECTATOR)
particle_textcopy(t->abovehead(), text, PART_TEXT, 2000, teamtextcolor[team], 4.0f, -8);
conoutf(CON_TEAMCHAT, "%s:%s %s", chatcolorname(t), teamtextcode[team], text);
conoutf(CON_CHAT, "%s: %s", chatcolorname(d), text);
break;
}
@ -934,10 +794,8 @@ namespace game
if(needclipboard >= 0) needclipboard++;
}
copystring(d->name, text, MAXNAMELEN+1);
d->team = getint(p);
if(!validteam(d->team)) d->team = 0;
d->playermodel = getint(p);
d->playercolor = getint(p);
d->playermodel = 0;
d->playercolor = 0;
break;
}
@ -963,7 +821,6 @@ namespace game
{
if(d)
{
if(d->state==CS_DEAD && d->lastpain) saveragdoll(d);
d->respawn();
}
parsestate(d, p);
@ -979,7 +836,6 @@ namespace game
int scn = getint(p);
gameent *s = getclient(scn);
if(!s) { parsestate(NULL, p); break; }
if(s->state==CS_DEAD && s->lastpain) saveragdoll(s);
if(s==player1)
{
if(editmode) toggleedit();
@ -988,37 +844,14 @@ namespace game
parsestate(s, p);
s->state = CS_ALIVE;
if(cmode) cmode->pickspawn(s);
else findplayerspawn(s, -1, m_teammode ? s->team : 0);
else findplayerspawn(s, -1, 0);
if(s == player1)
{
lasthit = 0;
}
if(cmode) cmode->respawned(s);
checkfollow();
addmsg(N_SPAWN, "rcii", s, s->lifesequence, s->gunselect);
break;
}
case N_HITPUSH:
{
int tcn = getint(p), atk = getint(p), damage = getint(p);
gameent *target = getclient(tcn);
vec dir;
loopk(3) dir[k] = getint(p)/DNF;
if(!target || !validatk(atk)) break;
target->hitpush(damage * (target->health<=0 ? deadpush : 1), dir, NULL, atk);
break;
}
case N_DIED:
{
int vcn = getint(p), acn = getint(p), frags = getint(p), tfrags = getint(p);
gameent *victim = getclient(vcn),
*actor = getclient(acn);
if(!actor) break;
actor->frags = frags;
if(!victim) break;
killed(victim, actor);
addmsg(N_SPAWN, "rci", s, s->lifesequence);
break;
}
@ -1179,10 +1012,6 @@ namespace game
d->ping = getint(p);
break;
case N_TIMEUP:
timeupdate(getint(p));
break;
case N_SERVMSG:
getstring(text, p);
conoutf("%s", text);

View file

@ -25,294 +25,47 @@ namespace entities
const char *itemname(int i)
{
return NULL;
#if 0
int t = ents[i]->type;
if(!validitem(t)) return NULL;
return itemstats[t-I_FIRST].name;
#endif
}
int itemicon(int i)
{
return -1;
#if 0
int t = ents[i]->type;
if(!validitem(t)) return -1;
return itemstats[t-I_FIRST].icon;
#endif
}
const char *entmdlname(int type)
{
static const char * const entmdlnames[MAXENTTYPES] =
{
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"game/teleport", NULL, NULL,
NULL
};
return entmdlnames[type];
return NULL;
}
const char *entmodel(const entity &e)
{
if(e.type == TELEPORT)
{
if(e.attr2 > 0) return mapmodelname(e.attr2);
if(e.attr2 < 0) return NULL;
}
return e.type < MAXENTTYPES ? entmdlname(e.type) : NULL;
return NULL;
}
void preloadentities()
{
loopi(MAXENTTYPES)
{
const char *mdl = entmdlname(i);
if(!mdl) continue;
preloadmodel(mdl);
}
loopv(ents)
{
extentity &e = *ents[i];
switch(e.type)
{
case TELEPORT:
if(e.attr2 > 0) preloadmodel(mapmodelname(e.attr2));
case JUMPPAD:
//if(e.attr4 > 0) preloadmapsound(e.attr4);
break;
}
}
}
void renderentities()
{
loopv(ents)
{
extentity &e = *ents[i];
int revs = 10;
switch(e.type)
{
case TELEPORT:
if(e.attr2 < 0) continue;
break;
default:
if(!e.spawned() || !validitem(e.type)) continue;
break;
}
const char *mdlname = entmodel(e);
if(mdlname)
{
vec p = e.o;
p.z += 1+sinf(lastmillis/100.0+e.o.x+e.o.y)/20;
rendermodel(mdlname, ANIM_MAPMODEL|ANIM_LOOP, p, lastmillis/(float)revs, 0, 0, MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED);
}
}
}
void addammo(int type, int &v, bool local)
{
#if 0
itemstat &is = itemstats[type-I_FIRST];
v += is.add;
if(v>is.max) v = is.max;
//if(local) msgsound(is.sound);
#endif
}
// these two functions are called when the server acknowledges that you really
// picked up the item (in multiplayer someone may grab it before you).
void pickupeffects(int n, gameent *d)
{
#if 0
if(!ents.inrange(n)) return;
extentity *e = ents[n];
int type = e->type;
if(!validitem(type)) return;
e->clearspawned();
e->clearnopickup();
if(!d) return;
itemstat &is = itemstats[type-I_FIRST];
gameent *h = followingplayer(player1);
if(d!=h || isthirdperson())
{
//particle_text(d->abovehead(), is.name, PART_TEXT, 2000, 0xFFC864, 4.0f, -8);
particle_icon(d->abovehead(), is.icon%4, is.icon/4, PART_HUD_ICON_GREY, 2000, 0xFFFFFF, 2.0f, -8);
}
playsound(itemstats[type-I_FIRST].sound, d!=h ? &d->o : NULL, NULL, 0, 0, 0, -1, 0, 1500);
d->pickup(type);
if(d==h) switch(type)
{
}
#endif
}
// these functions are called when the client touches the item
void teleporteffects(gameent *d, int tp, int td, bool local)
{
if(ents.inrange(tp) && ents[tp]->type == TELEPORT)
{
extentity &e = *ents[tp];
if(e.attr4 >= 0)
{
int snd = S_TELEPORT, flags = 0;
if(e.attr4 > 0) { snd = e.attr4; flags = SND_MAP; }
gameent *h = followingplayer(player1);
playsound(snd, d==h ? NULL : &e.o, NULL, flags);
if(d!=h && ents.inrange(td) && ents[td]->type == TELEDEST) playsound(snd, &ents[td]->o, NULL, flags);
}
}
if(local && d->clientnum >= 0)
{
sendposition(d);
packetbuf p(32, ENET_PACKET_FLAG_RELIABLE);
putint(p, N_TELEPORT);
putint(p, d->clientnum);
putint(p, tp);
putint(p, td);
sendclientpacket(p.finalize(), 0);
flushclient();
}
}
void jumppadeffects(gameent *d, int jp, bool local)
{
if(ents.inrange(jp) && ents[jp]->type == JUMPPAD)
{
extentity &e = *ents[jp];
if(e.attr4 >= 0)
{
int snd = S_JUMPPAD, flags = 0;
if(e.attr4 > 0) { snd = e.attr4; flags = SND_MAP; }
playsound(snd, d == followingplayer(player1) ? NULL : &e.o, NULL, flags);
}
}
if(local && d->clientnum >= 0)
{
sendposition(d);
packetbuf p(16, ENET_PACKET_FLAG_RELIABLE);
putint(p, N_JUMPPAD);
putint(p, d->clientnum);
putint(p, jp);
sendclientpacket(p.finalize(), 0);
flushclient();
}
}
void teleport(int n, gameent *d) // also used by monsters
{
int e = -1, tag = ents[n]->attr1, beenhere = -1;
for(;;)
{
e = findentity(TELEDEST, e+1);
if(e==beenhere || e<0) { conoutf(CON_WARN, "no teleport destination for tag %d", tag); return; }
if(beenhere<0) beenhere = e;
if(ents[e]->attr2==tag)
{
teleporteffects(d, n, e, true);
d->o = ents[e]->o;
d->yaw = ents[e]->attr1;
if(ents[e]->attr3 > 0)
{
vec dir;
vecfromyawpitch(d->yaw, 0, 1, 0, dir);
float speed = d->vel.magnitude2();
d->vel.x = dir.x*speed;
d->vel.y = dir.y*speed;
}
else d->vel = vec(0, 0, 0);
entinmap(d);
updatedynentcache(d);
break;
}
}
}
VARR(teleteam, 0, 1, 1);
void trypickup(int n, gameent *d)
{
extentity *e = ents[n];
switch(e->type)
{
default:
if(d->canpickup(e->type))
{
addmsg(N_ITEMPICKUP, "rci", d, n);
e->setnopickup(); // even if someone else gets it first
}
break;
case TELEPORT:
{
if(d->lastpickup==e->type && lastmillis-d->lastpickupmillis<500) break;
if(!teleteam && m_teammode) break;
if(e->attr3 > 0)
{
defformatstring(hookname, "can_teleport_%d", e->attr3);
if(!execidentbool(hookname, true)) break;
}
d->lastpickup = e->type;
d->lastpickupmillis = lastmillis;
teleport(n, d);
break;
}
case JUMPPAD:
{
if(d->lastpickup==e->type && lastmillis-d->lastpickupmillis<300) break;
d->lastpickup = e->type;
d->lastpickupmillis = lastmillis;
jumppadeffects(d, n, true);
d->falling = vec(0, 0, 0);
d->physstate = PHYS_FALL;
d->timeinair = 1;
d->vel = vec(e->attr3*10.0f, e->attr2*10.0f, e->attr1*12.5f);
break;
}
}
}
void checkitems(gameent *d)
{
if(d->state!=CS_ALIVE) return;
vec o = d->feetpos();
loopv(ents)
{
extentity &e = *ents[i];
if(e.type==NOTUSED) continue;
if((!e.spawned() || e.nopickup()) && e.type!=TELEPORT && e.type!=JUMPPAD) continue;
float dist = e.o.dist(o);
if(dist<(e.type==TELEPORT ? 16 : 12)) trypickup(i, d);
}
}
void putitems(packetbuf &p) // puts items in network stream and also spawns them locally
{
putint(p, N_ITEMLIST);
loopv(ents) if(validitem(ents[i]->type))
{
putint(p, i);
putint(p, ents[i]->type);
}
putint(p, -1);
}
void resetspawns() { loopv(ents) { extentity *e = ents[i]; e->clearspawned(); e->clearnopickup(); } }
void resetspawns() { }
void spawnitems(bool force)
{
loopv(ents)
{
extentity *e = ents[i];
if(validitem(e->type))
{
e->setspawned(force || !server::delayspawn(e->type));
e->clearnopickup();
}
}
}
void setspawn(int i, bool on) { if(ents.inrange(i)) { extentity *e = ents[i]; e->setspawned(on); e->clearnopickup(); } }
@ -331,44 +84,10 @@ namespace entities
void fixentity(extentity &e)
{
switch(e.type)
{
case FLAG:
e.attr5 = e.attr4;
e.attr4 = e.attr3;
case TELEDEST:
e.attr3 = e.attr2;
e.attr2 = e.attr1;
e.attr1 = (int)player1->yaw;
break;
}
}
void entradius(extentity &e, bool color)
{
switch(e.type)
{
case TELEPORT:
loopv(ents) if(ents[i]->type == TELEDEST && e.attr1==ents[i]->attr2)
{
renderentarrow(e, vec(ents[i]->o).sub(e.o).normalize(), e.o.dist(ents[i]->o));
break;
}
break;
case JUMPPAD:
renderentarrow(e, vec((int)(char)e.attr3*10.0f, (int)(char)e.attr2*10.0f, e.attr1*12.5f).normalize(), 4);
break;
case FLAG:
case TELEDEST:
{
vec dir;
vecfromyawpitch(e.attr1, 0, 1, 0, dir);
renderentarrow(e, dir, 4);
break;
}
}
}
bool printent(extentity &e, char *buf, int len)
@ -382,8 +101,6 @@ namespace entities
static const char * const entnames[MAXENTTYPES] =
{
"none?", "light", "mapmodel", "playerstart", "envmap", "particles", "sound", "spotlight", "decal",
"teleport", "teledest", "jumppad",
"flag"
};
return i>=0 && size_t(i)<sizeof(entnames)/sizeof(entnames[0]) ? entnames[i] : "";
}
@ -397,7 +114,6 @@ namespace entities
float dropheight(entity &e)
{
if(e.type==FLAG) return 0.0f;
return 4.0f;
}
#endif

View file

@ -2,7 +2,6 @@
namespace game
{
bool intermission = false;
int maptime = 0, maprealtime = 0, maplimit = -1;
int lasthit = 0, lastspawnattempt = 0;
@ -80,8 +79,6 @@ namespace game
void resetgamestate()
{
clearprojectiles();
clearbouncers();
}
gameent *spawnstate(gameent *d) // reset player state not persistent accross spawns
@ -101,7 +98,6 @@ namespace game
gameent *pointatplayer()
{
loopv(players) if(players[i] != player1 && intersect(players[i], player1->o, worldpos)) return players[i];
return NULL;
}
@ -173,32 +169,6 @@ namespace game
void otherplayers(int curtime)
{
loopv(players)
{
gameent *d = players[i];
if(d == player1) continue;
if(d->state==CS_DEAD && d->ragdoll) moveragdoll(d);
else if(!intermission)
{
if(lastmillis - d->lastaction >= d->gunwait) d->gunwait = 0;
}
const int lagtime = totalmillis-d->lastupdate;
if(!lagtime || intermission) continue;
else if(lagtime>1000 && d->state==CS_ALIVE)
{
d->state = CS_LAGGED;
continue;
}
if(d->state==CS_ALIVE || d->state==CS_EDITING)
{
crouchplayer(d, 10, false);
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 updateworld() // main game update loop
@ -207,30 +177,15 @@ namespace game
if(!curtime) { gets2c(); if(player1->clientnum>=0) c2sinfo(); return; }
physicsframe();
updateweapons(curtime);
otherplayers(curtime);
moveragdolls();
gets2c();
if(connected)
{
if(player1->state == CS_DEAD)
{
if(player1->ragdoll) moveragdoll(player1);
else if(lastmillis-player1->lastpain<2000)
{
player1->move = player1->strafe = 0;
moveplayer(player1, 10, true);
}
}
else if(!intermission)
{
if(player1->ragdoll) cleanragdoll(player1);
crouchplayer(player1, 10, true);
moveplayer(player1, 10, true);
swayhudgun(curtime);
entities::checkitems(player1);
if(cmode) cmode->checkitems(player1);
}
crouchplayer(player1, 10, true);
moveplayer(player1, 10, true);
entities::checkitems(player1);
if(cmode) cmode->checkitems(player1);
}
if(player1->clientnum>=0) c2sinfo(); // do this last, to reduce the effective frame lag
}
@ -238,7 +193,7 @@ namespace game
void spawnplayer(gameent *d) // place at random spawn
{
if(cmode) cmode->pickspawn(d);
else findplayerspawn(d, -1, m_teammode ? d->team : 0);
else findplayerspawn(d, -1, 0);
spawnstate(d);
if(d==player1)
{
@ -255,15 +210,6 @@ namespace game
{
if(player1->state==CS_DEAD)
{
player1->attacking = ACT_IDLE;
int wait = cmode ? cmode->respawnwait(player1) : 0;
if(wait>0)
{
lastspawnattempt = lastmillis;
//conoutf(CON_GAMEINFO, "\f2you must wait %d second%s before respawn!", wait, wait!=1 ? "s" : "");
return;
}
if(lastmillis < player1->lastpain + spawnwait) return;
respawnself();
}
}
@ -271,87 +217,36 @@ namespace game
// inputs
VARP(attackspawn, 0, 1, 1);
void doaction(int act)
{
if(!connected || intermission) return;
if((player1->attacking = act) && attackspawn) respawn();
}
ICOMMAND(shoot, "D", (int *down), doaction(*down ? ACT_SHOOT : ACT_IDLE));
ICOMMAND(melee, "D", (int *down), doaction(*down ? ACT_MELEE : ACT_IDLE));
VARP(jumpspawn, 0, 1, 1);
bool canjump()
{
if(!connected || intermission) return false;
if(!connected) return false;
if(jumpspawn) respawn();
return player1->state!=CS_DEAD;
}
bool cancrouch()
{
if(!connected || intermission) return false;
if(!connected) return false;
return player1->state!=CS_DEAD;
}
bool allowmove(physent *d)
{
if(d->type!=ENT_PLAYER) return true;
return !((gameent *)d)->lasttaunt || lastmillis-((gameent *)d)->lasttaunt>=1000;
return true;
}
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, "");
VARP(hitsound, 0, 0, 1);
void damaged(int damage, gameent *d, gameent *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;
gameent *h = hudplayer();
if(h!=player1 && actor==h && d!=actor)
{
if(hitsound && lasthit != lastmillis) playsound(S_HIT);
lasthit = lastmillis;
}
if(d==h)
{
damageblend(damage);
damagecompass(damage, actor->o);
}
damageeffect(damage, d, d!=h);
if(d->health<=0) { if(local) killed(d, actor); }
else if(d==h) playsound(S_PAIN2);
else playsound(S_PAIN1, &d->o);
}
void deathstate(gameent *d, bool restore)
{
d->state = CS_DEAD;
d->lastpain = lastmillis;
if(!restore)
{
gibeffect(max(-d->health, 0), d->vel, d);
d->deaths++;
}
if(d==player1)
{
disablezoom();
d->attacking = ACT_IDLE;
//d->pitch = 0;
d->roll = 0;
playsound(S_DIE2);
@ -372,39 +267,11 @@ namespace game
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;
else if(d->state!=CS_ALIVE && d->state != CS_LAGGED && d->state != CS_SPAWNING) return;
gameent *h = followingplayer(player1);
int contype = d==h || actor==h ? CON_FRAG_SELF : CON_FRAG_OTHER;
const char *dname = "", *aname = "";
if(m_teammode && teamcolorfrags)
{
dname = teamcolorname(d, "you");
aname = teamcolorname(actor, "you");
}
else
{
dname = colorname(d, NULL, "you");
aname = colorname(actor, NULL, "you");
}
if(d==actor)
conoutf(contype, "\f2%s suicided%s", dname, d==player1 ? "!" : "");
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) conoutf(contype, "\f2%s got fragged by %s", dname, aname);
else conoutf(contype, "\f2%s fragged %s", aname, dname);
}
deathstate(d);
}
@ -414,30 +281,8 @@ namespace game
{
maplimit = lastmillis + secs*1000;
}
else
{
intermission = true;
player1->attacking = ACT_IDLE;
if(cmode) cmode->gameover();
conoutf(CON_GAMEINFO, "\f2intermission:");
conoutf(CON_GAMEINFO, "\f2game has ended!");
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);
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<gameent *> clients;
gameent *newclient(int cn) // ensure valid entity
@ -474,7 +319,6 @@ namespace game
if(d)
{
if(notify && d->name[0]) conoutf("\f4leave:\f7 %s", colorname(d));
removeweapons(d);
removetrackedparticles(d);
removetrackeddynlights(d);
if(cmode) cmode->removeplayer(d);
@ -505,16 +349,11 @@ namespace game
void startgame()
{
clearprojectiles();
clearbouncers();
clearragdolls();
// reset perma-state
loopv(players) players[i]->startgame();
setclientmode();
intermission = false;
maptime = maprealtime = 0;
maplimit = -1;
@ -595,67 +434,18 @@ namespace game
const char *colorname(gameent *d, const char *name, const char * alt, const char *color)
{
if(!name) name = alt && d == player1 ? alt : d->name;
bool dup = !name[0] || duplicatename(d, name, alt);
if(dup || color[0])
{
if(dup) return tempformatstring("\fs%s%s \f5(%d)\fr", color, name, d->clientnum);
return tempformatstring("\fs%s%s\fr", color, name);
}
return name;
}
VARP(teamcolortext, 0, 1, 1);
const char *teamcolorname(gameent *d, const char *alt)
{
if(!teamcolortext || !m_teammode || !validteam(d->team) || d->state == CS_SPECTATOR) return colorname(d, NULL, alt);
return colorname(d, NULL, alt, teamtextcode[d->team]);
}
const char *teamcolor(const char *prefix, const char *suffix, int team, const char *alt)
{
if(!teamcolortext || !m_teammode || !validteam(team)) return alt;
return tempformatstring("\fs%s%s%s%s\fr", teamtextcode[team], prefix, teamnames[team], suffix);
}
VARP(teamsounds, 0, 1, 1);
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(gameent *d, int n, const vec *loc)
{
teamsound(isteam(d->team, player1->team), n, loc);
}
bool needminimap() { return false; }
void drawicon(int icon, float x, float y, float sz)
{
settexture("media/interface/hud/items.png");
float tsz = 0.25f, tx = tsz*(icon%4), ty = tsz*(icon/4);
gle::defvertex(2);
gle::deftexcoord0();
gle::begin(GL_TRIANGLE_STRIP);
gle::attribf(x, y); gle::attribf(tx, ty);
gle::attribf(x+sz, y); gle::attribf(tx+tsz, ty);
gle::attribf(x, y+sz); gle::attribf(tx, ty+tsz);
gle::attribf(x+sz, y+sz); gle::attribf(tx+tsz, ty+tsz);
gle::end();
}
float abovegameplayhud(int w, int h)
{
switch(hudplayer()->state)
{
case CS_EDITING:
case CS_SPECTATOR:
return 1;
default:
return 1650.0f/1800.0f;
}
return 1;
}
void drawhudicons(gameent *d)
@ -682,17 +472,9 @@ namespace game
return 0;
}
VARP(teamcrosshair, 0, 1, 1);
VARP(hitcrosshair, 0, 425, 1000);
const char *defaultcrosshair(int index)
{
switch(index)
{
case 2: return "media/interface/crosshair/default_hit.png";
case 1: return "media/interface/crosshair/teammate.png";
default: return "media/interface/crosshair/default.png";
}
return "media/interface/crosshair/default.png";
}
int selectcrosshair(vec &)

View file

@ -67,10 +67,6 @@ enum // static entity types
MAPSOUND = ET_SOUND,
SPOTLIGHT = ET_SPOTLIGHT,
DECAL = ET_DECAL,
TELEPORT, // attr1 = idx, attr2 = model, attr3 = tag
TELEDEST, // attr1 = angle, attr2 = idx
JUMPPAD, // attr1 = zpush, attr2 = ypush, attr3 = xpush
FLAG, // attr1 = angle, attr2 = team
MAXENTTYPES,
I_FIRST = 0,
@ -81,67 +77,12 @@ struct gameentity : extentity
{
};
enum { GUN_RAIL = 0, GUN_PULSE, NUMGUNS };
enum { ACT_IDLE = 0, ACT_SHOOT, ACT_MELEE, NUMACTS };
enum { ATK_RAIL_SHOOT = 0, ATK_RAIL_MELEE, ATK_PULSE_SHOOT, ATK_PULSE_MELEE, NUMATKS };
#define validgun(n) ((n) >= 0 && (n) < NUMGUNS)
#define validact(n) ((n) >= 0 && (n) < NUMACTS)
#define validatk(n) ((n) >= 0 && (n) < NUMATKS)
enum
{
M_TEAM = 1<<0,
M_OVERTIME = 1<<1,
M_EDIT = 1<<2,
M_DEMO = 1<<3,
M_LOCAL = 1<<4,
M_LOBBY = 1<<5,
M_RAIL = 1<<6,
M_PULSE = 1<<7
M_EDIT = 1<<0
};
static struct gamemodeinfo
{
const char *name, *prettyname;
int flags;
const char *info;
} gamemodes[] =
{
{ "demo", "Demo", M_DEMO | M_LOCAL, NULL},
{ "edit", "Edit", M_EDIT, "Cooperative Editing:\nEdit maps with multiple players simultaneously." },
{ "rdm", "rDM", M_LOBBY | M_RAIL, "Railgun Deathmatch:\nFrag everyone with railguns to score points." },
{ "pdm", "pDM", M_LOBBY | M_PULSE, "Pulse Rifle Deathmatch:\nFrag everyone with pulse rifles to score points." },
{ "rtdm", "rTDM", M_TEAM | M_RAIL, "Railgun Team Deathmatch:\nFrag \fs\f3the enemy team\fr with railguns to score points for \fs\f1your team\fr." },
{ "ptdm", "pTDM", M_TEAM | M_PULSE, "Pulse Rifle Team Deathmatch:\nFrag \fs\f3the enemy team\fr with pulse rifles to score points for \fs\f1your team\fr." },
};
#define STARTGAMEMODE (-1)
#define NUMGAMEMODES ((int)(sizeof(gamemodes)/sizeof(gamemodes[0])))
#define m_valid(mode) ((mode) >= STARTGAMEMODE && (mode) < STARTGAMEMODE + NUMGAMEMODES)
#define m_check(mode, flag) (m_valid(mode) && gamemodes[(mode) - STARTGAMEMODE].flags&(flag))
#define m_checknot(mode, flag) (m_valid(mode) && !(gamemodes[(mode) - STARTGAMEMODE].flags&(flag)))
#define m_checkall(mode, flag) (m_valid(mode) && (gamemodes[(mode) - STARTGAMEMODE].flags&(flag)) == (flag))
#define m_teammode false
#define m_overtime false
#define isteam(a,b) false
#define m_rail false
#define m_pulse false
#define m_demo false
#define m_edit true
#define m_lobby false
#define m_timed false
#define m_botmode false
#define m_mp(mode) false
enum { MM_AUTH = -1, MM_OPEN = 0, MM_VETO, MM_LOCKED, MM_PRIVATE, MM_PASSWORD, MM_START = MM_AUTH, MM_INVALID = MM_START - 1 };
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" };
// hardcoded sounds, defined in sounds.cfg
enum
@ -156,22 +97,16 @@ enum
// network messages codes, c2s, c2c, s2c
enum { PRIV_NONE = 0, PRIV_MASTER, PRIV_AUTH, PRIV_ADMIN };
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,
N_TRYSPAWN, N_SPAWNSTATE, N_SPAWN, N_FORCEDEATH,
N_GUNSELECT, N_TAUNT,
N_MAPCHANGE, N_MAPVOTE, N_TEAMINFO, N_ITEMSPAWN, N_ITEMPICKUP, N_ITEMACC, N_TELEPORT, N_JUMPPAD,
N_MAPCHANGE,
N_PING, N_PONG, N_CLIENTPING,
N_TIMEUP, N_FORCEINTERMISSION,
N_SERVMSG, N_ITEMLIST, N_RESUME<