|
|
1 | |
1 | /* |
2 | /* |
2 | * static char *rcsid_c_range_c = |
3 | * static char *rcsid_c_range_c = |
3 | * "$Id: c_range.C,v 1.4 2006/09/07 10:01:57 pippijn Exp $"; |
4 | * "$Id: c_range.C,v 1.5 2006/09/10 15:59:57 root Exp $"; |
4 | */ |
5 | */ |
5 | |
6 | |
6 | /* |
7 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
8 | |
9 | |
… | |
… | |
30 | * throwing, etc. |
31 | * throwing, etc. |
31 | */ |
32 | */ |
32 | |
33 | |
33 | #include <global.h> |
34 | #include <global.h> |
34 | #ifndef __CEXTRACT__ |
35 | #ifndef __CEXTRACT__ |
35 | #include <sproto.h> |
36 | # include <sproto.h> |
36 | #endif |
37 | #endif |
37 | #include <spells.h> |
38 | #include <spells.h> |
38 | #include <skills.h> |
39 | #include <skills.h> |
39 | #include <newclient.h> |
40 | #include <newclient.h> |
40 | #include <commands.h> |
41 | #include <commands.h> |
41 | |
42 | |
42 | |
43 | |
|
|
44 | int |
43 | int command_invoke(object *op, char *params) |
45 | command_invoke (object *op, char *params) |
44 | { |
46 | { |
45 | return command_cast_spell(op, params, 'i'); |
47 | return command_cast_spell (op, params, 'i'); |
46 | } |
48 | } |
47 | |
49 | |
|
|
50 | int |
48 | int command_cast(object *op, char *params) |
51 | command_cast (object *op, char *params) |
49 | { |
52 | { |
50 | return command_cast_spell(op, params, 'c'); |
53 | return command_cast_spell (op, params, 'c'); |
51 | } |
54 | } |
52 | |
55 | |
|
|
56 | int |
53 | int command_prepare(object *op, char *params) |
57 | command_prepare (object *op, char *params) |
54 | { |
58 | { |
55 | return command_cast_spell(op, params, 'p'); |
59 | return command_cast_spell (op, params, 'p'); |
56 | } |
60 | } |
57 | |
61 | |
58 | /* Shows all spells that op knows. If params is supplied, the must match |
62 | /* Shows all spells that op knows. If params is supplied, the must match |
59 | * that. Given there is more than one skill, we can't supply break |
63 | * that. Given there is more than one skill, we can't supply break |
60 | * them down to cleric/wizardry. |
64 | * them down to cleric/wizardry. |
61 | */ |
65 | */ |
|
|
66 | static void |
62 | static void show_matching_spells(object *op, char *params) |
67 | show_matching_spells (object *op, char *params) |
63 | { |
68 | { |
64 | object *spell; |
69 | object *spell; |
65 | char spell_sort[NROFREALSPELLS][MAX_BUF], tmp[MAX_BUF], *cp; |
70 | char spell_sort[NROFREALSPELLS][MAX_BUF], tmp[MAX_BUF], *cp; |
66 | int num_found=0, i; |
71 | int num_found = 0, i; |
67 | |
72 | |
68 | /* We go and see what spells the player has. We put them |
73 | /* We go and see what spells the player has. We put them |
69 | * into the spell_sort array so that we can sort them - |
74 | * into the spell_sort array so that we can sort them - |
70 | * we prefix the skill in the name so that the sorting |
75 | * we prefix the skill in the name so that the sorting |
71 | * works better. |
76 | * works better. |
72 | */ |
77 | */ |
73 | for (spell=op->inv; spell!=NULL; spell=spell->below) { |
78 | for (spell = op->inv; spell != NULL; spell = spell->below) |
|
|
79 | { |
74 | /* If it is a spell, and no params are passed, or they |
80 | /* If it is a spell, and no params are passed, or they |
75 | * match the name, process this spell. |
81 | * match the name, process this spell. |
76 | */ |
82 | */ |
77 | if (spell->type == SPELL && |
|
|
78 | (!params || !strncmp(params, spell->name, strlen(params)))) { |
83 | if (spell->type == SPELL && (!params || !strncmp (params, spell->name, strlen (params)))) |
|
|
84 | { |
79 | if (spell->path_attuned & op->path_denied) { |
85 | if (spell->path_attuned & op->path_denied) |
|
|
86 | { |
|
|
87 | sprintf (spell_sort[num_found++], "%s:%-22s %3s %3s", spell->skill ? &spell->skill : "generic", &spell->name, "den", "den"); |
|
|
88 | } |
|
|
89 | else |
|
|
90 | { |
80 | sprintf(spell_sort[num_found++], |
91 | sprintf (spell_sort[num_found++], |
81 | "%s:%-22s %3s %3s", spell->skill ? &spell->skill : "generic", |
|
|
82 | &spell->name, "den", "den"); |
|
|
83 | } else { |
|
|
84 | sprintf(spell_sort[num_found++], |
|
|
85 | "%s:%-22s %3d %3d", spell->skill ? &spell->skill : "generic", |
92 | "%s:%-22s %3d %3d", spell->skill ? &spell->skill : "generic", |
86 | &spell->name, spell->level, |
|
|
87 | SP_level_spellpoint_cost(op,spell, SPELL_HIGHEST)); |
93 | &spell->name, spell->level, SP_level_spellpoint_cost (op, spell, SPELL_HIGHEST)); |
88 | } |
94 | } |
89 | } |
95 | } |
90 | } |
96 | } |
91 | if (!num_found) { |
97 | if (!num_found) |
|
|
98 | { |
92 | /* If a matching string was passed along, now try it without that |
99 | /* If a matching string was passed along, now try it without that |
93 | * string. It is odd to do something like 'cast trans', |
100 | * string. It is odd to do something like 'cast trans', |
94 | * and it say you have no spells, when really, you do, but just |
101 | * and it say you have no spells, when really, you do, but just |
95 | * nothing that matches. |
102 | * nothing that matches. |
96 | */ |
103 | */ |
97 | if (params) |
104 | if (params) |
98 | show_matching_spells(op, NULL); |
105 | show_matching_spells (op, NULL); |
99 | else |
106 | else |
100 | new_draw_info(NDI_UNIQUE, 0, op, "You know no spells"); |
107 | new_draw_info (NDI_UNIQUE, 0, op, "You know no spells"); |
101 | } else { |
108 | } |
|
|
109 | else |
|
|
110 | { |
102 | /* Note in the code below that we make some |
111 | /* Note in the code below that we make some |
103 | * presumptions that there will be a colon in the |
112 | * presumptions that there will be a colon in the |
104 | * string. given the code above, this is always |
113 | * string. given the code above, this is always |
105 | * the case. |
114 | * the case. |
106 | */ |
115 | */ |
107 | qsort(spell_sort, num_found, MAX_BUF, (int (*)(const void*, const void*))strcmp); |
116 | qsort (spell_sort, num_found, MAX_BUF, (int (*)(const void *, const void *)) strcmp); |
108 | strcpy(tmp,"asdfg"); /* Dummy string so initial compare fails */ |
117 | strcpy (tmp, "asdfg"); /* Dummy string so initial compare fails */ |
109 | for (i=0; i<num_found; i++) { |
118 | for (i = 0; i < num_found; i++) |
|
|
119 | { |
110 | /* Different skill name, so print banner */ |
120 | /* Different skill name, so print banner */ |
111 | if (strncmp(tmp, spell_sort[i], strlen(tmp))) { |
121 | if (strncmp (tmp, spell_sort[i], strlen (tmp))) |
|
|
122 | { |
112 | strcpy(tmp, spell_sort[i]); |
123 | strcpy (tmp, spell_sort[i]); |
113 | cp = strchr(tmp, ':'); |
124 | cp = strchr (tmp, ':'); |
114 | *cp = '\0'; |
125 | *cp = '\0'; |
115 | new_draw_info(NDI_UNIQUE, 0, op, ""); |
126 | new_draw_info (NDI_UNIQUE, 0, op, ""); |
116 | new_draw_info_format(NDI_UNIQUE, 0,op,"%s spells %.*s [lvl] [sp]", |
127 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s spells %.*s [lvl] [sp]", tmp, 12 - strlen (tmp), " "); |
117 | tmp, 12-strlen(tmp), " "); |
|
|
118 | } |
128 | } |
119 | new_draw_info(NDI_UNIQUE, 0, op, strchr(spell_sort[i], ':') + 1); |
129 | new_draw_info (NDI_UNIQUE, 0, op, strchr (spell_sort[i], ':') + 1); |
120 | } |
130 | } |
121 | } |
131 | } |
122 | } |
132 | } |
123 | |
133 | |
124 | |
134 | |
… | |
… | |
127 | * and command is the first letter of the spell type (c=cast, i=invoke, |
137 | * and command is the first letter of the spell type (c=cast, i=invoke, |
128 | * p=prepare). Invoke casts a spell immediately, where as cast (and I believe |
138 | * p=prepare). Invoke casts a spell immediately, where as cast (and I believe |
129 | * prepare) just set up the range type. |
139 | * prepare) just set up the range type. |
130 | */ |
140 | */ |
131 | |
141 | |
|
|
142 | int |
132 | int command_cast_spell (object *op, char *params, char command) |
143 | command_cast_spell (object *op, char *params, char command) |
133 | { |
144 | { |
134 | int castnow=0; |
145 | int castnow = 0; |
135 | char *cp; |
146 | char *cp; |
136 | object *spob; |
147 | object *spob; |
137 | |
148 | |
138 | if (command=='i') castnow = 1; |
149 | if (command == 'i') |
|
|
150 | castnow = 1; |
139 | |
151 | |
140 | /* Remove control of the golem */ |
152 | /* Remove control of the golem */ |
141 | if(op->contr->ranges[range_golem]!=NULL) { |
153 | if (op->contr->ranges[range_golem] != NULL) |
|
|
154 | { |
142 | if (op->contr->golem_count == op->contr->ranges[range_golem]->count) { |
155 | if (op->contr->golem_count == op->contr->ranges[range_golem]->count) |
|
|
156 | { |
143 | remove_friendly_object(op->contr->ranges[range_golem]); |
157 | remove_friendly_object (op->contr->ranges[range_golem]); |
144 | remove_ob(op->contr->ranges[range_golem]); |
158 | remove_ob (op->contr->ranges[range_golem]); |
145 | free_object(op->contr->ranges[range_golem]); |
159 | free_object (op->contr->ranges[range_golem]); |
146 | } |
160 | } |
147 | op->contr->ranges[range_golem]=NULL; |
161 | op->contr->ranges[range_golem] = NULL; |
148 | op->contr->golem_count = 0; |
162 | op->contr->golem_count = 0; |
149 | } |
163 | } |
150 | |
164 | |
151 | if(params!=NULL) { |
165 | if (params != NULL) |
|
|
166 | { |
152 | int spellnumber = 0; |
167 | int spellnumber = 0; |
|
|
168 | |
153 | if ((spellnumber = atoi(params))) |
169 | if ((spellnumber = atoi (params))) |
154 | for (spob = op->inv; spob && spob->count != (tag_t) spellnumber; spob=spob->below); |
170 | for (spob = op->inv; spob && spob->count != (tag_t) spellnumber; spob = spob->below); |
|
|
171 | else |
155 | else spob = lookup_spell_by_name(op, params); |
172 | spob = lookup_spell_by_name (op, params); |
156 | |
173 | |
157 | if (spob && spob->type == SPELL) { |
174 | if (spob && spob->type == SPELL) |
|
|
175 | { |
158 | /* Now grab any extra data, if there is any. Forward pass |
176 | /* Now grab any extra data, if there is any. Forward pass |
159 | * any 'of' delimiter |
177 | * any 'of' delimiter |
160 | */ |
178 | */ |
161 | if (spellnumber) { |
179 | if (spellnumber) |
|
|
180 | { |
162 | /* if we passed a number, the options start at the second word */ |
181 | /* if we passed a number, the options start at the second word */ |
163 | cp = strchr(params, ' '); |
182 | cp = strchr (params, ' '); |
164 | if (cp) { |
183 | if (cp) |
|
|
184 | { |
165 | cp++; |
185 | cp++; |
166 | if (!strncmp(cp, "of ", 3)) cp+=3; |
186 | if (!strncmp (cp, "of ", 3)) |
|
|
187 | cp += 3; |
167 | } |
188 | } |
168 | } |
189 | } |
169 | else if (strlen(params) > (size_t) strlen(spob->name)) { |
190 | else if (strlen (params) > (size_t) strlen (spob->name)) |
|
|
191 | { |
170 | cp = params + strlen(spob->name); |
192 | cp = params + strlen (spob->name); |
171 | *cp = 0; |
193 | *cp = 0; |
172 | cp++; |
194 | cp++; |
173 | if (!strncmp(cp, "of ", 3)) cp+=3; |
195 | if (!strncmp (cp, "of ", 3)) |
|
|
196 | cp += 3; |
|
|
197 | } |
174 | } else |
198 | else |
175 | cp = NULL; |
199 | cp = NULL; |
176 | |
200 | |
177 | if (spob->skill && !find_skill_by_name(op, spob->skill)) { |
201 | if (spob->skill && !find_skill_by_name (op, spob->skill)) |
178 | new_draw_info_format(NDI_UNIQUE, 0, op, |
202 | { |
179 | "You need the skill %s to cast %s!", |
203 | new_draw_info_format (NDI_UNIQUE, 0, op, "You need the skill %s to cast %s!", &spob->skill, &spob->name); |
180 | &spob->skill, &spob->name); |
|
|
181 | return 1; |
204 | return 1; |
|
|
205 | } |
|
|
206 | |
|
|
207 | if (castnow) |
182 | } |
208 | { |
183 | |
|
|
184 | if (castnow) { |
|
|
185 | cast_spell(op,op,op->facing,spob,cp); |
209 | cast_spell (op, op, op->facing, spob, cp); |
|
|
210 | } |
186 | } else { |
211 | else |
|
|
212 | { |
187 | op->contr->ranges[range_magic] = spob; |
213 | op->contr->ranges[range_magic] = spob; |
188 | op->contr->shoottype = range_magic; |
214 | op->contr->shoottype = range_magic; |
189 | if(cp != NULL) { |
215 | if (cp != NULL) |
|
|
216 | { |
190 | strncpy(op->contr->spellparam, cp, MAX_BUF); |
217 | strncpy (op->contr->spellparam, cp, MAX_BUF); |
191 | op->contr->spellparam[MAX_BUF-1] = '\0'; |
218 | op->contr->spellparam[MAX_BUF - 1] = '\0'; |
|
|
219 | } |
192 | } else { |
220 | else |
|
|
221 | { |
193 | op->contr->spellparam[0] = '\0'; |
222 | op->contr->spellparam[0] = '\0'; |
194 | } |
223 | } |
195 | new_draw_info_format(NDI_UNIQUE, 0, op, |
224 | new_draw_info_format (NDI_UNIQUE, 0, op, "You ready the spell %s", &spob->name); |
196 | "You ready the spell %s", &spob->name); |
|
|
197 | } |
225 | } |
198 | return 0; |
226 | return 0; |
199 | } /* else fall through to below and print spells */ |
227 | } /* else fall through to below and print spells */ |
200 | } /* params supplied */ |
228 | } /* params supplied */ |
201 | |
229 | |
202 | /* We get here if cast was given without options or we could not find |
230 | /* We get here if cast was given without options or we could not find |
203 | * the requested spell. List all the spells the player knows. |
231 | * the requested spell. List all the spells the player knows. |
204 | */ |
232 | */ |
205 | new_draw_info(NDI_UNIQUE, 0,op,"Cast what spell? Choose one of:"); |
233 | new_draw_info (NDI_UNIQUE, 0, op, "Cast what spell? Choose one of:"); |
206 | show_matching_spells(op, params); |
234 | show_matching_spells (op, params); |
207 | return 1; |
235 | return 1; |
208 | } |
236 | } |
209 | |
237 | |
210 | /**************************************************************************/ |
238 | /**************************************************************************/ |
211 | |
239 | |
212 | /* Returns TRUE if the range specified (int r) is legal - that is, |
240 | /* Returns TRUE if the range specified (int r) is legal - that is, |
… | |
… | |
214 | * return 0 if there is no item of that range type that is usable. |
242 | * return 0 if there is no item of that range type that is usable. |
215 | * This function could probably be simplified, eg, everything |
243 | * This function could probably be simplified, eg, everything |
216 | * should index into the ranges[] array. |
244 | * should index into the ranges[] array. |
217 | */ |
245 | */ |
218 | |
246 | |
|
|
247 | int |
219 | int legal_range(object *op,int r) { |
248 | legal_range (object *op, int r) |
|
|
249 | { |
220 | |
250 | |
221 | switch(r) { |
251 | switch (r) |
|
|
252 | { |
222 | case range_none: /* "Nothing" is always legal */ |
253 | case range_none: /* "Nothing" is always legal */ |
223 | return 1; |
254 | return 1; |
224 | case range_bow: |
255 | case range_bow: |
225 | case range_misc: |
256 | case range_misc: |
226 | case range_magic: /* cast spells */ |
257 | case range_magic: /* cast spells */ |
227 | if (op->contr->ranges[r]) return 1; |
258 | if (op->contr->ranges[r]) |
|
|
259 | return 1; |
|
|
260 | else |
228 | else return 0; |
261 | return 0; |
229 | |
262 | |
230 | case range_golem: /* Use scrolls */ |
263 | case range_golem: /* Use scrolls */ |
231 | if (op->contr->ranges[range_golem] && |
|
|
232 | op->contr->ranges[range_golem]->count == op->contr->golem_count) |
264 | if (op->contr->ranges[range_golem] && op->contr->ranges[range_golem]->count == op->contr->golem_count) |
233 | return 1; |
265 | return 1; |
234 | else |
266 | else |
235 | return 0; |
267 | return 0; |
236 | |
268 | |
237 | case range_skill: |
269 | case range_skill: |
238 | if (op->chosen_skill) |
270 | if (op->chosen_skill) |
239 | return 1; |
271 | return 1; |
240 | else |
272 | else |
241 | return 0; |
273 | return 0; |
242 | } |
274 | } |
243 | /* No match above, must not be valid */ |
275 | /* No match above, must not be valid */ |
244 | return 0; |
276 | return 0; |
245 | } |
277 | } |
246 | |
278 | |
|
|
279 | void |
247 | void change_spell(object *op,char k) { |
280 | change_spell (object *op, char k) |
|
|
281 | { |
248 | |
282 | |
|
|
283 | do |
249 | do { |
284 | { |
250 | op->contr->shoottype = (rangetype) (op->contr->shoottype + ((k == '+') ? 1 : -1)); |
285 | op->contr->shoottype = (rangetype) (op->contr->shoottype + ((k == '+') ? 1 : -1)); |
251 | if(op->contr->shoottype >= range_size) |
286 | if (op->contr->shoottype >= range_size) |
252 | op->contr->shoottype = range_none; |
287 | op->contr->shoottype = range_none; |
253 | else if (op->contr->shoottype <= range_bottom) |
288 | else if (op->contr->shoottype <= range_bottom) |
254 | op->contr->shoottype = (rangetype)(range_size-1); |
289 | op->contr->shoottype = (rangetype) (range_size - 1); |
|
|
290 | } |
255 | } while (!legal_range(op,op->contr->shoottype)); |
291 | while (!legal_range (op, op->contr->shoottype)); |
256 | |
292 | |
257 | /* Legal range has already checked that we have an appropriate item |
293 | /* Legal range has already checked that we have an appropriate item |
258 | * that uses the slot, so we don't need to be too careful about |
294 | * that uses the slot, so we don't need to be too careful about |
259 | * checking the status of the object. |
295 | * checking the status of the object. |
260 | */ |
296 | */ |
261 | switch(op->contr->shoottype) { |
297 | switch (op->contr->shoottype) |
|
|
298 | { |
262 | case range_none: |
299 | case range_none: |
263 | new_draw_info(NDI_UNIQUE, 0,op, "No ranged attack chosen."); |
300 | new_draw_info (NDI_UNIQUE, 0, op, "No ranged attack chosen."); |
264 | break; |
301 | break; |
265 | |
302 | |
266 | case range_golem: |
303 | case range_golem: |
267 | new_draw_info(NDI_UNIQUE, 0,op, "You regain control of your golem."); |
304 | new_draw_info (NDI_UNIQUE, 0, op, "You regain control of your golem."); |
268 | break; |
305 | break; |
269 | |
306 | |
270 | case range_bow: |
307 | case range_bow: |
271 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to %s and %s.", query_name(op->contr->ranges[range_bow]), |
308 | new_draw_info_format (NDI_UNIQUE, 0, op, "Switched to %s and %s.", query_name (op->contr->ranges[range_bow]), |
272 | op->contr->ranges[range_bow]->race ? &op->contr->ranges[range_bow]->race : "nothing"); |
309 | op->contr->ranges[range_bow]->race ? &op->contr->ranges[range_bow]->race : "nothing"); |
273 | break; |
310 | break; |
274 | |
311 | |
275 | case range_magic: |
312 | case range_magic: |
276 | new_draw_info_format(NDI_UNIQUE, 0,op,"Switched to spells (%s).", |
313 | new_draw_info_format (NDI_UNIQUE, 0, op, "Switched to spells (%s).", &op->contr->ranges[range_magic]->name); |
277 | &op->contr->ranges[range_magic]->name); |
|
|
278 | break; |
314 | break; |
279 | |
315 | |
280 | case range_misc: |
316 | case range_misc: |
281 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to %s.", query_base_name(op->contr->ranges[range_misc], 0)); |
317 | new_draw_info_format (NDI_UNIQUE, 0, op, "Switched to %s.", query_base_name (op->contr->ranges[range_misc], 0)); |
282 | break; |
318 | break; |
283 | |
319 | |
284 | case range_skill: |
320 | case range_skill: |
285 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to skill: %s", op->chosen_skill ? |
321 | new_draw_info_format (NDI_UNIQUE, 0, op, "Switched to skill: %s", op->chosen_skill ? &op->chosen_skill->name : "none"); |
286 | &op->chosen_skill->name : "none"); |
|
|
287 | break; |
322 | break; |
288 | |
323 | |
289 | default: |
324 | default: |
290 | break; |
325 | break; |
291 | } |
326 | } |
292 | } |
327 | } |
293 | |
328 | |
294 | |
329 | |
|
|
330 | int |
295 | int command_rotateshoottype (object *op, char *params) |
331 | command_rotateshoottype (object *op, char *params) |
296 | { |
332 | { |
297 | if (!params) |
333 | if (!params) |
298 | change_spell(op,'+'); |
334 | change_spell (op, '+'); |
299 | else |
335 | else |
300 | change_spell(op, params[0]); |
336 | change_spell (op, params[0]); |
301 | return 0; |
337 | return 0; |
302 | } |
338 | } |
303 | |
|
|