1 /*
2  * Copyright 2011-2013 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 /* Based on:
20 ===========================================================================
21 ARX FATALIS GPL Source Code
22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
23 
24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
25 
26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
28 
29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code.  If not, see
33 <http://www.gnu.org/licenses/>.
34 
35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
38 
39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
41 ===========================================================================
42 */
43 // Code: Cyril Meynier
44 //
45 // Copyright (c) 1999-2000 ARKANE Studios SA. All rights reserved
46 
47 #include "game/Levels.h"
48 
49 #include <cstring>
50 
51 #include <boost/algorithm/string/predicate.hpp>
52 
53 //-----------------------------------------------------------------------------
54 //Used to know the true level of a "subdivided" level
ARX_LEVELS_GetRealNum(long num)55 long ARX_LEVELS_GetRealNum(long num)
56 {
57 	switch (num)
58 	{
59 		case 0:
60 		case 8:
61 		case 11:
62 		case 12:
63 			return 0;
64 			break;
65 		case 1:
66 		case 13:
67 		case 14:
68 			return 1;
69 			break;
70 		case 2:
71 		case 15:
72 			return 2;
73 			break;
74 		case 3:
75 		case 16:
76 		case 17:
77 			return 3;
78 			break;
79 		case 4:
80 		case 18:
81 		case 19:
82 			return 4;
83 			break;
84 		case 5:
85 		case 21:
86 			return 5;
87 			break;
88 		case 6:
89 		case 22:
90 			return 6;
91 			break;
92 		case 7:
93 		case 23:
94 			return 7;
95 			break;
96 	}
97 
98 	if (num < 0) return -1;
99 
100 	return num;
101 }
102 
GetLevelNumByName(const std::string & name)103 long GetLevelNumByName(const std::string& name)
104 {
105 	if ( !name.empty() )
106 	{
107 		if (boost::contains(name, "level10")) return 10;
108 
109 		if (boost::contains(name, "level11")) return 11;
110 
111 		if (boost::contains(name, "level12")) return 12;
112 
113 		if (boost::contains(name, "level13")) return 13;
114 
115 		if (boost::contains(name, "level14")) return 14;
116 
117 		if (boost::contains(name, "level15")) return 15;
118 
119 		if (boost::contains(name, "level16")) return 16;
120 
121 		if (boost::contains(name, "level17")) return 17;
122 
123 		if (boost::contains(name, "level18")) return 18;
124 
125 		if (boost::contains(name, "level19")) return 19;
126 
127 		if (boost::contains(name, "level20")) return 20;
128 
129 		if (boost::contains(name, "level21")) return 21;
130 
131 		if (boost::contains(name, "level22")) return 22;
132 
133 		if (boost::contains(name, "level23")) return 23;
134 
135 		if (boost::contains(name, "level24")) return 24;
136 
137 		if (boost::contains(name, "level25")) return 25;
138 
139 		if (boost::contains(name, "level26")) return 26;
140 
141 		if (boost::contains(name, "level27")) return 27;
142 
143 		if (boost::contains(name, "leveldemo2")) return 29;
144 
145 		if (boost::contains(name, "leveldemo3")) return 30;
146 
147 		if (boost::contains(name, "leveldemo4")) return 31;
148 
149 		if (boost::contains(name, "leveldemo")) return 28;
150 
151 		if (boost::contains(name, "level0")) return 0;
152 
153 		if (boost::contains(name, "level1")) return 1;
154 
155 		if (boost::contains(name, "level2")) return 2;
156 
157 		if (boost::contains(name, "level3")) return 3;
158 
159 		if (boost::contains(name, "level4")) return 4;
160 
161 		if (boost::contains(name, "level5")) return 5;
162 
163 		if (boost::contains(name, "level6")) return 6;
164 
165 		if (boost::contains(name, "level7")) return 7;
166 
167 		if (boost::contains(name, "level8")) return 8;
168 
169 		if (boost::contains(name, "level9")) return 9;
170 	}
171 
172 	return -1;
173 }
174 
GetLevelNameByNum(long num,char * name)175 void GetLevelNameByNum(long num, char * name)
176 {
177 	if (name)
178 	{
179 		strcpy(name, "none");
180 
181 		if (num == 0) strcpy(name, "0");
182 
183 		if (num == 1) strcpy(name, "1");
184 
185 		if (num == 2) strcpy(name, "2");
186 
187 		if (num == 3) strcpy(name, "3");
188 
189 		if (num == 4) strcpy(name, "4");
190 
191 		if (num == 5) strcpy(name, "5");
192 
193 		if (num == 6) strcpy(name, "6");
194 
195 		if (num == 7) strcpy(name, "7");
196 
197 		if (num == 8) strcpy(name, "8");
198 
199 		if (num == 9) strcpy(name, "9");
200 
201 		if (num == 10) strcpy(name, "10");
202 
203 		if (num == 11) strcpy(name, "11");
204 
205 		if (num == 12) strcpy(name, "12");
206 
207 		if (num == 13) strcpy(name, "13");
208 
209 		if (num == 14) strcpy(name, "14");
210 
211 		if (num == 15) strcpy(name, "15");
212 
213 		if (num == 16) strcpy(name, "16");
214 
215 		if (num == 17) strcpy(name, "17");
216 
217 		if (num == 18) strcpy(name, "18");
218 
219 		if (num == 19) strcpy(name, "19");
220 
221 		if (num == 20) strcpy(name, "20");
222 
223 		if (num == 21) strcpy(name, "21");
224 
225 		if (num == 22) strcpy(name, "22");
226 
227 		if (num == 23) strcpy(name, "23");
228 
229 		if (num == 24) strcpy(name, "24");
230 
231 		if (num == 25) strcpy(name, "25");
232 
233 		if (num == 26) strcpy(name, "26");
234 
235 		if (num == 27) strcpy(name, "27");
236 
237 		if (num == 28) strcpy(name, "demo");
238 
239 		if (num == 29) strcpy(name, "demo2");
240 
241 		if (num == 30) strcpy(name, "demo3");
242 
243 		if (num == 31) strcpy(name, "demo4");
244 	}
245 }
246