// Parcours les différentes familles de MP pour effectuer // les traitements nécessaires void LoadFamillesMP() { printf( "-- LOADING RAW MATERIAL FAMILIES --\n" ); // Preload wk.uxt, item_mp_family.typ, and item_mp_group.typ (avoid to reload them each time) FamilyTypContent.readFromFile( ITEM_MP_FAMILY_TYP ); GroupTypContent.readFromFile( ITEM_MP_GROUPE_TYP ); WKContent.readFromFile( WK_UXT ); // avoid huge resize of vector<string> MPFamilies.reserve(1000); CSString fileData, ligne; if ( ! CFile::fileExists( "rm_fam_prop.csv" ) ) { nlError( "rm_fam_prop.csv not found\n"); exit( 1 ); } fileData.readFromFile( "rm_fam_prop.csv" ); ligne = fileData.splitTo( "\n", true ); while ( ligne != "" ) { NewMP( ligne ); ligne = fileData.splitTo( "\n", true ); } // le Primitive Necklace n'étant pas spécifié dans la liste des MP // on le rajoute à la main CreatePrimitiveNecklace(); }
// Initialise les repertoires à partir de raw_material_generation.cfg void SetupDirectories() { CSString data; if ( ! CFile::fileExists( "raw_material_generation.cfg" ) ) { nlError( "raw_material_generation.cfg not found\n"); exit( 1 ); } data.readFromFile( "raw_material_generation.cfg" ); LEVEL_DESIGN_PATH = data.splitFrom( "LevelDesignPath = \"").splitTo( "\"" ); TRANSLATION_PATH = data.splitFrom( "TranslationPath = \"" ).splitTo( "\"" ); printf( "Level Design Path : %s\nTranslation Path : %s\n\n", LEVEL_DESIGN_PATH.c_str(), TRANSLATION_PATH.c_str() ); ITEM_MP_FAMILY_TYP = LEVEL_DESIGN_PATH + "leveldesign\\DFN\\game_elem\\_item\\item_mp_family.typ"; ITEM_MP_GROUPE_TYP = LEVEL_DESIGN_PATH + "leveldesign\\DFN\\game_elem\\_item\\item_mp_group.typ"; ITEM_MP_PARAM_DFN = LEVEL_DESIGN_PATH + "leveldesign\\DFN\\game_elem\\_item\\_item_mp_param.dfn"; MP_DIRECTORY = LEVEL_DESIGN_PATH + "leveldesign\\game_element\\sitem\\raw_material\\"; DEPOSIT_MPS = LEVEL_DESIGN_PATH + "leveldesign\\game_element\\deposit_system\\mps\\"; RAW_MATERIAL_ASSIGN = LEVEL_DESIGN_PATH + "leveldesign\\Game_elem\\Creature\\raw_material_assignment\\"; IC_FAMILIES_FORAGE_SOURCE = LEVEL_DESIGN_PATH + "leveldesign\\game_element\\forage_source\\_ic_families.forage_source"; WK_UXT = TRANSLATION_PATH + "work\\wk.uxt"; ITEM_WORDS_WK = TRANSLATION_PATH + "work\\item_words_wk.txt"; }
// Assigne une nouvelle MP à une creature void AssignerMP( const CSString& creatureName, const CSString& materialName ) { // on regarde si la créature est dégénérée ou non if ( ( creatureName.c_str()[3] != 'c' ) && ( creatureName.c_str()[3] != 'd' ) && ( creatureName.c_str()[3] != 'f' ) && ( creatureName.c_str()[3] != 'j' ) && ( creatureName.c_str()[3] != 'l' ) && ( creatureName.c_str()[3] != 'p' ) ) { } else { // lecture du fichier d'assignement CSString fileName = toString( "%s//_%s_mp.creature", RAW_MATERIAL_ASSIGN.c_str(), creatureName.c_str() ); CSString data; // création si le fichier n'existe pas if(!CFile::fileExists(fileName)) { CSString str; str = "<?xml version=\"1.0\"?>\r\n"; str+= "<FORM Version=\"0.0\" State=\"modified\">\r\n"; str+= " <STRUCT>\r\n"; str+= " <STRUCT Name=\"Harvest\">\r\n"; str+= " </STRUCT>\r\n"; str+= " </STRUCT>\r\n"; str+= " <STRUCT/>\r\n"; str+= " <STRUCT/>\r\n"; str+= " <STRUCT/>\r\n"; str+= " <STRUCT/>\r\n"; str+= "</FORM>\r\n"; str.writeToFile( fileName ); } // lecture data.readFromFile( fileName ); if ( !data.contains( materialName.c_str() ) ) { // on recherche le premier numéro de MP non utilisé CSString str = data; int nb= 0; while ( str.contains( "Name=\"MP" ) ) { str = str.splitFrom( "Name=\"MP" ); nb = str.firstWord().atoi(); } // on insère la nouvelle MP str = " <STRUCT Name=\"MP"; str += toString( "%d\">\r\n <ATOM Name=\"AssociatedItem\"", nb+1 ); str += toString( " Value=\"%s\"/>\r\n </STRUCT>\r\n </STRUCT>\r\n </STRUCT>\r\n", materialName.c_str() ); data = data.replace( " </STRUCT>\r\n </STRUCT>\r\n", str.c_str() ); data.writeToFile( fileName ); } } }
// update all items with new values int updateItems(const char *filename) { // verify file verifItemsFile(filename); CSString data; data.readFromFile(filename); CVectorSString lines; data.splitLines(lines); for (uint itemIndex=0 ; itemIndex<items.size() ; itemIndex++) { nlassert(fields.size() >= items[itemIndex].size()); cout << "Updating item " << itemIndex << endl; uint a, b; getItemBounds(lines, itemIndex, a, b); // no bound found, it's a new item if (b == 0) { addNewItem(lines, itemIndex); getItemBounds(lines, itemIndex, a, b); } for (uint fieldIndex=0 ; fieldIndex<items[itemIndex].size() ; fieldIndex++) updateItemField(lines, itemIndex, fieldIndex, a, b); } // rewrite file data.clear(); for (uint i=0 ; i<lines.size() ; i++) data += lines[i] + "\n"; data.writeToFile(filename); return 0; }
static void checkShutdownRequest() { // a little system to prevent us from eating too much CPU on systems that have a cstly 'fileExists()' static uint32 count=0; if ((++count)<10) return; count=0; // if there's no ctrl file to be found then giveup if (!NLMISC::CFile::fileExists(ShutdownRequestFileName)) return; // if a shutdown ctrl file exists then read it's contents (if the file doesn't exist this returns an empty string) CSString fileContents; fileContents.readFromFile(ShutdownRequestFileName.c_str()); // see if the file exists if (!fileContents.empty()) { NLMISC::CFile::deleteFile(ShutdownRequestFileName); fileContents= fileContents.strip().splitToOneOfSeparators(" \t\n\r\x1a"); // get rid of any unwanted junk surrounding the file contents nlinfo("Treating shutdown request from ctrl file %s: %s",ShutdownRequestFileName.c_str(),("#.State="+fileContents).c_str()); NLMISC::ICommand::execute("getViewAES #.State="+fileContents, *NLMISC::InfoLog); } }