… | |
… | |
254 | * flag has the current meaning: |
254 | * flag has the current meaning: |
255 | * 0x1: If set, don't update the range pointer. This is useful when we |
255 | * 0x1: If set, don't update the range pointer. This is useful when we |
256 | * need to ready a new skill, but don't want to clobber range. |
256 | * need to ready a new skill, but don't want to clobber range. |
257 | * return 1 on success, 0 on error |
257 | * return 1 on success, 0 on error |
258 | */ |
258 | */ |
259 | |
|
|
260 | int |
259 | int |
261 | change_skill (object *who, object *new_skill, int flag) |
260 | change_skill (object *who, object *new_skill, int flag) |
262 | { |
261 | { |
263 | int old_range; |
262 | int old_range; |
264 | |
263 | |
… | |
… | |
268 | old_range = who->contr->shoottype; |
267 | old_range = who->contr->shoottype; |
269 | |
268 | |
270 | if (who->chosen_skill && who->chosen_skill == new_skill) |
269 | if (who->chosen_skill && who->chosen_skill == new_skill) |
271 | { |
270 | { |
272 | /* optimization for changing skill to current skill */ |
271 | /* optimization for changing skill to current skill */ |
273 | if (who->type == PLAYER && !(flag & 0x1)) |
272 | if (!(flag & 0x1)) |
274 | who->contr->shoottype = range_skill; |
273 | who->contr->set_range (range_skill); |
275 | |
274 | |
276 | return 1; |
275 | return 1; |
277 | } |
276 | } |
278 | |
277 | |
279 | // move skill to front, so it will be preferred next time |
278 | // move skill to front, so it will be preferred next time |
280 | new_skill->remove (); |
279 | new_skill->remove (); |
281 | who->insert (new_skill); |
280 | who->insert (new_skill); |
282 | |
281 | |
283 | if (!new_skill || who->chosen_skill) |
|
|
284 | if (who->chosen_skill) |
|
|
285 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
|
|
286 | |
|
|
287 | /* Only goal in this case was to unapply a skill */ |
|
|
288 | if (!new_skill) |
282 | if (!new_skill) |
|
|
283 | { |
|
|
284 | if (who->chosen_skill) |
|
|
285 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
|
|
286 | |
|
|
287 | /* Only goal in this case was to unapply a skill */ |
289 | return 0; |
288 | return 0; |
|
|
289 | } |
290 | |
290 | |
291 | if (apply_special (who, new_skill, AP_APPLY)) |
291 | if (apply_special (who, new_skill, AP_APPLY)) |
292 | return 0; |
292 | return 0; |
293 | |
293 | |
294 | if (flag & 0x1) |
294 | if (!(flag & 0x1)) |
295 | who->contr->shoottype = (rangetype)old_range; |
295 | who->contr->set_range ((rangetype) old_range); |
296 | |
296 | |
297 | return 1; |
297 | return 1; |
298 | } |
298 | } |
299 | |
299 | |
300 | /* This function just clears the chosen_skill and range_skill values |
300 | /* This function just clears the chosen_skill and range_skill values |