bool IBattle::LoadOptionsPreset( const std::string& name ) { const std::string preset = FixPresetName(name); if (preset.empty()) return false; //preset not found m_preset = preset; for ( unsigned int i = 0; i < LSL::OptionsWrapper::LastOption; i++) { std::map<wxString,wxString> options = sett().GetHostingPreset( TowxString(m_preset), i ); if ( (LSL::OptionsWrapper::GameOption)i != LSL::OptionsWrapper::PrivateOptions ) { for ( std::map<wxString,wxString>::const_iterator itor = options.begin(); itor != options.end(); ++itor ) { wxLogWarning( itor->first + _T(" ::: ") + itor->second ); CustomBattleOptions().setSingleOption( STD_STRING(itor->first), STD_STRING(itor->second), (LSL::OptionsWrapper::GameOption)i ); } } else { if ( !options[_T("mapname")].IsEmpty() ) { if (LSL::usync().MapExists(STD_STRING(options[_T("mapname")]))) { SetLocalMap( STD_STRING(options[_T("mapname")]) ); SendHostInfo( HI_Map ); } else if ( !ui().OnPresetRequiringMap( options[_T("mapname")] ) ) { //user didn't want to download the missing map, so set to empty to not have it tried to be loaded again options[_T("mapname")] = wxEmptyString; sett().SetHostingPreset( TowxString(m_preset), i, options ); } } for( unsigned int j = 0; j <= GetLastRectIdx(); ++j ) { if ( GetStartRect( j ).IsOk() ) RemoveStartRect(j); // remove all rects that might come from map presets } SendHostInfo( IBattle::HI_StartRects ); unsigned int rectcount = s2l( options[_T("numrects")] ); for ( unsigned int loadrect = 0; loadrect < rectcount; loadrect++) { int ally = s2l(options[_T("rect_") + TowxString(loadrect) + _T("_ally")]); if ( ally == 0 ) continue; AddStartRect( ally - 1, s2l(options[_T("rect_") + TowxString(loadrect) + _T("_left")]), s2l(options[_T("rect_") + TowxString(loadrect) + _T("_top")]), s2l(options[_T("rect_") + TowxString(loadrect) + _T("_right")]), s2l(options[_T("rect_") + TowxString(loadrect) + _T("_bottom")]) ); } SendHostInfo( HI_StartRects ); wxStringTokenizer tkr( options[_T("restrictions")], _T('\t') ); m_restricted_units.clear(); while( tkr.HasMoreTokens() ) { wxString unitinfo = tkr.GetNextToken(); RestrictUnit( STD_STRING(unitinfo.BeforeLast(_T('='))), s2l( unitinfo.AfterLast(_T('=')) ) ); } SendHostInfo( HI_Restrictions ); Update( wxFormat( _T("%d_restrictions") ) % LSL::OptionsWrapper::PrivateOptions ); } } SendHostInfo( HI_Send_All_opts ); ui().ReloadPresetList(); return true; }
// ------------------------------------------------------------------------------------------------------------------------ /// /// Read out Host's CPU Speed /// /// \return Sum of each CPU's Speed of this Computer /// /// // ------------------------------------------------------------------------------------------------------------------------ wxString GetHostCPUSpeed() { int cpu_count = 0; int max_cpu_speed=0; #ifdef __WXMSW__ //afaik there is no way to determine the number of sub keys for a given key //so i'll hardcode some value here and hope bd doesn't hit me with a stick :P for (int i = 0; i< 16; ++i) { wxRegKey programreg( _T("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\")+ wxFormat(_T("%d") ) % i); long tmp; if ( programreg.QueryValue( _T("~MHz"), &tmp ) ) { if ( max_cpu_speed < tmp ) max_cpu_speed = tmp; cpu_count++; } } #else wxTextFile file( _T("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq") ); if ( file.Exists() ) { file.Open(); wxString line = file.GetFirstLine(); cpu_count++; int tmp = s2l( line ); tmp /= 1000; if ( max_cpu_speed < tmp ) max_cpu_speed = tmp; } else { wxTextFile file( _T("/proc/cpuinfo") ); if ( file.Exists() ) { file.Open(); for ( wxString line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine() ) { if ( line.Left(7) == _T("cpu MHz") ) { line = line.AfterLast( _T(' ') ).BeforeLast( _T('.') ); cpu_count++; int tmp = s2l( line ); if ( max_cpu_speed < tmp ) max_cpu_speed = tmp; } } } } #endif return TowxString( LSL::Util::Clamp( max_cpu_speed,0,max_cpu_speed ) ); }
void BattleRoomTab::UpdateBattleInfo( const wxString& Tag ) { if ( !m_battle ) return; long index = m_opt_list_map[ Tag ]; OptionsWrapper::GameOption type = ( OptionsWrapper::GameOption )s2l( Tag.BeforeFirst( '_' ) ); wxString key = Tag.AfterFirst( '_' ); wxString value; if ( ( type == OptionsWrapper::MapOption ) || ( type == OptionsWrapper::ModOption ) || ( type == OptionsWrapper::EngineOption ) ) { OptionType DataType = m_battle->CustomBattleOptions().GetSingleOptionType( key ); value = m_battle->CustomBattleOptions().getSingleValue( key, ( OptionsWrapper::GameOption )type ); if ( m_battle->CustomBattleOptions().getDefaultValue( key, type ) == value ) m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT ) ); else m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); if ( DataType == opt_bool ) { value = bool2yn( s2l( value ) ); // convert from 0/1 to literal Yes/No } else if ( DataType == opt_list ) { value = m_battle->CustomBattleOptions().GetNameListOptValue( key, type ); // get the key full name not short key } m_opts_list->SetItem( index, 1, value ); } else// if ( type == OptionsWrapper::PrivateOptions ) { if ( key == _T( "mapname" ) ) // the map has been changed { UpdateMapInfoSummary(); wxString mapname =m_battle->GetHostMapName(); int index_ = m_map_combo->FindString( mapname ); if ( index_ != wxNOT_FOUND ) m_map_combo->SetSelection( index_ ); else m_map_combo->SetValue( mapname ); //delete any eventual map option from the list and add options of the new map for ( int i = m_map_opts_index; i < m_opts_list->GetItemCount(); ) { m_opts_list->DeleteItem( i ); } AddMMOptionsToList( m_map_opts_index, OptionsWrapper::MapOption ); m_minimap->UpdateMinimap(); } else if ( key == _T( "restrictions" ) ) { m_opts_list->SetItem( index, 1, bool2yn( m_battle->RestrictedUnits().size() > 0 ) ); } } }
static BitVector *set_bits(BitVector *bv, char *bits) { static int bit_array[SET_BITS_MAX_CNT]; const int bit_cnt = s2l(bits, bit_array); int i; for (i = 0; i < bit_cnt; i++) { bv_set(bv, bit_array[i]); } return bv; }
static void do_test_top_docs(TestCase *tc, Searcher *searcher, Query *query, char *expected_hits, Sort *sort) { static int num_array[ARRAY_SIZE]; int i; int total_hits = s2l(expected_hits, num_array); TopDocs *top_docs = searcher_search(searcher, query, 0, total_hits, NULL, sort, NULL); Aiequal(total_hits, top_docs->total_hits); Aiequal(total_hits, top_docs->size); for (i = 0; i < top_docs->size; i++) { Hit *hit = top_docs->hits[i]; if (false && sort && searcher->doc_freq != isea_doc_freq) { FieldDoc *fd = (FieldDoc *)hit; int j; printf("%d == %d:%f ", num_array[i], hit->doc, hit->score); for (j = 0; j < fd->size; j++) { switch (fd->comparables[j].type) { case SORT_TYPE_SCORE: printf("sc:%f ", fd->comparables[j].val.f); break; case SORT_TYPE_FLOAT: printf("f:%f ", fd->comparables[j].val.f); break; case SORT_TYPE_DOC: printf("d:%ld ", fd->comparables[j].val.l); break; case SORT_TYPE_INTEGER: printf("i:%ld ", fd->comparables[j].val.l); break; case SORT_TYPE_STRING: printf("s:%s ", fd->comparables[j].val.s); break; default: printf("NA "); break; } } printf("\n"); } Aiequal(num_array[i], hit->doc); } td_destroy(top_docs); if (total_hits >= R_END) { top_docs = searcher_search(searcher, query, R_START, R_END - R_START, NULL, sort, NULL); for (i = R_START; i < R_END; i++) { Hit *hit = top_docs->hits[i - R_START]; Aiequal(num_array[i], hit->doc); /* printf("%d == %d\n", num_array[i], hit->doc); */ } td_destroy(top_docs); } }
void AddBotDialog::UpdateOption( const wxString& Tag ) { long index = m_opt_list_map[ Tag ]; OptionsWrapper::GameOption type = ( OptionsWrapper::GameOption )s2l( Tag.BeforeFirst( '_' ) ); wxString key = Tag.AfterFirst( '_' ); wxString value; OptionType DataType = m_battle.CustomBattleOptions().GetSingleOptionType( key ); value = m_battle.CustomBattleOptions().getSingleValue( key, ( OptionsWrapper::GameOption )type ); if ( m_battle.CustomBattleOptions().getDefaultValue( key, type ) == value ) m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT ) ); else m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); if ( DataType == opt_bool ) { value = bool2yn( s2l( value ) ); // convert from 0/1 to literal Yes/No } else if ( DataType == opt_list ) { value = m_battle.CustomBattleOptions().GetNameListOptValue( key, type ); // get the key full name not short key } m_opts_list->SetItem( index, 1, value ); m_opts_list->SetColumnWidth( 1, wxLIST_AUTOSIZE ); }
tmap load_map(const std::string &path) { std::ifstream in(path); tmap ret; std::string line; while (std::getline(in, line)) { size_t pos = line.find(' '); if (pos != std::string::npos) { ribosome::letter f = s2l(line.c_str(), pos); ret[f] = ribosome::lconvert::from_utf8(line.substr(pos + 1)); } } return ret; }
void IBattle::SaveOptionsPreset( const wxString& name ) { m_preset = FixPresetName(name); if (m_preset == _T("")) m_preset = name; //new preset for ( int i = 0; i < (int)OptionsWrapper::LastOption; i++) { if ( (OptionsWrapper::GameOption)i != OptionsWrapper::PrivateOptions ) { sett().SetHostingPreset( m_preset, (OptionsWrapper::GameOption)i, CustomBattleOptions().getOptionsMap( (OptionsWrapper::GameOption)i ) ); } else { std::map<wxString,wxString> opts; opts[_T("mapname")] = GetHostMapName(); unsigned int validrectcount = 0; if ( s2l (CustomBattleOptions().getSingleValue( _T("startpostype"), OptionsWrapper::EngineOption ) ) == ST_Choose ) { unsigned int boxcount = GetLastRectIdx(); for ( unsigned int boxnum = 0; boxnum <= boxcount; boxnum++ ) { BattleStartRect rect = GetStartRect( boxnum ); if ( rect.IsOk() ) { opts[_T("rect_") + TowxString(validrectcount) + _T("_ally")] = TowxString( rect.ally + 1 ); opts[_T("rect_") + TowxString(validrectcount) + _T("_left")] = TowxString( rect.left ); opts[_T("rect_") + TowxString(validrectcount) + _T("_top")] = TowxString( rect.top ); opts[_T("rect_") + TowxString(validrectcount) + _T("_bottom")] = TowxString( rect.bottom ); opts[_T("rect_") + TowxString(validrectcount) + _T("_right")] = TowxString( rect.right ); validrectcount++; } } } opts[_T("numrects")] = TowxString( validrectcount ); wxString restrictionsstring; for ( std::map<wxString, int>::const_iterator itor = m_restricted_units.begin(); itor != m_restricted_units.end(); ++itor ) { restrictionsstring << itor->first << _T('=') << TowxString(itor->second) << _T('\t'); } opts[_T("restrictions")] = restrictionsstring; sett().SetHostingPreset( m_preset, (OptionsWrapper::GameOption)i, opts ); } } sett().SaveSettings(); ui().ReloadPresetList(); }
void SingleOptionDialog::OnOk( wxCommandEvent& /*unused*/ ) { OptionsWrapper::GameOption optFlag = ( OptionsWrapper::GameOption )s2l( m_tag.BeforeFirst( '_' ) ); wxString key = m_tag.AfterFirst( '_' ); wxString value; if ( m_textctrl ) value = m_textctrl->GetValue(); else if ( m_combobox ) value = m_battle.CustomBattleOptions().GetNameListOptItemKey( key, m_combobox->GetValue(), optFlag ); else if ( m_spinctrl ) { double d = m_spinctrl->GetValue() ; value = wxString::Format( _T("%f"),d ); wxLogMessage( wxString::Format( _T("Got VALUE: %s -- %f") , value.c_str(), d ) ); } else if ( m_checkbox ) value = TowxString( m_checkbox->GetValue() ); m_battle.CustomBattleOptions().setSingleOption( key, value, optFlag ); m_battle.SendHostInfo( m_tag ); EndModal( wxID_OK ); }
void AddBotDialog::OnOptionActivate( wxListEvent& event ) { long index = event.GetIndex(); wxString tag; for ( OptionListMap::const_iterator itor = m_opt_list_map.begin(); itor != m_opt_list_map.end(); ++itor ) { if ( itor->second == index ) { tag = itor->first; break; } } OptionsWrapper& optWrap = m_battle.CustomBattleOptions(); OptionsWrapper::GameOption optFlag = ( OptionsWrapper::GameOption )s2l( tag.BeforeFirst( '_' ) ); wxString key = tag.AfterFirst( '_' ); OptionType type = optWrap.GetSingleOptionType( key ); if ( !optWrap.keyExists( key, optFlag, false, type ) ) return; SingleOptionDialog dlg( m_battle, tag ); dlg.ShowModal(); UpdateOption( tag ); }
void AddBotDialog::UpdateOption( const wxString& Tag ) { const long index = m_opt_list_map[ Tag ]; const LSL::OptionsWrapper::GameOption type = ( LSL::OptionsWrapper::GameOption )s2l( Tag.BeforeFirst( '_' ) ); const std::string key = STD_STRING(Tag.AfterFirst( '_' )); std::string value; const auto DataType = m_battle.CustomBattleOptions().GetSingleOptionType( key ); value = m_battle.CustomBattleOptions().getSingleValue( key, ( LSL::OptionsWrapper::GameOption )type ); if ( m_battle.CustomBattleOptions().getDefaultValue( key, type ) == value ) m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT ) ); else m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); if ( DataType == LSL::Enum::opt_bool ) { value = STD_STRING(bool2yn(LSL::Util::FromString<long>(value))); // convert from 0/1 to literal Yes/No } else if ( DataType == LSL::Enum::opt_list ) { value = m_battle.CustomBattleOptions().GetNameListOptValue( key, type ); // get the key full name not short key } m_opts_list->SetItem( index, 1, TowxString(value)); m_opts_list->SetColumnWidth( 1, wxLIST_AUTOSIZE ); }
static void check_filtered_hits(TestCase *tc, Searcher *searcher, Query *query, Filter *f, PostFilter *post_filter, char *expected_hits, char top) { static int num_array[ARRAY_SIZE]; int i; int total_hits = s2l(expected_hits, num_array); TopDocs *top_docs = searcher_search(searcher, query, 0, total_hits + 1, f, NULL, post_filter); Aiequal(total_hits, top_docs->total_hits); Aiequal(total_hits, top_docs->size); if ((top >= 0) && top_docs->size) { Aiequal(top, top_docs->hits[0]->doc); } /* printf("top_docs->size = %d\n", top_docs->size); */ for (i = 0; i < top_docs->size; i++) { Hit *hit = top_docs->hits[i]; char buf[1000]; sprintf(buf, "doc %d was found unexpectedly", hit->doc); Assert(ary_includes(num_array, total_hits, hit->doc), buf); /* only check the explanation if we got the correct docs. Obviously we * might want to remove this to visually check the explanations */ if (total_hits == top_docs->total_hits) { Explanation *e = searcher->explain(searcher, query, hit->doc); float escore = e->value; /* char *t; printf("%s\n", t = expl_to_s(e, 0)); free(t); */ if (post_filter) { escore *= post_filter->filter_func(hit->doc, escore, searcher, post_filter->arg); } Afequal(hit->score, escore); expl_destroy(e); } } td_destroy(top_docs); }
void BattleRoomTab::OnOptionActivate( wxListEvent& event ) { if ( !m_battle ) return; if ( !m_battle->IsFounderMe() ) return; long index = event.GetIndex(); if ( index == 0 ) return; wxString tag; for ( OptionListMap::const_iterator itor = m_opt_list_map.begin(); itor != m_opt_list_map.end(); ++itor ) { if ( itor->second == index ) { tag = itor->first; break; } } LSL::OptionsWrapper& optWrap = m_battle->CustomBattleOptions(); LSL::OptionsWrapper::GameOption optFlag = ( LSL::OptionsWrapper::GameOption )s2l( tag.BeforeFirst( '_' ) ); const std::string key = STD_STRING(tag.AfterFirst( '_' )); LSL::Enum::OptionType type = optWrap.GetSingleOptionType( key ); if ( !optWrap.keyExists( key, optFlag, false, type ) ) return; SingleOptionDialog dlg( *m_battle, tag ); dlg.ShowModal(); }
void PlaybackListFilter<PlaybackTabType>::SetDurationValue() { wxString dur = m_filter_duration_edit->GetValue(); const wxChar* mysep = _T(":"); int sep_count = dur.Replace(mysep,mysep); //i know, i know switch ( sep_count ) { default: break; case 0: m_duration_value = s2l( dur ); break; case 1: m_duration_value = s2l( dur.AfterFirst(*mysep) ) + ( s2l( dur.BeforeFirst(*mysep) ) * 60 ); break; case 2: m_duration_value = s2l( dur.AfterLast(*mysep) ) + ( s2l( dur.AfterFirst(*mysep).BeforeFirst(*mysep) ) * 60 ) + ( s2l( dur.BeforeFirst(*mysep) ) * 3600 ); break; } }
void SimpleServerEvents::OnSetBattleInfo( int battleid, const wxString& param, const wxString& value ) { wxLogDebugFunc( param + _T(", ") + value ); try { Battle& battle = m_serv.GetBattle( battleid ); battle.m_script_tags[param] = value; wxString key = param; if ( key.Left( 5 ) == _T("game/") ) { key = key.AfterFirst( '/' ); if ( key.Left( 11 ) == _T( "mapoptions/" ) ) { key = key.AfterFirst( '/' ); battle.CustomBattleOptions().setSingleOption( key, value, OptionsWrapper::MapOption ); battle.Update( wxString::Format(_T("%d_%s"), OptionsWrapper::MapOption, key.c_str() ) ); } else if ( key.Left( 11 ) == _T( "modoptions/" ) ) { key = key.AfterFirst( '/' ); battle.CustomBattleOptions().setSingleOption( key, value, OptionsWrapper::ModOption ); battle.Update( wxString::Format(_T("%d_%s"), OptionsWrapper::ModOption, key.c_str() ) ); } else if ( key.Left( 8 ) == _T( "restrict" ) ) { OnBattleDisableUnit( battleid, key.AfterFirst(_T('/')), s2l(value) ); } else if ( key.Left( 4 ) == _T( "team" ) && key.Find( _T("startpos") ) != wxNOT_FOUND ) { int team = s2l( key.BeforeFirst(_T('/')).Mid( 4 ) ); if ( key.Find( _T("startposx") ) != wxNOT_FOUND ) { int numusers = battle.GetNumUsers(); for ( int i = 0; i < numusers; i++ ) { User& usr = battle.GetUser( i ); UserBattleStatus& status = usr.BattleStatus(); if ( status.team == team ) { status.pos.x = s2l( value ); battle.OnUserBattleStatusUpdated( usr, status ); } } } else if ( key.Find( _T("startposy") ) != wxNOT_FOUND ) { int numusers = battle.GetNumUsers(); for ( int i = 0; i < numusers; i++ ) { User& usr = battle.GetUser( i ); UserBattleStatus& status = usr.BattleStatus(); if ( status.team == team ) { status.pos.y = s2l( value ); battle.OnUserBattleStatusUpdated( usr, status ); } } } } else { battle.CustomBattleOptions().setSingleOption( key, value, OptionsWrapper::EngineOption ); battle.Update( wxString::Format(_T("%d_%s"), OptionsWrapper::EngineOption, key.c_str() ) ); } } } catch (assert_exception) {} }
MapInfo SpringUnitSync::_GetMapInfoEx( const wxString& mapname ) { MapInfo info; if ( m_mapinfo_cache.TryGet( mapname, info ) ) return info; wxArrayString cache; try { try { cache = GetCacheFile( GetFileCachePath( mapname, m_maps_unchained_hash[mapname], false ) + _T(".infoex") ); ASSERT_EXCEPTION( cache.GetCount() >= 11, _T("not enough lines found in cache info ex") ); info.author = cache[0]; info.tidalStrength = s2l( cache[1] ); info.gravity = s2l( cache[2] ); info.maxMetal = s2d( cache[3] ); info.extractorRadius = s2d( cache[4] ); info.minWind = s2l( cache[5] ); info.maxWind = s2l( cache[6] ); info.width = s2l( cache[7] ); info.height = s2l( cache[8] ); wxArrayString posinfo = wxStringTokenize( cache[9], _T(' '), wxTOKEN_RET_EMPTY ); for ( unsigned int i = 0; i < posinfo.GetCount(); i++) { StartPos position; position.x = s2l( posinfo[i].BeforeFirst( _T('-') ) ); position.y = s2l( posinfo[i].AfterFirst( _T('-') ) ); info.positions.push_back( position ); } unsigned int LineCount = cache.GetCount(); for ( unsigned int i = 10; i < LineCount; i++ ) info.description << cache[i] << _T('\n'); } catch (...) { info = susynclib().GetMapInfoEx( m_unsorted_map_array.Index(mapname), 1 ); cache.Add ( info.author ); cache.Add( TowxString( info.tidalStrength ) ); cache.Add( TowxString( info.gravity ) ); cache.Add( TowxString( info.maxMetal ) ); cache.Add( TowxString( info.extractorRadius ) ); cache.Add( TowxString( info.minWind ) ); cache.Add( TowxString( info.maxWind ) ); cache.Add( TowxString( info.width ) ); cache.Add( TowxString( info.height ) ); wxString postring; for ( unsigned int i = 0; i < info.positions.size(); i++) { postring << TowxString( info.positions[i].x ) << _T('-') << TowxString( info.positions[i].y ) << _T(' '); } cache.Add( postring ); wxArrayString descrtoken = wxStringTokenize( info.description, _T('\n') ); unsigned int desclinecount = descrtoken.GetCount(); for ( unsigned int count = 0; count < desclinecount; count++ ) cache.Add( descrtoken[count] ); SetCacheFile( GetFileCachePath( mapname, m_maps_unchained_hash[mapname], false ) + _T(".infoex"), cache ); } } catch ( ... ) { info.width = 1; info.height = 1; } m_mapinfo_cache.Add( mapname, info ); return info; }
bool WidgetDownloadPanel::PopulateList() { bool success = true; wxHTTP http; http.SetTimeout(6); http.Connect(_T("spring.vsync.de")); // PHP file sending XML content wxInputStream *httpStream = http.GetInputStream(_T("/luaManager/lua_manager.php?m=0")); if (http.GetError() == wxPROTO_NOERR) { wxXmlDocument xml(*httpStream); wxXmlNode *node = xml.GetRoot()->GetChildren(); while (node) { int id = FromwxString<long>( node->GetPropVal( _T("ID"), TowxString( invalid_id ) ) ); if ( id != invalid_id ) { Widget w; w.w_id = id; wxXmlNode* item = node->GetChildren(); while( item ) { wxString name = item->GetName(); if ( name == _T("ImageCount") ) { w.num_images = s2l( item->GetNodeContent() ); } else if ( name == _T("DownloadCount") ) { w.num_downloads = s2l( item->GetNodeContent() ); } else if ( name == _T("Version") ) { wxString rev = item->GetNodeContent(); w.rev_major = s2l( rev.BeforeFirst( '.' ) ); w.rev_minor = s2l( rev.AfterFirst( '.' ) ); w.rev = rev; } else if ( name == _T("NameId") ) { w.n_id = s2l( item->GetNodeContent() ); } else if ( name == _T("Changelog") ) { w.changelog = item->GetNodeContent(); } else if ( name == _T("Mods") ) { w.mods = item->GetNodeContent(); } else if ( name == _T("Description") ) { wxString desc = item->GetNodeContent(); w.description = desc; desc.Replace( _T("\r\n"), _T(" "), true ); desc.Replace( _T("\n"), _T(" "), true ); desc.Replace( _T("\r"), _T(" "), true ); if ( desc.Len() > max_short_desc_length ) { desc = desc.Left( max_short_desc_length -1 ) + _T("..."); } w.short_description = desc; } else if ( name == _T("Author") ) { w.author = item->GetNodeContent(); } else if ( name == _T("Entry") ) { w.date = item->GetNodeContent(); } else if ( name == _T("Name") ) { w.name = item->GetNodeContent(); } item = item->GetNext(); } m_list->AddWidget( w ); } node = node->GetNext(); } } else success = false; http.Close(); wxDELETE(httpStream); return success; }
void BattleRoomTab::UpdateBattleInfo( const wxString& Tag ) { if ( !m_battle ) return; long index = m_opt_list_map[ Tag ]; OptionsWrapper::GameOption type = ( OptionsWrapper::GameOption )s2l( Tag.BeforeFirst( '_' ) ); wxString key = Tag.AfterFirst( '_' ); wxString value; if ( ( type == OptionsWrapper::MapOption ) || ( type == OptionsWrapper::ModOption ) || ( type == OptionsWrapper::EngineOption ) ) { OptionType DataType = m_battle->CustomBattleOptions().GetSingleOptionType( key ); value = m_battle->CustomBattleOptions().getSingleValue( key, ( OptionsWrapper::GameOption )type ); if ( m_battle->CustomBattleOptions().getDefaultValue( key, type ) == value ) m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT ) ); else m_opts_list->SetItemFont( index, wxFont( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ) ); if ( DataType == opt_bool ) { value = bool2yn( s2l( value ) ); // convert from 0/1 to literal Yes/No } else if ( DataType == opt_list ) { value = m_battle->CustomBattleOptions().GetNameListOptValue( key, type ); // get the key full name not short key } m_opts_list->SetItem( index, 1, value ); } else if ( type == OptionsWrapper::PrivateOptions ) { if ( key == _T( "mapname" ) ) // the map has been changed { try // updates map info summary { ASSERT_EXCEPTION( m_battle->MapExists(), _( "Map does not exist." ) ); UnitSyncMap map = m_battle->LoadMap(); m_opts_list->SetItem( m_opt_list_map[ _( "Size" ) ] , 1, wxString::Format( _T( "%.0fx%.0f" ), map.info.width / 512.0, map.info.height / 512.0 ) ); m_opts_list->SetItem( m_opt_list_map[ _( "Windspeed" ) ], 1, wxString::Format( _T( "%d-%d" ), map.info.minWind, map.info.maxWind ) ); m_opts_list->SetItem( m_opt_list_map[ _( "Tidal strength" ) ], 1, wxString::Format( _T( "%d" ), map.info.tidalStrength ) ); // m_opts_list->SetItem( 0, 1, ); } catch ( ... ) { m_opts_list->SetItem( m_opt_list_map[ _( "Size" ) ], 1, _T( "?x?" ) ); m_opts_list->SetItem( m_opt_list_map[ _( "Windspeed" ) ], 1, _T( "?-?" ) ); m_opts_list->SetItem( m_opt_list_map[ _( "Tidal strength" ) ], 1, _T( "?" ) ); } wxString mapname =m_battle->GetHostMapName(); int index_ = m_map_combo->FindString( mapname ); if ( index_ != wxNOT_FOUND ) m_map_combo->SetSelection( index_ ); else m_map_combo->SetValue( mapname ); //delete any eventual map option from the list and add options of the new map for ( int i = m_map_opts_index; i < m_opts_list->GetItemCount(); ) { m_opts_list->DeleteItem( i ); } AddMMOptionsToList( m_map_opts_index, OptionsWrapper::MapOption ); m_minimap->UpdateMinimap(); } else if ( key == _T( "restrictions" ) ) { m_opts_list->SetItem( index, 1, bool2yn( m_battle->RestrictedUnits().size() > 0 ) ); } } }
void Battle::FixTeamIDs( BalanceType balance_type, bool support_clans, bool strong_clans, int numcontrolteams ) { wxLogMessage(_T("Autobalancing teams, type=%d, clans=%d, strong_clans=%d, numcontrolteams=%d"),balance_type, support_clans, strong_clans, numcontrolteams); //size_t i; //int num_alliances; std::vector<ControlTeam> control_teams; if ( numcontrolteams == 0 || numcontrolteams == -1 ) numcontrolteams = GetNumUsers() - GetSpectators(); // 0 or -1 -> use num players, will use comshare only if no available team slots IBattle::StartType position_type = (IBattle::StartType)s2l( CustomBattleOptions().getSingleValue( _T("startpostype"), OptionsWrapper::EngineOption ) ); if ( ( position_type == ST_Fixed ) || ( position_type == ST_Random ) ) // if fixed start pos type or random, use max teams = start pos count { try { int mapposcount = LoadMap().info.positions.size(); numcontrolteams = std::min( numcontrolteams, mapposcount ); } catch( assert_exception ) {} } if ( numcontrolteams >= (int)( GetNumUsers() - GetSpectators() ) ) // autobalance behaves weird when trying to put one player per team and i CBA to fix it, so i'll reuse the old code :P { // apparently tasserver doesnt like when i fix/force ids of everyone. std::set<int> allteams; size_t numusers = GetNumUsers(); for( size_t i = 0; i < numusers; ++i ) { User &user = GetUser(i); if( !user.BattleStatus().spectator ) allteams.insert( user.BattleStatus().team ); } std::set<int> teams; int t = 0; for( size_t i = 0; i < GetNumUsers(); ++i ) { User &user = GetUser(i); if( !user.BattleStatus().spectator ) { if( teams.count( user.BattleStatus().team ) ) { while( allteams.count(t) || teams.count( t ) ) t++; ForceTeam( GetUser(i), t ); teams.insert( t ); } else { teams.insert( user.BattleStatus().team ); } } } return; } for ( int i = 0; i < numcontrolteams; i++ ) control_teams.push_back( ControlTeam( i ) ); wxLogMessage(_T("number of teams: %u"), control_teams.size() ); std::vector<User*> players_sorted; players_sorted.reserve( GetNumUsers() ); int player_team_counter = 0; for ( size_t i = 0; i < GetNumUsers(); ++i ) // don't count spectators { if ( !GetUser(i).BattleStatus().spectator ) { players_sorted.push_back( &GetUser(i) ); // -- server fail? it doesnt work right. //ForceTeam(GetUser(i),player_team_counter); player_team_counter++; } } shuffle( players_sorted ); std::map<wxString, ControlTeam> clan_teams; if ( support_clans ) { for ( size_t i = 0; i < players_sorted.size(); ++i ) { wxString clan = players_sorted[i]->GetClan(); if ( !clan.empty() ) { clan_teams[clan].AddPlayer( players_sorted[i] ); } } }; if ( balance_type != balance_random ) std::sort( players_sorted.begin(), players_sorted.end(), PlayerRankCompareFunction ); if ( support_clans ) { std::map<wxString, ControlTeam>::iterator clan_it = clan_teams.begin(); while ( clan_it != clan_teams.end() ) { ControlTeam &clan = (*clan_it).second; // if clan is too small (only 1 clan member in battle) or too big, dont count it as clan if ( ( clan.players.size() < 2 ) || ( !strong_clans && ( clan.players.size() > ( ( players_sorted.size() + control_teams.size() -1 ) / control_teams.size() ) ) ) ) { wxLogMessage(_T("removing clan %s"),(*clan_it).first.c_str()); std::map<wxString, ControlTeam>::iterator next = clan_it; ++next; clan_teams.erase( clan_it ); clan_it = next; continue; } wxLogMessage( _T("Inserting clan %s"), (*clan_it).first.c_str() ); std::sort( control_teams.begin(), control_teams.end() ); float lowestrank = control_teams[0].ranksum; int rnd_k = 1; // number of alliances with rank equal to lowestrank while ( size_t( rnd_k ) < control_teams.size() ) { if ( fabs( control_teams[rnd_k].ranksum - lowestrank ) > 0.01 ) break; rnd_k++; } wxLogMessage(_T("number of lowestrank teams with same rank=%d"), rnd_k ); control_teams[my_random( rnd_k )].AddTeam( clan ); ++clan_it; } } for (size_t i = 0; i < players_sorted.size(); ++i ) { // skip clanners, those have been added already. if ( clan_teams.count( players_sorted[i]->GetClan() ) > 0 ) { wxLogMessage( _T("clanner already added, nick=%s"),players_sorted[i]->GetNick().c_str() ); continue; } // find teams with lowest ranksum // insert current user into random one out of them // since performance doesnt matter here, i simply sort teams, // then find how many teams in beginning have lowest ranksum // note that balance player ranks range from 1 to 1.1 now // i.e. them are quasi equal // so we're essentially adding to teams with smallest number of players, // the one with smallest ranksum. std::sort( control_teams.begin(), control_teams.end() ); float lowestrank = control_teams[0].ranksum; int rnd_k = 1; // number of alliances with rank equal to lowestrank while ( size_t( rnd_k ) < control_teams.size() ) { if ( fabs ( control_teams[rnd_k].ranksum - lowestrank ) > 0.01 ) break; rnd_k++; } wxLogMessage( _T("number of lowestrank teams with same rank=%d"), rnd_k ); control_teams[my_random( rnd_k )].AddPlayer( players_sorted[i] ); } for ( size_t i=0; i < control_teams.size(); ++i ) { for ( size_t j = 0; j < control_teams[i].players.size(); ++j ) { ASSERT_LOGIC( control_teams[i].players[j], _T("fail in Autobalance teams, NULL player") ); wxString msg = wxString::Format( _T("setting player %s to team and ally %d"), control_teams[i].players[j]->GetNick().c_str(), i ); wxLogMessage( _T("%s"), msg.c_str() ); ForceTeam( *control_teams[i].players[j], control_teams[i].teamnum ); ForceAlly( *control_teams[i].players[j], control_teams[i].teamnum ); } } }
bool PlaybackListFilter<PlaybackTabType>::FilterPlayback( const typename PlaybackListFilter<PlaybackTabType>::PlaybackType& playback ) { if (!m_activ) return true; const OfflineBattle& battle = playback.battle; //Player Check if ( (m_filter_player_choice_value != -1) && !_IntCompare( battle.GetNumUsers() - battle.GetSpectators() , m_filter_player_choice_value , m_filter_player_mode ) ) return false; //Only Maps i have Check if (m_filter_map_show->GetValue() && !battle.MapExists()) return false; //Only Mods i have Check if (m_filter_mod_show->GetValue() && !battle.ModExists()) return false; //Strings Plain Text & RegEx Check (Case insensitiv) //Map: if ( !battle.GetHostMapName().Upper().Contains( m_filter_map_edit->GetValue().Upper() ) && !m_filter_map_expression->Matches(battle.GetHostMapName()) ) return false; //Mod: if ( !battle.GetHostModName().Upper().Contains( m_filter_mod_edit->GetValue().Upper() ) && !battle.GetHostModName().Upper().Contains( m_filter_mod_edit->GetValue().Upper() ) && !m_filter_mod_expression->Matches(battle.GetHostModName()) ) return false; if ( (!m_filter_filesize_edit->GetValue().IsEmpty() ) && !_IntCompare( playback.size , 1024 * s2l( m_filter_filesize_edit->GetValue()) , m_filter_filesize_mode) ) return false; //duration if ( (!m_filter_duration_edit->GetValue().IsEmpty() ) && !_IntCompare( playback.duration , m_duration_value , m_filter_duration_mode) ) return false; return true; }
long GetIntParam( wxString& params ) { return s2l( GetParamByChar( params, _T(' ') ) ); }
SingleOptionDialog::SingleOptionDialog( IBattle& battle, const wxString& optiontag ) : m_battle( battle ), m_tag( optiontag ), m_checkbox( 0 ), m_combobox( 0 ), m_spinctrl( 0 ), m_textctrl( 0 ) { OptionsWrapper& optWrap = m_battle.CustomBattleOptions(); OptionsWrapper::GameOption optFlag = ( OptionsWrapper::GameOption )s2l( optiontag.BeforeFirst( '_' ) ); wxString key = optiontag.AfterFirst( '_' ); OptionType type = optWrap.GetSingleOptionType( key ); Create( (wxWindow*)&ui().mw(), wxID_ANY, _( "Change option" ), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T( "OptionDialog" ) ); if ( !optWrap.keyExists( key, optFlag, false, type ) ) { EndModal( wxID_CANCEL ); return; } wxBoxSizer* m_main_sizer = new wxBoxSizer( wxVERTICAL ); // wxStaticText* m_labelctrl = wxStaticText(); switch ( type ) { case opt_bool: { mmOptionBool opt = optWrap.m_opts[optFlag].bool_map[key]; m_checkbox = new wxCheckBox( this, wxID_ANY, opt.name ); m_checkbox->SetToolTip( TE( opt.description ) ); m_checkbox->SetValue( opt.value ); m_main_sizer->Add( m_checkbox, 0, wxEXPAND ); break; } case opt_float: { mmOptionFloat opt = optWrap.m_opts[optFlag].float_map[key]; m_spinctrl = new SlSpinCtrlDouble<SingleOptionDialog>(); m_spinctrl->Create( this, wxID_ANY, _T( "" ), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, double( opt.min ), double( opt.max ), double( opt.value ), double( opt.stepping ), opt.key ); m_spinctrl->SetToolTip( TE( opt.description ) ); m_main_sizer->Add( m_spinctrl, 0, wxEXPAND ); break; } case opt_string: { mmOptionString opt = optWrap.m_opts[optFlag].string_map[key]; m_textctrl = new wxTextCtrl( this, wxID_ANY, opt.value, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, opt.key ); m_textctrl->SetToolTip( TE( opt.description ) ); m_main_sizer->Add( m_textctrl, 0, wxEXPAND ); break; } case opt_list: { mmOptionList opt = optWrap.m_opts[optFlag].list_map[key]; int temp = int( opt.cbx_choices.GetCount() - 1 ); int index = clamp( opt.cur_choice_index, 0, temp ); m_combobox = new wxComboBox( this, wxID_ANY, opt.cbx_choices[index], wxDefaultPosition, wxDefaultSize, opt.cbx_choices, wxCB_READONLY, wxDefaultValidator ); wxString tooltip = opt.description + _T( "\n" ); for ( ListItemVec::iterator itor = opt.listitems.begin(); itor != opt.listitems.end(); itor++ ) { tooltip += _T( "\n" ) + itor->name + _T( ": " ) + itor->desc; } m_combobox->SetToolTip( TE( tooltip ) ); m_main_sizer->Add( m_combobox, 0, wxEXPAND ); break; } default: { EndModal( wxID_CANCEL ); return; break; } } wxSize __SpacerSize_1 = wxDLG_UNIT( this, wxSize( 0, 0 ) ); m_main_sizer->Add( __SpacerSize_1.GetWidth(), __SpacerSize_1.GetHeight(), 0, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5 ); wxStaticLine* m_separator1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxSize( 10, -1 ), wxLI_HORIZONTAL, _T( "ID_STATICLINE1" ) ); m_main_sizer->Add( m_separator1, 0, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5 ); wxBoxSizer* m_buttons_sizer = new wxBoxSizer( wxHORIZONTAL ); m_cancel_button = new wxButton( this, ID_CANCEL, _( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_CANCEL" ) ); m_buttons_sizer->Add( m_cancel_button, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5 ); m_buttons_sizer->Add( 0, 0, 1, wxALL | wxEXPAND | wxSHAPED | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 0 ); m_ok_button = new wxButton( this, ID_OK, _( "Ok" ), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T( "ID_OK" ) ); m_buttons_sizer->Add( m_ok_button, 0, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5 ); m_main_sizer->Add( m_buttons_sizer, 0, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 0 ); m_main_sizer->Fit( this ); m_main_sizer->SetSizeHints( this ); SetSizer( m_main_sizer ); Layout(); Connect( ID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, ( wxObjectEventFunction )&SingleOptionDialog::OnCancel ); Connect( ID_OK, wxEVT_COMMAND_BUTTON_CLICKED, ( wxObjectEventFunction )&SingleOptionDialog::OnOk ); }
void AutoHost::OnSaidBattle( const wxString& /*unused*/, const wxString& msg ) { // do nothing if autohost functionality is disabled if ( !m_enabled ) return; // protect against command spam time_t currentTime = time( NULL ); if ( ( currentTime - m_lastActionTime ) < 5 ) return; // check for autohost commands wxString command = msg.BeforeFirst( _T( ' ' ) ); wxString params = msg.AfterFirst( _T( ' ' ) ); if ( command == _T( "!start" ) ) { StartBattle(); } else if ( command == _T( "!balance" ) ) { unsigned int num = s2l( params ); m_battle.Autobalance( IBattle::balance_random, false, false, num ); m_battle.DoAction( _T( "is auto-balancing alliances ..." ) ); } else if ( command == _T( "!cbalance" ) ) { unsigned int num = s2l( params ); m_battle.Autobalance( IBattle::balance_random, true, false, num ); m_battle.DoAction( _T( "is auto-balancing alliances ..." ) ); } else if ( command == _T( "!help" ) ) { m_battle.DoAction( _T( "The following commands are available ( <> = mandatory value, {} = optional value ):" ) ); m_battle.DoAction( _T( "!addbox <topx> <topy> <bottomx> <bottomy> {allynumber}: adds a <allynumber> start restriction to the given coordinates, coordinates range from 0 to 200." ) ); m_battle.DoAction( _T( "!balance {number}: tries to put players into allyteams by how many start boxes there are, uses {number} allyteams if present." ) ); m_battle.DoAction( _T( "!cbalance {number}: see !balance but tries to put clanmates together first." ) ); m_battle.DoAction( _T( "!fixcolors: changes players duplicate colours so they are unique." ) ); m_battle.DoAction( _T( "!fixids {number}: tries to put players into control teams by number, if number is omitted it assignes as different controlteam per player." ) ); m_battle.DoAction( _T( "!cfixids {number}: see !fixids but tries to put clanmates together first." ) ); m_battle.DoAction( _T( "!help: this guide." ) ); m_battle.DoAction( _T( "!listprofiles: lists the available battle profiles." ) ); m_battle.DoAction( _T( "!loadprofile profilename: loads an available battle profile." ) ); m_battle.DoAction( _T( "!lock: prevents more people to join." ) ); m_battle.DoAction( _T( "!map <name>: switches to <name>." ) ); m_battle.DoAction( _T( "!removebox <allynumber>: deletes <allynumber> start restriction's box." ) ); m_battle.DoAction( _T( "!ring {name}: rings players that are not ready or {name} if specified." ) ); m_battle.DoAction( _T( "!set <optionname> <value>: sets battle option <optionname> to <value>" ) ); m_battle.DoAction( _T( "!spectunsynced: sets all players with unsynced status to be spectators." ) ); m_battle.DoAction( _T( "!start: starts the battle." ) ); m_battle.DoAction( _T( "!unlock: opens the battle again." ) ); } else if ( command == _T( "!ring" ) ) { if ( !params.IsEmpty() ) { wxString user = GetBestMatch( m_userlist, params ); try { User& u = m_battle.GetUser( user ); m_battle.RingPlayer( u ); m_battle.DoAction( _T( "is ringing " ) + user ); } catch ( ... ) { m_battle.DoAction( _T( "cannot ring " ) + user ); } } else { m_battle.RingNotReadyPlayers(); m_battle.DoAction( _T( "is ringing players not ready ..." ) ); } } else if ( command == _T( "!listprofiles" ) ) { wxArrayString profilelist = m_battle.GetPresetList(); unsigned int count = profilelist.GetCount(); if ( count == 0 ) { m_battle.DoAction( _T( "There are no presets available." ) ); } else { m_battle.DoAction( _T( "The following presets are available:" ) ); for ( unsigned int i = 0; i < count; i++ ) { m_battle.DoAction( profilelist[i] ); } } } else if ( command == _T( "!loadprofile" ) ) { wxString profilename = GetBestMatch( m_battle.GetPresetList(), params ); if ( !m_battle.LoadOptionsPreset( profilename ) ) m_battle.DoAction( _T( "Profile not found, use !listprofiles for a list of available profiles." ) ); else m_battle.DoAction( _T( "has loaded profile: " ) + profilename ); } else if ( command == _T( "!fixcolors" ) ) { m_battle.FixColours(); m_battle.DoAction( _T( "is fixing colors." ) ); } else if ( command == _T( "!lock" ) ) { m_battle.SetIsLocked( true ); m_battle.DoAction( _T( "has locked the battle." ) ); m_battle.SendHostInfo( IBattle::HI_Locked ); } else if ( command == _T( "!unlock" ) ) { m_battle.SetIsLocked( false ); m_battle.DoAction( _T( "has unlocked the battle." ) ); m_battle.SendHostInfo( IBattle::HI_Locked ); } else if ( command == _T( "!fixids" ) ) { unsigned int num = s2l( params ); m_battle.FixTeamIDs( IBattle::balance_divide, false, false, num ); m_battle.DoAction( _T( "is auto-balancing control teams ..." ) ); } else if ( command == _T( "!cfixids" ) ) { unsigned int num = s2l( params ); m_battle.FixTeamIDs( IBattle::balance_divide, true, true, num ); m_battle.DoAction( _T( "is auto-balancing control teams ..." ) ); } else if ( command == _T( "!spectunsynced" ) ) { m_battle.ForceUnsyncedToSpectate(); m_battle.DoAction( _T( "is forcing unsynced players to be spectators." ) ); } else if ( command == _T( "!map" ) ) { if ( params.IsEmpty() ) m_battle.DoAction( _T( "cannot switch to void mapname" ) ); else { wxString mapname = GetBestMatch( usync().GetMapList(), params ); try { UnitSyncMap map = usync().GetMap( mapname ); m_battle.SetLocalMap( map ); m_battle.DoAction( _T( "is switching to map " ) + mapname ); m_battle.SendHostInfo( IBattle::HI_Map ); } catch ( ... ) { m_battle.DoAction( _T( "cannot switch to map " ) + mapname ); } } } else if ( command == _T( "!set" ) ) { wxString key = params.BeforeFirst( _T( ' ' ) ); wxString value = params.AfterFirst( _T( ' ' ) ); bool exists = m_battle.CustomBattleOptions().keyExists( key ); if ( exists ) { bool result = m_battle.CustomBattleOptions().setSingleOption( key, value ); if ( result ) { OptionsWrapper::GameOption section = m_battle.CustomBattleOptions().GetSection( key ); m_battle.SendHostInfo( wxString::Format( _T( "%d_%s" ), section, key.c_str() ) ); m_battle.DoAction( _T( "has set option " ) + key + _T( " to value " ) + value ); } else m_battle.DoAction( _T( "cannot set option " ) + key + _T( " to value " ) + value + _T( ", reason: invalid value." ) ); } else { m_battle.DoAction( _T( "cannot find option entry " ) + key ); } } else if ( command == _T( "!addbox" ) ) { long allynumber; long topleftx; long toplefty; long bottomrightx; long bottomrighty; wxArrayString values = wxStringTokenize( params, _T( " " ) ); int numvalues = values.GetCount(); if ( numvalues > 4 || numvalues < 3 ) m_battle.DoAction( _T( "has recieved an invalid number of params for !addbox" ) ); else { bool valueok = values[0].ToLong( &topleftx ); valueok = valueok && values[1].ToLong( &toplefty ); valueok = valueok && values[2].ToLong( &bottomrightx ); valueok = valueok && values[3].ToLong( &bottomrighty ); if ( numvalues == 5 ) { valueok = valueok && values[4].ToLong( &allynumber ); valueok = valueok && ( allynumber > 0 ); } else { allynumber = m_battle.GetNextFreeRectIdx(); } valueok = valueok && ( topleftx >= 0 ) && ( topleftx <= 200 ); valueok = valueok && ( toplefty >= 0 ) && ( toplefty <= 200 ); valueok = valueok && ( bottomrightx >= 0 ) && ( bottomrightx <= 200 ); valueok = valueok && ( bottomrighty >= 0 ) && ( bottomrighty <= 200 ); if ( valueok ) { allynumber = allynumber - 1; BattleStartRect rect = m_battle.GetStartRect( allynumber ); if ( rect.IsOk() ) { m_battle.DoAction( _T( "cannot add a startbox for allyteam " ) + TowxString( allynumber ) + _T( " because one is already present." ) ); } else { m_battle.AddStartRect( allynumber, topleftx, toplefty, bottomrightx, bottomrighty ); m_battle.SendHostInfo( IBattle::HI_StartRects ); m_battle.DoAction( _T( "has added start box for allyteam " ) + TowxString( allynumber ) ); } } else { m_battle.DoAction( _T( "has recieved an invalid param for !addbox" ) ); } } } else if ( command == _T( "!removebox" ) ) { long boxnumber; bool numberok = params.ToLong( &boxnumber ); if ( numberok ) { boxnumber = boxnumber - 1; BattleStartRect rect = m_battle.GetStartRect( boxnumber ); if ( rect.IsOk() ) { m_battle.RemoveStartRect( boxnumber ); m_battle.SendHostInfo( IBattle::HI_StartRects ); m_battle.DoAction( _T( "has removed the start box for allyteam " ) + TowxString( boxnumber ) ); } else { m_battle.DoAction( _T( "cannot find start box " ) + params ); } } else { m_battle.DoAction( _T( "has recieved an invalid param to !removebox command" ) ); } } else return; m_lastActionTime = currentTime; }