1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 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/>.
22 #include "sheet_manager.h"
24 #include "client_sheets/item_sheet.h"
26 #include "game_share/slot_types.h"
28 #include "nel/misc/common.h"
29 #include "nel/misc/progress_callback.h"
34 H_AUTO_DECL(RZ_HairSet
)
36 //=========================================================================
37 void CHairSet::init (NLMISC::IProgressCallback
&progress
)
39 H_AUTO_USE(RZ_HairSet
)
41 uint numHairItem
= SheetMngr
.getNumItem(SLOTTYPE::HEAD_SLOT
);
42 for(uint k
= 0; k
< numHairItem
; ++k
)
45 progress
.progress ((float)k
/(float)numHairItem
);
47 const CItemSheet
*item
= SheetMngr
.getItem(SLOTTYPE::HEAD_SLOT
, k
);
48 if (item
&& !item
->getShape().empty())
50 if (item
->getShape().find("cheveux", 0) != std::string::npos
)
53 std::string itemName
= NLMISC::toLowerAscii(item
->getShape());
55 // fortunately, first character of each race is distinct
58 case 'm': _Hairs
[Matis
].push_back(k
); break;
59 case 't': _Hairs
[Tryker
].push_back(k
); break;
60 case 'z': _Hairs
[Zorai
].push_back(k
); break;
61 case 'f': _Hairs
[Fyros
].push_back(k
); break;
68 //=========================================================================
69 void CHairSet::clear()
71 H_AUTO_USE(RZ_HairSet
)
72 for(uint k
= 0; k
< NumPeople
; ++k
)
74 NLMISC::contReset(_Hairs
[k
]);
78 //=========================================================================
79 uint
CHairSet::getNumHairItem(EGSPD::CPeople::TPeople gspeople
) const
81 H_AUTO_USE(RZ_HairSet
)
82 EPeople people
= convPeople(gspeople
);
83 return people
!= DontKnow
? (uint
)_Hairs
[people
].size() : 0;
87 //=========================================================================
88 sint
CHairSet::getHairItemId(EGSPD::CPeople::TPeople gspeople
, uint index
) const
90 H_AUTO_USE(RZ_HairSet
)
91 EPeople people
= convPeople(gspeople
);
92 if (people
== DontKnow
) return -1;
93 if (index
> _Hairs
[people
].size()) return -1;
94 return (sint
) _Hairs
[people
][index
];
98 //=========================================================================
99 sint
CHairSet::getHairItemFromId(EGSPD::CPeople::TPeople gspeople
, uint Id
) const
101 H_AUTO_USE(RZ_HairSet
)
102 EPeople people
= convPeople(gspeople
);
103 if (people
== DontKnow
) return -1;
104 TIntArray::const_iterator it
= std::find(_Hairs
[people
].begin(), _Hairs
[people
].end(), Id
);
105 if (it
!= _Hairs
[people
].end()) return (sint
)(it
- _Hairs
[people
].begin());
109 //=========================================================================
110 CHairSet::EPeople
CHairSet::convPeople(EGSPD::CPeople::TPeople people
)
112 H_AUTO_USE(RZ_HairSet
)
115 case EGSPD::CPeople::Fyros
: return Fyros
;
116 case EGSPD::CPeople::Matis
: return Matis
;
117 case EGSPD::CPeople::Tryker
: return Tryker
;
118 case EGSPD::CPeople::Zorai
: return Zorai
;
119 default: return DontKnow
;
123 //=========================================================================
124 EGSPD::CPeople::TPeople
CHairSet::convPeople(CHairSet::EPeople people
)
126 H_AUTO_USE(RZ_HairSet
)
127 if (people
> NumPeople
) return EGSPD::CPeople::EndPeople
;
128 static const EGSPD::CPeople::TPeople peopleConv
[] =
130 EGSPD::CPeople::Fyros
,
131 EGSPD::CPeople::Matis
,
132 EGSPD::CPeople::Tryker
,
133 EGSPD::CPeople::Zorai
,
135 return peopleConv
[people
];
139 //=========================================================================
140 bool CHairSet::isHairItemId(uint id
) const
142 H_AUTO_USE(RZ_HairSet
)
143 for(uint k
= 0; k
< NumPeople
; ++k
)
145 if (getHairItemFromId(convPeople((CHairSet::EPeople
) k
), id
) != -1) return true;
150 //=========================================================================
151 EGSPD::CPeople::TPeople
CHairSet::getPeopleFromHairItemID(uint id
) const
153 H_AUTO_USE(RZ_HairSet
)
154 for(uint k
= 0; k
< NumPeople
; ++k
)
156 if (getHairItemFromId(convPeople((CHairSet::EPeople
) k
), id
) != -1) return convPeople((CHairSet::EPeople
) k
);
158 return EGSPD::CPeople::EndPeople
;