diff options
Diffstat (limited to 'src/map/npc.c')
-rw-r--r-- | src/map/npc.c | 142 |
1 files changed, 81 insertions, 61 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index 16789b726..a79062c77 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -4,9 +4,37 @@ #define HERCULES_CORE -#include "../config/core.h" // NPC_SECURE_TIMEOUT_INPUT, NPC_SECURE_TIMEOUT_MENU, NPC_SECURE_TIMEOUT_NEXT, SECURE_NPCTIMEOUT, SECURE_NPCTIMEOUT_INTERVAL +#include "config/core.h" // NPC_SECURE_TIMEOUT_INPUT, NPC_SECURE_TIMEOUT_MENU, NPC_SECURE_TIMEOUT_NEXT, SECURE_NPCTIMEOUT, SECURE_NPCTIMEOUT_INTERVAL #include "npc.h" +#include "map/battle.h" +#include "map/chat.h" +#include "map/clif.h" +#include "map/guild.h" +#include "map/instance.h" +#include "map/intif.h" +#include "map/itemdb.h" +#include "map/log.h" +#include "map/map.h" +#include "map/mob.h" +#include "map/pc.h" +#include "map/pet.h" +#include "map/script.h" +#include "map/skill.h" +#include "map/status.h" +#include "map/unit.h" +#include "common/HPM.h" +#include "common/cbasetypes.h" +#include "common/db.h" +#include "common/ers.h" +#include "common/malloc.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/socket.h" +#include "common/strlib.h" +#include "common/timer.h" +#include "common/utils.h" + #include <errno.h> #include <math.h> #include <stdio.h> @@ -14,33 +42,6 @@ #include <string.h> #include <time.h> -#include "battle.h" -#include "chat.h" -#include "clif.h" -#include "instance.h" -#include "intif.h" -#include "itemdb.h" -#include "log.h" -#include "map.h" -#include "mob.h" -#include "pc.h" -#include "pet.h" -#include "script.h" -#include "skill.h" -#include "status.h" -#include "unit.h" -#include "../common/HPM.h" -#include "../common/cbasetypes.h" -#include "../common/db.h" -#include "../common/ers.h" -#include "../common/malloc.h" -#include "../common/nullpo.h" -#include "../common/showmsg.h" -#include "../common/socket.h" -#include "../common/strlib.h" -#include "../common/timer.h" -#include "../common/utils.h" - struct npc_interface npc_s; static int npc_id=START_NPC_NUM; @@ -62,34 +63,52 @@ static struct view_data npc_viewdb2[MAX_NPC_CLASS2_END-MAX_NPC_CLASS2_START]; /* for speedup */ unsigned int npc_market_qty[MAX_INVENTORY]; -static struct script_event_s -{ +static struct script_event_s { //Holds pointers to the commonly executed scripts for speedup. [Skotlex] struct event_data *event[UCHAR_MAX]; const char *event_name[UCHAR_MAX]; uint8 event_count; } script_event[NPCE_MAX]; -struct view_data* npc_get_viewdata(int class_) +/** + * Returns the viewdata for normal npc classes. + * @param class_ The NPC class ID. + * @return The viewdata, or NULL if the ID is invalid. + */ +struct view_data *npc_get_viewdata(int class_) { - //Returns the viewdata for normal npc classes. - if( class_ == INVISIBLE_CLASS ) + if (class_ == INVISIBLE_CLASS) return &npc_viewdb[0]; - if (npc->db_checkid(class_) || class_ == WARP_CLASS){ - if( class_ > MAX_NPC_CLASS2_START ){ - return &npc_viewdb2[class_-MAX_NPC_CLASS2_START]; - }else{ + if (npc->db_checkid(class_)) { + if (class_ < MAX_NPC_CLASS) { return &npc_viewdb[class_]; + } else if (class_ >= MAX_NPC_CLASS2_START && class_ < MAX_NPC_CLASS2_END) { + return &npc_viewdb2[class_-MAX_NPC_CLASS2_START]; } } return NULL; } -//Checks if a given id is a valid npc id. [Skotlex] -//Since new npcs are added all the time, the max valid value is the one before the first mob (Scorpion = 1001) +/** + * Checks if a given id is a valid npc id. + * + * Since new npcs are added all the time, the max valid value is the one before the first mob (Scorpion = 1001) + * + * @param id The NPC ID to validate. + * @return Whether the value is a valid ID. + */ bool npc_db_checkid(int id) { - return ((id >= 46 && id <= 125) || id == HIDDEN_WARP_CLASS || (id > 400 && id < MAX_NPC_CLASS) || id == INVISIBLE_CLASS || (id > MAX_NPC_CLASS2_START && id < MAX_NPC_CLASS2_END)); + if (id >= WARP_CLASS && id <= 125) // First subrange + return true; + if (id == HIDDEN_WARP_CLASS || id == INVISIBLE_CLASS) // Special IDs not included in the valid ranges + return true; + if (id > 400 && id < MAX_NPC_CLASS) // Second subrange + return true; + if (id >= MAX_NPC_CLASS2_START && id < MAX_NPC_CLASS2_END) // Second range + return true; + // Anything else is invalid + return false; } /// Returns a new npc id that isn't being used in id_db. @@ -185,7 +204,7 @@ int npc_enable_sub(struct block_list *bl, va_list ap) if (sd->npc_id != 0) return 0; - pc_stop_walking(sd,1); + pc_stop_walking(sd, STOPWALKING_FLAG_FIXPOS); npc->click(sd,nd); } } @@ -1565,8 +1584,8 @@ bool npc_trader_open(struct map_session_data *sd, struct npc_data *nd) { } /* nothing to display, no items available */ - if( i == nd->u.scr.shop->items ) { - clif->colormes(sd->fd,COLOR_RED, msg_sd(sd,881)); + if (i == nd->u.scr.shop->items) { + clif->messagecolor_self(sd->fd, COLOR_RED, msg_sd(sd,881)); return false; } @@ -2038,19 +2057,18 @@ int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_li script->setarray_pc(sd, "@sold_nameid", i, (void*)(intptr_t)sd->status.inventory[idx].nameid, &key_nameid); script->setarray_pc(sd, "@sold_quantity", i, (void*)(intptr_t)item_list[i*2+1], &key_amount); - - if (itemdb->isequip(sd->status.inventory[idx].nameid)) { - // process equipment based information into the arrays - script->setarray_pc(sd, "@sold_refine", i, (void*)(intptr_t)sd->status.inventory[idx].refine, &key_refine); - script->setarray_pc(sd, "@sold_attribute", i, (void*)(intptr_t)sd->status.inventory[idx].attribute, &key_attribute); - script->setarray_pc(sd, "@sold_identify", i, (void*)(intptr_t)sd->status.inventory[idx].identify, &key_identify); - - for (j = 0; j < MAX_SLOTS; j++) { - // store each of the cards from the equipment in the array - snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1); - script->setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card[j]); - } + + // process item based information into the arrays + script->setarray_pc(sd, "@sold_refine", i, (void*)(intptr_t)sd->status.inventory[idx].refine, &key_refine); + script->setarray_pc(sd, "@sold_attribute", i, (void*)(intptr_t)sd->status.inventory[idx].attribute, &key_attribute); + script->setarray_pc(sd, "@sold_identify", i, (void*)(intptr_t)sd->status.inventory[idx].identify, &key_identify); + + for (j = 0; j < MAX_SLOTS; j++) { + // store each of the cards/special info from the item in the array + snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1); + script->setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card[j]); } + } // invoke event @@ -2127,7 +2145,7 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list) } } - pc->delitem(sd, idx, amount, 0, 6, LOG_TYPE_NPC); + pc->delitem(sd, idx, amount, 0, DELITEM_SOLD, LOG_TYPE_NPC); } if( z > MAX_ZENY ) @@ -3537,7 +3555,7 @@ const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* st return strchr(start, '\n'); } - if (mobspawn.state.ai > 4 && ai != -1) { + if (mobspawn.state.ai >= AI_MAX && ai != -1) { ShowError("npc_parse_mob: Invalid ai %d for mob ID %d in file '%s', line '%d'.\n", mobspawn.state.ai, class_, filepath, strline(buffer, start - buffer)); if (retval) *retval = EXIT_FAILURE; return strchr(start, '\n'); @@ -3560,7 +3578,7 @@ const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* st mobspawn.level = mob_lv; if (size > 0 && size <= 2) mobspawn.state.size = size; - if (ai > 0 && ai <= 4) + if (ai > AI_NONE && ai < AI_MAX) mobspawn.state.ai = ai; if (mobspawn.num > 1 && battle_config.mob_count_rate != 100) { @@ -3812,13 +3830,14 @@ const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char } else if (!strcmpi(w3,"battleground")) { struct map_zone_data *zone; - if( state ) { - if( sscanf(w4, "%d", &state) == 1 ) + if (state) { + if (w4 && sscanf(w4, "%d", &state) == 1) map->list[m].flag.battleground = state; else map->list[m].flag.battleground = 1; // Default value - } else + } else { map->list[m].flag.battleground = 0; + } if( map->list[m].flag.battleground && map->list[m].flag.pvp ) { map->list[m].flag.pvp = 0; @@ -4624,6 +4643,7 @@ int do_init_npc(bool minimal) { } if( script->lang_export_fp ) { + ShowInfo("Lang exported to '%s'\n",script->lang_export_file); fclose(script->lang_export_fp); script->lang_export_fp = NULL; } |