1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
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.
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/>.
23 #include "stdpch.h" // First include for pre-compiled headers.
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"
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"
36 #include "sheet_manager.h"
37 //#include "client_cfg.h"
38 #include "client_sheets/entity_sheet.h"
39 #include "client_sheets/faction_sheet.h"
41 #include "game_share/visual_slot_manager.h"
50 using namespace NLMISC
;
52 using namespace NLGEORGES
;
59 CSheetManager SheetMngr
;
60 UFormLoader
*CSheetManager::FormLoader
= NULL
;
62 //bool ItemAssocFileOpen = false;
64 // there can be several instance of CSheetManager (for reload operations) -> ctruct the loader here rather than in CSheetManager ctor
70 nlassert (CSheetManager::FormLoader
== NULL
);
71 CSheetManager::FormLoader
= UFormLoader::createLoader ();
72 nlassert (CSheetManager::FormLoader
!= NULL
);
76 if (CSheetManager::FormLoader
)
78 UFormLoader::releaseLoader (CSheetManager::FormLoader
);
79 CSheetManager::FormLoader
= NULL
;
85 static CFormLoaderInit FormLoadInit
;
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", 32),
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";
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.
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
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
;
257 nlwarning("CSheetManager::loadSheet: Do not know how to create the class from the sheet '%s'.", sheetId
.toString().c_str());
261 // Build the sheet from an external file.
263 sheet
->build(form
->getRootNode());
266 SheetMngr
.processSheet(EntitySheet
);
268 // Error while loading the form.
271 // nlwarning("CSheetManager::loadSheet: Cannot load the form '%s'.", filename.c_str());
276 // ***************************************************************************
277 void CSheetManagerEntry::initSheet(CEntitySheet
*pES
, NLMISC::IStream
&s
, CEntitySheet::TType type
)
284 SheetMngr
.processSheet(pES
);
289 // ***************************************************************************
290 void CSheetManagerEntry::serial (NLMISC::IStream
&s
)
294 // if (EntitySheet != NULL)
295 // delete EntitySheet;
297 CEntitySheet::TType type
= CEntitySheet::TypeCount
;
302 case CEntitySheet::FAUNA
:
304 EntitySheet
= new CCharacterSheet
;
305 initSheet(EntitySheet
, s
, type
);
308 case CEntitySheet::FLORA
:
310 EntitySheet
= new CFloraSheet
;
311 initSheet(EntitySheet
, s
, type
);
314 case CEntitySheet::CHAR
:
316 EntitySheet
= new CPlayerSheet
;
317 initSheet(EntitySheet
, s
, type
);
320 case CEntitySheet::FX
:
322 EntitySheet
= new CFXSheet
;
323 initSheet(EntitySheet
, s
, type
);
326 case CEntitySheet::BUILDING
:
328 EntitySheet
= new CBuildingSheet
;
329 initSheet(EntitySheet
, s
, type
);
332 case CEntitySheet::ITEM
:
334 EntitySheet
= new CItemSheet
;
335 initSheet(EntitySheet
, s
, type
);
338 case CEntitySheet::PLANT
:
340 EntitySheet
= new CPlantSheet
;
341 initSheet(EntitySheet
, s
, type
);
344 case CEntitySheet::PACT
:
346 EntitySheet
= new CPactSheet
;
347 initSheet(EntitySheet
, s
, type
);
350 case CEntitySheet::MISSION
:
352 EntitySheet
= new CMissionSheet
;
353 initSheet(EntitySheet
, s
, type
);
356 case CEntitySheet::MISSION_ICON
:
358 EntitySheet
= new CMissionIconSheet
;
359 initSheet(EntitySheet
, s
, type
);
362 case CEntitySheet::RACE_STATS
:
364 EntitySheet
= new CRaceStatsSheet
;
365 initSheet(EntitySheet
, s
, type
);
368 case CEntitySheet::LIGHT_CYCLE
:
370 EntitySheet
= new CLightCycleSheet
;
371 initSheet(EntitySheet
, s
, type
);
374 case CEntitySheet::WEATHER_SETUP
:
376 EntitySheet
= new CWeatherSetupSheet
;
377 initSheet(EntitySheet
, s
, type
);
380 case CEntitySheet::CONTINENT
:
382 EntitySheet
= new CContinentSheet
;
383 initSheet(EntitySheet
, s
, type
);
386 case CEntitySheet::WORLD
:
388 EntitySheet
= new CWorldSheet
;
389 initSheet(EntitySheet
, s
, type
);
392 case CEntitySheet::WEATHER_FUNCTION_PARAMS
:
394 EntitySheet
= new CWeatherFunctionParamsSheet
;
395 initSheet(EntitySheet
, s
, type
);
398 case CEntitySheet::SBRICK
:
400 EntitySheet
= new CSBrickSheet
;
401 initSheet(EntitySheet
, s
, type
);
404 case CEntitySheet::SPHRASE
:
406 EntitySheet
= new CSPhraseSheet
;
407 initSheet(EntitySheet
, s
, type
);
410 case CEntitySheet::SKILLS_TREE
:
412 EntitySheet
= new CSkillsTreeSheet
;
413 initSheet(EntitySheet
, s
, type
);
416 case CEntitySheet::UNBLOCK_TITLES
:
418 EntitySheet
= new CUnblockTitlesSheet
;
419 initSheet(EntitySheet
, s
, type
);
422 case CEntitySheet::SUCCESS_TABLE
:
424 EntitySheet
= new CSuccessTableSheet
;
425 initSheet(EntitySheet
, s
, type
);
428 case CEntitySheet::AUTOMATON_LIST
:
430 EntitySheet
= new CAutomatonListSheet
;
431 initSheet(EntitySheet
, s
, type
);
434 case CEntitySheet::ANIMATION_SET_LIST
:
436 EntitySheet
= new CAnimationSetListSheet
;
437 initSheet(EntitySheet
, s
, type
);
440 case CEntitySheet::ANIMATION_FX
:
442 EntitySheet
= new CAnimationFXSheet
;
443 initSheet(EntitySheet
, s
, type
);
446 case CEntitySheet::ID_TO_STRING_ARRAY
:
448 EntitySheet
= new CIDToStringArraySheet
;
449 initSheet(EntitySheet
, s
, type
);
452 case CEntitySheet::EMOT
:
454 EntitySheet
= new CEmotListSheet
;
455 initSheet(EntitySheet
, s
, type
);
458 case CEntitySheet::FORAGE_SOURCE
:
460 EntitySheet
= new CForageSourceSheet
;
461 initSheet(EntitySheet
, s
, type
);
464 case CEntitySheet::ANIMATION_FX_SET
:
466 EntitySheet
= new CAnimationFXSetSheet
;
467 initSheet(EntitySheet
, s
, type
);
470 case CEntitySheet::ATTACK_LIST
:
472 EntitySheet
= new CAttackListSheet
;
473 initSheet(EntitySheet
, s
, type
);
476 case CEntitySheet::TEXT_EMOT
:
478 EntitySheet
= new CTextEmotListSheet
;
479 initSheet(EntitySheet
, s
, type
);
482 case CEntitySheet::SKY
:
484 EntitySheet
= new CSkySheet
;
485 initSheet(EntitySheet
, s
, type
);
488 case CEntitySheet::OUTPOST
:
490 EntitySheet
= new COutpostSheet
;
491 initSheet(EntitySheet
, s
, type
);
494 case CEntitySheet::OUTPOST_BUILDING
:
496 EntitySheet
= new COutpostBuildingSheet
;
497 initSheet(EntitySheet
, s
, type
);
500 case CEntitySheet::OUTPOST_SQUAD
:
502 EntitySheet
= new COutpostSquadSheet
;
503 initSheet(EntitySheet
, s
, type
);
506 case CEntitySheet::FACTION
:
508 EntitySheet
= new CFactionSheet
;
509 initSheet(EntitySheet
, s
, type
);
513 nlwarning("CSheetManager::load: Unknown type '%d' in the packed file. Rebuild=true and Ignore this sheet.", type
);
520 if (EntitySheet
!= NULL
)
522 s
.serialEnum(EntitySheet
->Type
);
523 EntitySheet
->Id
.serial(s
);
524 EntitySheet
->serial(s
);
528 // write a speudo entry into the stream
529 CEntitySheet::TType tmp
= CEntitySheet::UNKNOWN
;
535 // ***************************************************************************
536 void CSheetManagerEntry::removed()
538 // any action that is needed if the sheet no more exist.
539 if (EntitySheet
!= 0)
546 // ***************************************************************************
547 uint
CSheetManagerEntry::getVersion ()
552 //-----------------------------------------------
553 //-----------------------------------------------
554 void CSheetManagerEntry::setVersion(uint version
)
563 //-----------------------------------------------
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 //-----------------------------------------------
583 //-----------------------------------------------
584 CSheetManager::~CSheetManager()
589 //-----------------------------------------------
590 void CSheetManager::release()
592 _VisualSlots
.clear();
594 _EntitySheetContainer
.clear();
599 //-----------------------------------------------
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'.");
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();
625 //-----------------------------------------------
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.
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
;
647 _EntitySheetContainer
.clear();
649 TEntitySheetMap entitySheetContainer
;
650 for(uint i
=0; i
<nb
; ++i
)
652 // see if extension is wanted
656 for(uint l
= 0; l
< userExtensions
->size(); ++l
)
658 if (stricmp((*userExtensions
)[l
].c_str(), TypeVersion
[i
].Type
.c_str()) == 0)
670 entitySheetContainer
.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
);
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;
698 // Re-compute Visual Slot
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
);
728 // nb : if a new visual_slot.tab has just been generated don't forget
729 // to move it in data_common before dump.
731 dumpVisualSlotsIndex();
734 callBack
.popCropedValues();
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
);
746 ::loadFormNoPackedSheet(extensions
, _EntitySheetContainer
, wildcardFilter
);
749 callBack
.popCropedValues();
753 //-----------------------------------------------
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())
793 if(vs
[visualSlot
].Element
.empty())
796 itemNumber
= vs
[visualSlot
].Element
[vs
[visualSlot
].Element
.size()-1].Index
+1;
799 ProcessedItem
.insert(make_pair(sheetName
, itemNumber
));
801 vsElmt
.Index
= itemNumber
;
805 vsElmt
.Index
= (*it
).second
;
808 vsElmt
.SheetId
= (*itS
).first
;
809 vs
[visualSlot
].Element
.push_back(vsElmt
);
822 if(f
.open("visual_slot.tab"))
831 nlwarning("SheetMngr:load: cannot open/create the file 'visual_slot.tab'.");
834 //-----------------------------------------------
836 // Porcessing the sheet.
837 // \param sheet : sheet to process.
838 //-----------------------------------------------
839 void CSheetManager::processSheet (CEntitySheet
* /* sheet */)
844 //=======================================================================
845 const CSheetManager::TVisualSlotItemArray
*CSheetManager::getVSItems(CItemSheet
*sheet
) const
847 TItemSheet2SlotItemArray::const_iterator it
= _SheetToVS
.find(sheet
);
848 if (it
== _SheetToVS
.end())
850 return &(it
->second
);
853 //=======================================================================
854 sint
CSheetManager::getVSIndex(const std::string
&itemName
, SLOTTYPE::EVisualSlot slot
)
857 if (!si
.buildSheetId(itemName
))
859 nlwarning("<CSheetManager::getVSIndex> : cannot build id from item %s for the slot %d.", itemName
.c_str(), slot
);
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
);
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
);
875 CItemSheet
*is
= static_cast<CItemSheet
*>(it
->second
.EntitySheet
);
877 const TVisualSlotItemArray
*ia
= getVSItems(is
);
880 nlwarning("<CSheetManager::getVSIndex> : no items for the slot %d. while looking for %s", slot
, itemName
.c_str());
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
);
897 //-----------------------------------------------
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
;
913 //-----------------------------------------------
914 uint
CSheetManager::getNumItem(SLOTTYPE::EVisualSlot slot
)
916 // The slot is not a visible one.
917 if (slot
== SLOTTYPE::HIDDEN_SLOT
)
919 // Convert into an uint to remove warnings.
923 if(s
< _VisualSlots
.size())
925 return (uint
)_VisualSlots
[s
].size();
929 nlwarning("CSheetManager::getNumItem : invalid slot %d.", slot
);
934 //-----------------------------------------------
937 //-----------------------------------------------
938 CItemSheet
*CSheetManager::getItem(SLOTTYPE::EVisualSlot slot
, uint index
)
940 // The slot is not a visible one.
941 if(slot
== SLOTTYPE::HIDDEN_SLOT
)
944 // Convert into an uint to remove warnings.
948 if(s
< _VisualSlots
.size())
951 if(index
< _VisualSlots
[s
].size())
953 // Not the default Item.
955 return _VisualSlots
[s
][index
];
963 //nlwarning("CSheetManager::getItem : invalid index %d for the slot %d.", index, slot);
970 nlwarning("CSheetManager::getItem : invalid slot %d.", slot
);
976 //-----------------------------------------------
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");
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.");
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");
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.");
1004 nlwarning("CSheetManager::loadTyp: Cannot load the '_creature_3d_hair_color.typ' file.");
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
)
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");
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
];
1040 fprintf(vsIndexFile
,"%d : %s\n", j
, pIS
->Id
.toString().c_str());
1048 nlwarning("<CSheetManager::loadAllSheet> Can't open file to dump VS index");
1050 fclose(vsIndexFile
);