diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/mob.c | 9 | ||||
-rw-r--r-- | src/map/npc.c | 85 | ||||
-rw-r--r-- | src/map/npc.h | 3 |
3 files changed, 46 insertions, 51 deletions
diff --git a/src/map/mob.c b/src/map/mob.c index cb22f71c0..629653c8d 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -141,14 +141,9 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time) if ( md->tomb_nid ) mob->mvptomb_destroy(md); - CREATE(nd, struct npc_data, 1); - - nd->bl.id = md->tomb_nid = npc->get_new_npc_id(); - + nd = npc->create_npc(md->bl.m, md->bl.x, md->bl.y); + md->tomb_nid = nd->bl.id; nd->dir = md->ud.dir; - nd->bl.m = md->bl.m; - nd->bl.x = md->bl.x; - nd->bl.y = md->bl.y; nd->bl.type = BL_NPC; safestrncpy(nd->name, msg_txt(856), sizeof(nd->name)); // "Tomb" diff --git a/src/map/npc.c b/src/map/npc.c index ce668bfae..8c2f61d58 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2495,18 +2495,27 @@ bool npc_viewisid(const char * viewid) return true; } +struct npc_data* npc_create_npc(int m, int x, int y) +{ + struct npc_data *nd; + + CREATE(nd, struct npc_data, 1); + nd->bl.id = npc->get_new_npc_id(); + nd->bl.prev = nd->bl.next = NULL; + nd->bl.m = m; + nd->bl.x = x; + nd->bl.y = y; + + return nd; +} + //Add then display an npc warp on map struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y) { int i, flag = 0; struct npc_data *nd; - CREATE(nd, struct npc_data, 1); - nd->bl.id = npc->get_new_npc_id(); + nd = npc->create_npc(from_mapid, from_x, from_y); map->addnpc(from_mapid, nd); - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = from_mapid; - nd->bl.x = from_x; - nd->bl.y = from_y; safestrncpy(nd->exname, name, ARRAYLENGTH(nd->exname)); if (npc->name2id(nd->exname) != NULL) @@ -2574,14 +2583,8 @@ const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* s return strchr(start,'\n');;//try next } - CREATE(nd, struct npc_data, 1); - - nd->bl.id = npc->get_new_npc_id(); + nd = npc->create_npc(m, x, y); map->addnpc(m, nd); - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; npc->parsename(nd, w3, start, buffer, filepath); if (!battle_config.warp_point_debug) @@ -2716,17 +2719,12 @@ const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const char* s return strchr(start,'\n');// continue } - CREATE(nd, struct npc_data, 1); + nd = npc->create_npc(m, x, y); CREATE(nd->u.shop.shop_item, struct npc_item_list, i); memcpy(nd->u.shop.shop_item, items, sizeof(items[0])*i); aFree(items); nd->u.shop.count = i; - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; - nd->bl.id = npc->get_new_npc_id(); npc->parsename(nd, w3, start, buffer, filepath); nd->class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath); nd->speed = 200; @@ -2890,8 +2888,7 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* npc->convertlabel_db(label_list,filepath); } - CREATE(nd, struct npc_data, 1); - + nd = npc->create_npc(m, x, y); if( sscanf(w4, "%*[^,],%d,%d", &xs, &ys) == 2 ) {// OnTouch area defined nd->u.scr.xs = xs; @@ -2903,12 +2900,7 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* nd->u.scr.ys = -1; } - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; npc->parsename(nd, w3, start, buffer, filepath); - nd->bl.id = npc->get_new_npc_id(); nd->class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath); nd->speed = 200; nd->u.scr.script = scriptroot; @@ -3040,14 +3032,8 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch return end;// next line, try to continue } - CREATE(nd, struct npc_data, 1); - - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; + nd = npc->create_npc(m, x, y); npc->parsename(nd, w3, start, buffer, filepath); - nd->bl.id = npc->get_new_npc_id(); nd->class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath); nd->speed = 200; nd->src_id = src_id; @@ -3159,13 +3145,8 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) { return 1; } - CREATE(wnd, struct npc_data, 1); - wnd->bl.id = npc->get_new_npc_id(); + wnd = npc->create_npc(m, snd->bl.x, snd->bl.y); map->addnpc(m, wnd); - wnd->bl.prev = wnd->bl.next = NULL; - wnd->bl.m = m; - wnd->bl.x = snd->bl.x; - wnd->bl.y = snd->bl.y; safestrncpy(wnd->name, "", ARRAYLENGTH(wnd->name)); safestrncpy(wnd->exname, newname, ARRAYLENGTH(wnd->exname)); wnd->class_ = WARP_CLASS; @@ -3606,6 +3587,14 @@ const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* st return strchr(start,'\n');// continue } + +void npc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char* start, const char* buffer, const char* filepath, int *retval) +{ + ShowError("npc_parse_mapflag: unrecognized mapflag '%s' in file '%s', line '%d'.\n", w3, filepath, strline(buffer,start-buffer)); + if (retval) + *retval = EXIT_FAILURE; +} + /*========================================== * Set or disable mapflag on map * eg : bat_c01<TAB>mapflag<TAB>battleground<TAB>2 @@ -4013,13 +4002,20 @@ const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char } else if ( !strcmpi(w3,"nocashshop") ) { map->list[m].flag.nocashshop = (state) ? 1 : 0; } else { - ShowError("npc_parse_mapflag: unrecognized mapflag '%s' in file '%s', line '%d'.\n", w3, filepath, strline(buffer,start-buffer)); - if (retval) *retval = EXIT_FAILURE; + npc->parse_unknown_mapflag(mapname, w3, w4, start, buffer, filepath, retval); } return strchr(start,'\n');// continue } +const char* npc_parse_unknown_object(char *w1, char *w2, char *w3, char *w4, const char* start, const char* buffer, const char* filepath, int *retval) +{ + ShowError("npc_parsesrcfile: Unable to parse, probably a missing or extra TAB in file '%s', line '%d'. Skipping line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4); + start = strchr(start,'\n');// skip and continue + *retval = EXIT_FAILURE; + return start; +} + /** * Parses a script file and creates NPCs/functions/mapflags/monsters/etc * accordingly. @@ -4208,9 +4204,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { } else { - ShowError("npc_parsesrcfile: Unable to parse, probably a missing or extra TAB in file '%s', line '%d'. Skipping line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,p-buffer), w1, w2, w3, w4); - p = strchr(p,'\n');// skip and continue - success = EXIT_FAILURE; + p = npc->parse_unknown_object(w1, w2, w3, w4, p, buffer, filepath, &success); } } aFree(buffer); @@ -4663,6 +4657,7 @@ void npc_defaults(void) { npc->parsename = npc_parsename; npc->parseview = npc_parseview; npc->viewisid = npc_viewisid; + npc->create_npc = npc_create_npc; npc->add_warp = npc_add_warp; npc->parse_warp = npc_parse_warp; npc->parse_shop = npc_parse_shop; @@ -4682,7 +4677,9 @@ void npc_defaults(void) { npc->parse_mob2 = npc_parse_mob2; npc->parse_mob = npc_parse_mob; npc->parse_mapflag = npc_parse_mapflag; + npc->parse_unknown_mapflag = npc_parse_unknown_mapflag; npc->parsesrcfile = npc_parsesrcfile; + npc->parse_unknown_object = npc_parse_unknown_object; npc->script_event = npc_script_event; npc->read_event_script = npc_read_event_script; npc->path_db_clear_sub = npc_path_db_clear_sub; diff --git a/src/map/npc.h b/src/map/npc.h index 9c497ffe9..fba14d485 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -231,9 +231,11 @@ struct npc_interface { void (*parsename) (struct npc_data *nd, const char *name, const char *start, const char *buffer, const char *filepath); int (*parseview) (const char *w4, const char *start, const char *buffer, const char *filepath); bool (*viewisid) (const char *viewid); + struct npc_data* (*create_npc) (int m, int x, int y); struct npc_data* (*add_warp) (char *name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y); const char* (*parse_warp) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); const char* (*parse_shop) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); + const char* (*parse_unknown_object) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); void (*convertlabel_db) (struct npc_label_list *label_list, const char *filepath); const char* (*skip_script) (const char *start, const char *buffer, const char *filepath, int *retval); const char* (*parse_script) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int options, int *retval); @@ -250,6 +252,7 @@ struct npc_interface { void (*parse_mob2) (struct spawn_data *mobspawn); const char* (*parse_mob) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); const char* (*parse_mapflag) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); + void (*parse_unknown_mapflag) (const char *name, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); int (*parsesrcfile) (const char *filepath, bool runOnInit); int (*script_event) (struct map_session_data *sd, enum npce_event type); void (*read_event_script) (void); |