1 /*
2  *  Copyright (C) 2011-2016  OpenDungeons Team
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
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 General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "game/SkillType.h"
19 
20 #include "network/ODPacket.h"
21 #include "utils/Helper.h"
22 
23 namespace Skills
24 {
25 
fromString(const std::string & type)26 SkillType fromString(const std::string& type)
27 {
28     for(uint32_t i = 0; i < static_cast<uint32_t>(SkillType::countSkill); ++i)
29     {
30         SkillType skillType = static_cast<SkillType>(i);
31         if(type != toString(skillType))
32             continue;
33 
34         return skillType;
35     }
36 
37     return SkillType::nullSkillType;
38 }
39 
toString(SkillType type)40 std::string toString(SkillType type)
41 {
42     switch(type)
43     {
44         case SkillType::nullSkillType:
45             return "nullSkillType";
46         case SkillType::roomArena:
47             return "roomArena";
48         case SkillType::roomBridgeStone:
49             return "roomBridgeStone";
50         case SkillType::roomBridgeWooden:
51             return "roomBridgeWooden";
52         case SkillType::roomCasino:
53             return "roomCasino";
54         case SkillType::roomCrypt:
55             return "roomCrypt";
56         case SkillType::roomDormitory:
57             return "roomDormitory";
58         case SkillType::roomWorkshop:
59             return "roomWorkshop";
60         case SkillType::roomHatchery:
61             return "roomHatchery";
62         case SkillType::roomLibrary:
63             return "roomLibrary";
64         case SkillType::roomPrison:
65             return "roomPrison";
66         case SkillType::roomTorture:
67             return "roomTorture";
68         case SkillType::roomTrainingHall:
69             return "roomTrainingHall";
70         case SkillType::roomTreasury:
71             return "roomTreasury";
72         case SkillType::spellCallToWar:
73             return "spellCallToWar";
74         case SkillType::spellSummonWorker:
75             return "spellSummonWorker";
76         case SkillType::spellCreatureDefense:
77             return "spellCreatureDefense";
78         case SkillType::spellCreatureExplosion:
79             return "spellCreatureExplosion";
80         case SkillType::spellCreatureHaste:
81             return "spellCreatureHaste";
82         case SkillType::spellCreatureHeal:
83             return "spellCreatureHeal";
84         case SkillType::spellCreatureSlow:
85             return "spellCreatureSlow";
86         case SkillType::spellCreatureStrength:
87             return "spellCreatureStrength";
88         case SkillType::spellCreatureWeak:
89             return "spellCreatureWeak";
90         case SkillType::trapBoulder:
91             return "trapBoulder";
92         case SkillType::trapCannon:
93             return "trapCannon";
94         case SkillType::trapSpike:
95             return "trapSpike";
96         case SkillType::trapDoorWooden:
97             return "trapDoorWooden";
98         case SkillType::spellEyeEvil:
99             return "spellEyeEvil";
100         default:
101             return "Unknown enum value:" + Helper::toString(static_cast<int>(type));
102     }
103 }
104 
skillTypeToPlayerVisibleString(SkillType type)105 std::string skillTypeToPlayerVisibleString(SkillType type)
106 {
107     switch(type)
108     {
109         case SkillType::nullSkillType:
110             return "No Skill type";
111         case SkillType::roomArena:
112             return "The Arena Room";
113         case SkillType::roomBridgeStone:
114             return "The Stone Bridge Room";
115         case SkillType::roomBridgeWooden:
116             return "The Wooden Bridge Room";
117         case SkillType::roomCasino:
118             return "The Casino Room";
119         case SkillType::roomCrypt:
120             return "The Crypt Room";
121         case SkillType::roomDormitory:
122             return "The Dormitory Room";
123         case SkillType::roomWorkshop:
124             return "The Workshop Room";
125         case SkillType::roomHatchery:
126             return "The Hatchery Room";
127         case SkillType::roomLibrary:
128             return "The Library Room";
129         case SkillType::roomTrainingHall:
130             return "The TrainingHall Room";
131         case SkillType::roomTreasury:
132             return "The Treasury Room";
133         case SkillType::roomPrison:
134             return "The Prison Room";
135         case SkillType::roomTorture:
136             return "The Torture Room";
137         case SkillType::spellCallToWar:
138             return "The 'Call to War' Spell";
139         case SkillType::spellSummonWorker:
140             return "The 'Summon Worker' Spell";
141         case SkillType::spellCreatureHeal:
142             return "The 'Heal' Spell";
143         case SkillType::spellCreatureDefense:
144             return "The 'Defense' Spell";
145         case SkillType::spellCreatureExplosion:
146             return "The 'Explosion' Spell";
147         case SkillType::spellCreatureHaste:
148             return "The 'Haste' Spell";
149         case SkillType::spellCreatureSlow:
150             return "The 'Slow' Spell";
151         case SkillType::spellCreatureStrength:
152             return "The 'Strength' Spell";
153         case SkillType::spellCreatureWeak:
154             return "The 'Weak' Spell";
155         case SkillType::trapBoulder:
156             return "The Boulder Trap";
157         case SkillType::trapCannon:
158             return "The Cannon Trap";
159         case SkillType::trapSpike:
160             return "The Spike Trap";
161         case SkillType::trapDoorWooden:
162             return "The Wooden Door";
163         case SkillType::spellEyeEvil:
164             return "The 'Eye of evil' spell";
165         default:
166             return "Unknown enum value:" + Helper::toString(static_cast<int>(type));
167     }
168 }
169 }
170 
operator <<(ODPacket & os,const SkillType & type)171 ODPacket& operator<<(ODPacket& os, const SkillType& type)
172 {
173     os << static_cast<int32_t>(type);
174     return os;
175 }
176 
operator >>(ODPacket & is,SkillType & type)177 ODPacket& operator>>(ODPacket& is, SkillType& type)
178 {
179     int32_t tmp;
180     is >> tmp;
181     type = static_cast<SkillType>(tmp);
182     return is;
183 }
184 
operator <<(std::ostream & os,const SkillType & type)185 std::ostream& operator<<(std::ostream& os, const SkillType& type)
186 {
187     os << static_cast<int32_t>(type);
188     return os;
189 }
190 
operator >>(std::istream & is,SkillType & type)191 std::istream& operator>>(std::istream& is, SkillType& type)
192 {
193     int32_t tmp;
194     is >> tmp;
195     type = static_cast<SkillType>(tmp);
196     return is;
197 }
198