Updated stuff

This commit is contained in:
Olle Rosenquist 2007-07-22 09:16:44 +00:00
parent baa65960a0
commit efe39aece6
2 changed files with 80 additions and 1 deletions

View file

@ -380,7 +380,7 @@ void gameobject::post_reset()
}
}
void gameobject::tick()
void gameobject::tick_dm()
{
if(game_over_tick == -1)
{
@ -421,6 +421,60 @@ void gameobject::tick()
}
}
void gameobject::tick_tdm()
{
if(game_over_tick == -1)
{
// game is running
// gather some stats
int totalscore[2] = {0,0};
int topscore_count = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(players[i].client_id != -1)
totalscore[players[i].team] += players[i].score;
}
if (totalscore[0] >= config.scorelimit)
topscore_count++;
if (totalscore[1] >= config.scorelimit)
topscore_count++;
// check score win condition
if((config.scorelimit > 0 && (totalscore[0] >= config.scorelimit || totalscore[1] >= config.scorelimit)) ||
(config.timelimit > 0 && (server_tick()-round_start_tick) >= config.timelimit*server_tickspeed()*60))
{
if(topscore_count == 1)
endround();
else
sudden_death = 1;
}
}
else
{
// game over.. wait for restart
if(server_tick() > game_over_tick+server_tickspeed()*10)
startround();
}
}
void gameobject::tick()
{
switch(gametype)
{
case GAMETYPE_TDM:
{
tick_tdm();
break;
}
default:
{
tick_dm();
break;
}
}
}
void gameobject::snap(int snapping_client)
{
obj_game *game = (obj_game *)snap_new_item(OBJTYPE_GAME, id, sizeof(obj_game));
@ -434,6 +488,20 @@ void gameobject::snap(int snapping_client)
game->gametype = gametype;
}
int gameobject::getteam(int notthisid)
{
int numplayers[2] = {0,0};
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(players[i].client_id != -1 && players[i].client_id != notthisid)
{
numplayers[players[i].team]++;
}
}
return numplayers[0] > numplayers[1] ? 1 : 0;
}
gameobject gameobj;
//////////////////////////////////////////////////
@ -1526,10 +1594,18 @@ void mods_client_enter(int client_id)
client_info info; // fetch login name
if(server_getclientinfo(client_id, &info))
{
strcpy(players[client_id].name, info.name);
}
else
strcpy(players[client_id].name, "(bot)");
if (gameobj.gametype == GAMETYPE_TDM)
{
// Check which team the player should be on
players[client_id].team = gameobj.getteam(client_id);
}
msg_pack_start(MSG_SETNAME, MSGFLAG_VITAL);
msg_pack_int(client_id);
msg_pack_string(players[client_id].name, 64);

View file

@ -116,7 +116,10 @@ public:
gameobject();
virtual void post_reset();
virtual void tick();
virtual void tick_dm();
virtual void tick_tdm();
virtual void snap(int snapping_client);
virtual int getteam(int notthisid);
};
extern gameobject gameobj;