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/>.
20 #include "unblock_titles_sheet.h"
21 #include "nel/georges/u_form_elm.h"
22 #include "nel/misc/common.h"
23 #include "game_share/fame.h"
26 using namespace NLMISC
;
27 using namespace NLGEORGES
;
29 // Tokenize a string with space as separator
30 static void tokenize (const string
&zeString
, vector
<string
> &tokens
)
33 string sTmp
= zeString
;
36 while (((sTmp
[0] == ' ')||(sTmp
[0] == ':')) && !sTmp
.empty())
37 sTmp
= sTmp
.substr(1,sTmp
.size());
39 if (sTmp
.empty()) break;
41 string::size_type nextseppos1
= sTmp
.find(' ');
42 string::size_type nextseppos2
= sTmp
.find(':');
44 if ((nextseppos1
== string::npos
) && (nextseppos2
== string::npos
))
46 tokens
.push_back(sTmp
);
51 if ((nextseppos1
!= string::npos
) && (nextseppos2
!= string::npos
))
52 nextseppos1
= min(nextseppos1
, nextseppos2
);
53 else if (nextseppos2
!= string::npos
)
54 nextseppos1
= nextseppos2
;
56 tokens
.push_back (sTmp
.substr(0, nextseppos1
));
57 sTmp
= sTmp
.substr(nextseppos1
+1, sTmp
.size());
62 // ***************************************************************************
63 void CUnblockTitlesSheet::build(const UFormElm
&item
)
65 TitlesUnblock
.resize (CHARACTER_TITLE::NB_CHARACTER_TITLE
);
67 const UFormElm
*arrayTUElt
= NULL
;
68 if( item
.getNodeByName( &arrayTUElt
, "Titles" ) )
72 sint32 tmpLevel
, tmpQuality
;
74 nlverify( arrayTUElt
->getArraySize( NbTitlesUnblock
) );
76 for (uint i
= 0; i
< NbTitlesUnblock
; ++i
)
78 const UFormElm
* TUElt
= NULL
;
79 if( ! ( arrayTUElt
->getArrayNode( &TUElt
, i
) && TUElt
) )
81 nlwarning("<CSkillsTreeSheet::build> can't get array node of TitleUnblock in sheet");
87 TUElt
->getValueByName( TitleName
, "Title" );
88 CHARACTER_TITLE::ECharacterTitle title
= CHARACTER_TITLE::toCharacterTitle ( TitleName
);
89 //nlassert( skill != SKILLS::unknown );
90 if (title
>= CHARACTER_TITLE::NB_CHARACTER_TITLE
)
93 bool bReserved
= false;
94 if( ! TUElt
->getValueByName( bReserved
, "Reserved" ) )
96 nlwarning("<CSkillsTreeSheet::build> can't get node Reserved in sheet");
99 string strSkillsNeeded
;
100 if( ! TUElt
->getValueByName( strSkillsNeeded
, "SkillsNeeded" ) )
102 nlwarning("<CSkillsTreeSheet::build> can't get node SkillsNeeded in sheet");
105 string strBricksNeeded
;
106 if( ! TUElt
->getValueByName( strBricksNeeded
, "BricksNeeded" ) )
108 nlwarning("<CSkillsTreeSheet::build> can't get node SkillsNeeded in sheet");
112 if( ! TUElt
->getValueByName( strMinFames
, "MinFames" ) )
114 nlwarning("<CSkillsTreeSheet::build> can't get node MinFames in sheet");
118 if( ! TUElt
->getValueByName( strMaxFames
, "MaxFames" ) )
120 nlwarning("<CSkillsTreeSheet::build> can't get node MaxFames in sheet");
123 // cf TPVPClan enum (pvp_clan.h)
124 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].CivNeeded
, "CivNeeded" ) )
126 nlwarning("<CSkillsTreeSheet::build> can't get node CivNeeded in sheet");
129 // cf TPVPClan enum (pvp_clan.h)
130 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].CultNeeded
, "CultNeeded" ) )
132 nlwarning("<CSkillsTreeSheet::build> can't get node CultNeeded in sheet");
135 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].CharOldness
, "CharOldness" ) )
137 nlwarning("<CSkillsTreeSheet::build> can't get node CharOldness in sheet");
140 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].CharPlayedTime
, "CharPlayedTime" ) )
142 nlwarning("<CSkillsTreeSheet::build> can't get node CharPlayedTime in sheet");
145 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].AccountOldness
, "AccountOldness" ) )
147 nlwarning("<CSkillsTreeSheet::build> can't get node AccountOldness in sheet");
150 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].AuthorRating
, "AuthorRating" ) )
152 nlwarning("<CSkillsTreeSheet::build> can't get node AuthorRating in sheet");
155 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].AMRating
, "AMRating" ) )
157 nlwarning("<CSkillsTreeSheet::build> can't get node AMRating in sheet");
160 if( ! TUElt
->getValueByName( TitlesUnblock
[title
].OrganizerRating
, "OrganizerRating" ) )
162 nlwarning("<CSkillsTreeSheet::build> can't get node OrganizerRating in sheet");
165 string strItemsNeeded
;
166 if( ! TUElt
->getValueByName( strItemsNeeded
, "ItemsNeeded" ) )
168 nlwarning("<CSkillsTreeSheet::build> can't get node ItemsNeeded in sheet");
173 TitlesUnblock
[title
].Reserved
= bReserved
;
175 if( !strSkillsNeeded
.empty() )
177 uint16 skillsNeededSz
= (uint16
)TitlesUnblock
[title
].SkillsNeeded
.size();
178 TitlesUnblock
[title
].SkillsNeeded
.resize(skillsNeededSz
+1);
179 TitlesUnblock
[title
].SkillsLevelNeeded
.resize(skillsNeededSz
+1);
181 vector
<string
> vSkill
;
182 tokenize(strSkillsNeeded
, vSkill
);
183 for (j
= 0; j
< vSkill
.size()/2; ++j
)
185 TitlesUnblock
[title
].SkillsNeeded
[skillsNeededSz
].push_back(vSkill
[j
*2]);
186 fromString(vSkill
[j
*2+1], tmpLevel
);
187 TitlesUnblock
[title
].SkillsLevelNeeded
[skillsNeededSz
].push_back(tmpLevel
);
191 if( !strBricksNeeded
.empty() )
193 vector
<string
> vBrick
;
194 tokenize(strBricksNeeded
, vBrick
);
195 for (j
= 0; j
< vBrick
.size(); ++j
)
197 TitlesUnblock
[title
].BricksNeeded
.push_back(CSheetId(vBrick
[j
]+".sbrick"));
201 if( !strMinFames
.empty() )
203 vector
<string
> vFame
;
204 tokenize(strMinFames
, vFame
);
205 for (j
= 0; j
< vFame
.size()/2; ++j
)
207 PVP_CLAN::TPVPClan clan
= PVP_CLAN::fromString(vFame
[j
*2]);
208 if( clan
!= PVP_CLAN::Unknown
)
210 uint32 factionIndex
= PVP_CLAN::getFactionIndex( clan
);
211 nlassert(factionIndex
!= CStaticFames::INVALID_FACTION_INDEX
);
212 TitlesUnblock
[title
].MinFames
.push_back(factionIndex
);
213 fromString(vFame
[j
*2+1], tmpLevel
);
214 TitlesUnblock
[title
].MinFameLevels
.push_back(tmpLevel
);
218 if( !strMaxFames
.empty() )
220 vector
<string
> vFame
;
221 tokenize(strMaxFames
, vFame
);
222 for (j
= 0; j
< vFame
.size()/2; ++j
)
224 PVP_CLAN::TPVPClan clan
= PVP_CLAN::fromString(vFame
[j
*2]);
225 if( clan
!= PVP_CLAN::Unknown
)
227 uint32 factionIndex
= PVP_CLAN::getFactionIndex( clan
);
228 nlassert(factionIndex
!= CStaticFames::INVALID_FACTION_INDEX
);
229 TitlesUnblock
[title
].MaxFames
.push_back(factionIndex
);
230 fromString(vFame
[j
*2+1], tmpLevel
);
231 TitlesUnblock
[title
].MaxFameLevels
.push_back(tmpLevel
);
236 if( !strItemsNeeded
.empty() )
238 uint16 itemsNeededSz
= (uint16
)TitlesUnblock
[title
].ItemsNeeded
.size();
239 TitlesUnblock
[title
].ItemsNeeded
.resize(itemsNeededSz
+1);
240 TitlesUnblock
[title
].ItemsQualityNeeded
.resize(itemsNeededSz
+1);
242 vector
<string
> vItem
;
243 tokenize(strItemsNeeded
, vItem
);
244 for (j
= 0; j
< vItem
.size()/2; ++j
)
246 TitlesUnblock
[title
].ItemsNeeded
[itemsNeededSz
].push_back(CSheetId(vItem
[j
*2]+".sitem"));
247 fromString(vItem
[j
*2+1], tmpQuality
);
248 TitlesUnblock
[title
].ItemsQualityNeeded
[itemsNeededSz
].push_back(tmpQuality
);