//return the lowest currently unused key in the map of rects. unsigned int IBattle::GetNextFreeRectIdx() const { //check for unused allyno keys for(unsigned int i = 0; i <= GetLastRectIdx(); i++) { if(!GetStartRect(i).IsOk()) return i; } return GetNumRects(); //if all rects are in use, or no elements exist, return first possible available allyno. }
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; }
void Battle::LoadMapDefaults( const wxString& mapname ) { CustomBattleOptions().setSingleOption( _T("startpostype"), sett().GetMapLastStartPosType( mapname ), OptionsWrapper::EngineOption ); SendHostInfo( wxString::Format( _T("%d_startpostype"), OptionsWrapper::EngineOption ) ); for( unsigned int i = 0; i <= GetLastRectIdx(); ++i ) if ( GetStartRect( i ).IsOk() ) RemoveStartRect(i); // remove all rects SendHostInfo( IBattle::HI_StartRects ); std::vector<Settings::SettStartBox> savedrects = sett().GetMapLastRectPreset( mapname ); for ( std::vector<Settings::SettStartBox>::iterator itor = savedrects.begin(); itor != savedrects.end(); itor++ ) { AddStartRect( itor->ally, itor->topx, itor->topy, itor->bottomx, itor->bottomy ); } SendHostInfo( IBattle::HI_StartRects ); }
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 Battle::SaveMapDefaults() { // save map preset wxString mapname = LoadMap().name; wxString startpostype = CustomBattleOptions().getSingleValue( _T("startpostype"), OptionsWrapper::EngineOption ); sett().SetMapLastStartPosType( mapname, startpostype); std::vector<Settings::SettStartBox> rects; for( unsigned int i = 0; i <= GetLastRectIdx(); ++i ) { BattleStartRect rect = GetStartRect( i ); if ( rect.IsOk() ) { Settings::SettStartBox box; box.ally = rect.ally; box.topx = rect.left; box.topy = rect.top; box.bottomx = rect.right; box.bottomy = rect.bottom; rects.push_back( box ); } } sett().SetMapLastRectPreset( mapname, rects ); }