From 818acc5866707b9e294a87d2dd902aebb670707f Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 3 Jan 2016 03:45:30 +0100 Subject: Rewritten skill_tree parser in a more robust way - Fixes an issue that prevented skills with more than 4 pre-requisites or more than 3 pre-requisites and a minimum level from being parsed correctly (and without any warning or error messages). - Removes the limit on 5 pre-requisites (replaced a fixed size array with a VECTOR) - Reduces memory usage of skill_tree from 794kB to 440kB (32 bit) or 523kB (64 bit). - Fixes an issue that prevented multiple inheritance from working correctly in rare cases (incorrect definition order), without any warning or error messages. Now a warning is displayed if a job is inherited before being defined. - Fixes an issue that prevented skills inherited from being correctly merged with the skills defined for the current job. - Prevents a job from inheriting itself by accident. - Correctly detects skills defined twice for the same job. Signed-off-by: Haru --- src/map/atcommand.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/map/atcommand.c') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index c26daee54..d98ef8d94 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2015 Hercules Dev Team + * Copyright (C) 2012-2016 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -5364,12 +5364,13 @@ ACMD(displayskill) { * @skilltree by [MouseJstr] * prints the skill tree for a player required to get to a skill *------------------------------------------*/ -ACMD(skilltree) { +ACMD(skilltree) +{ struct map_session_data *pl_sd = NULL; uint16 skill_id; int meets, j, c=0; char target[NAME_LENGTH]; - struct skill_tree_entry *ent; + struct skill_tree_entry *entry; if(!*message || sscanf(message, "%5hu %23[^\r\n]", &skill_id, target) != 2) { clif->message(fd, msg_fd(fd,1167)); // Usage: @skilltree @@ -5387,21 +5388,19 @@ ACMD(skilltree) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1168), pc->job_name(c), pc->checkskill(pl_sd, NV_BASIC)); // Player is using %s skill tree (%d basic points). clif->message(fd, atcmd_output); - ARR_FIND( 0, MAX_SKILL_TREE, j, pc->skill_tree[c][j].id == 0 || pc->skill_tree[c][j].id == skill_id ); - if( j == MAX_SKILL_TREE || pc->skill_tree[c][j].id == 0 ) - { + ARR_FIND(0, MAX_SKILL_TREE, j, pc->skill_tree[c][j].id == 0 || pc->skill_tree[c][j].id == skill_id); + if (j == MAX_SKILL_TREE || pc->skill_tree[c][j].id == 0) { clif->message(fd, msg_fd(fd,1169)); // The player cannot use that skill. return false; } - ent = &pc->skill_tree[c][j]; + entry = &pc->skill_tree[c][j]; meets = 1; - for(j=0;jneed[j].id && pc->checkskill(sd,ent->need[j].id) < ent->need[j].lv) - { - safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1170), ent->need[j].lv, skill->dbs->db[ent->need[j].id].desc); // Player requires level %d of skill %s. + for (j = 0; j < VECTOR_LENGTH(entry->need); j++) { + struct skill_tree_requirement *req = &VECTOR_INDEX(entry->need, j); + if (pc->checkskill(sd, req->id) < req->lv) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1170), req->lv, skill->dbs->db[req->id].desc); // Player requires level %d of skill %s. clif->message(fd, atcmd_output); meets = 0; } -- cgit v1.2.3-70-g09d2