team shuffle fixes, cleanups

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1465 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2007-12-22 13:57:44 +00:00
parent d8b205455a
commit 4e0a0309f9
7 changed files with 39 additions and 43 deletions
+12 -18
View File
@@ -89,7 +89,7 @@ void changeteam(int team, bool respawn) // force team and respawn
c2sinit = false;
if(m_ctf) tryflagdrop(NULL);
filtertext(player1->team, team_string(team), false, MAXTEAMLEN);
if(respawn) spawnplayer(player1);
if(respawn) addmsg(SV_CHANGETEAM, "r");
}
void newteam(char *name)
@@ -130,16 +130,17 @@ extern void thrownade(playerent *d, const vec &vel, bounceent *p);
void deathstate(playerent *pl)
{
pl->lastpain = lastmillis;
pl->attacking = false;
pl->state = CS_DEAD;
pl->pitch = 0;
//pl->roll = 60;
pl->strafe = 0;
pl->lastpain = pl->lastaction = lastmillis;
pl->move = pl->pitch = pl->strafe = pl->roll = 0;
pl->attacking = false;
if(pl == player1)
{
dblend = 0;
if(pl->inhandnade) thrownade(pl, vec(0,0,0), pl->inhandnade);
showscores(true);
setscope(false);
if(editmode) toggleedit();
}
}
@@ -423,18 +424,8 @@ void dokill(playerent *pl, playerent *act, bool gib)
else outf("\f2%s %s %s", aname, death, pname);
}
pl->state = CS_DEAD;
pl->lastaction = lastmillis;
pl->pitch = 0;
//pl->roll = 60;
pl->move = pl->strafe = 0;
pl->attacking = false;
playsound(S_DIE1+rnd(2), NULL, NULL, pl == player1 ? NULL : &pl->o);
if(pl==player1)
{
showscores(true);
setscope(false);
dblend = 0;
if(pl->inhandnade) thrownade(pl, vec(0,0,0), pl->inhandnade);
if(m_ctf) tryflagdrop(pl!=act && isteam(act->team, pl->team));
}
@@ -448,6 +439,9 @@ void dokill(playerent *pl, playerent *act, bool gib)
if(pl==act || isteam(pl->team, act->team)) act->frags--;
else act->frags += gib ? 2 : 1;
}
deathstate(pl);
playsound(S_DIE1+rnd(2), NULL, NULL, pl == player1 ? NULL : &pl->o);
}
VAR(minutesremaining, 1, 0, 0);
@@ -495,7 +489,7 @@ void initclient()
{
clientmap[0] = 0;
newname("unarmed");
changeteam(rnd(2));
changeteam(rnd(2), false);
}
entity flagdummies[2]; // in case the map does not provide flags
+5 -7
View File
@@ -165,11 +165,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
case SV_MAPCHANGE:
getstring(text, p);
changemapserv(text, getint(p));
if(m_arena && joining>2)
{
deathstate(player1);
showscores(true);
}
if(m_arena && joining>2) deathstate(player1);
mapchanged = true;
break;
@@ -504,12 +500,14 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
int cn = getint(p);
playerent *d = cn==getclientnum() ? player1 : newclient(cn);
if(!d) break;
if(d==player1)
// FIXME
/*if(d==player1)
{
if(editmode) toggleedit();
showscores(true);
}
d->state = CS_DEAD;
d->state = CS_DEAD;*/
deathstate(d);
break;
}
+1 -1
View File
@@ -327,7 +327,7 @@ void writecfg()
FILE *f = openfile(cfgname, "w");
if(!f) return;
fprintf(f, "// automatically written on exit, DO NOT MODIFY\n// delete this file to have defaults.cfg overwrite these settings\n// modify settings in game, or put settings in autoexec.cfg to override anything\n\n");
fprintf(f, "name %s\nteam %s\nskin %d\n", player1->name, player1->team, player1->nextskin);
fprintf(f, "name %s\nskin %d\n", player1->name, player1->nextskin);
extern Texture *crosshair;
fprintf(f, "loadcrosshair %s\n", crosshair->name+strlen("packages/misc/crosshairs/"));
extern int lowfps, highfps;
+1 -1
View File
@@ -117,7 +117,7 @@ char msgsizesl[] = // size inclusive message token, 0 for variable
SV_ARENAWIN, 2,
SV_SETMASTER, 2, SV_SETADMIN, 0, SV_SERVOPINFO, 3,
SV_CALLVOTE, 0, SV_CALLVOTESUC, 1, SV_CALLVOTEERR, 2, SV_VOTE, 2, SV_VOTERESULT, 2,
SV_FORCETEAM, 2, SV_AUTOTEAM, 2,
SV_FORCETEAM, 2, SV_AUTOTEAM, 2, SV_CHANGETEAM, 1,
SV_WHOIS, 2, SV_WHOISINFO, 3,
SV_LISTDEMOS, 1, SV_SENDDEMOLIST, 0, SV_GETDEMO, 2, SV_SENDDEMO, 0, SV_DEMOPLAYBACK, 2,
SV_CONNECT, 0,
+1 -1
View File
@@ -24,7 +24,7 @@ enum
SV_ARENAWIN,
SV_SETMASTER, SV_SETADMIN, SV_SERVOPINFO,
SV_CALLVOTE, SV_CALLVOTESUC, SV_CALLVOTEERR, SV_VOTE, SV_VOTERESULT,
SV_FORCETEAM, SV_AUTOTEAM,
SV_FORCETEAM, SV_AUTOTEAM, SV_CHANGETEAM,
SV_WHOIS, SV_WHOISINFO,
SV_LISTDEMOS, SV_SENDDEMOLIST, SV_GETDEMO, SV_SENDDEMO, SV_DEMOPLAYBACK,
SV_CONNECT,
+18 -14
View File
@@ -220,7 +220,7 @@ struct client // server side version of "dynent" type
void reset()
{
name[0] = 0;
name[0] = team[0] = 0;
position.setsizenodelete(0);
messages.setsizenodelete(0);
isauthed = false;
@@ -228,6 +228,13 @@ struct client // server side version of "dynent" type
lastvotecall = 0;
mapchange();
}
void zap()
{
type = ST_EMPTY;
role = CR_DEFAULT;
isauthed = false;
}
};
vector<client *> clients;
@@ -380,15 +387,6 @@ int numclients() { return countclients(ST_EMPTY, true); }
int numlocalclients() { return countclients(ST_LOCAL); }
int numnonlocalclients() { return countclients(ST_TCPIP); }
void zapclient(int c)
{
if(!clients.inrange(c)) return;
clients[c]->type = ST_EMPTY;
clients[c]->isauthed = false;
clients[c]->role = CR_DEFAULT;
}
int freeteam()
{
int teamsize[2] = {0, 0};
@@ -954,7 +952,7 @@ void disconnect_client(int n, int reason = -1)
else printf("disconnected client (%s)\n", c.hostname);
c.peer->data = (void *)-1;
if(reason>=0) enet_peer_disconnect(c.peer, reason);
zapclient(n);
clients[n]->zap();
sendf(-1, 1, "rii", SV_CDIS, n);
checkvotes();
}
@@ -1296,7 +1294,7 @@ void shuffleteams()
{
int team = rnd(2);
if(teamsize[team] >= numplayers/2) team = team_opposite(team);
forceteam(i, team, false);
forceteam(i, team, true);
teamsize[team]++;
}
}
@@ -1618,7 +1616,7 @@ void welcomepacket(ucharbuf &p, int n)
putint(p, -1);
}
putint(p, SV_AUTOTEAM);
putint(p, autoteam);
putint(p, autoteam ? 1 : 0);
if(motd)
{
putint(p, SV_TEXT);
@@ -1776,6 +1774,12 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
break;
}
case SV_CHANGETEAM:
cl->state.state = CS_DEAD;
cl->state.respawn();
sendf(-1, 1, "rii", SV_FORCEDEATH, cl->clientnum);
break;
case SV_TRYSPAWN:
if(cl->state.state!=CS_DEAD || cl->state.lastspawn>=0 || !canspawn(cl)) break;
if(cl->state.lastdeath) cl->state.respawn();
@@ -2300,7 +2304,7 @@ void extinfo_teamscorebuf(ucharbuf &p)
#ifndef STANDALONE
void localdisconnect()
{
loopv(clients) if(clients[i]->type==ST_LOCAL) zapclient(i);
loopv(clients) if(clients[i]->type==ST_LOCAL) clients[i]->zap();
}
void localconnect()
+1 -1
View File
@@ -108,7 +108,7 @@ struct autoteamaction : enableaction
void perform()
{
sendf(-1, 1, "ri2", SV_AUTOTEAM, (autoteam = enable) == 1 ? 1 : 0);
if(m_teammode) shuffleteams();
if(m_teammode && enable) shuffleteams();
}
autoteamaction(bool enable) : enableaction(enable)
{