<commit_before>#include "ibattle.h"

#include <lslutils/debug.h>
#include <lslutils/misc.h>
#include <lslutils/conversion.h>
#include <lslutils/config.h>
#include <lslutils/autopointers.h>
#include <lslunitsync/unitsync.h>
#include <lslunitsync/optionswrapper.h>

//SL includes -- bad
#if HAVE_SPRINGLOBBY
    #include "settings.h"
#else
#include <lslutils/mock_settings.h>
#endif

#include "signals.h"
#include "tdfcontainer.h"

#include <algorithm>
#include <boost/foreach.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>

#define ASSERT_EXCEPTION(cond,msg) do { if (!(cond)) { LSL_THROW( battle, msg ); } } while (0)

namespace LSL {
namespace Battle {

boost::asio::io_service _io;
const boost::posix_time::seconds TIMER_INTERVAL(1000);
const unsigned int TIMER_ID               = 101;

BattleOptions::BattleOptions()
	: battleid(-1)
	, islocked(false)
	, battletype(Enum::BT_Played)
	, ispassworded(false)
	, rankneeded(0)
	, proxyhost("")
	, userelayhost(false)
	, lockexternalbalancechanges(false)
	, nattype(Enum::NAT_None)
	, port(Enum::DEFAULT_SERVER_PORT)
	, externaludpsourceport(Enum::DEFAULT_EXTERNAL_UDP_SOURCE_PORT)
	, internaludpsourceport(Enum::DEFAULT_EXTERNAL_UDP_SOURCE_PORT)
	, maxplayers(0)
    , spectators(0)
{}

IBattle::IBattle():
	m_map_loaded(false)
	, m_mod_loaded(false)
	, m_map_exists(false)
	, m_mod_exists(false)
	, m_previous_local_mod_name( std::string() )
	, m_ingame(false)
	, m_auto_unspec(false)
	, m_generating_script(false)
	, m_players_ready(0)
	, m_players_sync(0)
	, m_players_ok(0)
	, m_is_self_in(false)
    , m_timer ( new boost::asio::deadline_timer( _io, TIMER_INTERVAL ) )
    , m_opt_wrap( new OptionsWrapper() )
{
}


IBattle::~IBattle()
{
    m_timer->cancel();
	if ( m_is_self_in ) usync().UnSetCurrentMod();
}

bool IBattle::IsSynced()
{
	LoadMod();
	LoadMap();
	bool synced = true;
	if ( !m_host_map.hash.empty() || m_host_map.hash != "0" ) synced = synced && (m_local_map.hash == m_host_map.hash);
	if ( !m_host_map.name.empty() ) synced = synced && (m_local_map.name == m_host_map.name);
	if ( !m_host_mod.hash.empty() || m_host_mod.hash != "0" ) synced = synced && (m_local_mod.hash == m_host_mod.hash);
	if ( !m_host_mod.name.empty() ) synced = synced && (m_local_mod.name == m_host_mod.name);
	return synced;
}

std::vector<lslColor>& IBattle::GetFixColorsPalette( int numteams ) const
{
    return Util::GetBigFixColorsPalette( numteams );
}

lslColor IBattle::GetFixColor(int i) const<commit_msg>fix some initializtation order warnings<commit_after>#include "ibattle.h"

#include <lslutils/debug.h>
#include <lslutils/misc.h>
#include <lslutils/conversion.h>
#include <lslutils/config.h>
#include <lslutils/autopointers.h>
#include <lslunitsync/unitsync.h>
#include <lslunitsync/optionswrapper.h>

//SL includes -- bad
#if HAVE_SPRINGLOBBY
    #include "settings.h"
#else
#include <lslutils/mock_settings.h>
#endif

#include "signals.h"
#include "tdfcontainer.h"

#include <algorithm>
#include <boost/foreach.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>

#define ASSERT_EXCEPTION(cond,msg) do { if (!(cond)) { LSL_THROW( battle, msg ); } } while (0)

namespace LSL {
namespace Battle {

boost::asio::io_service _io;
const boost::posix_time::seconds TIMER_INTERVAL(1000);
const unsigned int TIMER_ID               = 101;

BattleOptions::BattleOptions()
	: battleid(-1)
	, battletype(Enum::BT_Played)
	, islocked(false)
	, ispassworded(false)
	, rankneeded(0)
	, lockexternalbalancechanges(false)
	, proxyhost("")
	, userelayhost(false)
	, relayhost("")
	, nattype(Enum::NAT_None)
	, port(Enum::DEFAULT_SERVER_PORT)
	, externaludpsourceport(Enum::DEFAULT_EXTERNAL_UDP_SOURCE_PORT)
	, internaludpsourceport(Enum::DEFAULT_EXTERNAL_UDP_SOURCE_PORT)
	, maxplayers(0)
    , spectators(0)
{}

IBattle::IBattle():
	m_map_loaded(false)
	, m_mod_loaded(false)
	, m_map_exists(false)
	, m_mod_exists(false)
	, m_previous_local_mod_name( std::string() )
    , m_opt_wrap( new OptionsWrapper() )
	, m_ingame(false)
	, m_auto_unspec(false)
	, m_players_ready(0)
	, m_players_sync(0)
	, m_players_ok(0)
	, m_is_self_in(false)
	, m_generating_script(false)
    , m_timer ( new boost::asio::deadline_timer( _io, TIMER_INTERVAL ) )
{
}


IBattle::~IBattle()
{
    m_timer->cancel();
	if ( m_is_self_in ) usync().UnSetCurrentMod();
}

bool IBattle::IsSynced()
{
	LoadMod();
	LoadMap();
	bool synced = true;
	if ( !m_host_map.hash.empty() || m_host_map.hash != "0" ) synced = synced && (m_local_map.hash == m_host_map.hash);
	if ( !m_host_map.name.empty() ) synced = synced && (m_local_map.name == m_host_map.name);
	if ( !m_host_mod.hash.empty() || m_host_mod.hash != "0" ) synced = synced && (m_local_mod.hash == m_host_mod.hash);
	if ( !m_host_mod.name.empty() ) synced = synced && (m_local_mod.name == m_host_mod.name);
	return synced;
}

std::vector<lslColor>& IBattle::GetFixColorsPalette( int numteams ) const
{
    return Util::GetBigFixColorsPalette( numteams );
}

lslColor IBattle::GetFixColor(int i) const
{'fraction_non_alphanumeric': 0.15115115115115116, 'fraction_numerical': 0.006806806806806807, 'mean_word_length': 5.7331536388140165, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5294481', 'n_tokens_mistral': 2041, 'n_tokens_neox': 2010, 'n_words': 308}