diff options
Diffstat (limited to 'src/map/npc.c')
-rw-r--r-- | src/map/npc.c | 682 |
1 files changed, 536 insertions, 146 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index a824d4216..7e1dab1b2 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2016 Hercules Dev Team + * Copyright (C) 2012-2018 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -25,6 +25,7 @@ #include "map/battle.h" #include "map/chat.h" +#include "map/clan.h" #include "map/clif.h" #include "map/guild.h" #include "map/instance.h" @@ -39,6 +40,7 @@ #include "map/skill.h" #include "map/status.h" #include "map/unit.h" +#include "map/achievement.h" #include "common/HPM.h" #include "common/cbasetypes.h" #include "common/db.h" @@ -59,7 +61,7 @@ #include <string.h> #include <time.h> -struct npc_interface npc_s; +static struct npc_interface npc_s; struct npc_interface *npc; @@ -68,7 +70,7 @@ static struct view_data npc_viewdb[MAX_NPC_CLASS]; static struct view_data npc_viewdb2[MAX_NPC_CLASS2_END-MAX_NPC_CLASS2_START]; /* for speedup */ -unsigned int npc_market_qty[MAX_INVENTORY]; +static unsigned int npc_market_qty[MAX_INVENTORY]; static struct script_event_s { //Holds pointers to the commonly executed scripts for speedup. [Skotlex] @@ -82,7 +84,7 @@ static struct script_event_s { * @param class_ The NPC class ID. * @return The viewdata, or NULL if the ID is invalid. */ -struct view_data *npc_get_viewdata(int class_) +static struct view_data *npc_get_viewdata(int class_) { if (class_ == INVISIBLE_CLASS) return &npc_viewdb[0]; @@ -104,7 +106,7 @@ struct view_data *npc_get_viewdata(int class_) * @param id The NPC ID to validate. * @return Whether the value is a valid ID. */ -bool npc_db_checkid(int id) +static bool npc_db_checkid(int id) { if (id >= WARP_CLASS && id <= 125) // First subrange return true; @@ -114,13 +116,16 @@ bool npc_db_checkid(int id) return true; if (id >= MAX_NPC_CLASS2_START && id < MAX_NPC_CLASS2_END) // Second range return true; + if (pc->db_checkid(id)) + return true; // Anything else is invalid return false; } /// Returns a new npc id that isn't being used in id_db. /// Fatal error if nothing is available. -int npc_get_new_npc_id(void) { +static int npc_get_new_npc_id(void) +{ if (npc->npc_id >= START_NPC_NUM && !map->blid_exists(npc->npc_id)) return npc->npc_id++;// available else {// find next id @@ -137,7 +142,7 @@ int npc_get_new_npc_id(void) { } } -int npc_isnear_sub(struct block_list *bl, va_list args) +static int npc_isnear_sub(struct block_list *bl, va_list args) { const struct npc_data *nd = NULL; @@ -154,7 +159,8 @@ int npc_isnear_sub(struct block_list *bl, va_list args) return 1; } -bool npc_isnear(struct block_list * bl) { +static bool npc_isnear(struct block_list *bl) +{ if( battle_config.min_npc_vendchat_distance > 0 && map->foreachinrange(npc->isnear_sub,bl, battle_config.min_npc_vendchat_distance, BL_NPC) ) return true; @@ -162,7 +168,7 @@ bool npc_isnear(struct block_list * bl) { return false; } -int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd) +static int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd) { char name[EVENT_NAME_LENGTH]; @@ -177,7 +183,7 @@ int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd) return npc->event(sd,name,1); } -int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd) +static int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd) { char name[EVENT_NAME_LENGTH]; @@ -190,7 +196,7 @@ int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd) return npc->event(sd, name, 2); } -int npc_onuntouch_event(struct map_session_data *sd, struct npc_data *nd) +static int npc_onuntouch_event(struct map_session_data *sd, struct npc_data *nd) { char name[EVENT_NAME_LENGTH]; @@ -206,7 +212,7 @@ int npc_onuntouch_event(struct map_session_data *sd, struct npc_data *nd) /*========================================== * Sub-function of npc_enable, runs OnTouch event when enabled *------------------------------------------*/ -int npc_enable_sub(struct block_list *bl, va_list ap) +static int npc_enable_sub(struct block_list *bl, va_list ap) { struct npc_data *nd; @@ -234,7 +240,7 @@ int npc_enable_sub(struct block_list *bl, va_list ap) /*========================================== * Disable / Enable NPC *------------------------------------------*/ -int npc_enable(const char* name, int flag) +static int npc_enable(const char *name, int flag) { struct npc_data* nd = npc->name2id(name); @@ -272,7 +278,7 @@ int npc_enable(const char* name, int flag) /*========================================== * NPC lookup (get npc_data through npcname) *------------------------------------------*/ -struct npc_data *npc_name2id(const char *name) +static struct npc_data *npc_name2id(const char *name) { return strdb_get(npc->name_db, name); } @@ -282,7 +288,8 @@ struct npc_data *npc_name2id(const char *name) /** * Timer to check for idle time and timeout the dialog if necessary **/ -int npc_rr_secure_timeout_timer(int tid, int64 tick, int id, intptr_t data) { +static int npc_rr_secure_timeout_timer(int tid, int64 tick, int id, intptr_t data) +{ #ifdef SECURE_NPCTIMEOUT struct map_session_data* sd = NULL; unsigned int timeout = NPC_SECURE_TIMEOUT_NEXT; @@ -329,7 +336,7 @@ int npc_rr_secure_timeout_timer(int tid, int64 tick, int id, intptr_t data) { /*========================================== * Dequeue event and add timer for execution (100ms) *------------------------------------------*/ -int npc_event_dequeue(struct map_session_data* sd) +static int npc_event_dequeue(struct map_session_data *sd) { nullpo_ret(sd); @@ -361,7 +368,7 @@ int npc_event_dequeue(struct map_session_data* sd) /** * @see DBCreateData */ -struct DBData npc_event_export_create(union DBKey key, va_list args) +static struct DBData npc_event_export_create(union DBKey key, va_list args) { struct linkdb_node** head_ptr; CREATE(head_ptr, struct linkdb_node*, 1); @@ -373,7 +380,7 @@ struct DBData npc_event_export_create(union DBKey key, va_list args) * exports a npc event label * called from npc_parse_script *------------------------------------------*/ -int npc_event_export(struct npc_data *nd, int i) +static int npc_event_export(struct npc_data *nd, int i) { char* lname; int pos; @@ -399,13 +406,13 @@ int npc_event_export(struct npc_data *nd, int i) return 0; } -int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char* eventname); //[Lance] +static int npc_event_sub(struct map_session_data *sd, struct event_data *ev, const char *eventname); //[Lance] /** * Exec name (NPC events) on player or global * Do on all NPC when called with foreach */ -void npc_event_doall_sub(void *key, void *data, va_list ap) +static void npc_event_doall_sub(void *key, void *data, va_list ap) { struct event_data* ev = data; int* c; @@ -431,7 +438,7 @@ void npc_event_doall_sub(void *key, void *data, va_list ap) } // runs the specified event (supports both single-npc and global events) -int npc_event_do(const char* name) +static int npc_event_do(const char *name) { nullpo_ret(name); if( name[0] == ':' && name[1] == ':' ) { @@ -448,7 +455,7 @@ int npc_event_do(const char* name) } // runs the specified event, with a RID attached (global only) -int npc_event_doall_id(const char* name, int rid) +static int npc_event_doall_id(const char *name, int rid) { int c = 0; struct linkdb_node **label_linkdb = strdb_get(npc->ev_label_db, name); @@ -461,7 +468,7 @@ int npc_event_doall_id(const char* name, int rid) } // runs the specified event (global only) -int npc_event_doall(const char* name) +static int npc_event_doall(const char *name) { return npc->event_doall_id(name, 0); } @@ -470,7 +477,8 @@ int npc_event_doall(const char* name) * Clock event execution * OnMinute/OnClock/OnHour/OnDay/OnDDHHMM *------------------------------------------*/ -int npc_event_do_clock(int tid, int64 tick, int id, intptr_t data) { +static int npc_event_do_clock(int tid, int64 tick, int id, intptr_t data) +{ static struct tm ev_tm_b; // tracks previous execution time time_t clock; struct tm* t; @@ -522,7 +530,7 @@ int npc_event_do_clock(int tid, int64 tick, int id, intptr_t data) { * OnInit event execution (the start of the event and watch) * @param reload Is the server reloading? **/ -void npc_event_do_oninit( bool reload ) +static void npc_event_do_oninit(bool reload) { ShowStatus("Event '"CL_WHITE"OnInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs."CL_CLL"\n", npc->event_doall("OnInit")); @@ -535,7 +543,7 @@ void npc_event_do_oninit( bool reload ) * Incorporation of the label for the timer event * called from npc_parse_script *------------------------------------------*/ -int npc_timerevent_export(struct npc_data *nd, int i) +static int npc_timerevent_export(struct npc_data *nd, int i) { int t = 0, len = 0; char *lname; @@ -574,7 +582,7 @@ struct timer_event_data { /*========================================== * triger 'OnTimerXXXX' events *------------------------------------------*/ -int npc_timerevent(int tid, int64 tick, int id, intptr_t data) +static int npc_timerevent(int tid, int64 tick, int id, intptr_t data) { int old_rid, old_timer; int64 old_tick; @@ -645,7 +653,8 @@ int npc_timerevent(int tid, int64 tick, int id, intptr_t data) /*========================================== * Start/Resume NPC timer *------------------------------------------*/ -int npc_timerevent_start(struct npc_data* nd, int rid) { +static int npc_timerevent_start(struct npc_data *nd, int rid) +{ int j; int64 tick = timer->gettick(); struct map_session_data *sd = NULL; //Player to whom script is attached. @@ -697,7 +706,7 @@ int npc_timerevent_start(struct npc_data* nd, int rid) { /*========================================== * Stop NPC timer *------------------------------------------*/ -int npc_timerevent_stop(struct npc_data* nd) +static int npc_timerevent_stop(struct npc_data *nd) { struct map_session_data *sd = NULL; int *tid; @@ -731,7 +740,7 @@ int npc_timerevent_stop(struct npc_data* nd) /*========================================== * Aborts a running NPC timer that is attached to a player. *------------------------------------------*/ -void npc_timerevent_quit(struct map_session_data* sd) +static void npc_timerevent_quit(struct map_session_data *sd) { const struct TimerData *td; struct npc_data* nd; @@ -796,7 +805,8 @@ void npc_timerevent_quit(struct map_session_data* sd) * Get the tick value of an NPC timer * If it's stopped, return stopped time *------------------------------------------*/ -int64 npc_gettimerevent_tick(struct npc_data* nd) { +static int64 npc_gettimerevent_tick(struct npc_data *nd) +{ int64 tick; nullpo_ret(nd); @@ -812,7 +822,7 @@ int64 npc_gettimerevent_tick(struct npc_data* nd) { /*========================================== * Set tick for running and stopped timer *------------------------------------------*/ -int npc_settimerevent_tick(struct npc_data* nd, int newtimer) +static int npc_settimerevent_tick(struct npc_data *nd, int newtimer) { bool flag; int old_rid; @@ -836,7 +846,7 @@ int npc_settimerevent_tick(struct npc_data* nd, int newtimer) return 0; } -int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char* eventname) +static int npc_event_sub(struct map_session_data *sd, struct event_data *ev, const char *eventname) { nullpo_retr(2, sd); nullpo_retr(2, eventname); @@ -867,7 +877,7 @@ int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char /*========================================== * NPC processing event type *------------------------------------------*/ -int npc_event(struct map_session_data* sd, const char* eventname, int ontouch) +static int npc_event(struct map_session_data *sd, const char *eventname, int ontouch) { struct event_data* ev = (struct event_data*)strdb_get(npc->ev_db, eventname); struct npc_data *nd; @@ -896,7 +906,8 @@ int npc_event(struct map_session_data* sd, const char* eventname, int ontouch) /*========================================== * Sub chk then execute area event type *------------------------------------------*/ -int npc_touch_areanpc_sub(struct block_list *bl, va_list ap) { +static int npc_touch_areanpc_sub(struct block_list *bl, va_list ap) +{ struct map_session_data *sd; int pc_id; char *name; @@ -923,7 +934,8 @@ int npc_touch_areanpc_sub(struct block_list *bl, va_list ap) { * Chk if sd is still touching his assigned npc. * If not, it unsets it and searches for another player in range. *------------------------------------------*/ -int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap) { +static int npc_touchnext_areanpc(struct map_session_data *sd, bool leavemap) +{ struct npc_data *nd; short xs, ys; @@ -952,7 +964,7 @@ int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap) { /*========================================== * Exec OnTouch for player if in range of area event *------------------------------------------*/ -int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y) +static int npc_touch_areanpc(struct map_session_data *sd, int16 m, int16 x, int16 y) { int xs,ys; int f = 1; @@ -1041,7 +1053,7 @@ int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y) /*========================================== * Exec OnUnTouch for player if out range of area event *------------------------------------------*/ -int npc_untouch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y) +static int npc_untouch_areanpc(struct map_session_data *sd, int16 m, int16 x, int16 y) { struct npc_data *nd = NULL; nullpo_retr(1, sd); @@ -1063,7 +1075,7 @@ int npc_untouch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y) // OnTouch NPC or Warp for Mobs // Return 1 if Warped -int npc_touch_areanpc2(struct mob_data *md) +static int npc_touch_areanpc2(struct mob_data *md) { int i, m, x, y, id; char eventname[EVENT_NAME_LENGTH]; @@ -1128,7 +1140,8 @@ int npc_touch_areanpc2(struct mob_data *md) //Flag determines the type of object to check for: //&1: NPC Warps //&2: NPCs with on-touch events. -int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range) { +static int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range) +{ int i; int x0,y0,x1,y1; int xs,ys; @@ -1187,7 +1200,7 @@ int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range) { * Chk if player not too far to access the npc. * Returns npc_data (success) or NULL (fail). *------------------------------------------*/ -struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* bl) +static struct npc_data *npc_checknear(struct map_session_data *sd, struct block_list *bl) { struct npc_data *nd = BL_CAST(BL_NPC, bl); int distance = AREA_SIZE + 1; @@ -1220,7 +1233,7 @@ struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* b /*========================================== * Make NPC talk in global chat (like npctalk) *------------------------------------------*/ -int npc_globalmessage(const char* name, const char* mes) +static int npc_globalmessage(const char *name, const char *mes) { struct npc_data* nd = npc->name2id(name); char temp[100]; @@ -1238,7 +1251,8 @@ int npc_globalmessage(const char* name, const char* mes) } // MvP tomb [GreenBox] -void run_tomb(struct map_session_data* sd, struct npc_data* nd) { +static void run_tomb(struct map_session_data *sd, struct npc_data *nd) +{ char buffer[200]; char time[10]; @@ -1266,7 +1280,7 @@ void run_tomb(struct map_session_data* sd, struct npc_data* nd) { * NPC 1st call when clicking on npc * Do specific action for NPC type (openshop, run scripts...) *------------------------------------------*/ -int npc_click(struct map_session_data* sd, struct npc_data* nd) +static int npc_click(struct map_session_data *sd, struct npc_data *nd) { nullpo_retr(1, sd); @@ -1320,7 +1334,8 @@ int npc_click(struct map_session_data* sd, struct npc_data* nd) /*========================================== * *------------------------------------------*/ -int npc_scriptcont(struct map_session_data* sd, int id, bool closing) { +static int npc_scriptcont(struct map_session_data *sd, int id, bool closing) +{ struct block_list *target = map->id2bl(id); nullpo_retr(1, sd); @@ -1369,7 +1384,8 @@ int npc_scriptcont(struct map_session_data* sd, int id, bool closing) { /*========================================== * Chk if valid call then open buy or selling list *------------------------------------------*/ -int npc_buysellsel(struct map_session_data* sd, int id, int type) { +static int npc_buysellsel(struct map_session_data *sd, int id, int type) +{ struct npc_data *nd; nullpo_retr(1, sd); @@ -1408,9 +1424,9 @@ int npc_buysellsel(struct map_session_data* sd, int id, int type) { } /*========================================== -* Cash Shop Buy List -*------------------------------------------*/ -int npc_cashshop_buylist(struct map_session_data *sd, int points, struct itemlist *item_list) + * Cash Shop Buy List + *------------------------------------------*/ +static int npc_cashshop_buylist(struct map_session_data *sd, int points, struct itemlist *item_list) { int i, j, new_, w, vt; struct npc_data *nd = NULL; @@ -1433,11 +1449,12 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, struct itemlis return ERROR_TYPE_NPC; if( nd->subtype != CASHSHOP ) { - if( nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type != NST_ZENY && nd->u.scr.shop->type != NST_MARKET ) { + if (nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type != NST_ZENY && nd->u.scr.shop->type != NST_MARKET && nd->u.scr.shop->type != NST_BARTER) { shop = nd->u.scr.shop->item; shop_size = nd->u.scr.shop->items; - } else + } else { return ERROR_TYPE_NPC; + } } else { shop = nd->u.shop.shop_item; shop_size = nd->u.shop.count; @@ -1511,7 +1528,7 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, struct itemlis } //npc_buylist for script-controlled shops. -int npc_buylist_sub(struct map_session_data *sd, struct itemlist *item_list, struct npc_data *nd) +static int npc_buylist_sub(struct map_session_data *sd, struct itemlist *item_list, struct npc_data *nd) { char npc_ev[EVENT_NAME_LENGTH]; int i; @@ -1543,7 +1560,7 @@ int npc_buylist_sub(struct map_session_data *sd, struct itemlist *item_list, str /** * Loads persistent NPC Market Data from SQL **/ -void npc_market_fromsql(void) +static void npc_market_fromsql(void) { struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); char name[NAME_LENGTH+1]; @@ -1558,9 +1575,9 @@ void npc_market_fromsql(void) return; } - SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &name[0], sizeof(name), NULL, NULL); - SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &itemid, 0, NULL, NULL); - SQL->StmtBindColumn(stmt, 2, SQLDT_INT, &amount, 0, NULL, NULL); + SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &name, sizeof name, NULL, NULL); + SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &itemid, sizeof itemid, NULL, NULL); + SQL->StmtBindColumn(stmt, 2, SQLDT_INT, &amount, sizeof amount, NULL, NULL); while ( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) { struct npc_data *nd = NULL; @@ -1568,11 +1585,11 @@ void npc_market_fromsql(void) if( !(nd = npc->name2id(name)) ) { ShowError("npc_market_fromsql: NPC '%s' not found! skipping...\n",name); - npc->market_delfromsql_sub(name, USHRT_MAX); + npc->market_delfromsql_sub(name, INT_MAX); continue; - } else if ( nd->subtype != SCRIPT || !nd->u.scr.shop || !nd->u.scr.shop->items || nd->u.scr.shop->type != NST_MARKET ) { + } else if (nd->subtype != SCRIPT || !nd->u.scr.shop || !nd->u.scr.shop->items || nd->u.scr.shop->type != NST_MARKET) { ShowError("npc_market_fromsql: NPC '%s' is not proper for market, skipping...\n",name); - npc->market_delfromsql_sub(name, USHRT_MAX); + npc->market_delfromsql_sub(name, INT_MAX); continue; } @@ -1594,9 +1611,10 @@ void npc_market_fromsql(void) /** * Saves persistent NPC Market Data into SQL **/ -void npc_market_tosql(struct npc_data *nd, unsigned short index) { +static void npc_market_tosql(struct npc_data *nd, int index) +{ nullpo_retv(nd); - Assert_retv(index < nd->u.scr.shop->items); + Assert_retv(index >= 0 && index < nd->u.scr.shop->items); if (SQL_ERROR == SQL->Query(map->mysql_handle, "REPLACE INTO `%s` VALUES ('%s','%d','%u')", map->npc_market_data_db, nd->exname, nd->u.scr.shop->item[index].nameid, nd->u.scr.shop->item[index].qty)) Sql_ShowDebug(map->mysql_handle); @@ -1604,8 +1622,9 @@ void npc_market_tosql(struct npc_data *nd, unsigned short index) { /** * Removes persistent NPC Market Data from SQL */ -void npc_market_delfromsql_sub(const char *npcname, unsigned short index) { - if( index == USHRT_MAX ) { +static void npc_market_delfromsql_sub(const char *npcname, int index) +{ + if (index == INT_MAX ) { if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `name`='%s'", map->npc_market_data_db, npcname) ) Sql_ShowDebug(map->mysql_handle); } else { @@ -1617,15 +1636,120 @@ void npc_market_delfromsql_sub(const char *npcname, unsigned short index) { /** * Removes persistent NPC Market Data from SQL **/ -void npc_market_delfromsql(struct npc_data *nd, unsigned short index) { +static void npc_market_delfromsql(struct npc_data *nd, int index) +{ nullpo_retv(nd); - Assert_retv(index == USHRT_MAX || index < nd->u.scr.shop->items); - npc->market_delfromsql_sub(nd->exname, index == USHRT_MAX ? index : nd->u.scr.shop->item[index].nameid); + Assert_retv(index == INT_MAX || (index >= 0 && index < nd->u.scr.shop->items)); + npc->market_delfromsql_sub(nd->exname, index == INT_MAX ? index : nd->u.scr.shop->item[index].nameid); +} + +/** + * Loads persistent NPC Barter Data from SQL + **/ +static void npc_barter_fromsql(void) +{ + struct SqlStmt *stmt = SQL->StmtMalloc(map->mysql_handle); + char name[NAME_LENGTH + 1]; + int itemid; + int amount; + int removeId; + int removeAmount; + + if (SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `name`, `itemId`, `amount`, `priceId`, `priceAmount` FROM `%s`", map->npc_barter_data_db) + || SQL_ERROR == SQL->StmtExecute(stmt) + ) { + SqlStmt_ShowDebug(stmt); + SQL->StmtFree(stmt); + return; + } + + SQL->StmtBindColumn(stmt, 0, SQLDT_STRING, &name, sizeof name, NULL, NULL); + SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &itemid, sizeof itemid, NULL, NULL); + SQL->StmtBindColumn(stmt, 2, SQLDT_UINT32, &amount, sizeof amount, NULL, NULL); + SQL->StmtBindColumn(stmt, 3, SQLDT_INT, &removeId, sizeof removeId, NULL, NULL); + SQL->StmtBindColumn(stmt, 4, SQLDT_INT, &removeAmount, sizeof removeAmount, NULL, NULL); + + while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) { + struct npc_data *nd = NULL; + unsigned short i; + + if (!(nd = npc->name2id(name))) { + ShowError("npc_barter_fromsql: NPC '%s' not found! skipping...\n",name); + npc->barter_delfromsql_sub(name, INT_MAX, 0, 0); + continue; + } else if (nd->subtype != SCRIPT || !nd->u.scr.shop || !nd->u.scr.shop->items || nd->u.scr.shop->type != NST_BARTER) { + ShowError("npc_barter_fromsql: NPC '%s' is not proper for barter, skipping...\n",name); + npc->barter_delfromsql_sub(name, INT_MAX, 0, 0); + continue; + } + + for (i = 0; i < nd->u.scr.shop->items; i++) { + struct npc_item_list *const item = &nd->u.scr.shop->item[i]; + if (item->nameid == itemid && item->value == removeId && item->value2 == removeAmount) { + item->qty = amount; + break; + } + } + + if (i == nd->u.scr.shop->items) { + ShowError("npc_barter_fromsql: NPC '%s' does not sell item %d (qty %d), deleting...\n", name, itemid, amount); + npc->barter_delfromsql_sub(name, itemid, removeId, removeAmount); + continue; + } + } + SQL->StmtFree(stmt); } + +/** + * Saves persistent NPC Barter Data into SQL + **/ +static void npc_barter_tosql(struct npc_data *nd, int index) +{ + nullpo_retv(nd); + Assert_retv(index >= 0 && index < nd->u.scr.shop->items); + const struct npc_item_list *const item = &nd->u.scr.shop->item[index]; + if (SQL_ERROR == SQL->Query(map->mysql_handle, "REPLACE INTO `%s` VALUES ('%s', '%d', '%u', '%u', '%d')", + map->npc_barter_data_db, nd->exname, item->nameid, item->qty, item->value, item->value2)) { + Sql_ShowDebug(map->mysql_handle); + } +} + +/** + * Removes persistent NPC Barter Data from SQL + */ +static void npc_barter_delfromsql_sub(const char *npcname, int itemId, int itemId2, int amount2) +{ + if (itemId == INT_MAX) { + if (SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `name`='%s'", map->npc_barter_data_db, npcname)) + Sql_ShowDebug(map->mysql_handle); + } else { + if (SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `name`='%s' AND `itemId`='%d' AND `priceId`='%d' AND `priceAmount`='%d' LIMIT 1", + map->npc_barter_data_db, npcname, itemId, itemId2, amount2)) { + Sql_ShowDebug(map->mysql_handle); + } + } +} + +/** + * Removes persistent NPC Barter Data from SQL + **/ +static void npc_barter_delfromsql(struct npc_data *nd, int index) +{ + nullpo_retv(nd); + if (index == INT_MAX) { + npc->barter_delfromsql_sub(nd->exname, INT_MAX, 0, 0); + } else { + Assert_retv(index >= 0 && index < nd->u.scr.shop->items); + const struct npc_item_list *const item = &nd->u.scr.shop->item[index]; + npc->barter_delfromsql_sub(nd->exname, item->nameid, item->value, item->value2); + } +} + /** * Judges whether to allow and spawn a trader's window. **/ -bool npc_trader_open(struct map_session_data *sd, struct npc_data *nd) { +static bool npc_trader_open(struct map_session_data *sd, struct npc_data *nd) +{ nullpo_retr(false, sd); nullpo_retr(false, nd); if( !nd->u.scr.shop || !nd->u.scr.shop->items ) @@ -1653,6 +1777,9 @@ bool npc_trader_open(struct map_session_data *sd, struct npc_data *nd) { clif->npc_market_open(sd,nd); } break; + case NST_BARTER: + clif->npc_barter_open(sd, nd); + break; default: clif->cashshop_show(sd,nd); break; @@ -1665,7 +1792,8 @@ bool npc_trader_open(struct map_session_data *sd, struct npc_data *nd) { * * @param master id of the original npc **/ -void npc_trader_update(int master) { +static void npc_trader_update(int master) +{ struct DBIterator *iter; struct block_list* bl; struct npc_data *master_nd = map->id2nd(master); @@ -1689,7 +1817,8 @@ void npc_trader_update(int master) { * @param nd shop * @param sd player **/ -void npc_trader_count_funds(struct npc_data *nd, struct map_session_data *sd) { +static void npc_trader_count_funds(struct npc_data *nd, struct map_session_data *sd) +{ char evname[EVENT_NAME_LENGTH]; struct event_data *ev = NULL; @@ -1729,7 +1858,8 @@ void npc_trader_count_funds(struct npc_data *nd, struct map_session_data *sd) { * * @return bool whether it was successful (if the script does not respond it will fail) **/ -bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, int points) { +static bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, int points) +{ char evname[EVENT_NAME_LENGTH]; struct event_data *ev = NULL; @@ -1739,8 +1869,8 @@ bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, snprintf(evname, EVENT_NAME_LENGTH, "%s::OnPayFunds",nd->exname); if ( (ev = strdb_get(npc->ev_db, evname)) ) { - pc->setreg(sd,script->add_str("@price"),price); - pc->setreg(sd,script->add_str("@points"),points); + pc->setreg(sd,script->add_variable("@price"),price); + pc->setreg(sd,script->add_variable("@points"),points); script->run_npc(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id); } else ShowError("npc_trader_pay: '%s' event '%s' not found, operation failed\n",nd->exname,evname); @@ -1750,7 +1880,8 @@ bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int price, /*========================================== * Cash Shop Buy *------------------------------------------*/ -int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int points) { +static int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int points) +{ struct npc_data *nd = NULL; struct item_data *item; struct npc_item_list *shop = NULL; @@ -1775,11 +1906,12 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po return ERROR_TYPE_ITEM_ID; // Invalid Item if( nd->subtype != CASHSHOP ) { - if( nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type != NST_ZENY && nd->u.scr.shop->type != NST_MARKET ) { + if (nd->subtype == SCRIPT && nd->u.scr.shop && nd->u.scr.shop->type != NST_ZENY && nd->u.scr.shop->type != NST_MARKET && nd->u.scr.shop->type != NST_BARTER) { shop = nd->u.scr.shop->item; shop_size = nd->u.scr.shop->items; - } else + } else { return ERROR_TYPE_NPC; + } } else { shop = nd->u.shop.shop_item; shop_size = nd->u.shop.count; @@ -1855,7 +1987,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po * @param item_list List of items. * @return result code for clif->parse_NpcBuyListSend. */ -int npc_buylist(struct map_session_data *sd, struct itemlist *item_list) +static int npc_buylist(struct map_session_data *sd, struct itemlist *item_list) { struct npc_data* nd; struct npc_item_list *shop = NULL; @@ -1924,7 +2056,11 @@ int npc_buylist(struct map_session_data *sd, struct itemlist *item_list) break; case ADDITEM_OVERAMOUNT: +#if PACKETVER >= 20110705 + return 9; +#else return 2; +#endif } value = pc->modifybuyvalue(sd,value); @@ -1978,7 +2114,7 @@ int npc_buylist(struct map_session_data *sd, struct itemlist *item_list) /** * Processes incoming npc market purchase list **/ -int npc_market_buylist(struct map_session_data *sd, struct itemlist *item_list) +static int npc_market_buylist(struct map_session_data *sd, struct itemlist *item_list) { struct npc_data* nd; struct npc_item_list *shop = NULL; @@ -2084,11 +2220,140 @@ int npc_market_buylist(struct map_session_data *sd, struct itemlist *item_list) return 0; } +/** + * Processes incoming npc barter purchase list + **/ +static int npc_barter_buylist(struct map_session_data *sd, struct barteritemlist *item_list) +{ + struct npc_data* nd; + struct npc_item_list *shop = NULL; + int w, new_; + unsigned short shop_size = 0; + + nullpo_retr(1, sd); + nullpo_retr(1, item_list); + + nd = npc->checknear(sd, map->id2bl(sd->npc_shopid)); + + if (nd == NULL || nd->subtype != SCRIPT || VECTOR_LENGTH(*item_list) == 0 || !nd->u.scr.shop || nd->u.scr.shop->type != NST_BARTER) + return 11; + + shop = nd->u.scr.shop->item; + shop_size = nd->u.scr.shop->items; + + w = 0; + new_ = 0; + + int items[MAX_INVENTORY] = { 0 }; + + // process entries in buy list, one by one + for (int i = 0; i < VECTOR_LENGTH(*item_list); ++i) { + struct barter_itemlist_entry *entry = &VECTOR_INDEX(*item_list, i); + + const int n = entry->removeIndex; + if (n < 0 || n >= sd->status.inventorySize) + return 11; // wrong inventory index + + int removeId = sd->status.inventory[n].nameid; + const int j = entry->shopIndex; + if (j < 0 || j >= shop_size) + return 13; // no such item in shop + if (entry->addId != shop[j].nameid && entry->addId != itemdb_viewid(shop[j].nameid)) + return 13; // no such item in shop + if (removeId != shop[j].value && removeId != itemdb_viewid(shop[j].value)) + return 13; // no such item in shop + entry->addId = shop[j].nameid; // item_avail replacement + removeId = shop[j].value; // item_avail replacement + + if (!itemdb->exists(entry->addId)) + return 13; // item no longer in itemdb + + const int removeAmount = shop[j].value2; + + if ((int)shop[j].qty != -1 && entry->addAmount > (int)shop[j].qty) + return 14; // not enough item amount in shop + + if (removeAmount * entry->addAmount > sd->status.inventory[n].amount) + return 14; // not enough item amount in inventory + + items[n] += removeAmount * entry->addAmount; + + if (items[n] > sd->status.inventory[n].amount) + return 14; // not enough item amount in inventory + + entry->addId = shop[j].nameid; //item_avail replacement + + npc_market_qty[i] = j; + + if (!itemdb->isstackable(entry->addId) && entry->addAmount > 1) { + //Exploit? You can't buy more than 1 of equipment types o.O + ShowWarning("Player %s (%d:%d) sent a hexed packet trying to buy %d of non-stackable item %d!\n", + sd->status.name, sd->status.account_id, sd->status.char_id, entry->addAmount, entry->addId); + entry->addAmount = 1; + } + + switch (pc->checkadditem(sd, entry->addId, entry->addAmount)) { + case ADDITEM_EXIST: + break; + case ADDITEM_NEW: + new_++; + break; + case ADDITEM_OVERAMOUNT: /* TODO find official response for this */ + return 1; + } + + w += itemdb_weight(entry->addId) * entry->addAmount; + w -= itemdb_weight(removeId) * removeAmount; + } + + if (w + sd->weight > sd->max_weight) + return 2; // Too heavy + + if (pc->inventoryblank(sd) < new_) + return 3; // Not enough space to store items + + for (int i = 0; i < sd->status.inventorySize; ++i) { + const int removeAmountTotal = items[i]; + if (removeAmountTotal == 0) + continue; + if (pc->delitem(sd, i, removeAmountTotal, 0, DELITEM_SOLD, LOG_TYPE_NPC) != 0) { + return 11; // unknown exploit + } + } + + for (int i = 0; i < VECTOR_LENGTH(*item_list); ++i) { + struct barter_itemlist_entry *entry = &VECTOR_INDEX(*item_list, i); + const int shopIdx = npc_market_qty[i]; + + if ((int)shop[shopIdx].qty != -1) { + if (entry->addAmount > (int)shop[shopIdx].qty) /* wohoo someone tampered with the packet. */ + return 14; + shop[shopIdx].qty -= entry->addAmount; + } + + npc->barter_tosql(nd, shopIdx); + + if (itemdb_type(entry->addId) == IT_PETEGG) { + pet->create_egg(sd, entry->addId); + } else { + struct item item_tmp; + memset(&item_tmp, 0, sizeof(item_tmp)); + item_tmp.nameid = entry->addId; + item_tmp.identify = 1; + pc->additem(sd, &item_tmp, entry->addAmount, LOG_TYPE_NPC); + } + } + + return 12; +} + /// npc_selllist for script-controlled shops -int npc_selllist_sub(struct map_session_data *sd, struct itemlist *item_list, struct npc_data *nd) +static int npc_selllist_sub(struct map_session_data *sd, struct itemlist *item_list, struct npc_data *nd) { char npc_ev[EVENT_NAME_LENGTH]; char card_slot[NAME_LENGTH]; + char opt_index_str[NAME_LENGTH]; + char opt_value_str[NAME_LENGTH]; int i, j; int key_nameid = 0; int key_amount = 0; @@ -2096,6 +2361,8 @@ int npc_selllist_sub(struct map_session_data *sd, struct itemlist *item_list, st int key_attribute = 0; int key_identify = 0; int key_card[MAX_SLOTS]; + int key_opt_idx[MAX_ITEM_OPTIONS]; + int key_opt_value[MAX_ITEM_OPTIONS]; nullpo_ret(sd); nullpo_ret(item_list); @@ -2115,6 +2382,17 @@ int npc_selllist_sub(struct map_session_data *sd, struct itemlist *item_list, st script->cleararray_pc(sd, card_slot, (void*)0); } + for (j = 0; j < MAX_ITEM_OPTIONS; j++) { // Clear Each item option entry + key_opt_idx[j] = 0; + key_opt_value[j] = 0; + + snprintf(opt_index_str, sizeof(opt_index_str), "@slot_opt_idx%d", j + 1); + script->cleararray_pc(sd, opt_index_str, (void*)0); + + snprintf(opt_value_str, sizeof(opt_value_str), "@slot_opt_val%d", j + 1); + script->cleararray_pc(sd, opt_value_str, (void*)0); + } + // save list of to be sold items for (i = 0; i < VECTOR_LENGTH(*item_list); i++) { struct itemlist_entry *entry = &VECTOR_INDEX(*item_list, i); @@ -2140,6 +2418,17 @@ int npc_selllist_sub(struct map_session_data *sd, struct itemlist *item_list, st script->setarray_pc(sd, card_slot, i, (void*)card, &key_card[j]); } + for (j = 0; j < MAX_ITEM_OPTIONS; j++) { + intptr_t opt_idx = item->option[j].index; + intptr_t opt_value = item->option[j].value; + + snprintf(opt_index_str, sizeof(opt_index_str), "@slot_opt_idx%d", j + 1); + script->setarray_pc(sd, opt_index_str, i, (void*)opt_idx, &key_opt_idx[j]); + + snprintf(opt_value_str, sizeof(opt_value_str), "@slot_opt_val%d", j + 1); + script->setarray_pc(sd, opt_value_str, i, (void*)opt_value, &key_opt_value[j]); + } + } // invoke event @@ -2152,7 +2441,7 @@ int npc_selllist_sub(struct map_session_data *sd, struct itemlist *item_list, st /// /// @param item_list 'n' pairs <index,amount> /// @return result code for clif->parse_NpcSellListSend -int npc_selllist(struct map_session_data *sd, struct itemlist *item_list) +static int npc_selllist(struct map_session_data *sd, struct itemlist *item_list) { int64 z; int i,skill_t, skill_idx = skill->get_index(MC_OVERCHARGE); @@ -2181,7 +2470,7 @@ int npc_selllist(struct map_session_data *sd, struct itemlist *item_list) struct itemlist_entry *entry = &VECTOR_INDEX(*item_list, i); int nameid, value, idx = entry->id; - if (idx >= MAX_INVENTORY || idx < 0 || entry->amount < 0) { + if (idx >= sd->status.inventorySize || idx < 0 || entry->amount < 0) { return 1; } @@ -2222,7 +2511,11 @@ int npc_selllist(struct map_session_data *sd, struct itemlist *item_list) } } + // Achievements [Smokexyz/Hercules] + achievement->validate_item_sell(sd, sd->status.inventory[idx].nameid, entry->amount); + pc->delitem(sd, idx, entry->amount, 0, DELITEM_SOLD, LOG_TYPE_NPC); + } if (z + sd->status.zeny > MAX_ZENY && nd->master_nd == NULL) @@ -2251,7 +2544,8 @@ int npc_selllist(struct map_session_data *sd, struct itemlist *item_list) //Atempt to remove an npc from a map //This doesn't remove it from map_db -int npc_remove_map(struct npc_data* nd) { +static int npc_remove_map(struct npc_data *nd) +{ int16 m,i; nullpo_retr(1, nd); @@ -2274,7 +2568,7 @@ int npc_remove_map(struct npc_data* nd) { /** * @see DBApply */ -int npc_unload_ev(union DBKey key, struct DBData *data, va_list ap) +static int npc_unload_ev(union DBKey key, struct DBData *data, va_list ap) { struct event_data* ev = DB->data2ptr(data); char* npcname = va_arg(ap, char *); @@ -2289,7 +2583,7 @@ int npc_unload_ev(union DBKey key, struct DBData *data, va_list ap) /** * @see DBApply */ -int npc_unload_ev_label(union DBKey key, struct DBData *data, va_list ap) +static int npc_unload_ev_label(union DBKey key, struct DBData *data, va_list ap) { struct linkdb_node **label_linkdb = DB->data2ptr(data); struct npc_data* nd = va_arg(ap, struct npc_data *); @@ -2301,7 +2595,7 @@ int npc_unload_ev_label(union DBKey key, struct DBData *data, va_list ap) //Chk if npc matches src_id, then unload. //Sub-function used to find duplicates. -int npc_unload_dup_sub(struct npc_data* nd, va_list args) +static int npc_unload_dup_sub(struct npc_data *nd, va_list args) { int src_id; @@ -2313,14 +2607,15 @@ int npc_unload_dup_sub(struct npc_data* nd, va_list args) } //Removes all npcs that are duplicates of the passed one. [Skotlex] -void npc_unload_duplicates(struct npc_data* nd) { +static void npc_unload_duplicates(struct npc_data *nd) +{ nullpo_retv(nd); map->foreachnpc(npc->unload_dup_sub,nd->bl.id); } //Removes an npc from map and db. //Single is to free name (for duplicates). -int npc_unload(struct npc_data* nd, bool single) +static int npc_unload(struct npc_data *nd, bool single) { nullpo_ret(nd); @@ -2420,7 +2715,7 @@ int npc_unload(struct npc_data* nd, bool single) // /// Clears the npc source file list -void npc_clearsrcfile(void) +static void npc_clearsrcfile(void) { struct npc_src_list* file = npc->src_files; @@ -2437,7 +2732,7 @@ void npc_clearsrcfile(void) * * @param name The file name to add. */ -void npc_addsrcfile(const char *name) +static void npc_addsrcfile(const char *name) { struct npc_src_list* file; struct npc_src_list* file_prev = NULL; @@ -2467,7 +2762,7 @@ void npc_addsrcfile(const char *name) * * @param name The file name to remove. */ -void npc_delsrcfile(const char *name) +static void npc_delsrcfile(const char *name) { struct npc_src_list* file = npc->src_files; struct npc_src_list* file_prev = NULL; @@ -2494,7 +2789,7 @@ void npc_delsrcfile(const char *name) * @param filepath The file path to retain. * @return A retained reference to filepath. */ -const char *npc_retainpathreference(const char *filepath) +static const char *npc_retainpathreference(const char *filepath) { struct npc_path_data * npd = NULL; nullpo_ret(filepath); @@ -2529,7 +2824,7 @@ const char *npc_retainpathreference(const char *filepath) * * @param filepath The file path to release. */ -void npc_releasepathreference(const char *filepath) +static void npc_releasepathreference(const char *filepath) { struct npc_path_data* npd = NULL; @@ -2548,7 +2843,8 @@ void npc_releasepathreference(const char *filepath) /// Parses and sets the name and exname of a npc. /// Assumes that m, x and y are already set in nd. -void npc_parsename(struct npc_data* nd, const char* name, const char* start, const char* buffer, const char* filepath) { +static void npc_parsename(struct npc_data *nd, const char *name, const char *start, const char *buffer, const char *filepath) +{ const char* p; struct npc_data* dnd;// duplicate npc char newname[NAME_LENGTH]; @@ -2591,7 +2887,7 @@ void npc_parsename(struct npc_data* nd, const char* name, const char* start, con do { ++i; - snprintf(newname, ARRAYLENGTH(newname), "%d_%d_%d_%d", i, nd->bl.m, nd->bl.x, nd->bl.y); + safesnprintf(newname, ARRAYLENGTH(newname), "%d_%d_%d_%d", i, nd->bl.m, nd->bl.x, nd->bl.y); } while( npc->name2id(newname) != NULL ); strcpy(this_mapname, (nd->bl.m == -1 ? "(not on a map)" : mapindex_id2name(map_id2index(nd->bl.m)))); @@ -2606,7 +2902,8 @@ void npc_parsename(struct npc_data* nd, const char* name, const char* start, con // Parse View // Support for using Constants in place of NPC View IDs. -int npc_parseview(const char* w4, const char* start, const char* buffer, const char* filepath) { +static int npc_parseview(const char *w4, const char *start, const char *buffer, const char *filepath) +{ int val = FAKE_NPC, i = 0; char viewid[1024]; // Max size of name from constants.conf, see script->read_constdb. @@ -2640,7 +2937,7 @@ int npc_parseview(const char* w4, const char* start, const char* buffer, const c // View is ID // Checks if given view is an ID or constant. -bool npc_viewisid(const char * viewid) +static bool npc_viewisid(const char *viewid) { nullpo_retr(false, viewid); if (atoi(viewid) != FAKE_NPC) { @@ -2664,7 +2961,7 @@ bool npc_viewisid(const char * viewid) * @param class_ The NPC view class. * @return A pointer to the created NPC data (ownership passed to the caller). */ -struct npc_data *npc_create_npc(enum npc_subtype subtype, int m, int x, int y, uint8 dir, int16 class_) +static struct npc_data *npc_create_npc(enum npc_subtype subtype, int m, int x, int y, uint8 dir, int16 class_) { struct npc_data *nd; @@ -2680,12 +2977,14 @@ struct npc_data *npc_create_npc(enum npc_subtype subtype, int m, int x, int y, u nd->area_size = AREA_SIZE + 1; nd->class_ = class_; nd->speed = 200; + nd->vd = npc_viewdb[0]; // Copy INVISIBLE_CLASS view data. Actual view data is set by npc->add_to_location() later. 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) { +static 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; @@ -2698,10 +2997,10 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short flag = 1; if (flag == 1) - snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp_%d_%d_%d", from_mapid, from_x, from_y); + safesnprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp_%d_%d_%d", from_mapid, from_x, from_y); for( i = 0; npc->name2id(nd->exname) != NULL; ++i ) - snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp%d_%d_%d_%d", i, from_mapid, from_x, from_y); + safesnprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp%d_%d_%d_%d", i, from_mapid, from_x, from_y); safestrncpy(nd->name, nd->exname, ARRAYLENGTH(nd->name)); nd->u.warp.mapindex = to_mapindex; @@ -2732,7 +3031,7 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short * (EXIT_FAILURE) status. May be NULL. * @return A pointer to the advanced buffer position. */ -const char *npc_parse_warp(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) +static const char *npc_parse_warp(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) { int x, y, xs, ys, to_x, to_y, m; unsigned short i; @@ -2799,7 +3098,7 @@ const char *npc_parse_warp(const char *w1, const char *w2, const char *w3, const * (EXIT_FAILURE) status. May be NULL. * @return A pointer to the advanced buffer position. */ -const char *npc_parse_shop(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) +static const char *npc_parse_shop(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) { //TODO: could be rewritten to NOT need this temp array [ultramage] // We could use nd->u.shop.shop_item to store directly the items, but this could lead @@ -2808,7 +3107,7 @@ const char *npc_parse_shop(const char *w1, const char *w2, const char *w3, const struct npc_item_list *items = NULL; size_t items_count = 40; // Starting items size - char *p; + const char *p; int x, y, dir, m, i, class_; struct npc_data *nd; enum npc_subtype type; @@ -2926,7 +3225,8 @@ const char *npc_parse_shop(const char *w1, const char *w2, const char *w3, const return strchr(start,'\n');// continue } -void npc_convertlabel_db(struct npc_label_list* label_list, const char *filepath) { +static void npc_convertlabel_db(struct npc_label_list *label_list, const char *filepath) +{ int i; nullpo_retv(label_list); @@ -2958,7 +3258,8 @@ void npc_convertlabel_db(struct npc_label_list* label_list, const char *filepath } // Skip the contents of a script. -const char* npc_skip_script(const char* start, const char* buffer, const char* filepath, int *retval) { +static const char *npc_skip_script(const char *start, const char *buffer, const char *filepath, int *retval) +{ const char* p; int curly_count; @@ -3044,7 +3345,7 @@ const char* npc_skip_script(const char* start, const char* buffer, const char* f * (EXIT_FAILURE) status. May be NULL. * @return A pointer to the advanced buffer position. */ -const char *npc_parse_script(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int options, int *retval) +static const char *npc_parse_script(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int options, int *retval) { int x, y, dir = 0, m, xs = 0, ys = 0; // [Valaris] thanks to fov struct script_code *scriptroot; @@ -3164,7 +3465,7 @@ const char *npc_parse_script(const char *w1, const char *w2, const char *w3, con * * @param nd The NPC to register. */ -void npc_add_to_location(struct npc_data *nd) +static void npc_add_to_location(struct npc_data *nd) { nullpo_retv(nd); @@ -3188,7 +3489,7 @@ void npc_add_to_location(struct npc_data *nd) /** * Duplicates a script (@see npc_duplicate_sub) */ -bool npc_duplicate_script_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) +static bool npc_duplicate_script_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) { int i; bool retval = true; @@ -3238,7 +3539,7 @@ bool npc_duplicate_script_sub(struct npc_data *nd, const struct npc_data *snd, i /** * Duplicates a shop or cash shop (@see npc_duplicate_sub) */ -bool npc_duplicate_shop_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) +static bool npc_duplicate_shop_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) { nullpo_retr(false, nd); nullpo_retr(false, snd); @@ -3256,7 +3557,7 @@ bool npc_duplicate_shop_sub(struct npc_data *nd, const struct npc_data *snd, int /** * Duplicates a warp (@see npc_duplicate_sub) */ -bool npc_duplicate_warp_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) +static bool npc_duplicate_warp_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) { nullpo_retr(false, nd); nullpo_retr(false, snd); @@ -3288,7 +3589,7 @@ bool npc_duplicate_warp_sub(struct npc_data *nd, const struct npc_data *snd, int * @param options The NPC options. * @retval false if there were any issues while creating and validating the NPC. */ -bool npc_duplicate_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) +static bool npc_duplicate_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options) { nullpo_retr(false, nd); nullpo_retr(false, snd); @@ -3346,7 +3647,7 @@ bool npc_duplicate_sub(struct npc_data *nd, const struct npc_data *snd, int xs, * @remark * Only `NPO_ONINIT` is available trough the options argument. */ -const char *npc_parse_duplicate(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int options, int *retval) +static const char *npc_parse_duplicate(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int options, int *retval) { int x, y, dir, m, xs = -1, ys = -1; char srcname[128]; @@ -3438,7 +3739,7 @@ const char *npc_parse_duplicate(const char *w1, const char *w2, const char *w3, * @return success state. * @retval 0 in case of successful creation. */ -int npc_duplicate4instance(struct npc_data *snd, int16 m) +static int npc_duplicate4instance(struct npc_data *snd, int16 m) { char newname[NAME_LENGTH]; int dm = -1, im = -1, xs = -1, ys = -1; @@ -3494,7 +3795,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) } //Set mapcell CELL_NPC to trigger event later -void npc_setcells(struct npc_data* nd) +static void npc_setcells(struct npc_data *nd) { int16 m, x, y, xs, ys; int i,j; @@ -3528,7 +3829,7 @@ void npc_setcells(struct npc_data* nd) } } -int npc_unsetcells_sub(struct block_list *bl, va_list ap) +static int npc_unsetcells_sub(struct block_list *bl, va_list ap) { struct npc_data *nd = NULL; int id = va_arg(ap, int); @@ -3543,7 +3844,8 @@ int npc_unsetcells_sub(struct block_list *bl, va_list ap) return 1; } -void npc_unsetcells(struct npc_data* nd) { +static void npc_unsetcells(struct npc_data *nd) +{ int16 m, x, y, xs, ys; int i,j, x0, x1, y0, y1; @@ -3583,7 +3885,7 @@ void npc_unsetcells(struct npc_data* nd) { map->foreachinarea( npc->unsetcells_sub, m, x0, y0, x1, y1, BL_NPC, nd->bl.id ); } -void npc_movenpc(struct npc_data* nd, int16 x, int16 y) +static void npc_movenpc(struct npc_data *nd, int16 x, int16 y) { int16 m; nullpo_retv(nd); @@ -3602,7 +3904,7 @@ void npc_movenpc(struct npc_data* nd, int16 x, int16 y) /// /// @param nd Target npc /// @param newname New display name -void npc_setdisplayname(struct npc_data* nd, const char* newname) +static void npc_setdisplayname(struct npc_data *nd, const char *newname) { nullpo_retv(nd); nullpo_retv(newname); @@ -3616,7 +3918,8 @@ void npc_setdisplayname(struct npc_data* nd, const char* newname) /// /// @param nd Target npc /// @param class_ New display class -void npc_setclass(struct npc_data* nd, short class_) { +static void npc_setclass(struct npc_data *nd, short class_) +{ nullpo_retv(nd); if( nd->class_ == class_ ) @@ -3630,8 +3933,20 @@ void npc_setclass(struct npc_data* nd, short class_) { clif->spawn(&nd->bl);// fade in } +static void npc_refresh(struct npc_data *nd) +{ + nullpo_retv(nd); + + if (map->list[nd->bl.m].users) { + // using here CLR_TRICKDEAD because other flags show effects. + // probably need use other flag or other way to refresh npc. + clif->clearunit_area(&nd->bl, CLR_TRICKDEAD); // fade out + clif->spawn(&nd->bl); // fade in + } +} + // @commands (script based) -int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const char* message, const char* eventname) +static int npc_do_atcmd_event(struct map_session_data *sd, const char *command, const char *message, const char *eventname) { struct event_data* ev = (struct event_data*)strdb_get(npc->ev_db, eventname); struct npc_data *nd; @@ -3718,7 +4033,7 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c * (EXIT_FAILURE) status. May be NULL. * @return A pointer to the advanced buffer position. */ -const char *npc_parse_function(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) +static const char *npc_parse_function(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) { struct DBMap *func_db; struct DBData old_data; @@ -3772,7 +4087,7 @@ const char *npc_parse_function(const char *w1, const char *w2, const char *w3, c * Parse Mob 2 - Actually Spawns Mob * [Wizputer] *------------------------------------------*/ -void npc_parse_mob2(struct spawn_data* mobspawn) +static void npc_parse_mob2(struct spawn_data *mobspawn) { int i; @@ -3802,7 +4117,7 @@ void npc_parse_mob2(struct spawn_data* mobspawn) * (EXIT_FAILURE) status. May be NULL. * @return A pointer to the advanced buffer position. */ -const char *npc_parse_mob(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) +static const char *npc_parse_mob(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) { int num, class_, m,x,y,xs,ys, i,j; int mob_lv = -1, ai = -1, size = -1; @@ -3817,7 +4132,12 @@ const char *npc_parse_mob(const char *w1, const char *w2, const char *w3, const memset(&mobspawn, 0, sizeof(struct spawn_data)); - mobspawn.state.boss = (strcmp(w2,"boss_monster") == 0 ? 1 : 0); + if (strcmp(w2, "boss_monster") == 0) + mobspawn.state.boss = BTYPE_MVP; + else if (strcmp(w2, "miniboss_monster") == 0) + mobspawn.state.boss = BTYPE_BOSS; + else + mobspawn.state.boss = BTYPE_NONE; // w1=<map name>,<x>,<y>,<xs>,<ys> // w3=<mob name>{,<mob level>} @@ -3909,10 +4229,10 @@ const char *npc_parse_mob(const char *w1, const char *w2, const char *w3, const } //Use db names instead of the spawn file ones. - if(battle_config.override_mob_names==1) - strcpy(mobspawn.name,"--en--"); - else if (battle_config.override_mob_names==2) - strcpy(mobspawn.name,"--ja--"); + if (battle_config.override_mob_names == 1) + strcpy(mobspawn.name, DEFAULT_MOB_NAME); + else if (battle_config.override_mob_names == 2) + strcpy(mobspawn.name, DEFAULT_MOB_JNAME); else safestrncpy(mobspawn.name, mobname, sizeof(mobspawn.name)); @@ -3983,7 +4303,7 @@ const char *npc_parse_mob(const char *w1, const char *w2, const char *w3, const * * @see npc_parse_mapflag */ -void npc_parse_unknown_mapflag(const char *name, const char *w3, const char *w4, const char* start, const char* buffer, const char* filepath, int *retval) +static void npc_parse_unknown_mapflag(const char *name, const char *w3, const 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) @@ -4015,7 +4335,7 @@ void npc_parse_unknown_mapflag(const char *name, const char *w3, const char *w4, * (EXIT_FAILURE) status. May be NULL. * @return A pointer to the advanced buffer position. */ -const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) +static const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) { int16 m; char mapname[32]; @@ -4098,6 +4418,11 @@ const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, co ShowWarning("npc_parse_mapflag: You can't set PvP and GvG flags for the same map! Removing GvG flags from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer,start-buffer)); if (retval) *retval = EXIT_FAILURE; } + if (state && map->list[m].flag.cvc) { + map->list[m].flag.cvc = 0; + ShowWarning("npc_parse_mapflag: You can't set CvC and PvP flags for the same map! Removing CvC flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer, start-buffer)); + if (retval) *retval = EXIT_FAILURE; + } if( state && map->list[m].flag.battleground ) { map->list[m].flag.battleground = 0; ShowWarning("npc_parse_mapflag: You can't set PvP and BattleGround flags for the same map! Removing BattleGround flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer,start-buffer)); @@ -4150,6 +4475,11 @@ const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, co ShowWarning("npc_parse_mapflag: You can't set PvP and GvG flags for the same map! Removing PvP flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer,start-buffer)); if (retval) *retval = EXIT_FAILURE; } + if (state && map->list[m].flag.cvc) { + map->list[m].flag.cvc = 0; + ShowWarning("npc_parse_mapflag: You can't set CvC and GvG flags for the same map! Removing CvC flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer, start-buffer)); + if (retval) *retval = EXIT_FAILURE; + } if( state && map->list[m].flag.battleground ) { map->list[m].flag.battleground = 0; ShowWarning("npc_parse_mapflag: You can't set GvG and BattleGround flags for the same map! Removing BattleGround flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer,start-buffer)); @@ -4192,11 +4522,47 @@ const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, co ShowWarning("npc_parse_mapflag: You can't set GvG and BattleGround flags for the same map! Removing GvG flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer,start-buffer)); if (retval) *retval = EXIT_FAILURE; } + if (map->list[m].flag.cvc) { + map->list[m].flag.cvc = 0; + ShowWarning("npc_parse_mapflag: You can't set CvC and BattleGround flags for the same map! Removing CvC flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer, start-buffer)); + if (retval) *retval = EXIT_FAILURE; + } if( state && (zone = strdb_get(map->zone_db, MAP_ZONE_BG_NAME)) != NULL && map->list[m].zone != zone ) { map->zone_change(m,zone,start,buffer,filepath); } } + else if (!strcmpi(w3, "cvc")) { + struct map_zone_data *zone; + + map->list[m].flag.cvc = state; + if (state && (map->list[m].flag.gvg || map->list[m].flag.gvg_dungeon || map->list[m].flag.gvg_castle)) { + map->list[m].flag.gvg = 0; + map->list[m].flag.gvg_dungeon = 0; + map->list[m].flag.gvg_castle = 0; + ShowWarning("npc_parse_mapflag: You can't set GvG and CvC flags for the same map! Removing GvG flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer, start-buffer)); + if (retval) { + *retval = EXIT_FAILURE; + } + } + if (state && map->list[m].flag.pvp) { + map->list[m].flag.pvp = 0; + ShowWarning("npc_parse_mapflag: You can't set PvP and CvC flags for the same map! Removing PvP flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer, start-buffer)); + if (retval) { + *retval = EXIT_FAILURE; + } + } + if (state && map->list[m].flag.battleground) { + map->list[m].flag.battleground = 0; + ShowWarning("npc_parse_mapflag: You can't set CvC and BattleGround flags for the same map! Removing BattleGround flag from %s in file '%s', line '%d'.\n", map->list[m].name, filepath, strline(buffer, start-buffer)); + if (retval) { + *retval = EXIT_FAILURE; + } + } + if (state && (zone = strdb_get(map->zone_db, MAP_ZONE_CVC_NAME)) != NULL && map->list[m].zone != zone) { + map->zone_change(m, zone, start, buffer, filepath); + } + } else if (!strcmpi(w3,"noexppenalty")) map->list[m].flag.noexppenalty=state; else if (!strcmpi(w3,"nozenypenalty")) @@ -4274,6 +4640,8 @@ const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, co map->list[m].flag.reset=state; else if (!strcmpi(w3,"notomb")) map->list[m].flag.notomb=state; + else if (!strcmpi(w3, "noautoloot")) + map->list[m].flag.noautoloot = state; else if (!strcmpi(w3,"adjust_unit_duration")) { int skill_id, k; char skill_name[MAP_ZONE_MAPFLAG_LENGTH], modifier[MAP_ZONE_MAPFLAG_LENGTH]; @@ -4422,6 +4790,10 @@ const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, co map->list[m].flag.nocashshop = (state) ? 1 : 0; } else if (!strcmpi(w3,"noviewid")) { map->list[m].flag.noviewid = (state) ? atoi(w4) : 0; + } else if (!strcmpi(w3, "pairship_startable")) { + map->list[m].flag.pairship_startable = (state) ? 1 : 0; + } else if (!strcmpi(w3, "pairship_endable")) { + map->list[m].flag.pairship_endable = (state) ? 1 : 0; } else { npc->parse_unknown_mapflag(mapname, w3, w4, start, buffer, filepath, retval); } @@ -4446,7 +4818,7 @@ const char *npc_parse_mapflag(const char *w1, const char *w2, const char *w3, co * (EXIT_FAILURE) status. May be NULL. * @return A pointer to the advanced buffer position. */ -const char *npc_parse_unknown_object(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) +static const char *npc_parse_unknown_object(const char *w1, const char *w2, const char *w3, const char *w4, const char *start, const char *buffer, const char *filepath, int *retval) { nullpo_retr(start, 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); @@ -4464,7 +4836,8 @@ const char *npc_parse_unknown_object(const char *w1, const char *w2, const char * @retval EXIT_SUCCESS if filepath was loaded correctly. * @retval EXIT_FAILURE if there were errors/warnings when loading filepath. */ -int npc_parsesrcfile(const char* filepath, bool runOnInit) { +static int npc_parsesrcfile(const char *filepath, bool runOnInit) +{ int success = EXIT_SUCCESS; int16 m, x, y; int lines = 0; @@ -4634,7 +5007,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { { p = npc->parse_duplicate(w1,w2,w3,w4, p, buffer, filepath, (runOnInit?NPO_ONINIT:NPO_NONE), &success); } - else if( (strcmp(w2,"monster") == 0 || strcmp(w2,"boss_monster") == 0) ) + else if (strcmp(w2,"monster") == 0 || strcmp(w2,"boss_monster") == 0 || strcmp(w2,"miniboss_monster") == 0) { p = npc->parse_mob(w1, w2, w3, w4, p, buffer, filepath, &success); } @@ -4652,7 +5025,7 @@ int npc_parsesrcfile(const char* filepath, bool runOnInit) { return success; } -int npc_script_event(struct map_session_data* sd, enum npce_event type) +static int npc_script_event(struct map_session_data *sd, enum npce_event type) { int i; if (type == NPCE_MAX) @@ -4666,7 +5039,7 @@ int npc_script_event(struct map_session_data* sd, enum npce_event type) return i; } -void npc_read_event_script(void) +static void npc_read_event_script(void) { int i; struct { @@ -4729,7 +5102,7 @@ void npc_read_event_script(void) /** * @see DBApply */ -int npc_path_db_clear_sub(union DBKey key, struct DBData *data, va_list args) +static int npc_path_db_clear_sub(union DBKey key, struct DBData *data, va_list args) { struct npc_path_data *npd = DB->data2ptr(data); nullpo_ret(npd); @@ -4741,7 +5114,7 @@ int npc_path_db_clear_sub(union DBKey key, struct DBData *data, va_list args) /** * @see DBApply */ -int npc_ev_label_db_clear_sub(union DBKey key, struct DBData *data, va_list args) +static int npc_ev_label_db_clear_sub(union DBKey key, struct DBData *data, va_list args) { struct linkdb_node **label_linkdb = DB->data2ptr(data); linkdb_final(label_linkdb); // linked data (struct event_data*) is freed when clearing ev_db @@ -4752,7 +5125,8 @@ int npc_ev_label_db_clear_sub(union DBKey key, struct DBData *data, va_list args * Main npc file processing * @param npc_min Minimum npc id - used to know how many NPCs were loaded **/ -void npc_process_files( int npc_min ) { +static void npc_process_files(int npc_min) +{ struct npc_src_list *file; // Current file ShowStatus("Loading NPCs...\r"); @@ -4772,7 +5146,8 @@ void npc_process_files( int npc_min ) { } //Clear then reload npcs files -int npc_reload(void) { +static int npc_reload(void) +{ int npc_new_min = npc->npc_id; struct s_mapiterator* iter; struct block_list* bl; @@ -4835,10 +5210,12 @@ int npc_reload(void) { npc->npc_mob = npc->npc_cache_mob = npc->npc_delay_mob = 0; // reset mapflags + map->zone_reload(); map->flags_init(); // Reprocess npc files and reload constants itemdb->name_constants(); + clan->set_constants(); npc_process_files( npc_new_min ); instance->reload(); @@ -4855,6 +5232,7 @@ int npc_reload(void) { // OnInit -> OnInterIfInit -> OnInterIfInitOnce -> OnAgitInit -> OnAgitInit2 npc->event_do_oninit( true ); npc->market_fromsql(); + npc->barter_fromsql(); // Execute rest of the startup events if connected to char-server. [Lance] // Executed when connection is established with char-server in chrif_connectack if( !intif->CheckForCharServer() ) { @@ -4870,7 +5248,7 @@ int npc_reload(void) { } //Unload all npc in the given file -bool npc_unloadfile(const char *filepath) +static bool npc_unloadfile(const char *filepath) { struct DBIterator *iter = db_iterator(npc->name_db); struct npc_data* nd = NULL; @@ -4894,7 +5272,8 @@ bool npc_unloadfile(const char *filepath) return found; } -void do_clear_npc(void) { +static void do_clear_npc(void) +{ db_clear(npc->name_db); db_clear(npc->ev_db); npc->ev_label_db->clear(npc->ev_label_db, npc->ev_label_db_clear_sub); @@ -4903,7 +5282,8 @@ void do_clear_npc(void) { /*========================================== * Destructor *------------------------------------------*/ -int do_final_npc(void) { +static int do_final_npc(void) +{ db_destroy(npc->ev_db); npc->ev_label_db->destroy(npc->ev_label_db, npc->ev_label_db_clear_sub); db_destroy(npc->name_db); @@ -4914,7 +5294,8 @@ int do_final_npc(void) { return 0; } -void npc_debug_warps_sub(struct npc_data* nd) { +static void npc_debug_warps_sub(struct npc_data *nd) +{ int16 m; nullpo_retv(nd); @@ -4942,7 +5323,8 @@ void npc_debug_warps_sub(struct npc_data* nd) { } } -static void npc_debug_warps(void) { +static void npc_debug_warps(void) +{ int16 m, i; for (m = 0; m < map->count; m++) for (i = 0; i < map->list[m].npc_num; i++) @@ -4952,7 +5334,8 @@ static void npc_debug_warps(void) { /*========================================== * npc initialization *------------------------------------------*/ -int do_init_npc(bool minimal) { +static int do_init_npc(bool minimal) +{ int i; unit->init_ud(&npc->base_ud); @@ -4966,7 +5349,6 @@ int do_init_npc(bool minimal) { npc_viewdb[i].class = i; for( i = MAX_NPC_CLASS2_START; i < MAX_NPC_CLASS2_END; i++ ) npc_viewdb2[i - MAX_NPC_CLASS2_START].class = i; - npc->ev_db = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, EVENT_NAME_LENGTH); npc->ev_label_db = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, NAME_LENGTH); npc->name_db = strdb_alloc(DB_OPT_BASE, NAME_LENGTH); @@ -4979,6 +5361,7 @@ int do_init_npc(bool minimal) { // Should be loaded before npc processing, otherwise labels could overwrite constant values // and lead to undefined behavior [Panikon] itemdb->name_constants(); + clan->set_constants(); if (!minimal) { npc->timer_event_ers = ers_new(sizeof(struct timer_event_data),"clif.c::timer_event_ers",ERS_OPT_NONE); @@ -5023,7 +5406,8 @@ int do_init_npc(bool minimal) { return 0; } -void npc_defaults(void) { +void npc_defaults(void) +{ npc = &npc_s; npc->npc_id = START_NPC_NUM; @@ -5155,10 +5539,16 @@ void npc_defaults(void) { npc->trader_pay = npc_trader_pay; npc->trader_update = npc_trader_update; npc->market_buylist = npc_market_buylist; + npc->barter_buylist = npc_barter_buylist; npc->trader_open = npc_trader_open; npc->market_fromsql = npc_market_fromsql; npc->market_tosql = npc_market_tosql; npc->market_delfromsql = npc_market_delfromsql; npc->market_delfromsql_sub = npc_market_delfromsql_sub; + npc->barter_fromsql = npc_barter_fromsql; + npc->barter_tosql = npc_barter_tosql; + npc->barter_delfromsql = npc_barter_delfromsql; + npc->barter_delfromsql_sub = npc_barter_delfromsql_sub; npc->db_checkid = npc_db_checkid; + npc->refresh = npc_refresh; } |