On Tue, 22 Sep 1998, Angus Mezick wrote: >Whoa, just getting back from vaca George? ;) No, I had the post queued for further investigation because I didn't have an answer at the time. :) >Well, here is my find_skill_num() function. It will match cast 'm m' to >magic missile. Woo Woo! Sorry about the indentation, C&P screwed it up a >little. I reverted my spell code to use: > {"armor", 30, 10, 2, POS_FIGHTING, > TAR_CHAR_ROOM, NON_VIOLENT, MAG_AFFECTS, > UU, 8,UU,10,UU,12,UU,UU,UU,15,15,UU,UU,UU,UU,UU,UU,UU,UU, > IS_SPELL,5}, >because we like this format better, so you might need to change some things. >(the last int is casting_time and the IS_SPELL is for sorting) What is UU? A #define for 0, -1, or something? >int find_skill_num(char *name) >{ [...] > char *first=get_buffer(256); > char *first2=get_buffer(256); > > if(*name=='!') > return -1; It's better to get the buffers when you need them, because the previous line above would cause them to be forgotten. > for(skindex=1;skindex<MAX_SPELLS;skindex++) > { > if (is_abbrev(name, spells[spell_sort_info[skindex]].spell_name)) > { > release_buffer(first2); > release_buffer(first); > return spell_sort_info[skindex]; > } > > ok = 1; [...] Which would also facilitate the removal of the two releases above. > temp = any_one_arg(spells[spell_sort_info[skindex]].spell_name, first); > temp2 = any_one_arg(name, first2); > while (*first && *first2 && ok) > { > if (!is_abbrev(first2, first)) > ok = 0; > temp = any_one_arg(temp, first); > temp2 = any_one_arg(temp2, first2); > } > > if (ok && !*first2) > { > release_buffer(first2); > release_buffer(first); > return spell_sort_info[skindex]; > } [...] And if you used a temporary integer here for the return value, i.e.: if (ok && !*first) { ret = spell_sort_info[skindex]; break; } > } > release_buffer(first2); > release_buffer(first); > return -1; >} Then you could change that line to 'return ret;', have 'ret' initialized to -1 at the top of the function and just fall through to here. That would reduce you to only 2 release_buffer() calls for 2 get_buffer() calls. This is largely nit-picking and looks fine otherwise. -- George Greer, greerga@circlemud.org | Genius may have its limitations, but http://mouse.van.ml.org/ (mostly) | stupidity is not thus handicapped. http://www.van.ml.org/CircleMUD/ | -- Elbert Hubbard +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST