Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / hair_set.cpp
blobe196ad8366c8b6e4ea55e4ce24f8cc6fb2fa302f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "stdpch.h"
24 #include "hair_set.h"
25 #include "sheet_manager.h"
26 // Client Sheets
27 #include "client_sheets/item_sheet.h"
28 // Game Share
29 #include "game_share/slot_types.h"
31 #include "nel/misc/common.h"
32 #include "nel/misc/progress_callback.h"
34 // hair set manager
35 CHairSet HairSet;
37 H_AUTO_DECL(RZ_HairSet)
39 //=========================================================================
40 void CHairSet::init (NLMISC::IProgressCallback &progress)
42 H_AUTO_USE(RZ_HairSet)
43 clear();
44 uint numHairItem = SheetMngr.getNumItem(SLOTTYPE::HEAD_SLOT);
45 for(uint k = 0; k < numHairItem; ++k)
47 // Progress bar
48 progress.progress ((float)k/(float)numHairItem);
50 const CItemSheet *item = SheetMngr.getItem(SLOTTYPE::HEAD_SLOT, k);
51 if (item && !item->getShape().empty())
53 if (item->getShape().find("cheveux", 0) != std::string::npos)
55 // get race
56 std::string itemName = NLMISC::toLowerAscii(item->getShape());
58 // fortunately, first character of each race is distinct
59 switch(itemName[0])
61 case 'm': _Hairs[Matis].push_back(k); break;
62 case 't': _Hairs[Tryker].push_back(k); break;
63 case 'z': _Hairs[Zorai].push_back(k); break;
64 case 'f': _Hairs[Fyros].push_back(k); break;
71 //=========================================================================
72 void CHairSet::clear()
74 H_AUTO_USE(RZ_HairSet)
75 for(uint k = 0; k < NumPeople; ++k)
77 NLMISC::contReset(_Hairs[k]);
81 //=========================================================================
82 uint CHairSet::getNumHairItem(EGSPD::CPeople::TPeople gspeople) const
84 H_AUTO_USE(RZ_HairSet)
85 EPeople people = convPeople(gspeople);
86 return people != DontKnow ? (uint)_Hairs[people].size() : 0;
90 //=========================================================================
91 sint CHairSet::getHairItemId(EGSPD::CPeople::TPeople gspeople, uint index) const
93 H_AUTO_USE(RZ_HairSet)
94 EPeople people = convPeople(gspeople);
95 if (people == DontKnow) return -1;
96 if (index > _Hairs[people].size()) return -1;
97 return (sint) _Hairs[people][index];
101 //=========================================================================
102 sint CHairSet::getHairItemFromId(EGSPD::CPeople::TPeople gspeople, uint Id) const
104 H_AUTO_USE(RZ_HairSet)
105 EPeople people = convPeople(gspeople);
106 if (people == DontKnow) return -1;
107 TIntArray::const_iterator it = std::find(_Hairs[people].begin(), _Hairs[people].end(), Id);
108 if (it != _Hairs[people].end()) return (sint)(it - _Hairs[people].begin());
109 else return -1;
112 //=========================================================================
113 CHairSet::EPeople CHairSet::convPeople(EGSPD::CPeople::TPeople people)
115 H_AUTO_USE(RZ_HairSet)
116 switch(people)
118 case EGSPD::CPeople::Fyros: return Fyros;
119 case EGSPD::CPeople::Matis: return Matis;
120 case EGSPD::CPeople::Tryker: return Tryker;
121 case EGSPD::CPeople::Zorai: return Zorai;
122 default: return DontKnow;
126 //=========================================================================
127 EGSPD::CPeople::TPeople CHairSet::convPeople(CHairSet::EPeople people)
129 H_AUTO_USE(RZ_HairSet)
130 if (people > NumPeople) return EGSPD::CPeople::EndPeople;
131 static const EGSPD::CPeople::TPeople peopleConv[] =
133 EGSPD::CPeople::Fyros,
134 EGSPD::CPeople::Matis,
135 EGSPD::CPeople::Tryker,
136 EGSPD::CPeople::Zorai,
138 return peopleConv[people];
142 //=========================================================================
143 bool CHairSet::isHairItemId(uint id) const
145 H_AUTO_USE(RZ_HairSet)
146 for(uint k = 0; k < NumPeople; ++k)
148 if (getHairItemFromId(convPeople((CHairSet::EPeople) k), id) != -1) return true;
150 return false;
153 //=========================================================================
154 EGSPD::CPeople::TPeople CHairSet::getPeopleFromHairItemID(uint id) const
156 H_AUTO_USE(RZ_HairSet)
157 for(uint k = 0; k < NumPeople; ++k)
159 if (getHairItemFromId(convPeople((CHairSet::EPeople) k), id) != -1) return convPeople((CHairSet::EPeople) k);
161 return EGSPD::CPeople::EndPeople;