Mercurial > might-and-magic-trilogy
comparison Spells.cpp @ 0:8b8875f5b359
Initial commit
author | Nomad |
---|---|
date | Fri, 05 Oct 2012 16:07:14 +0200 |
parents | |
children | 8be5293b6b33 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8b8875f5b359 |
---|---|
1 #include <stdlib.h> | |
2 | |
3 #include "Spells.h" | |
4 #include "Overlays.h" | |
5 #include "Allocator.h" | |
6 #include "LOD.h" | |
7 #include "stru123.h" | |
8 | |
9 #include "mm7_data.h" | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 struct SpellStats *pSpellStats; | |
16 | |
17 | |
18 stru324_spell stru_4E3ACC[102]; | |
19 SpellData pSpellDatas[95]; | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 //----- (0042EB31) -------------------------------------------------------- | |
27 bool SpellBuff::NotExpired() | |
28 { | |
29 bool result; // eax@1 | |
30 | |
31 result = 0; | |
32 if ( (signed __int64)this->uExpireTime > 0 ) | |
33 result = 1; | |
34 return result; | |
35 } | |
36 | |
37 | |
38 //----- (00458585) -------------------------------------------------------- | |
39 void SpellBuff::Reset() | |
40 { | |
41 SpellBuff *v1; // esi@1 | |
42 unsigned __int16 v2; // ax@1 | |
43 | |
44 v1 = this; | |
45 v2 = this->uOverlayID; | |
46 this->uSkill = 0; | |
47 this->uPower = 0; | |
48 this->uExpireTime = 0i64; | |
49 this->uCaster = 0; | |
50 this->uFlags = 0; | |
51 if ( v2 ) | |
52 { | |
53 ((OtherOverlay *)&stru_5E4C90.field_4B[20 * v2 + 105])->Reset(); | |
54 pOtherOverlayList->field_3EC = 1; | |
55 v1->uOverlayID = 0; | |
56 } | |
57 } | |
58 | |
59 //----- (004585CA) -------------------------------------------------------- | |
60 signed int SpellBuff::_4585CA(__int64 a2) | |
61 { | |
62 signed int result; // eax@3 | |
63 | |
64 if ( this->uExpireTime && (signed __int64)this->uExpireTime < a2 ) | |
65 { | |
66 this->uExpireTime = 0i64; | |
67 this->uPower = 0; | |
68 this->uSkill = 0; | |
69 this->uOverlayID = 0; | |
70 result = 1; | |
71 } | |
72 else | |
73 { | |
74 result = 0; | |
75 } | |
76 return result; | |
77 } | |
78 | |
79 //----- (004584E0) -------------------------------------------------------- | |
80 signed int SpellBuff::Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int a5, unsigned __int8 a6) | |
81 { | |
82 SpellBuff *v6; // esi@1 | |
83 signed int result; // eax@3 | |
84 int v8; // eax@4 | |
85 | |
86 v6 = this; | |
87 if ( this->uExpireTime && (signed __int64)uExpireTime < (signed __int64)this->uExpireTime ) | |
88 { | |
89 result = 0; | |
90 } | |
91 else | |
92 { | |
93 this->uSkill = uSkillLevel; | |
94 this->uPower = uPower; | |
95 LOWORD(v8) = this->uOverlayID; | |
96 this->uExpireTime = uExpireTime; | |
97 if ( (short)v8 ) | |
98 { | |
99 v8 = (unsigned __int16)v8; | |
100 if ( (unsigned __int16)v8 != a5 ) | |
101 { | |
102 ((OtherOverlay *)&stru_5E4C90.field_4B[20 * v8 + 105])->Reset(); | |
103 pOtherOverlayList->field_3EC = 1; | |
104 v6->uOverlayID = 0; | |
105 } | |
106 } | |
107 v6->uOverlayID = a5; | |
108 v6->uCaster = a6; | |
109 result = 1; | |
110 } | |
111 return result; | |
112 } | |
113 | |
114 //----- (0045384A) -------------------------------------------------------- | |
115 void SpellStats::Initialize() | |
116 { | |
117 SpellStats *v1; // esi@1 | |
118 const char *v2; // ebp@3 | |
119 char *v3; // edi@3 | |
120 signed int v4; // ebx@4 | |
121 char *v5; // esi@4 | |
122 char v6; // cl@5 | |
123 int v7; // eax@5 | |
124 size_t v8; // ebp@40 | |
125 int v9; // eax@41 | |
126 int v10; // eax@42 | |
127 int v11; // eax@43 | |
128 char *v12; // [sp+10h] [bp-10h]@3 | |
129 signed int v13; // [sp+14h] [bp-Ch]@4 | |
130 signed int v14; // [sp+18h] [bp-8h]@3 | |
131 int v15; // [sp+1Ch] [bp-4h]@9 | |
132 | |
133 v1 = this; | |
134 if ( pSpellsTXT_Raw ) | |
135 pAllocator->FreeChunk(pSpellsTXT_Raw); | |
136 pSpellsTXT_Raw = 0; | |
137 v2 = "\r"; | |
138 pSpellsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spells.txt", 0); | |
139 strtok(pSpellsTXT_Raw, "\r"); | |
140 strtok(0, "\r"); | |
141 v14 = 1; | |
142 v12 = (char *)&pSpellDatas[1].field_10; | |
143 v3 = (char *)&v1->pInfos[1].uSchool; | |
144 do | |
145 { | |
146 v4 = 0; | |
147 v5 = strtok(0, v2) + 1; | |
148 v13 = 0; | |
149 do | |
150 { | |
151 v6 = *v5; | |
152 v7 = 0; | |
153 while ( v6 != 9 && v6 ) | |
154 { | |
155 ++v7; | |
156 v6 = v5[v7]; | |
157 } | |
158 v15 = (int)&v5[v7]; | |
159 if ( !v5[v7] ) | |
160 v13 = 1; | |
161 v5[v7] = 0; | |
162 if ( v7 ) | |
163 { | |
164 switch ( v4 ) | |
165 { | |
166 case 2: | |
167 *((char **)v3 - 7) = RemoveQuotes(v5); | |
168 break; | |
169 case 3: | |
170 *v3 = 4; | |
171 if ( _strcmpi("fire", v5) ) | |
172 { | |
173 if ( _strcmpi("air", v5) ) | |
174 { | |
175 if ( _strcmpi("water", v5) ) | |
176 { | |
177 if ( _strcmpi("earth", v5) ) | |
178 { | |
179 if ( _strcmpi("spirit", v5) ) | |
180 { | |
181 if ( _strcmpi("mind", v5) ) | |
182 { | |
183 if ( _strcmpi("body", v5) ) | |
184 { | |
185 if ( _strcmpi("light", v5) ) | |
186 { | |
187 if ( _strcmpi("dark", v5) ) | |
188 { | |
189 if ( !_strcmpi("magic", v5) ) | |
190 *v3 = 5; | |
191 } | |
192 else | |
193 { | |
194 *v3 = 10; | |
195 } | |
196 } | |
197 else | |
198 { | |
199 *v3 = 9; | |
200 } | |
201 } | |
202 else | |
203 { | |
204 *v3 = 8; | |
205 } | |
206 } | |
207 else | |
208 { | |
209 *v3 = 7; | |
210 } | |
211 } | |
212 else | |
213 { | |
214 *v3 = 6; | |
215 } | |
216 } | |
217 else | |
218 { | |
219 *v3 = 3; | |
220 } | |
221 } | |
222 else | |
223 { | |
224 *v3 = 2; | |
225 } | |
226 } | |
227 else | |
228 { | |
229 *v3 = 1; | |
230 } | |
231 } | |
232 else | |
233 { | |
234 *v3 = 0; | |
235 } | |
236 break; | |
237 case 4: | |
238 *((char **)v3 - 6) = RemoveQuotes(v5); | |
239 break; | |
240 case 5: | |
241 *((char **)v3 - 5) = RemoveQuotes(v5); | |
242 break; | |
243 case 6: | |
244 *((char **)v3 - 4) = RemoveQuotes(v5); | |
245 break; | |
246 case 7: | |
247 *((char **)v3 - 3) = RemoveQuotes(v5); | |
248 break; | |
249 case 8: | |
250 *((char **)v3 - 2) = RemoveQuotes(v5); | |
251 break; | |
252 case 9: | |
253 *((char **)v3 - 1) = RemoveQuotes(v5); | |
254 break; | |
255 case 10: | |
256 v4 = 0; | |
257 v8 = strlen(v5); | |
258 if ( (signed int)v8 > 0 ) | |
259 { | |
260 do | |
261 { | |
262 v9 = tolower((unsigned __int8)v5[v4]) - 99; | |
263 if ( v9 ) | |
264 { | |
265 v10 = v9 - 2; | |
266 if ( v10 ) | |
267 { | |
268 v11 = v10 - 8; | |
269 if ( v11 ) | |
270 { | |
271 if ( v11 == 11 ) | |
272 *v12 |= 8u; | |
273 } | |
274 else | |
275 { | |
276 *v12 |= 1u; | |
277 } | |
278 } | |
279 else | |
280 { | |
281 *v12 |= 2u; | |
282 } | |
283 } | |
284 else | |
285 { | |
286 *v12 |= 4u; | |
287 } | |
288 ++v4; | |
289 } | |
290 while ( v4 < (signed int)v8 ); | |
291 } | |
292 v2 = "\r"; | |
293 break; | |
294 default: | |
295 break; | |
296 } | |
297 } | |
298 else | |
299 { | |
300 v13 = 1; | |
301 } | |
302 ++v4; | |
303 v5 = (char *)(v15 + 1); | |
304 } | |
305 while ( v4 - 1 <= 10 && !v13 ); | |
306 if ( !(v14 % 11) ) | |
307 strtok(0, v2); | |
308 v12 += 20; | |
309 ++v14; | |
310 v3 += 36; | |
311 } | |
312 while ( (signed int)v12 <= (signed int)&pSpellDatas[90].field_12 ); | |
313 } |