Add infos into target window
[ryzomcore.git] / ryzom / client / src / sheet_manager.cpp
blob8388079347c3fbb9034cdb5e9eb3b8becab97593
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2020 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /////////////
21 // INCLUDE //
22 /////////////
23 #include "stdpch.h" // First include for pre-compiled headers.
24 // Misc
25 #include "nel/misc/path.h"
26 #include "nel/misc/file.h"
27 #include "nel/misc/smart_ptr.h"
28 #include "nel/misc/sheet_id.h"
29 // Georges
30 #include "nel/georges/u_form.h"
31 #include "nel/georges/u_form_elm.h"
32 #include "nel/georges/u_form_loader.h"
33 #include "nel/georges/u_type.h"
34 #include "nel/georges/load_form.h"
35 // Client
36 #include "sheet_manager.h"
37 //#include "client_cfg.h"
38 #include "client_sheets/entity_sheet.h"
39 #include "client_sheets/faction_sheet.h"
40 // Game Share
41 #include "game_share/visual_slot_manager.h"
43 #ifdef DEBUG_NEW
44 #define new DEBUG_NEW
45 #endif
47 ///////////
48 // USING //
49 ///////////
50 using namespace NLMISC;
51 using namespace std;
52 using namespace NLGEORGES;
55 /////////////
56 // GLOBALS //
57 /////////////
58 // Sheet manager.
59 CSheetManager SheetMngr;
60 UFormLoader *CSheetManager::FormLoader = NULL;
61 //COFile fItemAssoc;
62 //bool ItemAssocFileOpen = false;
64 // there can be several instance of CSheetManager (for reload operations) -> ctruct the loader here rather than in CSheetManager ctor
65 class CFormLoaderInit
67 public:
68 CFormLoaderInit()
70 nlassert (CSheetManager::FormLoader == NULL);
71 CSheetManager::FormLoader = UFormLoader::createLoader ();
72 nlassert (CSheetManager::FormLoader != NULL);
74 ~CFormLoaderInit()
76 if (CSheetManager::FormLoader)
78 UFormLoader::releaseLoader (CSheetManager::FormLoader);
79 CSheetManager::FormLoader = NULL;
85 static CFormLoaderInit FormLoadInit;
87 class CTypeVersion
89 public:
90 std::string Type;
91 uint Version;
93 CTypeVersion(std::string type, uint version) {Type=type; Version=version;}
96 // if you change these values please rebuild the packed_sheets with an updated sheets_packer binary.
97 // This is the only way to have correct version in both client and packed_sheets
98 CTypeVersion TypeVersion [] =
100 CTypeVersion("creature", 17),
101 // CTypeVersion("player", 0),
102 CTypeVersion("fx", 0),
103 CTypeVersion("building", 2),
104 CTypeVersion("sitem", 44),
105 CTypeVersion("item", 44),
106 CTypeVersion("plant", 5),
107 CTypeVersion("death_impact", 0),
108 // CTypeVersion("mission", 0),
109 CTypeVersion("race_stats", 3),
110 CTypeVersion("light_cycle", 0),
111 CTypeVersion("weather_setup", 1),
112 CTypeVersion("continent", 12),
113 CTypeVersion("world", 1),
114 CTypeVersion("weather_function_params", 2),
115 CTypeVersion("mission_icon", 0),
116 CTypeVersion("sbrick", 33),
117 CTypeVersion("sphrase", 4),
118 CTypeVersion("skill_tree", 5),
119 CTypeVersion("titles", 1),
120 CTypeVersion("succes_chances_table", 1),
121 CTypeVersion("automaton_list", 23),
122 CTypeVersion("animset_list", 25),
123 CTypeVersion("animation_fx", 4),
124 CTypeVersion("id_to_string_array", 1),
125 CTypeVersion("emot", 1),
126 CTypeVersion("forage_source", 2),
127 CTypeVersion("flora", 0),
128 CTypeVersion("animation_fx_set", 3),
129 CTypeVersion("attack_list", 9),
130 CTypeVersion("text_emotes", 1),
131 CTypeVersion("sky", 5),
132 CTypeVersion("outpost", 0),
133 CTypeVersion("outpost_building", 1),
134 CTypeVersion("outpost_squad", 1),
135 CTypeVersion("faction", 0),
137 // This is just a value for CVS conflict generation.
138 const char *LastPackedFilenameVersionIncrementer= "nico";
142 /////////////
143 // MEMBERS //
144 /////////////
145 static uint Version = 2;
148 ////////////////////////
149 // CSheetManagerEntry //
150 ////////////////////////
152 // ***************************************************************************
153 CSheetManagerEntry::CSheetManagerEntry () : EntitySheet(NULL)
157 //-----------------------------------------------
158 // ~CSheetManagerEntry :
159 //-----------------------------------------------
160 CSheetManagerEntry::~CSheetManagerEntry ()
162 // Release the sheet.
163 if(EntitySheet != 0)
165 delete EntitySheet;
166 EntitySheet = 0;
168 }// ~CSheetManagerEntry //
171 // ***************************************************************************
172 void CSheetManagerEntry::readGeorges (const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const NLMISC::CSheetId &sheetId)
174 // Load the form with given sheet id
175 if (form)
177 // if (EntitySheet != NULL)
178 // delete EntitySheet;
180 CEntitySheet *sheet = NULL;
182 std::string extension = NLMISC::CSheetId::fileExtensionFromType(sheetId.getSheetType());
184 // create the new structure
185 if (extension == "creature")
186 sheet = new CCharacterSheet;
187 else if(extension == "player")
188 sheet = new CPlayerSheet;
189 else if(extension == "fx")
190 sheet = new CFXSheet;
191 else if(extension == "building")
192 sheet = new CBuildingSheet;
193 else if(extension == "sitem" || extension == "item" )
194 sheet = new CItemSheet;
195 else if(extension == "plant")
196 sheet = new CPlantSheet;
197 else if(extension == "death_impact")
198 sheet = new CPactSheet;
199 else if(extension == "mission")
200 sheet = new CMissionSheet;
201 else if(extension == "race_stats")
202 sheet = new CRaceStatsSheet;
203 else if(extension == "light_cycle")
204 sheet = new CLightCycleSheet;
205 else if(extension == "weather_setup")
206 sheet = new CWeatherSetupSheet;
207 else if(extension == "continent")
208 sheet = new CContinentSheet;
209 else if(extension == "world")
210 sheet = new CWorldSheet;
211 else if(extension == "weather_function_params")
212 sheet = new CWeatherFunctionParamsSheet;
213 else if(extension == "mission_icon")
214 sheet = new CMissionIconSheet;
215 else if(extension == "sbrick")
216 sheet = new CSBrickSheet;
217 else if(extension == "sphrase")
218 sheet = new CSPhraseSheet;
219 else if(extension == "skill_tree")
220 sheet = new CSkillsTreeSheet;
221 else if(extension == "titles")
222 sheet = new CUnblockTitlesSheet;
223 else if(extension == "succes_chances_table")
224 sheet = new CSuccessTableSheet;
225 else if(extension == "automaton_list")
226 sheet = new CAutomatonListSheet;
227 else if(extension == "animset_list")
228 sheet = new CAnimationSetListSheet;
229 else if(extension == "animation_fx")
230 sheet = new CAnimationFXSheet;
231 else if(extension == "id_to_string_array")
232 sheet = new CIDToStringArraySheet;
233 else if(extension == "emot")
234 sheet = new CEmotListSheet;
235 else if(extension == "forage_source")
236 sheet = new CForageSourceSheet;
237 else if(extension == "flora")
238 sheet = new CFloraSheet;
239 else if(extension == "animation_fx_set")
240 sheet = new CAnimationFXSetSheet;
241 else if(extension == "attack_list")
242 sheet = new CAttackListSheet;
243 else if(extension == "text_emotes")
244 sheet = new CTextEmotListSheet;
245 else if(extension == "sky")
246 sheet = new CSkySheet;
247 else if(extension == "outpost")
248 sheet = new COutpostSheet;
249 else if(extension == "outpost_building")
250 sheet = new COutpostBuildingSheet;
251 else if(extension == "outpost_squad")
252 sheet = new COutpostSquadSheet;
253 else if(extension == "faction")
254 sheet = new CFactionSheet;
255 else
257 nlwarning("CSheetManager::loadSheet: Do not know how to create the class from the sheet '%s'.", sheetId.toString().c_str());
258 return;
261 // Build the sheet from an external file.
262 sheet->Id = sheetId;
263 sheet->build(form->getRootNode());
265 EntitySheet = sheet;
266 SheetMngr.processSheet(EntitySheet);
268 // Error while loading the form.
269 else
271 // nlwarning("CSheetManager::loadSheet: Cannot load the form '%s'.", filename.c_str());
272 EntitySheet = 0;
276 // ***************************************************************************
277 void CSheetManagerEntry::initSheet(CEntitySheet *pES, NLMISC::IStream &s, CEntitySheet::TType type)
279 if (pES != NULL)
281 pES->Id.serial(s);
282 pES->serial(s);
283 pES->Type = type;
284 SheetMngr.processSheet(pES);
289 // ***************************************************************************
290 void CSheetManagerEntry::serial (NLMISC::IStream &s)
292 if (s.isReading())
294 // if (EntitySheet != NULL)
295 // delete EntitySheet;
297 CEntitySheet::TType type = CEntitySheet::TypeCount;
298 s.serialEnum(type);
300 switch(type)
302 case CEntitySheet::FAUNA:
304 EntitySheet = new CCharacterSheet;
305 initSheet(EntitySheet, s, type);
307 break;
308 case CEntitySheet::FLORA:
310 EntitySheet = new CFloraSheet;
311 initSheet(EntitySheet, s, type);
313 break;
314 case CEntitySheet::CHAR:
316 EntitySheet = new CPlayerSheet;
317 initSheet(EntitySheet, s, type);
319 break;
320 case CEntitySheet::FX:
322 EntitySheet = new CFXSheet;
323 initSheet(EntitySheet, s, type);
325 break;
326 case CEntitySheet::BUILDING:
328 EntitySheet = new CBuildingSheet;
329 initSheet(EntitySheet, s, type);
331 break;
332 case CEntitySheet::ITEM:
334 EntitySheet = new CItemSheet;
335 initSheet(EntitySheet, s, type);
337 break;
338 case CEntitySheet::PLANT:
340 EntitySheet = new CPlantSheet;
341 initSheet(EntitySheet, s, type);
343 break;
344 case CEntitySheet::PACT:
346 EntitySheet = new CPactSheet;
347 initSheet(EntitySheet, s, type);
349 break;
350 case CEntitySheet::MISSION:
352 EntitySheet = new CMissionSheet;
353 initSheet(EntitySheet, s, type);
355 break;
356 case CEntitySheet::MISSION_ICON:
358 EntitySheet = new CMissionIconSheet;
359 initSheet(EntitySheet, s, type);
361 break;
362 case CEntitySheet::RACE_STATS:
364 EntitySheet = new CRaceStatsSheet;
365 initSheet(EntitySheet, s, type);
367 break;
368 case CEntitySheet::LIGHT_CYCLE:
370 EntitySheet = new CLightCycleSheet;
371 initSheet(EntitySheet, s, type);
373 break;
374 case CEntitySheet::WEATHER_SETUP:
376 EntitySheet = new CWeatherSetupSheet;
377 initSheet(EntitySheet, s, type);
379 break;
380 case CEntitySheet::CONTINENT:
382 EntitySheet = new CContinentSheet;
383 initSheet(EntitySheet, s, type);
385 break;
386 case CEntitySheet::WORLD:
388 EntitySheet = new CWorldSheet;
389 initSheet(EntitySheet, s, type);
391 break;
392 case CEntitySheet::WEATHER_FUNCTION_PARAMS:
394 EntitySheet = new CWeatherFunctionParamsSheet;
395 initSheet(EntitySheet, s, type);
397 break;
398 case CEntitySheet::SBRICK:
400 EntitySheet = new CSBrickSheet;
401 initSheet(EntitySheet, s, type);
403 break;
404 case CEntitySheet::SPHRASE:
406 EntitySheet = new CSPhraseSheet;
407 initSheet(EntitySheet, s, type);
409 break;
410 case CEntitySheet::SKILLS_TREE:
412 EntitySheet = new CSkillsTreeSheet;
413 initSheet(EntitySheet, s, type);
415 break;
416 case CEntitySheet::UNBLOCK_TITLES:
418 EntitySheet = new CUnblockTitlesSheet;
419 initSheet(EntitySheet, s, type);
421 break;
422 case CEntitySheet::SUCCESS_TABLE:
424 EntitySheet = new CSuccessTableSheet;
425 initSheet(EntitySheet, s, type);
427 break;
428 case CEntitySheet::AUTOMATON_LIST:
430 EntitySheet = new CAutomatonListSheet;
431 initSheet(EntitySheet, s, type);
433 break;
434 case CEntitySheet::ANIMATION_SET_LIST:
436 EntitySheet = new CAnimationSetListSheet;
437 initSheet(EntitySheet, s, type);
439 break;
440 case CEntitySheet::ANIMATION_FX:
442 EntitySheet = new CAnimationFXSheet;
443 initSheet(EntitySheet, s, type);
445 break;
446 case CEntitySheet::ID_TO_STRING_ARRAY:
448 EntitySheet = new CIDToStringArraySheet;
449 initSheet(EntitySheet, s, type);
451 break;
452 case CEntitySheet::EMOT:
454 EntitySheet = new CEmotListSheet;
455 initSheet(EntitySheet, s, type);
457 break;
458 case CEntitySheet::FORAGE_SOURCE:
460 EntitySheet = new CForageSourceSheet;
461 initSheet(EntitySheet, s, type);
463 break;
464 case CEntitySheet::ANIMATION_FX_SET:
466 EntitySheet = new CAnimationFXSetSheet;
467 initSheet(EntitySheet, s, type);
469 break;
470 case CEntitySheet::ATTACK_LIST:
472 EntitySheet = new CAttackListSheet;
473 initSheet(EntitySheet, s, type);
475 break;
476 case CEntitySheet::TEXT_EMOT:
478 EntitySheet = new CTextEmotListSheet;
479 initSheet(EntitySheet, s, type);
481 break;
482 case CEntitySheet::SKY:
484 EntitySheet = new CSkySheet;
485 initSheet(EntitySheet, s, type);
487 break;
488 case CEntitySheet::OUTPOST:
490 EntitySheet = new COutpostSheet;
491 initSheet(EntitySheet, s, type);
493 break;
494 case CEntitySheet::OUTPOST_BUILDING:
496 EntitySheet = new COutpostBuildingSheet;
497 initSheet(EntitySheet, s, type);
499 break;
500 case CEntitySheet::OUTPOST_SQUAD:
502 EntitySheet = new COutpostSquadSheet;
503 initSheet(EntitySheet, s, type);
505 break;
506 case CEntitySheet::FACTION:
508 EntitySheet = new CFactionSheet;
509 initSheet(EntitySheet, s, type);
511 break;
512 default:
513 nlwarning("CSheetManager::load: Unknown type '%d' in the packed file. Rebuild=true and Ignore this sheet.", type);
514 EntitySheet = NULL;
515 break;
518 else
520 if (EntitySheet != NULL)
522 s.serialEnum(EntitySheet->Type);
523 EntitySheet->Id.serial(s);
524 EntitySheet->serial(s);
526 else
528 // write a speudo entry into the stream
529 CEntitySheet::TType tmp = CEntitySheet::UNKNOWN;
530 s.serialEnum(tmp);
535 // ***************************************************************************
536 void CSheetManagerEntry::removed()
538 // any action that is needed if the sheet no more exist.
539 if (EntitySheet != 0)
541 delete EntitySheet;
542 EntitySheet = 0;
546 // ***************************************************************************
547 uint CSheetManagerEntry::getVersion ()
549 return Version;
552 //-----------------------------------------------
553 //-----------------------------------------------
554 void CSheetManagerEntry::setVersion(uint version)
556 Version = version;
557 }// setVersion //
560 /////////////
561 // METHODS //
562 /////////////
563 //-----------------------------------------------
564 // CSheetManager :
565 // Constructor.
566 //-----------------------------------------------
567 CSheetManager::CSheetManager()
569 _NbEyesColor = 0; // Default is no color available for the eyes.
571 // Slot 0 is invalid.
572 for(uint i=0; i<SLOTTYPE::NB_SLOT; ++i)
574 TItemVector slotList;
575 slotList.push_back(0);
576 _VisualSlots.push_back(slotList);
580 //-----------------------------------------------
581 // CSheetManager :
582 // Destructor.
583 //-----------------------------------------------
584 CSheetManager::~CSheetManager()
586 release();
589 //-----------------------------------------------
590 void CSheetManager::release()
592 _VisualSlots.clear();
594 _EntitySheetContainer.clear();
596 _SheetToVS.clear();
599 //-----------------------------------------------
600 // load :
601 // Load all sheets.
602 //-----------------------------------------------
603 void CSheetManager::load(NLMISC::IProgressCallback &callBack, bool updatePackedSheet, bool needComputeVS, bool dumpVSIndex)
605 // Open The Item Association File
606 // if(!fItemAssoc.open(getLogDirectory() + "item_association.dbg", false, true))
607 // nlwarning("CSheetManager::load: Cannot Open the 'item_association.txt'.");
608 // else
609 // ItemAssocFileOpen = true;
611 // Initialize the Sheet DB.
612 loadAllSheet(callBack, updatePackedSheet, needComputeVS, dumpVSIndex);
614 // Close the Item Association File.
615 // fItemAssoc.close();
616 // ItemAssocFileOpen = false;
618 // Optimize memory taken by all strings of all sheets
619 ClientSheetsStrings.memoryCompress();
621 return;
622 }// load //
625 //-----------------------------------------------
626 // loadAllSheet :
627 // Load all sheets.
628 //-----------------------------------------------
629 void CSheetManager::loadAllSheet(NLMISC::IProgressCallback &callBack, bool updatePackedSheet, bool needComputeVS, bool dumpVSIndex, bool forceRecompute /*= false*/, const std::vector<std::string> *userExtensions /*= NULL*/)
632 callBack.progress (0);
633 callBack.pushCropedValues (0, 0.5f);
635 // Get some information from typ files.
636 loadTyp();
638 // prepare a list of sheets extension to load.
639 vector<string> extensions;
641 uint sizeTypeVersion = sizeof(TypeVersion);
642 uint sizeCTypeVersion = sizeof(CTypeVersion);
643 uint nb = sizeTypeVersion/sizeCTypeVersion;
645 if (!userExtensions)
647 _EntitySheetContainer.clear();
649 TEntitySheetMap entitySheetContainer;
650 for(uint i=0; i<nb; ++i)
652 // see if extension is wanted
653 bool found = false;
654 if (userExtensions)
656 for(uint l = 0; l < userExtensions->size(); ++l)
658 if (stricmp((*userExtensions)[l].c_str(), TypeVersion[i].Type.c_str()) == 0)
660 found = true;
664 else
666 found = true;
668 if (found)
670 entitySheetContainer.clear();
671 extensions.clear();
672 extensions.push_back(TypeVersion[i].Type);
673 CSheetManagerEntry::setVersion(TypeVersion[i].Version);
674 string path = CPath::lookup(TypeVersion[i].Type + ".packed_sheets", false);
675 if (forceRecompute && !path.empty())
677 // delete previous packed sheets
678 NLMISC::CFile::deleteFile(path);
679 path.clear();
681 if(path.empty())
682 path = CPath::standardizePath(_OutputDataPath) + TypeVersion[i].Type + ".packed_sheets";
683 ::loadForm(extensions, path, entitySheetContainer, updatePackedSheet);
685 TEntitySheetMap::iterator it = entitySheetContainer.begin();
686 while(it != entitySheetContainer.end())
688 _EntitySheetContainer[(*it).first] = (*it).second;
689 (*it).second.EntitySheet = 0;
690 // Next
691 ++it;
698 // Re-compute Visual Slot
699 if(needComputeVS)
700 computeVS();
702 // Compute Visual Slots
704 for(uint i=0; i<SLOTTYPE::NB_SLOT; ++i)
705 _VisualSlots[i].resize(CVisualSlotManager::getInstance()->getNbIndex((SLOTTYPE::EVisualSlot)i)+1, 0); // Nb Index +1 because index 0 is reserve for empty.
708 TEntitySheetMap::iterator it = _EntitySheetContainer.begin();
709 while(it != _EntitySheetContainer.end())
711 std::vector<CVisualSlotManager::TIdxbyVS> result;
712 CVisualSlotManager::getInstance()->sheet2Index((*it).first, result);
714 for(uint i=0; i<result.size(); ++i)
716 if(dynamic_cast<CItemSheet *>((*it).second.EntitySheet))
718 _SheetToVS[dynamic_cast<CItemSheet *>((*it).second.EntitySheet)].push_back(std::make_pair(result[i].VisualSlot, result[i].Index));
719 _VisualSlots[result[i].VisualSlot][result[i].Index] = dynamic_cast<CItemSheet *>((*it).second.EntitySheet);
723 ++it;
727 // Dump visual slots
728 // nb : if a new visual_slot.tab has just been generated don't forget
729 // to move it in data_common before dump.
730 if(dumpVSIndex)
731 dumpVisualSlotsIndex();
734 callBack.popCropedValues();
735 }// loadAllSheet //
738 // ***************************************************************************
739 void CSheetManager::loadAllSheetNoPackedSheet(NLMISC::IProgressCallback &callBack, const std::vector<std::string> &extensions, const std::string &wildcardFilter)
742 callBack.progress (0);
743 callBack.pushCropedValues (0, 0.5f);
745 // load all forms
746 ::loadFormNoPackedSheet(extensions, _EntitySheetContainer, wildcardFilter);
749 callBack.popCropedValues();
753 //-----------------------------------------------
754 // computeVS :
755 // compute Visual Slots for this sheet.
756 //-----------------------------------------------
757 void CSheetManager::computeVS()
759 static std::map< std::string, uint16 > ProcessedItem;
760 map< string, uint16 >::iterator it;
762 CVisualSlotManager::TVisualSlot vs;
763 vs.resize(SLOTTYPE::NB_SLOT);
766 TEntitySheetMap::iterator itS = _EntitySheetContainer.begin();
767 while(itS != _EntitySheetContainer.end())
769 // Visual Slots are only valid for Items.
770 CItemSheet *item = dynamic_cast<CItemSheet *>((*itS).second.EntitySheet);
771 if (item && (*itS).first.getSheetType()==CSheetId::typeFromFileExtension(std::string("sitem")))
773 for(uint j=0; j<SLOTTYPE::NB_SLOT_TYPE; ++j)
775 SLOTTYPE::TSlotType slotType= (SLOTTYPE::TSlotType)j;
776 if( item->hasSlot(slotType) )
778 SLOTTYPE::EVisualSlot visualSlot = SLOTTYPE::convertTypeToVisualSlot(slotType);
779 if(visualSlot != SLOTTYPE::HIDDEN_SLOT)
781 string currentSheet = ((*itS).first).toString();
783 CVisualSlotManager::TElement vsElmt;
785 string sheetName = toString("%s%d", currentSheet.c_str(), visualSlot);
787 // Is the sheet already process (could be process by a sheet with a different lvl)
788 it = ProcessedItem.find( sheetName );
789 // Insert if not found
790 if(it == ProcessedItem.end())
792 uint itemNumber;
793 if(vs[visualSlot].Element.empty())
794 itemNumber = 1;
795 else
796 itemNumber = vs[visualSlot].Element[vs[visualSlot].Element.size()-1].Index+1;
798 // Item Processed
799 ProcessedItem.insert(make_pair(sheetName, itemNumber));
801 vsElmt.Index = itemNumber;
803 else
805 vsElmt.Index = (*it).second;
808 vsElmt.SheetId = (*itS).first;
809 vs[visualSlot].Element.push_back(vsElmt);
815 // Next Sheet
816 ++itS;
820 // Open the file.
821 NLMISC::COFile f;
822 if(f.open("visual_slot.tab"))
824 // Dump entities.
825 f.serialCont(vs);
827 // Close the File.
828 f.close();
830 else
831 nlwarning("SheetMngr:load: cannot open/create the file 'visual_slot.tab'.");
832 }// computeVS //
834 //-----------------------------------------------
835 // processSheet :
836 // Porcessing the sheet.
837 // \param sheet : sheet to process.
838 //-----------------------------------------------
839 void CSheetManager::processSheet (CEntitySheet * /* sheet */)
841 // For now: no op
842 }// processSheet //
844 //=======================================================================
845 const CSheetManager::TVisualSlotItemArray *CSheetManager::getVSItems(CItemSheet *sheet) const
847 TItemSheet2SlotItemArray::const_iterator it = _SheetToVS.find(sheet);
848 if (it == _SheetToVS.end())
849 return NULL;
850 return &(it->second);
853 //=======================================================================
854 sint CSheetManager::getVSIndex(const std::string &itemName, SLOTTYPE::EVisualSlot slot)
856 NLMISC::CSheetId si;
857 if (!si.buildSheetId(itemName))
859 nlwarning("<CSheetManager::getVSIndex> : cannot build id from item %s for the slot %d.", itemName.c_str(), slot);
860 return -1;
863 TEntitySheetMap::iterator it = _EntitySheetContainer.find(si);;
864 if (it == _EntitySheetContainer.end())
866 nlwarning("<CSheetManager::getVSIndex> : cannot find %s for the slot %d.", itemName.c_str(), slot);
867 return -1;
869 if (it->second.EntitySheet == 0 || it->second.EntitySheet->type() != CEntitySheet::ITEM)
871 nlwarning("<CSheetManager::getVSIndex> : %s is not an item for the slot %d.", itemName.c_str(), slot);
872 return -1;
875 CItemSheet *is = static_cast<CItemSheet *>(it->second.EntitySheet);
877 const TVisualSlotItemArray *ia = getVSItems(is);
878 if (ia == NULL)
880 nlwarning("<CSheetManager::getVSIndex> : no items for the slot %d. while looking for %s", slot, itemName.c_str());
881 return -1;
884 TVisualSlotItemArray::const_iterator first(ia->begin()), last(ia->end());
885 for(; first != last; ++first)
887 if (first->first == slot)
889 return first->second;
893 nlwarning("<CSheetManager::getVSIndex> : cannot find %s for the slot %d.", itemName.c_str(), slot);
894 return -1;
897 //-----------------------------------------------
898 // get :
899 // Get a sheet from its number.
900 // \param uint32 num : sheet number.
901 // \return CEntitySheet * : pointer on the sheet according to the param or 0 if any pb.
902 //-----------------------------------------------
903 CEntitySheet *CSheetManager::get(CSheetId num)
905 TEntitySheetMap::iterator it = _EntitySheetContainer.find(num);
906 if(it != _EntitySheetContainer.end())
907 return it->second.EntitySheet;
908 else
909 return NULL;
910 }// get //
913 //-----------------------------------------------
914 uint CSheetManager::getNumItem(SLOTTYPE::EVisualSlot slot)
916 // The slot is not a visible one.
917 if (slot == SLOTTYPE::HIDDEN_SLOT)
918 return 0;
919 // Convert into an uint to remove warnings.
920 uint s = (uint)slot;
922 // Check slot.
923 if(s < _VisualSlots.size())
925 return (uint)_VisualSlots[s].size();
927 else
929 nlwarning("CSheetManager::getNumItem : invalid slot %d.", slot);
930 return 0;
934 //-----------------------------------------------
935 // getItem :
936 // Get the real.
937 //-----------------------------------------------
938 CItemSheet *CSheetManager::getItem(SLOTTYPE::EVisualSlot slot, uint index)
940 // The slot is not a visible one.
941 if(slot == SLOTTYPE::HIDDEN_SLOT)
942 return 0;
944 // Convert into an uint to remove warnings.
945 uint s = (uint)slot;
947 // Check slot.
948 if(s < _VisualSlots.size())
950 // Check index.
951 if(index < _VisualSlots[s].size())
953 // Not the default Item.
954 if(index != 0)
955 return _VisualSlots[s][index];
956 // Default Item.
957 else
958 return NULL;
960 // Bad index.
961 else
963 //nlwarning("CSheetManager::getItem : invalid index %d for the slot %d.", index, slot);
964 return NULL;
967 // Bad slot.
968 else
970 nlwarning("CSheetManager::getItem : invalid slot %d.", slot);
971 return NULL;
973 }// getItem //
976 //-----------------------------------------------
977 // loadTyp :
978 // Get Some information from 'typ' files.
979 //-----------------------------------------------
980 void CSheetManager::loadTyp()
982 // Read the Eyes Color 'typ'
983 NLMISC::CSmartPtr<NLGEORGES::UType> smartPtr = FormLoader->loadFormType("_creature_3d_eyes_color.typ");
984 if(smartPtr)
986 string maxStr = smartPtr->getMax();
987 fromString(maxStr, _NbEyesColor);
988 if(_NbEyesColor <= 0)
989 nlwarning("CSheetManager::loadTyp: There no is Color available for the eyes.");
991 else
992 nlwarning("CSheetManager::loadTyp: Cannot load the '_creature_3d_eyes_color.typ' file.");
994 // Read the Hair Color 'typ'
995 smartPtr = FormLoader->loadFormType("_creature_3d_hair_color.typ");
996 if(smartPtr)
998 string maxStr = smartPtr->getMax();
999 fromString(maxStr, _NbHairColor);
1000 if(_NbHairColor <= 0)
1001 nlwarning("CSheetManager::loadTyp: There is no Color available for the hair.");
1003 else
1004 nlwarning("CSheetManager::loadTyp: Cannot load the '_creature_3d_hair_color.typ' file.");
1005 }// initTyp //
1008 // ***************************************************************************
1009 void CSheetManager::dumpVisualSlots()
1011 for(uint k = 0; k < _VisualSlots.size(); ++k)
1013 TItemVector &iv = _VisualSlots[k];
1014 for(uint l = 0; l < iv.size(); ++l)
1016 if (iv[l])
1018 nlinfo("Slot %d, item %d = %s", (int) k, (int) l, iv[l]->Id.toString().c_str());
1025 // ***************************************************************************
1026 void CSheetManager::dumpVisualSlotsIndex()
1028 FILE * vsIndexFile = nlfopen(getLogDirectory() + "vs_index.txt", "w");
1029 if( vsIndexFile )
1031 for (uint i=0; i < SLOTTYPE::NB_SLOT; ++i)
1033 fprintf(vsIndexFile,"VISUAL SLOT : %d\n", i);
1034 TItemVector &rVTmp = _VisualSlots[i];
1035 for (uint j = 0; j < rVTmp.size(); ++j)
1037 CItemSheet *pIS = rVTmp[j];
1038 if (pIS != NULL)
1040 fprintf(vsIndexFile,"%d : %s\n", j, pIS->Id.toString().c_str());
1042 //nlSleep(100);
1046 else
1048 nlwarning("<CSheetManager::loadAllSheet> Can't open file to dump VS index");
1050 fclose(vsIndexFile);