CNrpHUDConfig::CNrpHUDConfig() : INrpConfig(CLASS_HUDCONFIG, CLASS_HUDCONFIG) { RegProperty( FONT_SIMPLE, NrpText("") ); RegProperty( FONT_TOOLTIP, NrpText("") ); Load( L"config/hud.ini" ); }
const NParam& INrpConfig::operator[](OPTION_NAME& key) const { PARAMS::iterator node = _params.find( key.ToLower() ); if( node != _params.end() ) { return *(node->second); } NrpText err = NrpText( "invalid key " ) + NrpText( key ); Log(HW) << "error: invalid key " << const_cast< INrpConfig* >( this )->ObjectTypeName() << ":" << key << term; throw std::exception( err ); }
void OpFileSystem::CreateDirectorySnapshot( const NrpText& directory, const NrpText& templateName, const NrpText& itemName, IniFile* ini, const NrpText& funcUpdate ) { _wfinddata_t fdata; intptr_t hFile; assert( directory.size() ); if( directory.size() ) { hFile = _wfindfirst( ( CheckEndSlash( directory )+ anyFile ).ToWide(), &fdata); while( hFile ) { if ( !( firstEntry == fdata.name || secondEntry == fdata.name ) )// это удалять не надо if ((( fdata.attrib & _A_SUBDIR ) == _A_SUBDIR ) || ( fdata.attrib == _A_SUBDIR ))// найдена папка { CreateDirectorySnapshot( CheckEndSlash( directory ) + NrpText( fdata.name ), templateName, itemName, ini, funcUpdate ); } else// иначе найден файл { if( _wcsicmp( itemName.ToWide(), fdata.name ) == 0 ) { NrpText fileName = CheckEndSlash( directory )+ fdata.name; IniFile rv( fileName ); int number= ini->Get( SECTION_OPTIONS, templateName + numTemplate, (int)0 ); NrpText intName = rv.Get( SECTION_PROPERTIES, INrpConfig::uniqTemplate, NrpText( "" ) ); ini->Set( SECTION_OPTIONS, CreateKeyName( number ), intName ); ini->Set( SECTION_OPTIONS, templateName + NrpText( (int)number ), fileName ); ini->Set( SECTION_OPTIONS, templateName + numTemplate, number+1 ); if( funcUpdate.size() && GetTickCount() - lastTimeUpdate > 500 ) { lastTimeUpdate = GetTickCount(); CNrpScript::Instance().DoString( funcUpdate + "(" + NrpText( number ) + ")" ); } } } if( _wfindnext( hFile, &fdata) != 0 ) break; } } _findclose( hFile ); }
void CNrpConfigSyncer::_WriteUnknown( const NParam& prop, const NrpText& key, IniFile& ini, const NrpText& section ) { NrpText dd = const_cast< NParam& >( prop ).GetType(); if( dd.find( L"enum" ) == 0 ) { _WriteInt( prop, key, ini, section ); } else ini.Set( section, key + _d( t_unknown ), NrpText("") ); }
CNrpUser* CNrpLaborMarket::CreateRandomUser( NrpText userType ) { TECHS genres; _GetTechsByGroup( PT_GENRE, genres ); size_t randomParams = 1 + rand() % genres.size();//сколько параметров будем создавать int maxParamValue = 1 + rand() % 100;//максимальное значение параметров std::map< NrpText, NrpText > skillMap; skillMap[ "coder" ] = SKILL_CODING; skillMap[ "designer" ] = SKILL_DRAWING; skillMap[ "composer" ] = SKILL_SOUND; skillMap[ NrpTester::ClassName() ] = SKILL_TESTING; NrpText userName; CNrpUser* ptrUser = NULL; do { userName = GlobalPeopleName[ rand() % PEOPLE_NAME_COUNT ] + " " + GlobalPeopleSurname[ rand() % PEOPLE_SURNAME_COUNT ]; ptrUser = GetUser( userName ); } while ( ptrUser != NULL ); if( userType == CNrpAiUser::ClassName() ) ptrUser = new CNrpAiUser( userName, NULL ); else if( userType == NrpTester::ClassName() ) ptrUser = new NrpTester( userName ); else ptrUser = new CNrpUser( userType, userName ); CNrpUser& refUser = *ptrUser; ptrUser->SetSkill( skillMap[ userType ], maxParamValue ); refUser[ WORK_QUALITY ] = RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ); refUser[ WORK_SPEED ] = RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ); refUser[ TALANT ] = RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ); refUser[ STAMINA ] = RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ); refUser[ STABILITY ] = RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ); refUser[ CHARACTER ] = RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ); if( (int)refUser[ WANTMONEY ] < (int)_nrpApp[ MINIMUM_USER_SALARY ] ) refUser[ WANTMONEY ] = _nrpApp[ MINIMUM_USER_SALARY ]; char name[64] = { 0 }; snprintf( name, 64, "media/face/face%03d.png", rand() % 2 ); refUser[ TEXTURENORMAL ] = NrpText( name ); for( size_t cnt=0; cnt < randomParams; cnt++ ) { NrpText genreName = (*genres[ rand() % genres.size() ])[ INTERNAL_NAME ]; ptrUser->SetGenreExperience( genreName, RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ) ); ptrUser->SetGenrePreferences( genreName, RandomUserParam( maxParamValue, _nrpApp[ DEV_FORCE ] ) ); } return ptrUser; }
void CNrpLaborMarket::_LoadUsers( const NrpText& fileName ) { IniFile sv( fileName ); int maxUser = _self[ USERNUMBER ]; for( int i=0; i < maxUser; i++ ) { NrpText name = sv.Get( SECTION_USERS, CreateKeyUser(i), NrpText("") ); NrpText className = sv.Get( SECTION_USERS, CreateKeyType(i), NrpText("") ); NrpText fileName = (NrpText)_nrpApp[ SAVEDIR_USERS ] + name + ".user"; if( !OpFileSystem::IsExist( fileName ) ) { assert( false && "user config file not found" ); continue; } CNrpUser* user = NULL; if( className == CNrpPlayer::ClassName() ) user = new CNrpPlayer( fileName ); else { if( className == CNrpAiUser::ClassName() ) user = new CNrpAiUser( fileName ); else { if( className == NrpTester::ClassName() ) user = new NrpTester( name ); else user = new CNrpUser( className, name ); user->Load( fileName ); } } assert( user ); AddUser( user ); } }
void CNrpPlant::Load( const NrpText& saveFolder ) { NrpText fileName = OpFileSystem::CheckEndSlash( saveFolder ) + "plant.ini"; assert( OpFileSystem::IsExist( fileName ) ); INrpConfig::Load( fileName ); IniFile rv( fileName ); int maxNumber = (int)Param( WORKNUMBER ) + (int)Param( REKLAMENUMBER ); for( int k=0; k < maxNumber; k++ ) { NrpText type = rv.Get( SECTION_WORKS, CreateKeyType( k ), NrpText("") ); NrpText saveFile = rv.Get( SECTION_WORKS, CreateKeyWork( k ), NrpText("") ); if( OpFileSystem::IsExist( saveFile ) ) { if( type == CNrpPlantWork::ClassName() ) AddWork( new CNrpPlantWork( saveFile, true ) ); else if( type == CNrpReklameWork::ClassName() ) AddReklame( CNrpReklameWork( saveFile ) ); } } }
void OpFileSystem::Copy( const NrpText& pathOld, const NrpText& pathNew ) { NrpText newfile; intptr_t hFile; if( !IsExist( pathNew ) ) CreateDirectory( pathNew ); _wfinddata_t fdata; assert( IsExist( pathOld ) ); if( IsExist( pathOld ) ) { hFile = _wfindfirst( ( CheckEndSlash( pathOld )+ anyFile ).ToWide(), &fdata); while( hFile > 0 ) { if ( fdata.attrib & _A_SUBDIR ) // если нашли папку { if( !( firstEntry == fdata.name || secondEntry == fdata.name ) ) { Copy( CheckEndSlash( pathOld ) + NrpText( fdata.name ), CheckEndSlash( pathNew ) + NrpText( fdata.name ) );// Рекурсивный вызов } } else // если нашли файл { newfile = CheckEndSlash( pathNew ) + fdata.name; CopyFileW( ( CheckEndSlash( pathOld ) + fdata.name ).ToWide(), newfile.ToWide(), true); } if( _wfindnext( hFile, &fdata) != 0 ) break; } _findclose( hFile ); } return; }
void OpFileSystem::Remove( const NrpText& pathTo ) { if( !IsFolder( pathTo ) ) //файл можно удалить сразу DeleteFileW( pathTo.ToWide() ); else { NrpText mStr = CheckEndSlash( pathTo ); _wfinddata_t fdata; intptr_t hFile; assert( IsExist( mStr ) ); if( IsExist( mStr ) ) { hFile = _wfindfirst( ( mStr + anyFile ).ToWide(), &fdata); while( hFile > 0 ) { if ( !( firstEntry == fdata.name || secondEntry == fdata.name ) )// это удалять не надо if ((( fdata.attrib & _A_SUBDIR ) == _A_SUBDIR ) || ( fdata.attrib == _A_SUBDIR ))// найдена папка { Remove( CheckEndSlash( mStr ) + NrpText( fdata.name ) ); } else// иначе найден файл { DeleteFileW( ( CheckEndSlash( mStr ) + fdata.name ).ToWide() ); } if( _wfindnext( hFile, &fdata) != 0 ) break; } _findclose( hFile ); } if( !RemoveDirectoryW( RemoveEndSlash( mStr ).ToWide() ) ) { int rr = GetLastError(); rr = rr; } } }
NrpText _d( const NrpText& text ) { return NrpText(":") + text; }
void CNrpConfigSyncer::_ReadDim2u( IniKey* p ) { _config->RegProperty<core::dimension2du>( p->GetShortKey().c_str(), NrpText( p->GetValue().c_str() ).ToDim2du() ); }
void CNrpConfigSyncer::_ReadTime( IniKey* p ) { (*_config)[ p->GetShortKey().c_str() ] = NrpTime( NrpText( p->GetValue().c_str() ) ); }
void CNrpConfigSyncer::_ReadBool( IniKey* p ) { (*_config)[ p->GetShortKey().c_str() ] = NrpText( p->GetValue().c_str() ).ToBool(); }