Cleaned up map data checks (#3405)
* Fixes #3398 and fixes #3402. * Sped up pc_isUseitem, pc_setpos, and pc_dead map data checks. Thanks to @uddevil!
This commit is contained in:
parent
a5af358bf7
commit
bde33e762c
@ -4,9 +4,9 @@
|
||||
#ifndef UTILILITIES_HPP
|
||||
#define UTILILITIES_HPP
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "cbasetypes.hpp"
|
||||
@ -28,7 +28,7 @@ namespace rathena {
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a key-value pair and return the key value
|
||||
* Find a key-value pair and return the key value as a reference
|
||||
* @param map: Map to search through
|
||||
* @param key: Key wanted
|
||||
* @return Key value on success or nullptr on failure
|
||||
@ -60,7 +60,7 @@ namespace rathena {
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a key-value pair and return the key value
|
||||
* Find a key-value pair and return the key value as a reference
|
||||
* @param map: Unordered Map to search through
|
||||
* @param key: Key wanted
|
||||
* @return Key value on success or nullptr on failure
|
||||
|
@ -2760,7 +2760,10 @@ int map_delinstancemap(int m)
|
||||
aFree(mapdata->block);
|
||||
aFree(mapdata->block_mob);
|
||||
map_free_questinfo(m);
|
||||
mapdata->flag.clear();
|
||||
mapdata->drop_list.clear();
|
||||
mapdata->damage_adjust = {};
|
||||
mapdata->skill_damage.clear();
|
||||
|
||||
mapindex_removemap( mapdata->index );
|
||||
map_removemapdb(mapdata);
|
||||
@ -3546,6 +3549,7 @@ void map_flags_init(void){
|
||||
struct map_data *mapdata = &map[i];
|
||||
union u_mapflag_args args = {};
|
||||
|
||||
mapdata->flag.reserve(MF_MAX); // Reserve the bucket size
|
||||
args.flag_val = 100;
|
||||
|
||||
// additional mapflag data
|
||||
|
@ -4882,7 +4882,10 @@ bool pc_isUseitem(struct map_session_data *sd,int n)
|
||||
return false;
|
||||
if (pc_has_permission(sd,PC_PERM_ITEM_UNCONDITIONAL))
|
||||
return true;
|
||||
if(map_getmapflag(sd->bl.m, MF_NOITEMCONSUMPTION)) //consumable but mapflag prevent it
|
||||
|
||||
struct map_data *mapdata = map_getmapdata(sd->bl.m);
|
||||
|
||||
if(mapdata->flag[MF_NOITEMCONSUMPTION]) //consumable but mapflag prevent it
|
||||
return false;
|
||||
//Prevent mass item usage. [Skotlex]
|
||||
if( DIFF_TICK(sd->canuseitem_tick,gettick()) > 0 ||
|
||||
@ -4900,14 +4903,14 @@ bool pc_isUseitem(struct map_session_data *sd,int n)
|
||||
return false; // You cannot use this item while storage is open.
|
||||
}
|
||||
|
||||
if (item->flag.dead_branch && (map_getmapflag(sd->bl.m, MF_NOBRANCH) || map_flag_gvg2(sd->bl.m)))
|
||||
if (item->flag.dead_branch && (mapdata->flag[MF_NOBRANCH] || mapdata_flag_gvg2(mapdata)))
|
||||
return false;
|
||||
|
||||
switch( nameid ) {
|
||||
case ITEMID_WING_OF_FLY:
|
||||
case ITEMID_GIANT_FLY_WING:
|
||||
case ITEMID_N_FLY_WING:
|
||||
if( map_getmapflag(sd->bl.m, MF_NOTELEPORT) || map_flag_gvg2(sd->bl.m) ) {
|
||||
if( mapdata->flag[MF_NOTELEPORT] || mapdata_flag_gvg2(mapdata) ) {
|
||||
clif_skill_teleportmessage(sd,0);
|
||||
return false;
|
||||
}
|
||||
@ -4948,7 +4951,7 @@ bool pc_isUseitem(struct map_session_data *sd,int n)
|
||||
clif_displaymessage(sd->fd, msg_txt(sd,663));
|
||||
return false;
|
||||
}
|
||||
if( map_getmapflag(sd->bl.m, MF_NORETURN) && nameid != ITEMID_WING_OF_FLY && nameid != ITEMID_GIANT_FLY_WING && nameid != ITEMID_N_FLY_WING )
|
||||
if( mapdata->flag[MF_NORETURN] && nameid != ITEMID_WING_OF_FLY && nameid != ITEMID_GIANT_FLY_WING && nameid != ITEMID_N_FLY_WING )
|
||||
return false;
|
||||
break;
|
||||
case ITEMID_MERCENARY_RED_POTION:
|
||||
@ -4967,7 +4970,7 @@ bool pc_isUseitem(struct map_session_data *sd,int n)
|
||||
break;
|
||||
|
||||
case ITEMID_NEURALIZER:
|
||||
if( !map_getmapflag(sd->bl.m, MF_RESET) )
|
||||
if( !mapdata->flag[MF_RESET] )
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
@ -5477,8 +5480,6 @@ int pc_steal_coin(struct map_session_data *sd,struct block_list *target)
|
||||
*------------------------------------------*/
|
||||
enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype)
|
||||
{
|
||||
int16 m;
|
||||
|
||||
nullpo_retr(SETPOS_OK,sd);
|
||||
|
||||
if( !mapindex || !mapindex_id2name(mapindex) ) {
|
||||
@ -5494,8 +5495,7 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
|
||||
pc_setrestartvalue(sd,1);
|
||||
}
|
||||
|
||||
m = map_mapindex2mapid(mapindex);
|
||||
|
||||
int16 m = map_mapindex2mapid(mapindex);
|
||||
struct map_data *mapdata = map_getmapdata(m);
|
||||
|
||||
sd->state.changemap = (sd->mapindex != mapindex);
|
||||
@ -5555,7 +5555,7 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
|
||||
if (sd->regen.state.gc)
|
||||
sd->regen.state.gc = 0;
|
||||
// make sure vending is allowed here
|
||||
if (sd->state.vending && map_getmapflag(m, MF_NOVENDING)) {
|
||||
if (sd->state.vending && mapdata->flag[MF_NOVENDING]) {
|
||||
clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
|
||||
vending_closevending(sd);
|
||||
}
|
||||
@ -5638,7 +5638,7 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
|
||||
sd->bl.x = sd->ud.to_x = x;
|
||||
sd->bl.y = sd->ud.to_y = y;
|
||||
|
||||
if( sd->status.guild_id > 0 && map_getmapflag(m, MF_GVG_CASTLE) )
|
||||
if( sd->status.guild_id > 0 && mapdata->flag[MF_GVG_CASTLE] )
|
||||
{ // Increased guild castle regen [Valaris]
|
||||
struct guild_castle *gc = guild_mapindex2gc(sd->mapindex);
|
||||
if(gc && gc->guild_id == sd->status.guild_id)
|
||||
@ -5701,11 +5701,11 @@ char pc_randomwarp(struct map_session_data *sd, clr_type type)
|
||||
|
||||
nullpo_ret(sd);
|
||||
|
||||
if (map_getmapflag(sd->bl.m, MF_NOTELEPORT)) //Teleport forbidden
|
||||
return 3;
|
||||
|
||||
struct map_data *mapdata = map_getmapdata(sd->bl.m);
|
||||
|
||||
if (mapdata->flag[MF_NOTELEPORT]) //Teleport forbidden
|
||||
return 3;
|
||||
|
||||
do {
|
||||
x = rnd()%(mapdata->xs-2)+1;
|
||||
y = rnd()%(mapdata->ys-2)+1;
|
||||
@ -7743,6 +7743,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
{
|
||||
int i=0,k=0;
|
||||
unsigned int tick = gettick();
|
||||
struct map_data *mapdata = map_getmapdata(sd->bl.m);
|
||||
|
||||
// Activate Steel body if a super novice dies at 99+% exp [celest]
|
||||
// Super Novices have no kill or die functions attached when saved by their angel
|
||||
@ -7757,7 +7758,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
if(battle_config.pc_invincible_time)
|
||||
pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
|
||||
sc_start(&sd->bl,&sd->bl,status_skill2sc(MO_STEELBODY),100,5,skill_get_time(MO_STEELBODY,5));
|
||||
if(map_flag_gvg2(sd->bl.m))
|
||||
if(mapdata_flag_gvg2(mapdata))
|
||||
pc_respawn_timer(INVALID_TIMER, gettick(), sd->bl.id, 0);
|
||||
return 0;
|
||||
}
|
||||
@ -7778,7 +7779,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
|
||||
if(sd->status.pet_id > 0 && sd->pd) {
|
||||
struct pet_data *pd = sd->pd;
|
||||
if( !map_getmapflag(sd->bl.m, MF_NOEXPPENALTY) ) {
|
||||
if( !mapdata->flag[MF_NOEXPPENALTY] ) {
|
||||
pet_set_intimate(pd, pd->pet.intimate - pd->get_pet_db()->die);
|
||||
if( pd->pet.intimate < 0 )
|
||||
pd->pet.intimate = 0;
|
||||
@ -7900,7 +7901,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
}
|
||||
|
||||
if(battle_config.bone_drop==2
|
||||
|| (battle_config.bone_drop==1 && map_getmapflag(sd->bl.m, MF_PVP)))
|
||||
|| (battle_config.bone_drop==1 && mapdata->flag[MF_PVP]))
|
||||
{
|
||||
struct item item_tmp;
|
||||
memset(&item_tmp,0,sizeof(item_tmp));
|
||||
@ -7919,8 +7920,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
// changed penalty options, added death by player if pk_mode [Valaris]
|
||||
if(battle_config.death_penalty_type
|
||||
&& (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE // only novices will receive no penalty
|
||||
&& !map_getmapflag(sd->bl.m, MF_NOEXPPENALTY) && !map_flag_gvg2(sd->bl.m)
|
||||
&& !sd->sc.data[SC_BABY] && !sd->sc.data[SC_LIFEINSURANCE])
|
||||
&& !sd->sc.data[SC_BABY] && !sd->sc.data[SC_LIFEINSURANCE]
|
||||
&& !mapdata->flag[MF_NOEXPPENALTY] && !mapdata_flag_gvg2(mapdata))
|
||||
{
|
||||
uint32 base_penalty = 0;
|
||||
uint32 job_penalty = 0;
|
||||
@ -7967,19 +7968,17 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
if (base_penalty || job_penalty)
|
||||
pc_lostexp(sd, base_penalty, job_penalty);
|
||||
|
||||
if( zeny_penalty > 0 && !map_getmapflag(sd->bl.m, MF_NOZENYPENALTY)) {
|
||||
if( zeny_penalty > 0 && !mapdata->flag[MF_NOZENYPENALTY]) {
|
||||
zeny_penalty = (uint32)( sd->status.zeny * ( zeny_penalty / 10000. ) );
|
||||
if(zeny_penalty)
|
||||
pc_payzeny(sd, zeny_penalty, LOG_TYPE_PICKDROP_PLAYER, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if( map_getmapflag( sd->bl.m, MF_PVP_NIGHTMAREDROP ) ) { // Moved this outside so it works when PVP isn't enabled and during pk mode [Ancyker]
|
||||
for(int j=0;j<MAX_DROP_PER_MAP;j++){
|
||||
struct map_data *mapdata = map_getmapdata(sd->bl.m);
|
||||
int id = mapdata->drop_list[j].drop_id;
|
||||
int per = mapdata->drop_list[j].drop_per;
|
||||
enum e_nightmare_drop_type type = mapdata->drop_list[j].drop_type;
|
||||
if( mapdata->flag[MF_PVP_NIGHTMAREDROP] ) { // Moved this outside so it works when PVP isn't enabled and during pk mode [Ancyker]
|
||||
for (const auto &it : mapdata->drop_list) {
|
||||
int id = it.drop_id, per = it.drop_per;
|
||||
enum e_nightmare_drop_type type = it.drop_type;
|
||||
|
||||
if(id == 0)
|
||||
continue;
|
||||
@ -8026,7 +8025,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
}
|
||||
// pvp
|
||||
// disable certain pvp functions on pk_mode [Valaris]
|
||||
if( map_getmapflag(sd->bl.m, MF_PVP) && !battle_config.pk_mode && !map_getmapflag(sd->bl.m, MF_PVP_NOCALCRANK) ) {
|
||||
if( !battle_config.pk_mode && mapdata->flag[MF_PVP] && !mapdata->flag[MF_PVP_NOCALCRANK] ) {
|
||||
sd->pvp_point -= 5;
|
||||
sd->pvp_lost++;
|
||||
if( src && src->type == BL_PC ) {
|
||||
@ -8040,7 +8039,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
|
||||
}
|
||||
}
|
||||
//GvG
|
||||
if( map_flag_gvg2(sd->bl.m) ) {
|
||||
if( mapdata_flag_gvg2(mapdata) ) {
|
||||
add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
|
||||
return 1|8;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user