… | |
… | |
158 | } |
158 | } |
159 | |
159 | |
160 | skill->inv_splay (); |
160 | skill->inv_splay (); |
161 | |
161 | |
162 | if (!skill_tool->flag [FLAG_APPLIED]) |
162 | if (!skill_tool->flag [FLAG_APPLIED]) |
163 | if (apply_special (who, skill_tool, AP_APPLY)) |
163 | if (apply_special (who, skill_tool, AP_APPLY | AP_NO_READY)) |
164 | return 0; |
164 | return 0; |
165 | |
165 | |
166 | return skill; |
166 | return skill; |
167 | } |
167 | } |
168 | |
168 | |
… | |
… | |
201 | return skop; |
201 | return skop; |
202 | |
202 | |
203 | return 0; |
203 | return 0; |
204 | } |
204 | } |
205 | |
205 | |
206 | /* This changes the objects skill to new_skill. |
206 | /* This changes the objects chosen_skill to new_skill. |
207 | * note that this function doesn't always need to get used - |
|
|
208 | * you can now add skill exp to the player without the chosen_skill being |
|
|
209 | * set. This function is of most interest to players to update |
|
|
210 | * the various range information. |
|
|
211 | * return 1 on success, 0 on error |
207 | * return 1 on success, 0 on error |
212 | */ |
208 | */ |
213 | int |
209 | bool |
214 | change_skill (object *who, object *new_skill, int flag) |
210 | object::change_skill (object *new_skill) |
215 | { |
211 | { |
216 | if (who->type != PLAYER) |
212 | if (type != PLAYER) |
217 | return 0; |
213 | return 0; |
218 | |
214 | |
219 | #if 0 |
|
|
220 | // optimise this supposedly common case |
215 | // optimise this supposedly common case |
221 | if (new_skill == who->chosen_skill) |
216 | if (new_skill == chosen_skill) |
222 | return 1; |
217 | return 1; |
223 | #endif |
|
|
224 | |
218 | |
225 | if (!new_skill) |
219 | if (chosen_skill) |
226 | { |
|
|
227 | LOG (llevError | logBacktrace, "change_skill called on %s with NULL skill\n", |
|
|
228 | who->debug_desc ()); |
|
|
229 | return 0; |
|
|
230 | } |
220 | { |
|
|
221 | chosen_skill->flag [FLAG_APPLIED] = false; |
|
|
222 | change_abil (this, chosen_skill); |
|
|
223 | } |
231 | |
224 | |
232 | // the skill could be readied already because it is used by a weapon. |
225 | chosen_skill = new_skill; |
233 | who->change_weapon (0); |
226 | |
|
|
227 | if (chosen_skill) |
|
|
228 | { |
|
|
229 | chosen_skill->flag [FLAG_APPLIED] = true; |
|
|
230 | change_abil (this, chosen_skill); |
234 | new_skill->inv_splay (); |
231 | chosen_skill->inv_splay (); |
|
|
232 | } |
235 | |
233 | |
236 | if (apply_special (who, new_skill, AP_APPLY)) |
234 | update_stats (); |
237 | return 0; |
|
|
238 | |
|
|
239 | return 1; |
235 | return 1; |
240 | } |
236 | } |
241 | |
237 | |
242 | /* This function just clears the chosen_skill and range_skill values |
238 | /* This function just clears the chosen_skill and range_skill values |
243 | * in the player. |
239 | * in the player. |
244 | */ |
240 | */ |
245 | void |
241 | void |
246 | clear_skill (object *who) |
242 | clear_skill (object *who) |
247 | { |
243 | { |
|
|
244 | if (who->chosen_skill) |
|
|
245 | { |
|
|
246 | who->chosen_skill->flag [FLAG_APPLIED] = false; |
248 | who->chosen_skill = 0; |
247 | who->chosen_skill = 0; |
249 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
248 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
|
|
249 | } |
250 | |
250 | |
251 | if (player *pl = who->contr) |
251 | if (player *pl = who->contr) |
252 | if (pl->ranged_ob && pl->ranged_ob->type == SKILL) |
252 | if (pl->ranged_ob && pl->ranged_ob->type == SKILL) |
253 | pl->ranged_ob = 0; |
253 | pl->ranged_ob = 0; |
254 | } |
254 | } |
… | |
… | |
856 | { |
856 | { |
857 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
857 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
858 | return 0; |
858 | return 0; |
859 | } |
859 | } |
860 | |
860 | |
861 | change_skill (op, find_skill_by_name (op, tmp->skill), 1); |
861 | pl->combat_ob = tmp; |
862 | } |
862 | } |
863 | else |
863 | else |
864 | { |
864 | { |
865 | if (!skill) |
865 | if (!skill) |
866 | { |
866 | { |
… | |
… | |
879 | return 0; |
879 | return 0; |
880 | } |
880 | } |
881 | } |
881 | } |
882 | } |
882 | } |
883 | |
883 | |
884 | /* now try to ready the new skill */ |
884 | pl->combat_ob = skill; |
885 | if (!change_skill (op, skill, 0)) |
885 | apply_special (op, skill, AP_APPLY); |
886 | { /* oh oh, trouble! */ |
|
|
887 | new_draw_info_format (NDI_UNIQUE, 0, op, "Couldn't change to skill %s", &skill->name); |
|
|
888 | return 0; |
|
|
889 | } |
|
|
890 | } |
886 | } |
891 | |
887 | |
892 | if (!pl->combat_ob) |
888 | if (!pl->combat_ob) |
893 | { |
889 | { |
894 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
890 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
… | |
… | |
1039 | |
1035 | |
1040 | return 0; |
1036 | return 0; |
1041 | } |
1037 | } |
1042 | |
1038 | |
1043 | return skill_attack (NULL, op, dir, string, skill); |
1039 | return skill_attack (NULL, op, dir, string, skill); |
1044 | |
|
|
1045 | } |
1040 | } |
|
|
1041 | |