about summary refs log tree commit diff
path: root/src/game/server/srv_tdm.cpp
blob: 3ed35dca4a923e88d363d0675600173f8fdf3ea5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <engine/config.h>
#include "srv_common.h"
#include "srv_tdm.h"

void gameobject_tdm::tick()
{
	if(game_over_tick == -1)
	{
		// game is running
		teamscore[0] = 0;
		teamscore[1] = 0;
		
		// gather some stats
		int topscore_count = 0;
		for(int i = 0; i < MAX_CLIENTS; i++)
		{
			if(players[i].client_id != -1)
				teamscore[players[i].team] += players[i].score;
		}
		if (teamscore[0] >= config.scorelimit)
			topscore_count++;
		if (teamscore[1] >= config.scorelimit)
			topscore_count++;
		
		// check score win condition
		if((config.scorelimit > 0 && (teamscore[0] >= config.scorelimit || teamscore[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();
	}
}