Blame view

d2mercs.c 12.7 KB
1
2
#include "d2mercs.h"
3
#include <stdio.h>
4
5
#include <stdlib.h>
6
7
8
9
10
11
12
D2Merc getMerc(D2CharHeader* c) {
    D2Merc mercData;
    switch(c->mercenaryType){
        case 0:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
13
        break;
14
15
16
17
        case 1:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_COLD_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
18
        break;
19
20
21
22
        case 2:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
23
        break;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
        case 3:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_COLD_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 4:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 5:
            mercData.type = D2S_MERCTYPE_ROGUE;
            mercData.subtype = D2S_MERCSUBTYPE_COLD_ARROW;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 6:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_COMBAT;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 7:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_DEFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 8:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_OFFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 9:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_COMBAT;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 10:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_DEFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 11:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_OFFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 12:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_COMBAT;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 13:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_DEFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 14:
            mercData.type = D2S_MERCTYPE_DESERT;
            mercData.subtype = D2S_MERCSUBTYPE_OFFENSIVE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 15:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 16:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_COLD;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 17:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_LIGHTNING;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 18:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 19:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_COLD;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 20:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_LIGHTNING;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 21:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_FIRE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 22:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_COLD;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 23:
            mercData.type = D2S_MERCTYPE_SORCEROR;
            mercData.subtype = D2S_MERCSUBTYPE_LIGHTNING;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        case 24:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 25:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NORMAL;
        break;
        case 26:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 27:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_NIGHTMARE;
        break;
        case 28:
            mercData.type = D2S_MERCTYPE_BARBARIAN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_HELL;
        break;
        default:
            mercData.type = D2S_MERCTYPE_UNKNOWN;
            mercData.subtype = D2S_MERCSUBTYPE_NONE;
            mercData.difficulty = D2S_DIFFICULTY_UNKNOWN;
158
159
        break;
    }
160
161
162
    if(mercData.type == D2S_MERCTYPE_UNKNOWN) {
        fprintf(stderr,"libd2char error: Unable to retrieve name for mercID %d, mercNameID %d\n",c->mercenaryType, c->mercenaryNameID);
        return mercData;
163
    }
164
165
    mercData.name = mercNames[c->mercenaryNameID + mercData.type];
    return mercData;
166
167
}
168
169
int setMerc(D2CharHeader* c, D2Merc* mercData) {
    switch(mercData->type) {
170
        case D2S_MERCTYPE_ROGUE:
171
            switch(mercData->subtype) {
172
                case D2S_MERCSUBTYPE_FIRE_ARROW:
173
                    switch(mercData->difficulty) {
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 0;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 2;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 4;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_COLD_ARROW:
189
                    switch(mercData->difficulty) {
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 1;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 3;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 5;
                            return 0;
                        break;
                    }
                break;
            }
        break;
        case D2S_MERCTYPE_DESERT:
207
            switch(mercData->subtype) {
208
                case D2S_MERCSUBTYPE_COMBAT:
209
                    switch(mercData->difficulty) {
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 6;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 9;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 12;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_DEFENSIVE:
225
                    switch(mercData->difficulty) {
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 7;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 10;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 13;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_OFFENSIVE:
241
                    switch(mercData->difficulty) {
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 8;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 11;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 14;
                            return 0;
                        break;
                    }
                break;
            }
        break;
        case D2S_MERCTYPE_SORCEROR:
259
            switch(mercData->subtype) {
260
                case D2S_MERCSUBTYPE_FIRE:
261
                    switch(mercData->difficulty) {
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 15;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 18;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 21;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_COLD:
277
                    switch(mercData->difficulty) {
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 16;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 19;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 22;
                            return 0;
                        break;
                    }
                break;
                case D2S_MERCSUBTYPE_LIGHTNING:
293
                    switch(mercData->difficulty) {
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
                        case D2S_DIFFICULTY_NORMAL:
                            c->mercenaryType = 17;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_NIGHTMARE:
                            c->mercenaryType = 20;
                            return 0;
                        break;
                        case D2S_DIFFICULTY_HELL:
                            c->mercenaryType = 23;
                            return 0;
                        break;
                    }
                break;
            }
        break;
        case D2S_MERCTYPE_BARBARIAN:
            // There's actually 2 identifiers for barbarians in each difficulty, they don't seem to have 
            // noticeable effect in game, so I'm considering only one of them. If you want to specifcially
            // change to the other type, you probably know already what the mercID is so change it directly
            // in the header instead of using this function
315
            switch(mercData->difficulty) {
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
                case D2S_DIFFICULTY_NORMAL:
                    c->mercenaryType = 24;
                    return 0;
                break;
                case D2S_DIFFICULTY_NIGHTMARE:
                    c->mercenaryType = 26;
                    return 0;
                break;
                case D2S_DIFFICULTY_HELL:
                    c->mercenaryType = 28;
                    return 0;
                break;
            }
        break;
    }
    fprintf(stderr,"libd2char error: invalid combination of parameters for setMerc()\n");
    return -1;
333
}