--- deliantra/server/server/skill_util.C 2010/04/14 22:35:41 1.96 +++ deliantra/server/server/skill_util.C 2010/04/15 00:36:51 1.97 @@ -53,6 +53,8 @@ # undef def }; +vector skillvec; + static int attack_hth (object *pl, int dir, const char *string, object *skill); static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); @@ -63,22 +65,29 @@ void init_skills () { - for_all_archetypes (at) - if (at->type == SKILL) + // nop +} + +void +add_skill_archetype (object *o) +{ + printf ("<%s><%s>\n", &o->name, &o->skill);//D + + assert (("skill name must equal skill skill", o->name == o->skill)); + + for (vector::iterator i = skillvec.begin (); i != skillvec.end (); ++i) + if ((*i)->name == o->name) { - if (skill_names[at->subtype]) - LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", - at->subtype, &skill_names[at->subtype], &at->skill); - else - skill_names[at->subtype] = at->skill; + // replace existing entry + SKILL_INDEX (o) = i - skillvec.begin (); + *i = o; + return; } - /* This isn't really an error if there is no skill subtype set, but - * checking for this may catch some user errors. - */ - for (int i = 1; i < NUM_SKILLS; i++) - if (!skill_names[i]) - LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); + // add new entry + assert (("only CS_NUM_SKILLS skills supported by client protocol", skillvec.size () < CS_NUM_SKILLS)); + SKILL_INDEX (o) = skillvec.size (); + skillvec.push_back (o); } /* This function goes through the player inventory and sets @@ -89,24 +98,21 @@ void player::link_skills () { - for (int i = 0; i < NUM_SKILLS; ++i) + for (int i = 0; i < CS_NUM_SKILLS; ++i) last_skill_ob [i] = 0; for (object *tmp = ob->inv; tmp; tmp = tmp->below) if (tmp->type == SKILL) { - assert (IN_RANGE_EXC (tmp->subtype, 0, NUM_SKILLS)); + int idx = SKILL_INDEX (tmp); - if (last_skill_ob [tmp->subtype] != tmp) - { - /* This is really a warning, hence no else below */ - if (last_skill_ob [tmp->subtype]) - LOG (llevError, "Multiple skills with the same subtype? %s, %s\n", - &last_skill_ob [tmp->subtype]->skill, &tmp->skill); + assert (IN_RANGE_EXC (idx, 0, CS_NUM_SKILLS)); - last_skill_ob [tmp->subtype] = tmp; + if (last_skill_ob [idx] != tmp) + { + last_skill_ob [idx] = tmp; if (ns) - ns->last_skill_exp [tmp->subtype] = -1; + ns->last_skill_exp [idx] = -1; } } } @@ -197,6 +203,8 @@ * This code is basically the same as find_skill_by_name() above, * but instead a skill name, we search by matching number. * this replaces find_skill. + * + * MUST NOT BE USED IN NEW CODE! (schmorp) */ object * find_skill_by_number (object *who, int skillno)