/**/
main()
{
	if(level.ex_roundbased) return;
	
	shouldcount = true;
	color = (0,1,0);
	clcolch = 0;
	
	while(shouldcount)
	{
		anscore = false;
		antime = undefined;
		passedtime = (getTime() - level.starttime) / 1000;
		secondsleft = int((level.timelimit*60) - (passedtime));
		wait 1;

		if(level.ex_timeannouncer != 2 && isDefined(level.clock) && clcolch == 0)
		{
			level.clock.color = (0,1,0);
			clcolch = 1;
		}

		if(level.scorelimit != 0 && level.ex_teamplay)
		{
			alliescore = getTeamScore("allies");
			axisscore = getTeamScore("axis");

			if(axisscore >= level.scorelimit || alliescore >= level.scorelimit) shouldcount = false;
		}

		if (secondsleft < 5) shouldcount = false;
		
		if(level.mapended) return;

		if(secondsleft > 300) continue;

		if (secondsleft == 300) { antime = "fivemins"; color = (0,1,1); anscore = true; }     // 5 mins
		if (secondsleft == 120) { antime = "twomins"; color = (.1,.6,.5); anscore = true; }   // 2 mins
		if (secondsleft == 60) { antime = "onemin"; color = (.7,.2,.2); anscore = true; }     // 1 min
		if (secondsleft == 30) { antime = "thirtysecs"; color = (.7,.7,.7); anscore = true; } // 30 secs
		if (secondsleft == 20) { antime = "twentysecs"; color = (1,1,0); }                    // 20 secs
		if (secondsleft == 10) { antime = "tensecs"; color = (1,0,0); anscore = true; }       // 10 secs
		if (secondsleft == 5) antime = "fftto";                                               // 5 secs

		if(isDefined(antime))
		{
			if(level.ex_timeannouncer != 2 && isDefined(level.clock)) level.clock.color = color;
			
			players = getEntArray("player", "classname");

			for(ta=0;ta<players.size;ta++)
				if(isplayer(players[ta])) players[ta] thread announce(antime,anscore);
		}
	}
}

announce(antime,anscore)
{
	// announce time
	if(level.ex_antime) self playLocalSound(antime);
	
	if(!anscore || !level.ex_anscore || level.scorelimit <= 0 || !level.ex_teamplay)
		return;

	alliescore = getTeamScore("allies");
	axisscore = getTeamScore("axis");
	team = undefined;
	txt = undefined;
	aname = undefined;
	closetowin = false;

	if(axisscore == alliescore)
	{
		self iprintln(&"SCORES_LEVEL");
		return;
	}

	if(axisscore < alliescore)
	{
		ascore = level.scorelimit - alliescore;
		team = "allies";
	}
	else
	{
		ascore = level.scorelimit - axisscore;
		team = "axis";
	}

	if(ascore > (level.scorelimit - 10))
	 	closetowin = true;
	
	if( self.pers["team"] == "allies") // if teams are not near winning, show scores
	{
		aname = &"SCORES_GERMAN";
		
		if(!closetowin)
		{
			if(alliescore < axisscore)
				self iprintln(&"SCORES_YOUR_TEAM", (axisscore - alliescore), &"SCORES_BEHIND", aname);
			else if(alliescore > axisscore)
				self iprintln(&"SCORES_YOUR_TEAM", (alliescore - axisscore), &"SCORES_AHEAD", aname);
		}
	}
	else
	{
		switch(game["allies"])
		{
			case "american":
				aname = &"SCORES_AMERICAN";
				break;
	
			case "british":
				aname = &"SCORES_BRITISH";
				break;
		
			case "russian":
				aname = &"SCORES_RUSSIAN";
				break;
		}
		
		if(!closetowin)
		{
			if(axisscore < alliescore)
				self iprintln(&"SCORES_YOUR_TEAM", (alliescore - axisscore), &"SCORES_BEHIND", aname);
			else if(axisscore > alliescore)
				self iprintln(&"SCORES_YOUR_TEAM", (axisscore - alliescore), &"SCORES_AHEAD", aname);
		}
	}

	if(!closetowin) return;

	// a team is close to winning
	if(self.pers["team"] != team) self iprintln(&"SCORES_TEAM_LOSING_MSGA", aname, &"SCORES_TEAM_LOSING_MSGB", ascore, &"SCORES_TEAM_WINNING");
	else self iprintln(&"SCORES_YOUR_TEAM", ascore, &"SCORES_TEAM_WINNING");
}
