d2mercs.c
9.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include "d2mercs.h"
#include <stdio.h>
#include <stdlib.h>
const char* getMercName(uint16_t mercID, uint16_t mercNameID) {
int offset = getMercType(mercID);
if(offset == D2S_MERCTYPE_UNKNOWN) {
fprintf(stderr,"libd2char error: Unable to retrieve name for mercID %d, mercNameID %d\n",mercID, mercNameID);
return NULL;
}
return mercNames[mercNameID + offset];
}
D2S_MERCTYPE getMercType(uint16_t mercID) {
if(mercID >= 0 && mercID <= 5) {
return D2S_MERCTYPE_ROGUE;
} else if(mercID >= 6 && mercID <= 14) {
return D2S_MERCTYPE_DESERT;
} else if(mercID >= 15 && mercID <= 23) {
return D2S_MERCTYPE_SORCEROR;
} else if(mercID >= 24 && mercID <= 29) {
return D2S_MERCTYPE_BARBARIAN;
} else {
return D2S_MERCTYPE_UNKNOWN;
}
}
D2S_MERCSUBTYPE getMercSubType(uint16_t mercID) {
D2S_MERCSUBTYPE subtype;
switch(getMercType(mercID)) {
case D2S_MERCTYPE_ROGUE:
if(mercID == 0 || mercID == 2 || mercID == 4) {
subtype = D2S_MERCSUBTYPE_FIRE_ARROW;
} else {
subtype = D2S_MERCSUBTYPE_COLD_ARROW;
}
break;
case D2S_MERCTYPE_DESERT:
if(mercID == 6 || mercID == 9 || mercID == 12) {
subtype = D2S_MERCSUBTYPE_COMBAT;
} if(mercID == 7 || mercID == 10 || mercID == 13) {
subtype = D2S_MERCSUBTYPE_DEFENSIVE;
} else {
subtype = D2S_MERCSUBTYPE_OFFENSIVE;
}
break;
case D2S_MERCTYPE_SORCEROR:
if(mercID == 15 || mercID == 18 || mercID == 21) {
subtype = D2S_MERCSUBTYPE_FIRE;
} if(mercID == 16 || mercID == 19 || mercID == 22) {
subtype = D2S_MERCSUBTYPE_COLD;
} else {
subtype = D2S_MERCSUBTYPE_LIGHTNING;
}
break;
case D2S_MERCTYPE_BARBARIAN:
case D2S_MERCTYPE_UNKNOWN:
subtype = D2S_MERCSUBTYPE_NONE;
break;
}
return subtype;
}
D2S_DIFFICULTY getMercDifficulty(uint16_t mercID) {
if(mercID == 0 || mercID == 1 ||
mercID == 6 || mercID == 7 || mercID == 8 ||
mercID == 15 || mercID == 16 || mercID == 17 ||
mercID == 24 || mercID == 25) {
return D2S_DIFFICULTY_NORMAL;
} else if (mercID == 2 || mercID == 3 ||
mercID == 9 || mercID == 10 || mercID == 11 ||
mercID == 18 || mercID == 19 || mercID == 20 ||
mercID == 26 || mercID == 27) {
return D2S_DIFFICULTY_NIGHTMARE;
} else if (mercID == 4 || mercID == 5 ||
mercID == 12 || mercID == 13 || mercID == 14 ||
mercID == 21 || mercID == 22 || mercID == 23 ||
mercID == 28 || mercID == 29) {
return D2S_DIFFICULTY_HELL;
}
return D2S_DIFFICULTY_UNKNOWN;
}
int setMerc(D2CharHeader* c, D2S_MERCTYPE type, D2S_MERCSUBTYPE subtype, D2S_DIFFICULTY difficulty) {
switch(type) {
case D2S_MERCTYPE_ROGUE:
switch(subtype) {
case D2S_MERCSUBTYPE_FIRE_ARROW:
switch(difficulty) {
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:
switch(difficulty) {
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:
switch(subtype) {
case D2S_MERCSUBTYPE_COMBAT:
switch(difficulty) {
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:
switch(difficulty) {
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:
switch(difficulty) {
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:
switch(subtype) {
case D2S_MERCSUBTYPE_FIRE:
switch(difficulty) {
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:
switch(difficulty) {
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:
switch(difficulty) {
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
switch(difficulty) {
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;
}