Ejemplo n.º 1
0
void IBattle::ForceSpectator( User& user, bool spectator )
{
	if ( IsFounderMe() || user.BattleStatus().IsBot() ) {
		UserBattleStatus& status = user.BattleStatus();

		if ( !status.spectator ) { // leaving spectator status
			PlayerJoinedTeam( status.team );
			PlayerJoinedAlly( status.ally );
			if ( status.ready && !status.IsBot() ) m_players_ready++;
		}

		if (spectator) { // entering spectator status
			PlayerLeftTeam( status.team );
			PlayerLeftAlly( status.ally );
			if ( status.ready && !status.IsBot() ) m_players_ready--;
		}

		if ( IsFounderMe() ) {
			if ( status.spectator != spectator ) {
				if ( spectator ) {
					m_opts.spectators++;
				} else {
					m_opts.spectators--;
				}
				SendHostInfo( HI_Spectators );
			}
		}
		user.BattleStatus().spectator = spectator;
	}
}
Ejemplo n.º 2
0
User& IBattle::OnUserAdded( User& user )
{
	UserList::AddUser( user );
	UserBattleStatus& bs = user.BattleStatus();
	bs.spectator = false;
	bs.ready = false;
	bs.sync = SYNC_UNKNOWN;
	if ( !bs.IsBot() && IsFounderMe() && GetBattleType() == BT_Played ) {
		bs.team = GetFreeTeam( &user == &GetMe() );
		bs.ally = GetFreeAlly( &user == &GetMe() );
		bs.colour = GetFreeColour( user );
	}
	if ( IsFounderMe() && ( ( bs.pos.x < 0 ) || ( bs.pos.y < 0 ) ) ) {
		UserPosition& pos = bs.pos;
		pos = GetFreePosition();
		UserPositionChanged( user );
	}
	if ( !bs.spectator ) {
		PlayerJoinedAlly( bs.ally );
		PlayerJoinedTeam( bs.team );
	}
	if ( bs.spectator && IsFounderMe() ) m_opts.spectators++;
	if ( !bs.spectator && !bs.IsBot() ) {
		if ( bs.ready ) m_players_ready++;
		if ( bs.sync) m_players_sync++;
		if ( !bs.ready || !bs.sync ) m_ready_up_map[user.GetNick()] = time(0);
		if ( bs.ready && bs.sync ) m_players_ok++;
	}
	return user;
}
Ejemplo n.º 3
0
void IBattle::OnUserBattleStatusUpdated( User &user, UserBattleStatus status )
{

    UserBattleStatus previousstatus = user.BattleStatus();

    user.UpdateBattleStatus( status );
	unsigned int oldspeccount = m_opts.spectators;
	m_opts.spectators = 0;
	m_players_sync = 0;
	m_players_ready = 0;
	m_players_ok = 0;
	m_teams_sizes.clear();
	m_ally_sizes.clear();
	for ( unsigned int i = 0; i < GetNumUsers(); i++ )
	{
		User& loopuser = GetUser( i );
		UserBattleStatus& loopstatus = loopuser.BattleStatus();
		if ( loopstatus.spectator ) m_opts.spectators++;
		if ( !loopstatus.IsBot() )
		{
			if ( !loopstatus.spectator )
			{
				if ( loopstatus.ready && loopstatus.spectator ) m_players_ready++;
				if ( loopstatus.sync ) m_players_sync++;
				if ( loopstatus.ready && loopstatus.sync ) m_players_ok++;
				PlayerJoinedTeam( loopstatus.team );
				PlayerJoinedAlly( loopstatus.ally );
			}
		}
	}
	if ( oldspeccount != m_opts.spectators  )
	{
		if ( IsFounderMe() ) SendHostInfo( HI_Spectators );
	}
	if ( !status.IsBot() )
	{
		if ( ( status.ready && status.sync ) || status.spectator )
		{
			std::map<wxString, time_t>::iterator itor = m_ready_up_map.find( user.GetNick() );
			if ( itor != m_ready_up_map.end() )
			{
				m_ready_up_map.erase( itor );
			}
		}
		if ( ( !status.ready || !status.sync ) && !status.spectator )
		{
			std::map<wxString, time_t>::iterator itor = m_ready_up_map.find( user.GetNick() );
			if ( itor == m_ready_up_map.end() )
			{
				m_ready_up_map[user.GetNick()] = time(0);
			}
		}
	}
}
Ejemplo n.º 4
0
void IBattle::ForceAlly( User& user, int ally )
{

	if ( IsFounderMe() || user.BattleStatus().IsBot() ) {
		if ( !user.BattleStatus().spectator ) {
			PlayerLeftAlly( user.BattleStatus().ally );
			PlayerJoinedAlly( ally );
		}
		user.BattleStatus().ally = ally;
	}

}
Ejemplo n.º 5
0
//! (koshi) don't delete commented things please, they might be need in the future and i'm lazy
void IBattle::GetBattleFromScript( bool loadmapmod )
{

	BattleOptions opts;
	std::stringstream ss (GetScript());
	LSL::TDF::PDataList script( LSL::TDF::ParseTDF(ss) );

	LSL::TDF::PDataList replayNode ( script->Find("GAME") );
	if ( replayNode.ok() ) {

		std::string modname = replayNode->GetString("GameType");
		std::string modhash = replayNode->GetString("ModHash");
		if ( !modhash.empty() ) modhash = STD_STRING(MakeHashUnsigned(TowxString(modhash)));
		SetHostMod( modname, modhash );

		//don't have the maphash, what to do?
		//ui download function works with mapname if hash is empty, so works for now
		std::string mapname    = replayNode->GetString("MapName");
		std::string maphash    = replayNode->GetString("MapHash");
		if ( !maphash.empty() ) maphash = STD_STRING(MakeHashUnsigned(TowxString(maphash)));
		SetHostMap( mapname, maphash );

//        opts.ip         = replayNode->GetString( _T("HostIP") );
//        opts.port       = replayNode->GetInt  ( _T("HostPort"), DEFAULT_EXTERNAL_UDP_SOURCE_PORT );
		opts.spectators = 0;

		int playernum = replayNode->GetInt("NumPlayers", 0);
		int usersnum = replayNode->GetInt("NumUsers", 0);
		if ( usersnum > 0 ) playernum = usersnum;
//        int allynum = replayNode->GetInt  ( _T("NumAllyTeams"), 1);
//        int teamnum = replayNode->GetInt  ( _T("NumTeams"), 1);



		LSL::StringVector sides;
		if ( loadmapmod ) {
			sides = LSL::usync().GetSides(modname);
		}

		IBattle::TeamVec parsed_teams = GetParsedTeamsVec();
		IBattle::AllyVec parsed_allies = GetParsedAlliesVec();

		//[PLAYERX] sections
		for ( int i = 0; i < playernum ; ++i ) {
			LSL::TDF::PDataList player ( replayNode->Find(stdprintf("PLAYER%d", i)));
			LSL::TDF::PDataList bot ( replayNode->Find(stdprintf("AI%d", i )));
			if ( player.ok() || bot.ok() ) {
				if ( bot.ok() ) player = bot;
				User user(player->GetString("Name"), boost::to_upper_copy(player->GetString("CountryCode")), 0);
				UserBattleStatus& status = user.BattleStatus();
				status.isfromdemo = true;
				status.spectator = player->GetInt("Spectator", 0 );
				opts.spectators += user.BattleStatus().spectator;
				status.team = player->GetInt("Team");
				if ( !status.spectator ) {
					PlayerJoinedTeam( status.team );
				}
				status.sync = true;
				status.ready = true;
				if ( status.spectator ) m_opts.spectators++;
				else {
					if ( !bot.ok() ) {
						if ( status.ready) m_players_ready++;
						if ( status.sync ) m_players_sync++;
						if ( status.sync && status.ready ) m_players_ok++;
					}
				}

				//! (koshi) changed this from ServerRankContainer to RankContainer
				user.Status().rank = (UserStatus::RankContainer)player->GetInt("Rank", -1 );

				if ( bot.ok() ) {
					status.aishortname = bot->GetString("ShortName");
					status.aiversion = bot->GetString("Version");
					int ownerindex = bot->GetInt("Host");
					LSL::TDF::PDataList aiowner (replayNode->Find(stdprintf("PLAYER%d", ownerindex)));
					if ( aiowner.ok() ) {
						status.owner = aiowner->GetString("Name");
					}
				}

				IBattle::TeamInfoContainer teaminfos = parsed_teams[user.BattleStatus().team];
				if ( !teaminfos.exist ) {
					LSL::TDF::PDataList team( replayNode->Find( stdprintf("TEAM%d", user.BattleStatus().team) ));
					if ( team.ok() ) {
						teaminfos.exist = true;
						teaminfos.TeamLeader = team->GetInt("TeamLeader", 0 );
						teaminfos.StartPosX = team->GetInt("StartPosX", -1 );
						teaminfos.StartPosY = team->GetInt("StartPosY", -1 );
						teaminfos.AllyTeam = team->GetInt("AllyTeam", 0 );
						teaminfos.RGBColor = GetColorFromFloatStrng(TowxString(team->GetString("RGBColor")));
						teaminfos.SideName = team->GetString("Side", "");
						teaminfos.Handicap = team->GetInt("Handicap", 0 );
						const int sidepos = LSL::Util::IndexInSequence(sides, teaminfos.SideName);
						teaminfos.SideNum = sidepos;
						parsed_teams[ user.BattleStatus().team ] = teaminfos;
					}
				}
				if ( teaminfos.exist ) {
					status.ally = teaminfos.AllyTeam;
					status.pos.x = teaminfos.StartPosX;
					status.pos.y = teaminfos.StartPosY;
					status.colour = teaminfos.RGBColor;
					status.handicap = teaminfos.Handicap;
					if ( !status.spectator ) {
						PlayerJoinedAlly( status.ally );
					}
					if ( teaminfos.SideNum >= 0 ) status.side = teaminfos.SideNum;
					IBattle::AllyInfoContainer allyinfos = parsed_allies[user.BattleStatus().ally];
					if ( !allyinfos.exist ) {
						LSL::TDF::PDataList ally( replayNode->Find(stdprintf("ALLYTEAM%d", user.BattleStatus().ally) ) );
						if ( ally.ok() ) {
							allyinfos.exist = true;
							allyinfos.NumAllies = ally->GetInt("NumAllies", 0 );
							allyinfos.StartRectLeft = ally->GetInt("StartRectLeft", 0 );
							allyinfos.StartRectTop = ally->GetInt("StartRectTop", 0 );
							allyinfos.StartRectRight = ally->GetInt("StartRectRight", 0 );
							allyinfos.StartRectBottom = ally->GetInt("StartRectBottom", 0 );
							parsed_allies[ user.BattleStatus().ally ] = allyinfos;
							AddStartRect( user.BattleStatus().ally, allyinfos.StartRectTop, allyinfos.StartRectTop, allyinfos.StartRectRight, allyinfos.StartRectBottom );
						}
					}
				}

				AddUserFromDemo( user );
			}

		}
		SetParsedTeamsVec( parsed_teams );
		SetParsedAlliesVec( parsed_allies );

		//MMoptions, this'll fail unless loading map/mod into wrapper first
		if ( loadmapmod ) {
			LoadScriptMMOpts("mapoptions", replayNode );
			LoadScriptMMOpts("modoptions", replayNode );
		}

		opts.maxplayers = playernum ;

	}
	SetBattleOptions( opts );
}