// Converts NPC warp data to unified s_warplog_warp structure. // Note that src.map / dst.map variables have map_ids instead of mapindices. bool linkdata_convert(const struct s_map_npcdata *npcdata, int idx, bool inner, struct s_warplog_warp *out) { if (!out) return false; if ( ( inner && npcdata->inner_warps[idx] ) || ( !inner && npcdata->outer_warps[idx] ) ) { TBL_NPC *wnd = ( inner ? npcdata->inner_warps[idx] : npcdata->outer_warps[idx] ); struct npc_data_append *wnda; if( !(wnda = getFromNPCD(wnd, 0)) ) { ShowError("Unable to find NPC ID for NPC '%s'. Skipping...\n", wnd->exname); return false; } out->gid = wnda->npcid; out->src.map = wnd->bl.m; out->src.x = wnd->bl.x; out->src.y = wnd->bl.y; out->dst.map = map->mapindex2mapid(wnd->u.warp.mapindex); out->dst.x = wnd->u.warp.x; out->dst.y = wnd->u.warp.y; } else { struct s_warplog_warp *warp = ( inner ? npcdata->inner_links[idx] : npcdata->outer_links[idx] ); out->gid = warp->gid; out->src.map = map->mapindex2mapid(warp->src.map); out->src.x = warp->src.x; out->src.y = warp->src.y; out->dst.map = map->mapindex2mapid(warp->dst.map); out->dst.x = warp->dst.x; out->dst.y = warp->dst.y; } return true; }
void atcommand_createnavigationlua_sub_warp(FILE *fp_link, TBL_NPC *nd, int mnext, int nlink) { struct npc_data_append *nda; if( !(nda = getFromNPCD(nd, 0)) ) { ShowError("Unable to find NPC ID for NPC '%s'. Skipping...\n", nd->exname); return; } fprintf(fp_link, OUT_INDENT "{" OUT_SEPARATOR); fprintf(fp_link, OUT_INDENT OUT_INDENT "\"%s\"," OUT_SEPARATOR, map->list[nd->bl.m].name); // Map gat fprintf(fp_link, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nda->npcid); // GID fprintf(fp_link, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, 200); // 200 = warp , 201 = npc script (free?), 202 = Kafra Dungeon Warp, // 203 = Cool Event Dungeon Warp, 204 Kafra/Cool Event/Alberta warp, // 205 = airport (Currently we only support warps) fprintf(fp_link, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, (nd->vd->class_ == WARP_CLASS) ? 99999 : nd->vd->class_); // sprite id, 99999 = warp portal fprintf(fp_link, OUT_INDENT OUT_INDENT "\"%s_%s_%d\"," OUT_SEPARATOR, map->list[nd->bl.m].name, map->list[mnext].name, nlink); // Name fprintf(fp_link, OUT_INDENT OUT_INDENT "\"\"," OUT_SEPARATOR); // Unique Name fprintf(fp_link, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nd->bl.x); // Link X fprintf(fp_link, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nd->bl.y); // Link Y fprintf(fp_link, OUT_INDENT OUT_INDENT "\"%s\"," OUT_SEPARATOR, map->list[mnext].name); // Link to Map fprintf(fp_link, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nd->u.warp.x); // Link to X fprintf(fp_link, OUT_INDENT OUT_INDENT "%d" OUT_SEPARATOR, nd->u.warp.y); // Link to Y fprintf(fp_link, OUT_INDENT "},\n"); }
void atcommand_createnavigationlua_sub_npc(FILE *fp_npc, TBL_NPC *nd, int nnpc) { char visible_name[256]; char *delimiter; struct npc_data_append *nda; if( !(nda = getFromNPCD(nd, 0)) ) { ShowError("Unable to find NPC ID for NPC '%s'. Skipping...\n", nd->exname); return; } safestrncpy(visible_name, nd->name, sizeof(visible_name)); delimiter = strchr(visible_name,'#'); if ( delimiter != 0 ) *delimiter = 0; fprintf(fp_npc, OUT_INDENT "{" OUT_SEPARATOR); fprintf(fp_npc, OUT_INDENT OUT_INDENT "\"%s\"," OUT_SEPARATOR, map->list[nd->bl.m].name); // Map gat fprintf(fp_npc, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nda->npcid); // GID fprintf(fp_npc, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, (nd->subtype == SHOP || nd->subtype == CASHSHOP) ? 102 : 101); // 101 = Npc, 102 = Trader fprintf(fp_npc, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nd->class_); // Sprite ID fprintf(fp_npc, OUT_INDENT OUT_INDENT "\"%s\"," OUT_SEPARATOR, visible_name); // NPC Name fprintf(fp_npc, OUT_INDENT OUT_INDENT "\"\"," OUT_SEPARATOR); // Unique Name fprintf(fp_npc, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nd->bl.x); // X fprintf(fp_npc, OUT_INDENT OUT_INDENT "%d," OUT_SEPARATOR, nd->bl.y); // Y fprintf(fp_npc, OUT_INDENT "},\n"); }
struct npc_extra_data *nsd_search(struct npc_data *nd, bool create) { struct npc_extra_data *nsd = NULL; if (nd == NULL) return NULL; nsd = getFromNPCD(nd, 0); if (create == true && nsd == NULL) { CREATE(nsd, struct npc_extra_data, 1); nsd->items = 0; addToNPCD(nd, nsd, 0, true); }
bool atcommand_createnavigationlua_sub(void) { int global_mob_idx = 17104; int n=0; int m; int mobidx, npcidx, warpidx; FILE *fp_mob, *fp_map, *fp_link, *fp_npc, *fp_npcdist, *fp_linkdist; int nlink = 0, nnpc = 0; struct s_map_npcdata *map_npcdata = NULL; struct walkpath_data_navi wpd; memset(&wpd, '\0', sizeof(wpd)); ShowStatus("Creating navigation LUA files. This can take several minutes.\n"); if (!createdirectory(DIRECTORYNAME)) { ShowError("do_navigationlua: Unable to create output directory.\n"); return false; } fp_mob = fopen(DIRECTORYNAME PATHSEP_STR "navi_mob_" NAMESUFFIX ".lua", "wt+"); fp_map = fopen(DIRECTORYNAME PATHSEP_STR "navi_map_" NAMESUFFIX ".lua", "wt+"); fp_link = fopen(DIRECTORYNAME PATHSEP_STR "navi_link_" NAMESUFFIX ".lua", "wt+"); fp_npc = fopen(DIRECTORYNAME PATHSEP_STR "navi_npc_" NAMESUFFIX ".lua", "wt+"); fp_npcdist = fopen(DIRECTORYNAME PATHSEP_STR "navi_npcdistance_" NAMESUFFIX ".lua", "wt+"); fp_linkdist = fopen(DIRECTORYNAME PATHSEP_STR "navi_linkdistance_" NAMESUFFIX ".lua", "wt+"); if( !fp_mob || !fp_map || !fp_link || !fp_npc || !fp_npcdist || !fp_linkdist ) { ShowError("do_navigationlua: Unable to open output file.\n"); return false; } map_npcdata = (struct s_map_npcdata *)aCalloc(sizeof(struct s_map_npcdata), map->count); ShowStatus("Stage 1: creating maps and objects list...\n"); writeheader(fp_map, "Navi_Map"); writeheader(fp_mob, "Navi_Mob"); writeheader(fp_npc, "Navi_Npc"); writeheader(fp_link, "Navi_Link"); writeheader(fp_npcdist, "Navi_NpcDistance"); writeheader(fp_linkdist, "Navi_Distance"); for( m=0; m < map->count; m++ ) { //int nmapnpc=0; atcommand_createnavigationlua_sub_map(fp_map, m); // Warps/NPCs for( npcidx = 0; npcidx < map->list[m].npc_num; npcidx++ ) { TBL_NPC *nd = map->list[m].npc[npcidx]; struct npc_data_append *nda; if( !nd ) continue; if( !(nda = getFromNPCD(nd, 0)) ) { CREATE(nda,struct npc_data_append,1); addToNPCD(nd, nda, 0, true); } if( nd->subtype == WARP ) { int mnext = map->mapindex2mapid(nd->u.warp.mapindex); if( mnext < 0 ) continue; nda->npcid = 13350 + nlink; atcommand_createnavigationlua_sub_warp(fp_link, nd, mnext, nlink); map_npcdata[mnext].inner_warps[map_npcdata[mnext].ninner_warps++] = nd; map_npcdata[m].outer_warps[map_npcdata[m].nouter_warps++] = nd; nlink++; } else { if( nd->class_ == -1 || nd->class_ == INVISIBLE_CLASS || nd->class_ == HIDDEN_WARP_CLASS || nd->class_ == FLAG_CLASS ) continue; nda->npcid = 11984 + nnpc; atcommand_createnavigationlua_sub_npc(fp_npc, nd, nnpc); map_npcdata[m].npcs[map_npcdata[m].nnpcs] = nd; map_npcdata[m].nnpcs++; nnpc++; } } // Mobs for( mobidx=0; mobidx < MAX_MOB_LIST_PER_MAP; mobidx++ ) { struct mob_db *mobinfo; if( !map->list[m].moblist[mobidx] ) continue; mobinfo = mob->db(map->list[m].moblist[mobidx]->class_); if( mobinfo == mob->dummy ) continue; atcommand_createnavigationlua_sub_mob(fp_mob, m, mobinfo, map->list[m].moblist[mobidx]->num, global_mob_idx+n); n++; } ShowStatus("Created %s objects list (%d/%d)\n", map->list[m].name, m+1, map->count); }