diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index a1c7d227..22faae7d 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -621,29 +621,41 @@ void initclient() changeteam(rnd(2), false); } -entity flagdummies[2]; // in case the map does not provide flags +entity flagdummies[2] = // in case the map does not provide flags +{ + entity(-1, -1, -1, CTF_FLAG, 0, 0, 0, 0), + entity(-1, -1, -1, CTF_FLAG, 0, 1, 0, 0) +}; + +void initflag(int i) +{ + flaginfo &f = flaginfos[i]; + f.flagent = &flagdummies[i]; + f.pos = vec(f.flagent->x, f.flagent->y, f.flagent->z); + f.ack = true; + f.actor = NULL; + f.actor_cn = -1; + f.team = i; + f.state = m_ktf ? CTFF_IDLE : CTFF_INBASE; +} + +void zapplayerflags(playerent *p) +{ + loopi(2) if(flaginfos[i].state==CTFF_STOLEN && flaginfos[i].actor==p) initflag(i); +} void preparectf(bool cleanonly=false) { - loopi(2) flaginfos[i].flagent = &flagdummies[i]; + loopi(2) initflag(i); if(!cleanonly) { - loopi(2) - { - flaginfo &f = flaginfos[i]; - f.ack = true; - f.actor = NULL; - f.actor_cn = -1; - f.team = i; - f.state = m_ktf ? CTFF_IDLE : CTFF_INBASE; - } loopv(ents) { entity &e = ents[i]; if(e.type==CTF_FLAG) { e.spawned = true; - if(e.attr2>2) { conoutf("\f3invalid ctf-flag entity (%i)", i); e.attr2 = 0; } + if(e.attr2>=2) { conoutf("\f3invalid ctf-flag entity (%i)", i); e.attr2 = 0; } flaginfo &f = flaginfos[e.attr2]; f.flagent = &e; f.pos.x = (float) e.x; diff --git a/source/src/entity.h b/source/src/entity.h index 1c75bf23..3df62fb5 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -379,11 +379,13 @@ struct playerent : dynent, playerstate extern void removebounceents(playerent *owner); extern void detachsounds(playerent *owner); extern void removedynlights(physent *owner); + extern void zapplayerflags(playerent *owner); extern physent *camera1; extern void togglespect(); removebounceents(this); detachsounds(this); removedynlights(this); + zapplayerflags(this); if(this==camera1) togglespect(); }