diff options
author | gepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-02-29 23:53:22 +0000 |
---|---|---|
committer | gepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-02-29 23:53:22 +0000 |
commit | bdab46b7af1e9220ec1f3332ff36deeb6e3c7953 (patch) | |
tree | 1d5746dcceac62b91ef9f7a66ed974d6b077c873 /src/map | |
parent | 9d2966cd099b99f5318bce0b4737b8201086dfde (diff) | |
download | hercules-bdab46b7af1e9220ec1f3332ff36deeb6e3c7953.tar.gz hercules-bdab46b7af1e9220ec1f3332ff36deeb6e3c7953.tar.bz2 hercules-bdab46b7af1e9220ec1f3332ff36deeb6e3c7953.tar.xz hercules-bdab46b7af1e9220ec1f3332ff36deeb6e3c7953.zip |
Some NPC code cleanup (event labels).
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15640 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/npc.c | 77 |
1 files changed, 20 insertions, 57 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index 12fce2ab4..9d239fb77 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -270,33 +270,22 @@ int npc_event_dequeue(struct map_session_data* sd) /*========================================== * exports a npc event label - * npc_parse_script->strdb_foreachから呼ばれる + * called from npc_parse_script *------------------------------------------*/ -int npc_event_export(char* lname, void* data, va_list ap) +static int npc_event_export(struct npc_data *nd, int i) { - int pos = (int)data; - struct npc_data* nd = va_arg(ap, struct npc_data *); - - if ((lname[0]=='O' || lname[0]=='o')&&(lname[1]=='N' || lname[1]=='n')) { + char* lname = nd->u.scr.label_list[i].name; + int pos = nd->u.scr.label_list[i].pos; + if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) { struct event_data *ev; char buf[EVENT_NAME_LENGTH]; - char* p = strchr(lname, ':'); - // エクスポートされる - ev = (struct event_data *) aMalloc(sizeof(struct event_data)); - if (ev==NULL) { - ShowFatalError("npc_event_export: out of memory !\n"); - exit(EXIT_FAILURE); - }else if (p==NULL || (p-lname)>NAME_LENGTH) { - ShowFatalError("npc_event_export: label name error !\n"); - exit(EXIT_FAILURE); - }else{ - ev->nd = nd; - ev->pos = pos; - *p = '\0'; - snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); - *p = ':'; - strdb_put(ev_db, buf, ev); - } + snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); + // generate the data and insert it + CREATE(ev, struct event_data, 1); + ev->nd = nd; + ev->pos = pos; + if (strdb_put(ev_db, buf, ev) != NULL) // There was already another event of the same name? + return 1; } return 0; } @@ -2362,23 +2351,10 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons //----------------------------------------- // イベント用ラベルデータのエクスポート - for (i = 0; i < nd->u.scr.label_list_num; i++) - { - char* lname = nd->u.scr.label_list[i].name; - int pos = nd->u.scr.label_list[i].pos; - - if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) - { - struct event_data* ev; - char buf[EVENT_NAME_LENGTH]; - snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); - - // generate the data and insert it - CREATE(ev, struct event_data, 1); - ev->nd = nd; - ev->pos = pos; - if( strdb_put(ev_db, buf, ev) != NULL )// There was already another event of the same name? - ShowWarning("npc_parse_script : duplicate event %s (%s)\n", buf, filepath); + for (i = 0; i < nd->u.scr.label_list_num; i++) { + if (npc_event_export(nd, i)) { + ShowWarning("npc_parse_script : duplicate event %s::%s (%s)\n", + nd->exname, nd->u.scr.label_list[i].name, filepath); } } @@ -2550,23 +2526,10 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch //Handle labels //----------------------------------------- // イベント用ラベルデータのエクスポート - for (i = 0; i < nd->u.scr.label_list_num; i++) - { - char* lname = nd->u.scr.label_list[i].name; - int pos = nd->u.scr.label_list[i].pos; - - if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) - { - struct event_data* ev; - char buf[EVENT_NAME_LENGTH]; - snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); - - // generate the data and insert it - CREATE(ev, struct event_data, 1); - ev->nd = nd; - ev->pos = pos; - if( strdb_put(ev_db, buf, ev) != NULL )// There was already another event of the same name? - ShowWarning("npc_parse_duplicate : duplicate event %s (%s)\n", buf, filepath); + for (i = 0; i < nd->u.scr.label_list_num; i++) { + if (npc_event_export(nd, i)) { + ShowWarning("npc_parse_duplicate : duplicate event %s::%s (%s)\n", + nd->exname, nd->u.scr.label_list[i].name, filepath); } } |