1 /***************************************************************************
2  *   Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com>          *
3  *                                                                         *
4  *   Part of the Free Heroes2 Engine:                                      *
5  *   http://sourceforge.net/projects/fheroes2                              *
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
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 General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21  ***************************************************************************/
22 #ifndef H2ARTIFACT_H
23 #define H2ARTIFACT_H
24 
25 #include <set>
26 #include <vector>
27 
28 #include "interface_itemsbar.h"
29 #include "mp2.h"
30 #include "ui_tool.h"
31 
32 class Spell;
33 class Heroes;
34 class StatusBar;
35 class StreamBase;
36 
37 class Artifact
38 {
39 public:
40     enum level_t
41     {
42         ART_NONE = 0,
43         ART_LEVEL1 = 0x01,
44         ART_LEVEL2 = 0x02,
45         ART_LEVEL3 = 0x04,
46         ART_LEVEL123 = ART_LEVEL1 | ART_LEVEL2 | ART_LEVEL3,
47         ART_ULTIMATE = 0x08,
48         ART_LOYALTY = 0x10,
49         ART_NORANDOM = 0x20
50     };
51 
52     enum type_t
53     {
54         ULTIMATE_BOOK,
55         ULTIMATE_SWORD,
56         ULTIMATE_CLOAK,
57         ULTIMATE_WAND,
58         ULTIMATE_SHIELD,
59         ULTIMATE_STAFF,
60         ULTIMATE_CROWN,
61         GOLDEN_GOOSE,
62         ARCANE_NECKLACE,
63         CASTER_BRACELET,
64         MAGE_RING,
65         WITCHES_BROACH,
66         MEDAL_VALOR,
67         MEDAL_COURAGE,
68         MEDAL_HONOR,
69         MEDAL_DISTINCTION,
70         FIZBIN_MISFORTUNE,
71         THUNDER_MACE,
72         ARMORED_GAUNTLETS,
73         DEFENDER_HELM,
74         GIANT_FLAIL,
75         BALLISTA,
76         STEALTH_SHIELD,
77         DRAGON_SWORD,
78         POWER_AXE,
79         DIVINE_BREASTPLATE,
80         MINOR_SCROLL,
81         MAJOR_SCROLL,
82         SUPERIOR_SCROLL,
83         FOREMOST_SCROLL,
84         ENDLESS_SACK_GOLD,
85         ENDLESS_BAG_GOLD,
86         ENDLESS_PURSE_GOLD,
87         NOMAD_BOOTS_MOBILITY,
88         TRAVELER_BOOTS_MOBILITY,
89         RABBIT_FOOT,
90         GOLDEN_HORSESHOE,
91         GAMBLER_LUCKY_COIN,
92         FOUR_LEAF_CLOVER,
93         TRUE_COMPASS_MOBILITY,
94         SAILORS_ASTROLABE_MOBILITY,
95         EVIL_EYE,
96         ENCHANTED_HOURGLASS,
97         GOLD_WATCH,
98         SKULLCAP,
99         ICE_CLOAK,
100         FIRE_CLOAK,
101         LIGHTNING_HELM,
102         EVERCOLD_ICICLE,
103         EVERHOT_LAVA_ROCK,
104         LIGHTNING_ROD,
105         SNAKE_RING,
106         ANKH,
107         BOOK_ELEMENTS,
108         ELEMENTAL_RING,
109         HOLY_PENDANT,
110         PENDANT_FREE_WILL,
111         PENDANT_LIFE,
112         SERENITY_PENDANT,
113         SEEING_EYE_PENDANT,
114         KINETIC_PENDANT,
115         PENDANT_DEATH,
116         WAND_NEGATION,
117         GOLDEN_BOW,
118         TELESCOPE,
119         STATESMAN_QUILL,
120         WIZARD_HAT,
121         POWER_RING,
122         AMMO_CART,
123         TAX_LIEN,
124         HIDEOUS_MASK,
125         ENDLESS_POUCH_SULFUR,
126         ENDLESS_VIAL_MERCURY,
127         ENDLESS_POUCH_GEMS,
128         ENDLESS_CORD_WOOD,
129         ENDLESS_CART_ORE,
130         ENDLESS_POUCH_CRYSTAL,
131         SPIKED_HELM,
132         SPIKED_SHIELD,
133         WHITE_PEARL,
134         BLACK_PEARL,
135 
136         MAGIC_BOOK,
137 
138         DUMMY1,
139         DUMMY2,
140         DUMMY3,
141         DUMMY4,
142 
143         SPELL_SCROLL,
144         ARM_MARTYR,
145         BREASTPLATE_ANDURAN,
146         BROACH_SHIELDING,
147         BATTLE_GARB,
148         CRYSTAL_BALL,
149         HEART_FIRE,
150         HEART_ICE,
151         HELMET_ANDURAN,
152         HOLY_HAMMER,
153         LEGENDARY_SCEPTER,
154         MASTHEAD,
155         SPHERE_NEGATION,
156         STAFF_WIZARDRY,
157         SWORD_BREAKER,
158         SWORD_ANDURAN,
159         SPADE_NECROMANCY,
160 
161         UNKNOWN
162     };
163 
164     Artifact( int = UNKNOWN );
165 
166     bool operator==( const Spell & ) const;
167     bool operator==( const Artifact & ) const;
168     bool operator!=( const Artifact & ) const;
169     int GetID( void ) const;
170 
171     bool isUltimate( void ) const;
172     bool isAlchemistRemove( void ) const;
173     bool isValid( void ) const;
174 
175     void Reset( void );
176 
177     u32 ExtraValue( void ) const;
178     int Level( void ) const;
179     int LoyaltyLevel( void ) const;
180     int Type( void ) const;
181     int getArtifactValue() const;
182 
183     /* objnarti.icn */
184     u32 IndexSprite( void ) const;
185     /* artfx.icn */
186     u32 IndexSprite32( void ) const;
187     /* artifact.icn */
188     u32 IndexSprite64( void ) const;
189 
190     void SetSpell( int );
191     int GetSpell( void ) const;
192 
193     const char * GetName( void ) const;
194     std::string GetDescription( void ) const;
195 
196     static int Rand( level_t );
197     static Artifact FromMP2IndexSprite( u32 );
198     static const char * GetScenario( const Artifact & );
199 
200 private:
201     friend StreamBase & operator<<( StreamBase &, const Artifact & );
202     friend StreamBase & operator>>( StreamBase &, Artifact & );
203 
204     int id;
205     int ext;
206 };
207 
208 StreamBase & operator<<( StreamBase &, const Artifact & );
209 StreamBase & operator>>( StreamBase &, Artifact & );
210 
211 u32 GoldInsteadArtifact( const MP2::MapObjectType objectType );
212 
213 namespace fheroes2
214 {
215     void ResetArtifactStats();
216     void ExcludeArtifactFromRandom( const int artifactID );
217 }
218 
219 struct ArtifactSetData
220 {
221     ArtifactSetData( const uint32_t artifactID, const std::string & assembleMessage );
222 
223     uint32_t _assembledArtifactID = Artifact::UNKNOWN;
224     std::string _assembleMessage;
225 
226     bool operator<( const ArtifactSetData & other ) const;
227 };
228 
229 class BagArtifacts : public std::vector<Artifact>
230 {
231 public:
232     BagArtifacts();
233 
234     bool ContainSpell( const Spell & ) const;
235     bool isPresentArtifact( const Artifact & ) const;
236     bool PushArtifact( const Artifact & );
237 
238     void RemoveArtifact( const Artifact & art );
239 
240     bool isFull( void ) const;
241     bool ContainUltimateArtifact( void ) const;
242 
243     void RemoveScroll( const Artifact & );
244     void exchangeArtifacts( BagArtifacts & giftBag );
245 
246     int getArtifactValue() const;
247     u32 CountArtifacts( void ) const;
248     u32 Count( const Artifact & ) const;
249 
250     std::set<ArtifactSetData> assembleArtifactSetIfPossible();
251 
252     std::string String( void ) const;
253 };
254 
255 class ArtifactsBar : public Interface::ItemsActionBar<Artifact>
256 {
257 public:
258     ArtifactsBar( const Heroes * hero, const bool mini, const bool ro, const bool change, const bool allowOpeningMagicBook, StatusBar * bar );
259 
260     void RedrawBackground( const fheroes2::Rect &, fheroes2::Image & ) override;
261     void RedrawItem( Artifact &, const fheroes2::Rect &, bool, fheroes2::Image & ) override;
262 
263     void ResetSelected( void );
264     void Redraw( fheroes2::Image & dstsf = fheroes2::Display::instance() );
265 
266     bool ActionBarLeftMouseSingleClick( Artifact & artifact ) override;
267     bool ActionBarLeftMouseSingleClick( Artifact & artifact1, Artifact & artifact2 ) override;
268     bool ActionBarLeftMouseDoubleClick( Artifact & artifact ) override;
269     bool ActionBarRightMouseHold( Artifact & artifact ) override;
270 
271     bool QueueEventProcessing( std::string * = nullptr );
272     bool QueueEventProcessing( ArtifactsBar &, std::string * = nullptr );
273 
274     bool ActionBarCursor( Artifact & ) override;
275     bool ActionBarCursor( Artifact &, Artifact & ) override;
276 
277 protected:
278     fheroes2::MovableSprite spcursor;
279 
280 private:
281     const Heroes * _hero;
282     fheroes2::Image backsf;
283     const bool use_mini_sprite;
284     const bool read_only;
285     const bool can_change;
286     const bool _allowOpeningMagicBook;
287     StatusBar * _statusBar;
288     std::string msg;
289 
290     static bool isMagicBook( const Artifact & artifact );
291 
292     void messageMagicBookAbortTrading() const;
293 };
294 
295 #endif
296