当前位置: 首页>>代码示例>>C++>>正文


C++ Language::SetID方法代码示例

本文整理汇总了C++中Language::SetID方法的典型用法代码示例。如果您正苦于以下问题:C++ Language::SetID方法的具体用法?C++ Language::SetID怎么用?C++ Language::SetID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Language的用法示例。


在下文中一共展示了Language::SetID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ParseSection


//.........这里部分代码省略.........
      else if ( key == "icon" ) t.SetImage( StrToNum( val ) );
      else if ( key == "armour" ) t.SetDefence( StrToNum( val ) );
      else if ( key == "speed" ) t.SetMoves( StrToNum( val ) );
      else if ( key == "price" ) t.SetCost( StrToNum( val ) );
      else if ( key == "weight" ) t.SetWeight( StrToNum( val ) );
      else if ( key == "transslots" ) t.SetTransSlots( StrToNum( val ) );
      else if ( key == "transminweight" ) t.SetTransMinWeight( StrToNum( val ) );
      else if ( key == "transmaxweight" ) t.SetTransMaxWeight( StrToNum( val ) );
      else if ( key == "portrait" ) {
        vector<string>::iterator it =
                find( info.portraits.begin(), info.portraits.end(), val );
        if ( it == info.portraits.end() ) {
          t.SetPortrait( info.portraits.size() );
          info.portraits.push_back( val );
        } else {
          t.SetPortrait( distance( info.portraits.begin(), it ) );
        }
      }
      else if ( key.substr( 0, 5 ) == "power" ) {
        string type = ParseOpt( key );

        if ( type == "" ) rc = 1;
        else rc = ParsePower( val, type, t );
      }
      else if ( key.substr( 0, 4 ) == "name" ) {
        string lang = ParseOpt( key );

        if ( lang == "" ) rc = 1;
        else if ( lang.size() != 2 ) {
          rc = 1;
          cerr << "Error near line " << line << ": '" << val << "' is not a valid language" << endl;
        } else {
          map <string, Language>::iterator it = names.find( lang );
          if ( it == names.end() ) {
            // only accept new languages for the first unit
            if ( units.size() == 0 ) {
              Language l;
              l.SetID( lang.c_str() );
              l.AddMsg( val );
              names[lang] = l;
              named = true;
            } else
              cerr << "Warning near line " << line << ": New language '" << lang << "' ignored" << endl;
          } else {
            it->second.AddMsg( val );
            named = true;
          }
        }
      } else {
        rc = 1;
        cerr << "Error near line " << line << ": Invalid keyword '" << key << "' in this context" << endl;
      }
    }

    if ( t.Firepower( U_GROUND ) == 0 ) {
      t.SetMinRangeGround( 0 );
      t.SetMaxRangeGround( 0 );
    }
    if ( t.Firepower( U_SHIP ) == 0 ) {
      t.SetMinRangeShip( 0 );
      t.SetMaxRangeShip( 0 );
    }
    if ( t.Firepower( U_AIR ) == 0 ) {
      t.SetMinRangeAir( 0 );
      t.SetMaxRangeAir( 0 );
    }
    if ( t.Slots() > 0 ) t.AddFlags( U_TRANSPORT );
    if ( t.Terrain() == 0 ) {
      rc = 1;
      cerr << "Error near line " << line << ": Unit does not specify terrain" << endl;
    }

    if ( !named ) {
      rc = 1;
      cerr << "Error near line " << line << ": Unit does not specify a name" << endl;
    } else {
      unsigned short msgs = names[CF_LANG_DEFAULT].Size();
      for ( map<string, Language>::iterator it = names.begin();
            it != names.end(); ++it ) {
        if ( it->second.Size() != msgs ) {
          const char *defname = names[CF_LANG_DEFAULT].GetMsg(msgs-1);
          if ( defname ) {
            cerr << "Warning near line " << line
                 << ": Unit does not specify name for language '" << it->first
                 << "', using '" << CF_LANG_DEFAULT << "' default ("
                 << defname << ')' << endl;
            it->second.AddMsg( defname );
          } else {
            rc = 1;
            cerr << "Error near line " << line
                 << ": Unit does not specify name for language '" << it->first << "'" << endl;
          }
        }
      }
    }

    units.push_back( t );
  }
  return rc;
}
开发者ID:drodin,项目名称:Crimson,代码行数:101,代码来源:mkunitset.cpp


注:本文中的Language::SetID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。