1 | /* |
1 | /* |
2 | * static char *rcsid_c_range_c = |
2 | * static char *rcsid_c_range_c = |
3 | * "$Id: c_range.C,v 1.1 2006/08/13 17:16:04 elmex Exp $"; |
3 | * "$Id: c_range.C,v 1.2 2006/08/29 08:01:37 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
40 | #include <commands.h> |
40 | #include <commands.h> |
41 | |
41 | |
42 | |
42 | |
43 | int command_invoke(object *op, char *params) |
43 | int command_invoke(object *op, char *params) |
44 | { |
44 | { |
45 | return command_cast_spell(op, params, 'i'); |
45 | return command_cast_spell(op, params, 'i'); |
46 | } |
46 | } |
47 | |
47 | |
48 | int command_cast(object *op, char *params) |
48 | int command_cast(object *op, char *params) |
49 | { |
49 | { |
50 | return command_cast_spell(op, params, 'c'); |
50 | return command_cast_spell(op, params, 'c'); |
51 | } |
51 | } |
52 | |
52 | |
53 | int command_prepare(object *op, char *params) |
53 | int command_prepare(object *op, char *params) |
54 | { |
54 | { |
55 | return command_cast_spell(op, params, 'p'); |
55 | return command_cast_spell(op, params, 'p'); |
56 | } |
56 | } |
57 | |
57 | |
58 | /* Shows all spells that op knows. If params is supplied, the must match |
58 | /* 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 |
59 | * that. Given there is more than one skill, we can't supply break |
60 | * them down to cleric/wizardry. |
60 | * them down to cleric/wizardry. |
… | |
… | |
69 | * into the spell_sort array so that we can sort them - |
69 | * into the spell_sort array so that we can sort them - |
70 | * we prefix the skill in the name so that the sorting |
70 | * we prefix the skill in the name so that the sorting |
71 | * works better. |
71 | * works better. |
72 | */ |
72 | */ |
73 | for (spell=op->inv; spell!=NULL; spell=spell->below) { |
73 | for (spell=op->inv; spell!=NULL; spell=spell->below) { |
74 | /* If it is a spell, and no params are passed, or they |
74 | /* If it is a spell, and no params are passed, or they |
75 | * match the name, process this spell. |
75 | * match the name, process this spell. |
76 | */ |
76 | */ |
77 | if (spell->type == SPELL && |
77 | if (spell->type == SPELL && |
78 | (!params || !strncmp(params, spell->name, strlen(params)))) { |
78 | (!params || !strncmp(params, spell->name, strlen(params)))) { |
79 | if (spell->path_attuned & op->path_denied) { |
79 | if (spell->path_attuned & op->path_denied) { |
80 | sprintf(spell_sort[num_found++], |
80 | sprintf(spell_sort[num_found++], |
81 | "%s:%-22s %3s %3s", spell->skill?spell->skill:"generic", |
81 | "%s:%-22s %3s %3s", spell->skill?spell->skill:"generic", |
82 | spell->name, "den", "den"); |
82 | spell->name, "den", "den"); |
83 | } else { |
83 | } else { |
84 | sprintf(spell_sort[num_found++], |
84 | sprintf(spell_sort[num_found++], |
85 | "%s:%-22s %3d %3d", spell->skill?spell->skill:"generic", |
85 | "%s:%-22s %3d %3d", spell->skill?spell->skill:"generic", |
86 | spell->name, spell->level, |
86 | spell->name, spell->level, |
87 | SP_level_spellpoint_cost(op,spell, SPELL_HIGHEST)); |
87 | SP_level_spellpoint_cost(op,spell, SPELL_HIGHEST)); |
88 | } |
88 | } |
89 | } |
89 | } |
90 | } |
90 | } |
91 | if (!num_found) { |
91 | if (!num_found) { |
92 | /* If a matching string was passed along, now try it without that |
92 | /* If a matching string was passed along, now try it without that |
93 | * string. It is odd to do something like 'cast trans', |
93 | * string. It is odd to do something like 'cast trans', |
94 | * and it say you have no spells, when really, you do, but just |
94 | * and it say you have no spells, when really, you do, but just |
95 | * nothing that matches. |
95 | * nothing that matches. |
96 | */ |
96 | */ |
97 | if (params) |
97 | if (params) |
98 | show_matching_spells(op, NULL); |
98 | show_matching_spells(op, NULL); |
99 | else |
99 | else |
100 | new_draw_info(NDI_UNIQUE, 0, op, "You know no spells"); |
100 | new_draw_info(NDI_UNIQUE, 0, op, "You know no spells"); |
101 | } else { |
101 | } else { |
102 | /* Note in the code below that we make some |
102 | /* Note in the code below that we make some |
103 | * presumptions that there will be a colon in the |
103 | * presumptions that there will be a colon in the |
104 | * string. given the code above, this is always |
104 | * string. given the code above, this is always |
105 | * the case. |
105 | * the case. |
106 | */ |
106 | */ |
107 | qsort(spell_sort, num_found, MAX_BUF, (int (*)(const void*, const void*))strcmp); |
107 | qsort(spell_sort, num_found, MAX_BUF, (int (*)(const void*, const void*))strcmp); |
108 | strcpy(tmp,"asdfg"); /* Dummy string so initial compare fails */ |
108 | strcpy(tmp,"asdfg"); /* Dummy string so initial compare fails */ |
109 | for (i=0; i<num_found; i++) { |
109 | for (i=0; i<num_found; i++) { |
110 | /* Different skill name, so print banner */ |
110 | /* Different skill name, so print banner */ |
111 | if (strncmp(tmp, spell_sort[i], strlen(tmp))) { |
111 | if (strncmp(tmp, spell_sort[i], strlen(tmp))) { |
112 | strcpy(tmp, spell_sort[i]); |
112 | strcpy(tmp, spell_sort[i]); |
113 | cp = strchr(tmp, ':'); |
113 | cp = strchr(tmp, ':'); |
114 | *cp = '\0'; |
114 | *cp = '\0'; |
115 | new_draw_info(NDI_UNIQUE, 0, op, ""); |
115 | new_draw_info(NDI_UNIQUE, 0, op, ""); |
116 | new_draw_info_format(NDI_UNIQUE, 0,op,"%s spells %.*s [lvl] [sp]", |
116 | new_draw_info_format(NDI_UNIQUE, 0,op,"%s spells %.*s [lvl] [sp]", |
117 | tmp, 12-strlen(tmp), " "); |
117 | tmp, 12-strlen(tmp), " "); |
118 | } |
118 | } |
119 | new_draw_info(NDI_UNIQUE, 0, op, strchr(spell_sort[i], ':') + 1); |
119 | new_draw_info(NDI_UNIQUE, 0, op, strchr(spell_sort[i], ':') + 1); |
120 | } |
120 | } |
121 | } |
121 | } |
122 | } |
122 | } |
123 | |
123 | |
124 | |
124 | |
125 | |
125 | |
… | |
… | |
137 | |
137 | |
138 | if (command=='i') castnow = 1; |
138 | if (command=='i') castnow = 1; |
139 | |
139 | |
140 | /* Remove control of the golem */ |
140 | /* Remove control of the golem */ |
141 | if(op->contr->ranges[range_golem]!=NULL) { |
141 | if(op->contr->ranges[range_golem]!=NULL) { |
142 | if (op->contr->golem_count == op->contr->ranges[range_golem]->count) { |
142 | if (op->contr->golem_count == op->contr->ranges[range_golem]->count) { |
143 | remove_friendly_object(op->contr->ranges[range_golem]); |
143 | remove_friendly_object(op->contr->ranges[range_golem]); |
144 | remove_ob(op->contr->ranges[range_golem]); |
144 | remove_ob(op->contr->ranges[range_golem]); |
145 | free_object(op->contr->ranges[range_golem]); |
145 | free_object(op->contr->ranges[range_golem]); |
146 | } |
146 | } |
147 | op->contr->ranges[range_golem]=NULL; |
147 | op->contr->ranges[range_golem]=NULL; |
148 | op->contr->golem_count = 0; |
148 | op->contr->golem_count = 0; |
149 | } |
149 | } |
150 | |
150 | |
151 | if(params!=NULL) { |
151 | if(params!=NULL) { |
152 | int spellnumber = 0; |
152 | int spellnumber = 0; |
153 | if (spellnumber = atoi(params)) |
153 | if (spellnumber = atoi(params)) |
154 | for (spob = op->inv; spob && spob->count != spellnumber; spob=spob->below); |
154 | for (spob = op->inv; spob && spob->count != spellnumber; spob=spob->below); |
155 | else spob = lookup_spell_by_name(op, params); |
155 | else spob = lookup_spell_by_name(op, params); |
156 | |
156 | |
157 | if (spob && spob->type == SPELL) { |
157 | if (spob && spob->type == SPELL) { |
158 | /* Now grab any extra data, if there is any. Forward pass |
158 | /* Now grab any extra data, if there is any. Forward pass |
159 | * any 'of' delimiter |
159 | * any 'of' delimiter |
160 | */ |
160 | */ |
161 | if (spellnumber) { |
161 | if (spellnumber) { |
162 | /* if we passed a number, the options start at the second word */ |
162 | /* if we passed a number, the options start at the second word */ |
163 | cp = strchr(params, ' '); |
163 | cp = strchr(params, ' '); |
164 | if (cp) { |
164 | if (cp) { |
165 | cp++; |
165 | cp++; |
166 | if (!strncmp(cp, "of ", 3)) cp+=3; |
166 | if (!strncmp(cp, "of ", 3)) cp+=3; |
167 | } |
167 | } |
168 | } |
168 | } |
169 | else if (strlen(params) > strlen(spob->name)) { |
169 | else if (strlen(params) > strlen(spob->name)) { |
170 | cp = params + strlen(spob->name); |
170 | cp = params + strlen(spob->name); |
171 | *cp = 0; |
171 | *cp = 0; |
172 | cp++; |
172 | cp++; |
173 | if (!strncmp(cp, "of ", 3)) cp+=3; |
173 | if (!strncmp(cp, "of ", 3)) cp+=3; |
174 | } else |
174 | } else |
175 | cp = NULL; |
175 | cp = NULL; |
176 | |
176 | |
177 | if (spob->skill && !find_skill_by_name(op, spob->skill)) { |
177 | if (spob->skill && !find_skill_by_name(op, spob->skill)) { |
178 | new_draw_info_format(NDI_UNIQUE, 0, op, |
178 | new_draw_info_format(NDI_UNIQUE, 0, op, |
179 | "You need the skill %s to cast %s!", |
179 | "You need the skill %s to cast %s!", |
180 | spob->skill, spob->name); |
180 | spob->skill, spob->name); |
181 | return 1; |
181 | return 1; |
182 | } |
182 | } |
183 | |
183 | |
184 | if (castnow) { |
184 | if (castnow) { |
185 | cast_spell(op,op,op->facing,spob,cp); |
185 | cast_spell(op,op,op->facing,spob,cp); |
186 | } else { |
186 | } else { |
187 | op->contr->ranges[range_magic] = spob; |
187 | op->contr->ranges[range_magic] = spob; |
188 | op->contr->shoottype = range_magic; |
188 | op->contr->shoottype = range_magic; |
189 | if(cp != NULL) { |
189 | if(cp != NULL) { |
190 | strncpy(op->contr->spellparam, cp, MAX_BUF); |
190 | strncpy(op->contr->spellparam, cp, MAX_BUF); |
191 | op->contr->spellparam[MAX_BUF-1] = '\0'; |
191 | op->contr->spellparam[MAX_BUF-1] = '\0'; |
192 | } else { |
192 | } else { |
193 | op->contr->spellparam[0] = '\0'; |
193 | op->contr->spellparam[0] = '\0'; |
194 | } |
194 | } |
195 | new_draw_info_format(NDI_UNIQUE, 0, op, |
195 | new_draw_info_format(NDI_UNIQUE, 0, op, |
196 | "You ready the spell %s", spob->name); |
196 | "You ready the spell %s", spob->name); |
197 | } |
197 | } |
198 | return 0; |
198 | return 0; |
199 | } /* else fall through to below and print spells */ |
199 | } /* else fall through to below and print spells */ |
200 | } /* params supplied */ |
200 | } /* params supplied */ |
201 | |
201 | |
202 | /* We get here if cast was given without options or we could not find |
202 | /* 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. |
203 | * the requested spell. List all the spells the player knows. |
204 | */ |
204 | */ |
… | |
… | |
217 | */ |
217 | */ |
218 | |
218 | |
219 | int legal_range(object *op,int r) { |
219 | int legal_range(object *op,int r) { |
220 | |
220 | |
221 | switch(r) { |
221 | switch(r) { |
222 | case range_none: /* "Nothing" is always legal */ |
222 | case range_none: /* "Nothing" is always legal */ |
223 | return 1; |
223 | return 1; |
224 | case range_bow: |
224 | case range_bow: |
225 | case range_misc: |
225 | case range_misc: |
226 | case range_magic: /* cast spells */ |
226 | case range_magic: /* cast spells */ |
227 | if (op->contr->ranges[r]) return 1; |
227 | if (op->contr->ranges[r]) return 1; |
228 | else return 0; |
228 | else return 0; |
229 | |
229 | |
230 | case range_golem: /* Use scrolls */ |
230 | case range_golem: /* Use scrolls */ |
231 | if (op->contr->ranges[range_golem] && |
231 | if (op->contr->ranges[range_golem] && |
232 | op->contr->ranges[range_golem]->count == op->contr->golem_count) |
232 | op->contr->ranges[range_golem]->count == op->contr->golem_count) |
233 | return 1; |
233 | return 1; |
234 | else |
234 | else |
235 | return 0; |
235 | return 0; |
236 | |
236 | |
237 | case range_skill: |
237 | case range_skill: |
238 | if (op->chosen_skill) |
238 | if (op->chosen_skill) |
239 | return 1; |
239 | return 1; |
240 | else |
240 | else |
241 | return 0; |
241 | return 0; |
242 | } |
242 | } |
243 | /* No match above, must not be valid */ |
243 | /* No match above, must not be valid */ |
244 | return 0; |
244 | return 0; |
245 | } |
245 | } |
246 | |
246 | |
247 | void change_spell(object *op,char k) { |
247 | void change_spell(object *op,char k) { |
248 | |
248 | |
249 | do { |
249 | do { |
250 | op->contr->shoottype = (rangetype) (op->contr->shoottype + ((k == '+') ? 1 : -1)); |
250 | op->contr->shoottype = (rangetype) (op->contr->shoottype + ((k == '+') ? 1 : -1)); |
251 | if(op->contr->shoottype >= range_size) |
251 | if(op->contr->shoottype >= range_size) |
252 | op->contr->shoottype = range_none; |
252 | op->contr->shoottype = range_none; |
253 | else if (op->contr->shoottype <= range_bottom) |
253 | else if (op->contr->shoottype <= range_bottom) |
254 | op->contr->shoottype = (rangetype)(range_size-1); |
254 | op->contr->shoottype = (rangetype)(range_size-1); |
255 | } while (!legal_range(op,op->contr->shoottype)); |
255 | } while (!legal_range(op,op->contr->shoottype)); |
256 | |
256 | |
257 | /* Legal range has already checked that we have an appropriate item |
257 | /* 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 |
258 | * that uses the slot, so we don't need to be too careful about |
259 | * checking the status of the object. |
259 | * checking the status of the object. |
260 | */ |
260 | */ |
261 | switch(op->contr->shoottype) { |
261 | switch(op->contr->shoottype) { |
262 | case range_none: |
262 | case range_none: |
263 | new_draw_info(NDI_UNIQUE, 0,op, "No ranged attack chosen."); |
263 | new_draw_info(NDI_UNIQUE, 0,op, "No ranged attack chosen."); |
264 | break; |
264 | break; |
265 | |
265 | |
266 | case range_golem: |
266 | case range_golem: |
267 | new_draw_info(NDI_UNIQUE, 0,op, "You regain control of your golem."); |
267 | new_draw_info(NDI_UNIQUE, 0,op, "You regain control of your golem."); |
268 | break; |
268 | break; |
269 | |
269 | |
270 | case range_bow: |
270 | case range_bow: |
271 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to %s and %s.", query_name(op->contr->ranges[range_bow]), |
271 | 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"); |
272 | op->contr->ranges[range_bow]->race ? op->contr->ranges[range_bow]->race : "nothing"); |
273 | break; |
273 | break; |
274 | |
274 | |
275 | case range_magic: |
275 | case range_magic: |
276 | new_draw_info_format(NDI_UNIQUE, 0,op,"Switched to spells (%s).", |
276 | new_draw_info_format(NDI_UNIQUE, 0,op,"Switched to spells (%s).", |
277 | op->contr->ranges[range_magic]->name); |
277 | op->contr->ranges[range_magic]->name); |
278 | break; |
278 | break; |
279 | |
279 | |
280 | case range_misc: |
280 | case range_misc: |
281 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to %s.", query_base_name(op->contr->ranges[range_misc], 0)); |
281 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to %s.", query_base_name(op->contr->ranges[range_misc], 0)); |
282 | break; |
282 | break; |
283 | |
283 | |
284 | case range_skill: |
284 | case range_skill: |
285 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to skill: %s", op->chosen_skill ? |
285 | new_draw_info_format(NDI_UNIQUE, 0,op, "Switched to skill: %s", op->chosen_skill ? |
286 | op->chosen_skill->name : "none"); |
286 | op->chosen_skill->name : "none"); |
287 | break; |
287 | break; |
288 | |
288 | |
289 | default: |
289 | default: |
290 | break; |
290 | break; |
291 | } |
291 | } |
292 | } |
292 | } |
293 | |
293 | |
294 | |
294 | |
295 | int command_rotateshoottype (object *op, char *params) |
295 | int command_rotateshoottype (object *op, char *params) |