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
23 #include <algorithm>
24
25 #include "artifact.h"
26 #include "settings.h"
27 #include "spell_storage.h"
28
SpellStorage()29 SpellStorage::SpellStorage()
30 {
31 reserve( 67 );
32 }
33
GetSpells(int lvl) const34 SpellStorage SpellStorage::GetSpells( int lvl ) const
35 {
36 SpellStorage result;
37 result.reserve( 20 );
38 for ( const_iterator it = begin(); it != end(); ++it )
39 if ( lvl == -1 || ( *it ).isLevel( lvl ) )
40 result.push_back( *it );
41 return result;
42 }
43
Append(const Spell & sp)44 void SpellStorage::Append( const Spell & sp )
45 {
46 if ( sp != Spell::NONE && end() == std::find( begin(), end(), sp ) )
47 push_back( sp );
48 }
49
Append(const SpellStorage & st)50 void SpellStorage::Append( const SpellStorage & st )
51 {
52 for ( const Spell & sp : st ) {
53 if ( std::find( begin(), end(), sp ) == end() ) {
54 push_back( sp );
55 }
56 }
57 }
58
isPresentSpell(const Spell & spell) const59 bool SpellStorage::isPresentSpell( const Spell & spell ) const
60 {
61 return end() != std::find( begin(), end(), spell );
62 }
63
hasAdventureSpell(const int lvl) const64 bool SpellStorage::hasAdventureSpell( const int lvl ) const
65 {
66 for ( const_iterator it = begin(); it != end(); ++it ) {
67 if ( ( *it ).Level() == lvl && ( *it ).isAdventure() )
68 return true;
69 }
70
71 return false;
72 }
73
String(void) const74 std::string SpellStorage::String( void ) const
75 {
76 std::string output;
77
78 for ( const_iterator it = begin(); it != end(); ++it ) {
79 output += it->GetName();
80 output += ", ";
81 }
82
83 return output;
84 }
85
Append(const BagArtifacts & bag)86 void SpellStorage::Append( const BagArtifacts & bag )
87 {
88 for ( BagArtifacts::const_iterator it = bag.begin(); it != bag.end(); ++it )
89 Append( *it );
90 }
91
Append(const Artifact & art)92 void SpellStorage::Append( const Artifact & art )
93 {
94 switch ( art.GetID() ) {
95 case Artifact::SPELL_SCROLL:
96 Append( Spell( art.GetSpell() ) );
97 break;
98
99 case Artifact::CRYSTAL_BALL:
100 if ( Settings::Get().ExtWorldArtifactCrystalBall() ) {
101 Append( Spell( Spell::IDENTIFYHERO ) );
102 Append( Spell( Spell::VISIONS ) );
103 }
104 break;
105
106 case Artifact::BATTLE_GARB:
107 Append( Spell( Spell::TOWNPORTAL ) );
108 break;
109
110 default:
111 break;
112 }
113 }
114