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 "available_phrases.h"
21 #include "game_share/egs_sheets/egs_sheets.h"
22 #include "game_share/egs_sheets/egs_static_rolemaster_phrase.h"
24 #include <nel/misc/command.h> // TEMP
26 using namespace NLMISC
;
31 * Accessors for sheet sphrases
33 #define GET_SHEET_ID(it) (*it).first
34 #define GET_PHRASE(it) (*it).second
40 bool skillMatchesOneOfList( const CPlayerSkill
& skill
, const vector
<CPlayerSkill
>& skillList
)
42 vector
<CPlayerSkill
>::const_iterator ips
;
43 for ( ips
=skillList
.begin(); ips
!=skillList
.end(); ++ips
)
45 const CPlayerSkill
& playerSkill
= *ips
;
46 //nldebug ( "Player: %s %u Required: %s %u", playerSkill.Code.c_str(), playerSkill.Value, skill.Code.c_str(), skill.Value );
47 if ( playerSkill
.isAsSkilledAs( skill
) )
58 * Return false if the phrase contains bricks that require a skill level that the player doesn't have
59 * or if it contains bricks that require a brick that the player doesn't have.
61 bool isPlayerAllowedToGetAllBricksFromPhrase( const CSheetId
& phraseSheetId
,
62 const vector
<CPlayerSkill
>& playerSkills
,
63 const set
<CSheetId
>& bricksAlreadyKnown
)
65 const CStaticRolemasterPhrase
*phrase
= CSheets::getSRolemasterPhrase( phraseSheetId
);
69 //nldebug( "Phrase %s", phraseSheetId.toString().c_str() );
70 const vector
<CSheetId
>& bricks
= phrase
->Bricks
;
71 vector
<CSheetId
>::const_iterator ibs
;
72 for ( ibs
=bricks
.begin(); ibs
!=bricks
.end(); ++ibs
)
74 const CStaticBrick
*staticBrick
= CSheets::getSBrickForm( *ibs
);
77 //nldebug( " Brick %s", (*ibs).toString().c_str() );
79 // Check if one of the skills match one of the player's
80 if ( ! staticBrick
->LearnRequiresOneOfSkills
.empty() )
82 //nldebug( " -> Requires one of %u skills", staticBrick->LearnRequiresOneOfSkills.size() );
83 vector
<CPlayerSkill
>::const_iterator irs
;
84 for ( irs
=staticBrick
->LearnRequiresOneOfSkills
.begin(); irs
!=staticBrick
->LearnRequiresOneOfSkills
.end(); ++irs
)
86 const CPlayerSkill
& requiredSkill
= *irs
;
87 if ( skillMatchesOneOfList( requiredSkill
, playerSkills
) )
90 if ( irs
== staticBrick
->LearnRequiresOneOfSkills
.end() )
91 return false; // not found
94 // Check if all required bricks are known by the player
95 vector
<CSheetId
>::const_iterator ibl
;
96 for ( ibl
=staticBrick
->LearnRequiresBricks
.begin(); ibl
!=staticBrick
->LearnRequiresBricks
.end(); ++ibl
)
98 const CSheetId
& brickRequiredSheetId
= *ibl
;
99 if ( bricksAlreadyKnown
.find( brickRequiredSheetId
) == bricksAlreadyKnown
.end() )
110 void buildAvailablePhrasesList( const string
& brickFilter
,
111 const set
<CSheetId
>& bricksAlreadyKnown
,
112 const set
<CSheetId
>& phrasesAlreadyKnown
,
113 const vector
<CPlayerSkill
>& playerSkills
,
114 vector
<CSheetId
>& result
)
116 // Browse all the phrases
117 const CAllRolemasterPhrases
& phrasesMap
= CSheets::getSRolemasterPhrases();
118 CAllRolemasterPhrases::const_iterator ip
;
119 for ( ip
=phrasesMap
.begin(); ip
!=phrasesMap
.end(); ++ip
)
121 const CSheetId
& phraseSheetId
= GET_SHEET_ID(ip
);
122 const string
& phraseCode
= phraseSheetId
.toString();
124 // Match the brick filter
125 if ( phraseCode
.substr( 1, brickFilter
.size() ) == brickFilter
)
127 // Exclude the phrase if the player already knows it
128 if ( phrasesAlreadyKnown
.find( phraseSheetId
) == phrasesAlreadyKnown
.end() )
130 // Exclude the phrase if it contains bricks that require a skill level or a brick that the player doesn't have
131 if ( isPlayerAllowedToGetAllBricksFromPhrase( phraseSheetId
, playerSkills
, bricksAlreadyKnown
) )
133 result
.push_back( phraseSheetId
);
141 NLMISC_COMMAND( testRolemaster
, "Test rolemaster phrases selection", "" )
143 string brickFilter
= "bf";
144 set
<CSheetId
> knownBricks
, knownPhrases
;
145 vector
<CPlayerSkill
> playerSkills
;
146 CPlayerSkill playerSkill
;
147 playerSkill
.Code
= "FM1B";
148 playerSkill
.Value
= 200;
149 playerSkills
.push_back( playerSkill
);
150 vector
<CSheetId
> result
;
151 buildAvailablePhrasesList( brickFilter
, knownBricks
, knownPhrases
, playerSkills
, result
);
152 vector
<CSheetId
>::const_iterator iv
;
153 for ( iv
=result
.begin(); iv
!=result
.end(); ++iv
)
155 nlinfo( "%s", (*iv
).toString().c_str() );
157 nlinfo( "Found %u phrases", result
.size() );