diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-07-17 02:57:06 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-07-19 21:53:40 +0300 |
commit | 2f80262667ece77ceb69de42b2cc4ce84aed6881 (patch) | |
tree | 326d86dae61a32bbd5a51ad9f2afdf2c91aba07a /src/map/mob.c | |
parent | b67565957203e5efae25b1a29d072c1b954ce394 (diff) | |
download | hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.tar.gz hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.tar.bz2 hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.tar.xz hercules-2f80262667ece77ceb69de42b2cc4ce84aed6881.zip |
Add new constant MAX_ITEM_ID for maximum allowed item id.
For clients older than 2018-07-04 Re maximum supported and enabled id is 65535 (0xffff).
For newer clients miximum id is 2147483648. Enabled by default 131072 (0x20000)
Diffstat (limited to 'src/map/mob.c')
-rw-r--r-- | src/map/mob.c | 75 |
1 files changed, 64 insertions, 11 deletions
diff --git a/src/map/mob.c b/src/map/mob.c index 403e3a2f2..0dbff9211 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -88,6 +88,7 @@ struct item_drop_ratio { int mob_id[MAX_ITEMRATIO_MOBS]; }; static struct item_drop_ratio *item_drop_ratio_db[MAX_ITEMDB]; +static struct DBMap *item_drop_ratio_other_db = NULL; static struct eri *item_drop_ers; //For loot drops delay structures. static struct eri *item_drop_list_ers; @@ -3791,6 +3792,28 @@ static unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned shor return (unsigned int)cap_value(rate,rate_min,rate_max); } +static struct item_drop_ratio *mob_get_item_drop_ratio(int nameid) +{ + Assert_retr(NULL, nameid > 0); + if (nameid < ARRAYLENGTH(item_drop_ratio_db)) { + return item_drop_ratio_db[nameid]; + } else { + return (struct item_drop_ratio *)idb_get(item_drop_ratio_other_db, nameid); + } +} + +static void mob_set_item_drop_ratio(int nameid, struct item_drop_ratio *ratio) +{ + Assert_retv(nameid > 0); + if (nameid < ARRAYLENGTH(item_drop_ratio_db)) { + Assert_retv(item_drop_ratio_db[nameid] == NULL); + item_drop_ratio_db[nameid] = ratio; + } else { + Assert_retv(idb_get(item_drop_ratio_other_db, nameid) == NULL); + idb_put(item_drop_ratio_other_db, nameid, ratio); + } +} + /** * Check if global item drop rate is overridden for given item * in db/mob_item_ratio.txt @@ -3800,16 +3823,19 @@ static unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned shor */ static void item_dropratio_adjust(int nameid, int mob_id, int *rate_adjust) { + struct item_drop_ratio *dropRatio; nullpo_retv(rate_adjust); - if( item_drop_ratio_db[nameid] ) { - if( item_drop_ratio_db[nameid]->mob_id[0] ) { // only for listed mobs + + dropRatio = mob->get_item_drop_ratio(nameid); + if (dropRatio) { + if (dropRatio->mob_id[0] ) { // only for listed mobs int i; - ARR_FIND(0, MAX_ITEMRATIO_MOBS, i, item_drop_ratio_db[nameid]->mob_id[i] == mob_id); - if(i < MAX_ITEMRATIO_MOBS) // found - *rate_adjust = item_drop_ratio_db[nameid]->drop_ratio; + ARR_FIND(0, MAX_ITEMRATIO_MOBS, i, dropRatio->mob_id[i] == mob_id); + if (i < MAX_ITEMRATIO_MOBS) // found + *rate_adjust = dropRatio->drop_ratio; } else // for all mobs - *rate_adjust = item_drop_ratio_db[nameid]->drop_ratio; + *rate_adjust = dropRatio->drop_ratio; } } @@ -5142,6 +5168,7 @@ static bool mob_readdb_race2(char *fields[], int columns, int current) static bool mob_readdb_itemratio(char *str[], int columns, int current) { int nameid, ratio, i; + struct item_drop_ratio *dropRatio; nullpo_retr(false, str); nameid = atoi(str[0]); @@ -5154,12 +5181,15 @@ static bool mob_readdb_itemratio(char *str[], int columns, int current) ratio = atoi(str[1]); - if(item_drop_ratio_db[nameid] == NULL) - item_drop_ratio_db[nameid] = (struct item_drop_ratio*)aCalloc(1, sizeof(struct item_drop_ratio)); + dropRatio = mob->get_item_drop_ratio(nameid); + if (dropRatio == NULL) { + dropRatio = (struct item_drop_ratio*)aCalloc(1, sizeof(struct item_drop_ratio)); + mob->set_item_drop_ratio(nameid, dropRatio); + } - item_drop_ratio_db[nameid]->drop_ratio = ratio; - for(i = 0; i < columns-2; i++) - item_drop_ratio_db[nameid]->mob_id[i] = atoi(str[i+2]); + dropRatio->drop_ratio = ratio; + for (i = 0; i < columns - 2; i++) + dropRatio->mob_id[i] = atoi(str[i + 2]); return true; } @@ -5183,6 +5213,19 @@ static void mob_load(bool minimal) sv->readdb(map->db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, mob->readdb_race2); } +/** + * @see DBApply + */ +static int mob_final_ratio_sub(union DBKey key, struct DBData *data, va_list ap) +{ + struct item_drop_ratio *ratio = DB->data2ptr(data); + + if (ratio) + aFree(ratio); + + return 0; +} + static void mob_reload(void) { int i; @@ -5201,6 +5244,7 @@ static void mob_reload(void) item_drop_ratio_db[i] = NULL; } } + mob->item_drop_ratio_other_db->clear(mob->item_drop_ratio_other_db, mob->final_ratio_sub); mob->load(false); } @@ -5291,6 +5335,8 @@ static int do_final_mob(void) item_drop_ratio_db[i] = NULL; } } + mob->item_drop_ratio_other_db->clear(mob->item_drop_ratio_other_db, mob->final_ratio_sub); + db_destroy(mob->item_drop_ratio_other_db); ers_destroy(item_drop_ers); ers_destroy(item_drop_list_ers); return 0; @@ -5334,6 +5380,10 @@ void mob_defaults(void) memcpy(mob->splendide, mob_splendide, sizeof(mob->splendide)); memcpy(mob->mora, mob_mora, sizeof(mob->mora)); + item_drop_ratio_other_db = idb_alloc(DB_OPT_BASE); + mob->item_drop_ratio_db = item_drop_ratio_db; + mob->item_drop_ratio_other_db = item_drop_ratio_other_db; + /* */ mob->reload = mob_reload; mob->init = do_init_mob; @@ -5438,6 +5488,9 @@ void mob_defaults(void) mob->readdb_race2 = mob_readdb_race2; mob->readdb_itemratio = mob_readdb_itemratio; mob->load = mob_load; + mob->get_item_drop_ratio = mob_get_item_drop_ratio; + mob->set_item_drop_ratio = mob_set_item_drop_ratio; + mob->final_ratio_sub = mob_final_ratio_sub; mob->clear_spawninfo = mob_clear_spawninfo; mob->destroy_mob_db = mob_destroy_mob_db; mob->skill_db_libconfig = mob_skill_db_libconfig; |