… | |
… | |
84 | * up the last_skills[] array in the player object. |
84 | * up the last_skills[] array in the player object. |
85 | * the last_skills[] is used to more quickly lookup skills - |
85 | * the last_skills[] is used to more quickly lookup skills - |
86 | * mostly used for sending exp. |
86 | * mostly used for sending exp. |
87 | */ |
87 | */ |
88 | void |
88 | void |
89 | link_player_skills (object *op) |
89 | player::link_skills () |
90 | { |
90 | { |
|
|
91 | for (int i = 0; i < NUM_SKILLS; ++i) |
|
|
92 | last_skill_ob [i] = 0; |
|
|
93 | |
91 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
94 | for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
92 | if (tmp->type == SKILL) |
95 | if (tmp->type == SKILL) |
93 | { |
96 | { |
94 | /* This is really a warning, hence no else below */ |
97 | assert (IN_RANGE_EXC (tmp->subtype, 0, NUM_SKILLS)); |
95 | if (op->contr->last_skill_ob[tmp->subtype] && op->contr->last_skill_ob[tmp->subtype] != tmp) |
|
|
96 | LOG (llevError, "Multiple skills with the same subtype? %s, %s\n", |
|
|
97 | &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill); |
|
|
98 | |
98 | |
99 | if (tmp->subtype >= NUM_SKILLS) |
99 | if (last_skill_ob [tmp->subtype] != tmp) |
100 | LOG (llevError, "Invalid subtype number %d (range 0-%d)\n", tmp->subtype, NUM_SKILLS); |
|
|
101 | else |
|
|
102 | { |
100 | { |
|
|
101 | /* This is really a warning, hence no else below */ |
|
|
102 | if (last_skill_ob [tmp->subtype]) |
|
|
103 | LOG (llevError, "Multiple skills with the same subtype? %s, %s\n", |
|
|
104 | &last_skill_ob [tmp->subtype]->skill, &tmp->skill); |
|
|
105 | |
103 | op->contr->last_skill_ob[tmp->subtype] = tmp; |
106 | last_skill_ob [tmp->subtype] = tmp; |
104 | op->contr->ns->last_skill_exp[tmp->subtype] = -1; //TODO: this should go |
107 | if (ns) |
|
|
108 | ns->last_skill_exp [tmp->subtype] = -1; |
105 | } |
109 | } |
106 | } |
110 | } |
107 | } |
111 | } |
108 | |
112 | |
109 | static object * |
113 | static object * |
… | |
… | |
149 | * but not the skill itself, give it to them. |
153 | * but not the skill itself, give it to them. |
150 | */ |
154 | */ |
151 | object *skill = find_skill (who, skill_tool->skill); |
155 | object *skill = find_skill (who, skill_tool->skill); |
152 | |
156 | |
153 | if (!skill) |
157 | if (!skill) |
154 | { |
|
|
155 | skill = give_skill_by_name (who, skill_tool->skill); |
158 | skill = give_skill_by_name (who, skill_tool->skill); |
156 | link_player_skills (who); |
|
|
157 | } |
|
|
158 | |
159 | |
159 | if (!skill_tool->flag [FLAG_APPLIED]) |
160 | if (!skill_tool->flag [FLAG_APPLIED]) |
160 | if (apply_special (who, splay (skill_tool), AP_APPLY | AP_NO_READY)) |
161 | if (apply_special (who, splay (skill_tool), AP_APPLY | AP_NO_READY)) |
161 | return 0; |
162 | return 0; |
162 | |
163 | |
… | |
… | |
618 | LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); |
619 | LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); |
619 | return 2; |
620 | return 2; |
620 | } |
621 | } |
621 | |
622 | |
622 | SET_FLAG (tmp, FLAG_CAN_USE_SKILL); |
623 | SET_FLAG (tmp, FLAG_CAN_USE_SKILL); |
623 | link_player_skills (pl); |
624 | |
624 | return 1; |
625 | return 1; |
625 | } |
626 | } |
626 | |
627 | |
627 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
628 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
628 | /* Probably belongs in some global utils-type file? */ |
629 | /* Probably belongs in some global utils-type file? */ |