1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef RY_SBRICK_MANAGER_H
24 #define RY_SBRICK_MANAGER_H
26 #include "nel/misc/types_nl.h"
27 #include "../client_sheets/sbrick_sheet.h"
28 #include "game_share/sabrina_com.h"
29 #include "game_share/skills.h"
30 #include "nel/misc/cdb.h"
31 #include "brick_learned_callback.h"
34 // ***************************************************************************
36 * Manager of Sabrina Bricks.
37 * \author Lionel Berenguier
38 * \author Nevrax France
46 ///get the singleton 's instance
47 static CSBrickManager
* getInstance()
50 _Instance
= new CSBrickManager
;
55 static void releaseInstance();
57 // Initialize by loading bricks done at init time
60 // Init the rest done at initInGame time
63 // Uninit in game data
67 * get a brick from its sheetId
68 * param id : the id of the sheet
70 CSBrickSheet
*getBrick(const NLMISC::CSheetId
&id
) const
72 uint32 shid
= id
.getShortId();
73 CSBrickSheet
*result
= NULL
;
74 if (shid
< _BrickVector
.size())
75 result
= _BrickVector
[shid
];
77 // nlwarning("Missing brick '%s'", id.toString().c_str());
82 * \return a sheet id of a brick
84 NLMISC::CSheetId
getBrickSheet(uint family
, uint index
) const;
87 * \return a family bit set
89 sint64
getKnownBrickBitField(uint family
) const;
92 * \return the DB pointing on the BitField for this family.
94 class NLMISC::CCDBNodeLeaf
* getKnownBrickBitFieldDB(uint family
) const;
97 * \return true if the brick is learn by the player.
99 bool isBrickKnown(CSBrickSheet
*brick
) const
103 // IndexInFamily-1 because start at 1 in the sheets
104 return ( getKnownBrickBitField(brick
->BrickFamily
) & ( sint64(1)<<(brick
->IndexInFamily
-1)) )!=0;
106 /// same with sheetId
107 bool isBrickKnown(NLMISC::CSheetId id
) const
109 return isBrickKnown(getBrick(id
));
112 /// Get list of all bricks for a family
113 const std::vector
<NLMISC::CSheetId
> &getFamilyBricks(uint family
) const;
115 /// Get list of all root bricks
116 const std::vector
<NLMISC::CSheetId
> &getRootBricks() const {return _Roots
;}
118 /// Get the SabrinaCom info retriever.
119 const CSabrinaCom
&getSabrinaCom() const {return _SabrinaCom
;}
121 /// Get the Interface Brick (visual only) related to a skill
122 NLMISC::CSheetId
getVisualBrickForSkill(SKILLS::ESkills s
);
124 /// Get the Interface Brick (visual only) used to remove a optional or credit brick
125 NLMISC::CSheetId
getInterfaceRemoveBrick();
127 /// Modify a list of bricks to keep only the knowns one
128 void filterKnownBricks(std::vector
<NLMISC::CSheetId
> &bricks
);
130 /// \name Brick Properties
132 // get a prop Id from its name.
133 uint
getBrickPropId(const std::string
&name
);
134 // Important Ids for properties (to compute cost, range etc...).
138 uint StaWeightFactorId
;
144 // append to the set a callback when a brick is learned
145 void appendBrickLearnedCallback(IBrickLearnedCallback
*cb
);
146 void removeBrickLearnedCallback(IBrickLearnedCallback
*cb
);
153 /// Singleton's instance
154 static CSBrickManager
* _Instance
;
156 /// Number of families
159 /// Number of bricks in each family
160 std::vector
<uint
> _NbBricksPerFamily
;
162 /// Map linking a sheet id to a brick record.
163 // std::map<NLMISC::CSheetId,CSBrickSheet*> _Bricks;
164 std::vector
<CSBrickSheet
*> _BrickVector
;
166 /// Structure storing all bricks. each entry of the vector
167 /// represent a family, described by a vector containing all
168 /// the bricks of the family
169 std::vector
<std::vector
<NLMISC::CSheetId
> > _SheetsByFamilies
;
171 /// Vector of bit fields describing the known bricks of each family
172 std::vector
<NLMISC::CCDBNodeLeaf
*> _FamiliesBits
;
174 /// List of roots only
175 std::vector
<NLMISC::CSheetId
> _Roots
;
177 /// Mapper of SkillToBrick
178 NLMISC::CSheetId _VisualBrickForSkill
[SKILLS::NUM_SKILLS
];
184 void makeVisualBrickForSkill();
186 // GameShare infos on Sabrina.
187 class CBrickContainer
: public CSabrinaCom::IBrickContainer
189 virtual sint32
getSabrinaCost(NLMISC::CSheetId id
) const;
190 virtual float getSabrinaRelativeCost(NLMISC::CSheetId id
) const;
191 virtual sint32
getNumParameters(NLMISC::CSheetId id
) const;
192 virtual BRICK_FAMILIES::TBrickFamily
getBrickFamily(NLMISC::CSheetId id
, uint
& indexInFamily
) const;
193 virtual BRICK_TYPE::EBrickType
getBrickType(NLMISC::CSheetId id
) const;
194 virtual TOOL_TYPE::TCraftingToolType
getFaberPlanToolType(NLMISC::CSheetId id
) const;
196 CBrickContainer _BrickContainer
;
197 CSabrinaCom _SabrinaCom
;
200 std::map
<std::string
, uint
> _BrickPropIdMap
;
202 void compileBrickProperties();
204 // see getInterfaceRemoveBrick
205 NLMISC::CSheetId _InterfaceRemoveBrick
;
207 // Observer when a brick is learned
208 struct CBrickFamilyObs
: public NLMISC::ICDBNode::IPropertyObserver
210 CSBrickManager
*Owner
;
212 virtual void update (NLMISC::ICDBNode
*node
);
214 friend struct CBrickFamilyObs
;
215 CBrickFamilyObs _BrickFamilyObs
;
216 typedef std::set
<IBrickLearnedCallback
*> TBLCBSet
;
217 TBLCBSet _BrickLearnedCallbackSet
;
221 #endif // NL_SBRICK_MANAGER_H
223 /* End of sbrick_manager.h */