From 83b2e0b3ceda907b7186acfcc56c214fc04d9c13 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 7 Feb 2013 19:38:32 -0800 Subject: Remove some macros --- src/map/atcommand.cpp | 238 +++++-------- src/map/battle.cpp | 466 ++++++++++++------------- src/map/battle.t.hpp | 10 - src/map/chat.cpp | 10 +- src/map/chrif.cpp | 8 +- src/map/clif.cpp | 300 ++++++++-------- src/map/clif.hpp | 15 +- src/map/clif.t.hpp | 21 ++ src/map/intif.cpp | 169 +++++---- src/map/itemdb.cpp | 2 +- src/map/itemdb.hpp | 61 +++- src/map/magic-expr-eval.hpp | 6 +- src/map/magic-expr.cpp | 329 +++++++++--------- src/map/magic-expr.hpp | 18 +- src/map/magic-interpreter-aux.hpp | 14 +- src/map/magic-interpreter-base.cpp | 50 +-- src/map/magic-interpreter-lexer.lpp | 2 +- src/map/magic-interpreter-parser.ypp | 149 ++++---- src/map/magic-interpreter.hpp | 6 +- src/map/magic-interpreter.t.hpp | 72 +--- src/map/magic-stmt.cpp | 289 +++++++++------- src/map/magic.cpp | 10 +- src/map/map.cpp | 102 +++--- src/map/map.hpp | 58 ++-- src/map/map.t.hpp | 163 --------- src/map/mob.cpp | 452 ++++++++++++------------ src/map/mob.hpp | 7 +- src/map/mob.t.hpp | 13 - src/map/npc.cpp | 72 ++-- src/map/npc.hpp | 21 +- src/map/party.cpp | 5 +- src/map/path.cpp | 36 +- src/map/pc.cpp | 654 ++++++++++++++++++----------------- src/map/pc.hpp | 5 +- src/map/pc.t.hpp | 9 +- src/map/script.cpp | 65 ++-- src/map/skill-pools.cpp | 18 +- src/map/skill.cpp | 403 +++++++++++---------- src/map/skill.hpp | 12 +- src/map/skill.t.hpp | 104 +----- src/map/trade.cpp | 12 +- 41 files changed, 2108 insertions(+), 2348 deletions(-) create mode 100644 src/map/clif.t.hpp (limited to 'src/map') diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index a6994d5..dd3aae8 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -69,7 +69,6 @@ ATCOMMAND_FUNC(model); ATCOMMAND_FUNC(spawn); ATCOMMAND_FUNC(killmonster); ATCOMMAND_FUNC(killmonster2); -ATCOMMAND_FUNC(produce); ATCOMMAND_FUNC(gat); ATCOMMAND_FUNC(packet); ATCOMMAND_FUNC(statuspoint); @@ -223,7 +222,6 @@ AtCommandInfo atcommand_info[] = { {AtCommand_Spawn, "@spawn", 50, atcommand_spawn}, {AtCommand_KillMonster, "@killmonster", 60, atcommand_killmonster}, {AtCommand_KillMonster2, "@killmonster2", 40, atcommand_killmonster2}, - {AtCommand_Produce, "@produce", 60, atcommand_produce}, {AtCommand_GAT, "@gat", 99, atcommand_gat}, // debug function {AtCommand_Packet, "@packet", 99, atcommand_packet}, // debug function {AtCommand_StatusPoint, "@stpoint", 60, atcommand_statuspoint}, @@ -723,7 +721,7 @@ int atcommand_charwarp(const int fd, struct map_session_data *sd, "You are not authorised to warp this player from its actual map."); return -1; } - if (pc_setpos(pl_sd, map_name, x, y, 3) == 0) + if (pc_setpos(pl_sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) { clif_displaymessage(pl_sd->fd, "Warped."); clif_displaymessage(fd, "Player warped (message sends to player too)."); @@ -801,7 +799,7 @@ int atcommand_warp(const int fd, struct map_session_data *sd, "You are not authorised to warp you from your actual map."); return -1; } - if (pc_setpos(sd, map_name, x, y, 3) == 0) + if (pc_setpos(sd, map_name, x, y, BeingRemoveWhy::WARPED) == 0) clif_displaymessage(fd, "Warped."); else { @@ -887,7 +885,7 @@ int atcommand_goto(const int fd, struct map_session_data *sd, "You are not authorised to warp you from your actual map."); return -1; } - pc_setpos(sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y, 3); + pc_setpos(sd, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y, BeingRemoveWhy::WARPED); std::string output = STRPRINTF("Jump to %s", character); clif_displaymessage(fd, output); } @@ -930,7 +928,7 @@ int atcommand_jump(const int fd, struct map_session_data *sd, "You are not authorised to warp you from your actual map."); return -1; } - pc_setpos(sd, sd->mapname, x, y, 3); + pc_setpos(sd, sd->mapname, x, y, BeingRemoveWhy::WARPED); std::string output = STRPRINTF("Jump to %d %d", x, y); clif_displaymessage(fd, output); } @@ -1345,7 +1343,7 @@ int atcommand_load(const int fd, struct map_session_data *sd, } pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, - sd->status.save_point.y, 0); + sd->status.save_point.y, BeingRemoveWhy::GONE); clif_displaymessage(fd, "Warping to respawn point."); return 0; @@ -1373,7 +1371,7 @@ int atcommand_speed(const int fd, struct map_session_data *sd, sd->speed = speed; //sd->walktimer = x; //この文を追加 by れ - clif_updatestatus(sd, SP_SPEED); + clif_updatestatus(sd, SP::SPEED); clif_displaymessage(fd, "Speed changed."); } else @@ -1538,8 +1536,8 @@ int atcommand_alive(const int fd, struct map_session_data *sd, pc_setstand(sd); if (battle_config.pc_invincible_time > 0) pc_setinvincibletimer(sd, battle_config.pc_invincible_time); - clif_updatestatus(sd, SP_HP); - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::HP); + clif_updatestatus(sd, SP::SP); clif_resurrection(&sd->bl, 1); clif_displaymessage(fd, "You've been revived! It's a miracle!"); @@ -1735,9 +1733,9 @@ int atcommand_baselevelup(const int fd, struct map_session_data *sd, for (i = 1; i <= level; i++) sd->status.status_point += (sd->status.base_level + i + 14) / 4; sd->status.base_level += level; - clif_updatestatus(sd, SP_BASELEVEL); - clif_updatestatus(sd, SP_NEXTBASEEXP); - clif_updatestatus(sd, SP_STATUSPOINT); + clif_updatestatus(sd, SP::BASELEVEL); + clif_updatestatus(sd, SP::NEXTBASEEXP); + clif_updatestatus(sd, SP::STATUSPOINT); pc_calcstatus(sd, 0); pc_heal(sd, sd->status.max_hp, sd->status.max_sp); clif_misceffect(&sd->bl, 0); @@ -1759,11 +1757,11 @@ int atcommand_baselevelup(const int fd, struct map_session_data *sd, (sd->status.base_level + i + 14) / 4; if (sd->status.status_point < 0) sd->status.status_point = 0; - clif_updatestatus(sd, SP_STATUSPOINT); + clif_updatestatus(sd, SP::STATUSPOINT); } // to add: remove status points from stats sd->status.base_level += level; - clif_updatestatus(sd, SP_BASELEVEL); - clif_updatestatus(sd, SP_NEXTBASEEXP); + clif_updatestatus(sd, SP::BASELEVEL); + clif_updatestatus(sd, SP::NEXTBASEEXP); pc_calcstatus(sd, 0); clif_displaymessage(fd, "Base level lowered."); } @@ -1775,7 +1773,7 @@ int atcommand_baselevelup(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -// TODO: merge this with pc_setparam(SP_JOBLEVEL) +// TODO: merge this with pc_setparam(SP::JOBLEVEL) // then fix the funny 50 and/or 10 limitation. int atcommand_joblevelup(const int fd, struct map_session_data *sd, const char *, const char *message) @@ -1801,10 +1799,10 @@ int atcommand_joblevelup(const int fd, struct map_session_data *sd, if (level > up_level || level > (up_level - sd->status.job_level)) // fix positiv overflow level = up_level - sd->status.job_level; sd->status.job_level += level; - clif_updatestatus(sd, SP_JOBLEVEL); - clif_updatestatus(sd, SP_NEXTJOBEXP); + clif_updatestatus(sd, SP::JOBLEVEL); + clif_updatestatus(sd, SP::NEXTJOBEXP); sd->status.skill_point += level; - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); clif_misceffect(&sd->bl, 1); clif_displaymessage(fd, "Job level raised."); @@ -1819,14 +1817,14 @@ int atcommand_joblevelup(const int fd, struct map_session_data *sd, if (level < -up_level || level < (1 - sd->status.job_level)) // fix negativ overflow level = 1 - sd->status.job_level; sd->status.job_level += level; - clif_updatestatus(sd, SP_JOBLEVEL); - clif_updatestatus(sd, SP_NEXTJOBEXP); + clif_updatestatus(sd, SP::JOBLEVEL); + clif_updatestatus(sd, SP::NEXTJOBEXP); if (sd->status.skill_point > 0) { sd->status.skill_point += level; if (sd->status.skill_point < 0) sd->status.skill_point = 0; - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::SKILLPOINT); } // to add: remove status points from skills pc_calcstatus(sd, 0); clif_displaymessage(fd, "Job level lowered."); @@ -2029,9 +2027,9 @@ int atcommand_model(const int fd, struct map_session_data *sd, cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) { { - pc_changelook(sd, LOOK_HAIR, hair_style); - pc_changelook(sd, LOOK_HAIR_COLOR, hair_color); - pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color); + pc_changelook(sd, LOOK::HAIR, hair_style); + pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); + pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); clif_displaymessage(fd, "Appearence changed."); } } @@ -2065,7 +2063,7 @@ int atcommand_dye(const int fd, struct map_session_data *sd, if (cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) { { - pc_changelook(sd, LOOK_CLOTHES_COLOR, cloth_color); + pc_changelook(sd, LOOK::CLOTHES_COLOR, cloth_color); clif_displaymessage(fd, "Appearence changed."); } } @@ -2099,7 +2097,7 @@ int atcommand_hair_style(const int fd, struct map_session_data *sd, if (hair_style >= MIN_HAIR_STYLE && hair_style <= MAX_HAIR_STYLE) { { - pc_changelook(sd, LOOK_HAIR, hair_style); + pc_changelook(sd, LOOK::HAIR, hair_style); clif_displaymessage(fd, "Appearence changed."); } } @@ -2133,7 +2131,7 @@ int atcommand_hair_color(const int fd, struct map_session_data *sd, if (hair_color >= MIN_HAIR_COLOR && hair_color <= MAX_HAIR_COLOR) { { - pc_changelook(sd, LOOK_HAIR_COLOR, hair_color); + pc_changelook(sd, LOOK::HAIR_COLOR, hair_color); clif_displaymessage(fd, "Appearence changed."); } } @@ -2262,7 +2260,7 @@ void atcommand_killmonster_sub(const int fd, struct map_session_data *sd, } map_foreachinarea(std::bind(atkillmonster_sub, ph::_1, drop), map_id, 0, 0, map[map_id].xs, - map[map_id].ys, BL_MOB); + map[map_id].ys, BL::MOB); clif_displaymessage(fd, "All monsters killed!"); @@ -2305,7 +2303,7 @@ int atcommand_list_nearby(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "Nearby players:"); map_foreachinarea(std::bind(atlist_nearby_sub, ph::_1, fd), sd->bl.m, sd->bl.x - 1, sd->bl.y - 1, - sd->bl.x + 1, sd->bl.x + 1, BL_PC); + sd->bl.x + 1, sd->bl.x + 1, BL::PC); return 0; } @@ -2322,70 +2320,6 @@ int atcommand_killmonster2(const int fd, struct map_session_data *sd, return 0; } -/*========================================== - * - *------------------------------------------ - */ -int atcommand_produce(const int fd, struct map_session_data *sd, - const char *, const char *message) -{ - char item_name[100]; - int item_id, attribute = 0, star = 0; - struct item_data *item_data; - struct item tmp_item; - - memset(item_name, '\0', sizeof(item_name)); - - if (!message || !*message - || sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1) - { - clif_displaymessage(fd, - "Please, enter at least an item name/id (usage: @produce <# of very's>)."); - return -1; - } - - item_id = 0; - if ((item_data = itemdb_searchname(item_name)) != NULL || - (item_data = itemdb_exists(atoi(item_name))) != NULL) - item_id = item_data->nameid; - - if (itemdb_exists(item_id) && - (item_id <= 500 || item_id > 1099) && - (item_id < 4001 || item_id > 4148) && - (item_id < 7001 || item_id > 10019) && itemdb_isequip(item_id)) - { - if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE) - attribute = ATTRIBUTE_NORMAL; - if (star < MIN_STAR || star > MAX_STAR) - star = 0; - memset(&tmp_item, 0, sizeof tmp_item); - tmp_item.nameid = item_id; - tmp_item.amount = 1; - tmp_item.identify = 1; - tmp_item.card[0] = 0x00ff; - tmp_item.card[1] = ((star * 5) << 8) + attribute; - *((unsigned long *) (&tmp_item.card[2])) = sd->char_id; - clif_misceffect(&sd->bl, 3); // 他人にも成功を通知 - PickupFail flag; - if ((flag = pc_additem(sd, &tmp_item, 1)) != PickupFail::OKAY) - clif_additem(sd, 0, 0, flag); - } - else - { - if (battle_config.error_log) - PRINTF("@produce NOT WEAPON [%d]\n", item_id); - std::string output; - if (item_id != 0 && itemdb_exists(item_id)) - output = STRPRINTF("This item (%d: '%s') is not an equipment.", item_id, item_data->name); - else - output = STRPRINTF("%s", "This item is not an equipment."); - clif_displaymessage(fd, output); - return -1; - } - - return 0; -} - /*========================================== * *------------------------------------------ @@ -2457,7 +2391,7 @@ int atcommand_statuspoint(const int fd, struct map_session_data *sd, if (new_status_point != (int) sd->status.status_point) { sd->status.status_point = (short) new_status_point; - clif_updatestatus(sd, SP_STATUSPOINT); + clif_updatestatus(sd, SP::STATUSPOINT); clif_displaymessage(fd, "Number of status points changed!"); } else @@ -2497,7 +2431,7 @@ int atcommand_skillpoint(const int fd, struct map_session_data *sd, if (new_skill_point != (int) sd->status.skill_point) { sd->status.skill_point = (short) new_skill_point; - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::SKILLPOINT); clif_displaymessage(fd, "Number of skill points changed!"); } else @@ -2537,7 +2471,7 @@ int atcommand_zeny(const int fd, struct map_session_data *sd, if (new_zeny != sd->status.zeny) { sd->status.zeny = new_zeny; - clif_updatestatus(sd, SP_ZENY); + clif_updatestatus(sd, SP::ZENY); clif_displaymessage(fd, "Number of zenys changed!"); } else @@ -2683,7 +2617,7 @@ int atcommand_recall(const int fd, struct map_session_data *sd, "You are not authorised to warp this player from its actual map."); return -1; } - pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2); + pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, BeingRemoveWhy::QUIT); std::string output = STRPRINTF("%s recalled!", character); clif_displaymessage(fd, output); } @@ -2727,8 +2661,8 @@ int atcommand_revive(const int fd, struct map_session_data *sd, pc_setstand(pl_sd); if (battle_config.pc_invincible_time > 0) pc_setinvincibletimer(sd, battle_config.pc_invincible_time); - clif_updatestatus(pl_sd, SP_HP); - clif_updatestatus(pl_sd, SP_SP); + clif_updatestatus(pl_sd, SP::HP); + clif_updatestatus(pl_sd, SP::SP); clif_resurrection(&pl_sd->bl, 1); clif_displaymessage(fd, "Character revived."); } @@ -3377,8 +3311,8 @@ void atcommand_raise_sub(struct map_session_data *sd) sd->status.hp = sd->status.max_hp; sd->status.sp = sd->status.max_sp; pc_setstand(sd); - clif_updatestatus(sd, SP_HP); - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::HP); + clif_updatestatus(sd, SP::SP); clif_resurrection(&sd->bl, 1); clif_displaymessage(sd->fd, "Mercy has been shown."); } @@ -3466,9 +3400,9 @@ int atcommand_character_baselevel(const int fd, struct map_session_data *sd, pl_sd->status.status_point += (pl_sd->status.base_level + i + 14) / 4; pl_sd->status.base_level += level; - clif_updatestatus(pl_sd, SP_BASELEVEL); - clif_updatestatus(pl_sd, SP_NEXTBASEEXP); - clif_updatestatus(pl_sd, SP_STATUSPOINT); + clif_updatestatus(pl_sd, SP::BASELEVEL); + clif_updatestatus(pl_sd, SP::NEXTBASEEXP); + clif_updatestatus(pl_sd, SP::STATUSPOINT); pc_calcstatus(pl_sd, 0); pc_heal(pl_sd, pl_sd->status.max_hp, pl_sd->status.max_sp); clif_misceffect(&pl_sd->bl, 0); @@ -3490,13 +3424,13 @@ int atcommand_character_baselevel(const int fd, struct map_session_data *sd, (pl_sd->status.base_level + i + 14) / 4; if (pl_sd->status.status_point < 0) pl_sd->status.status_point = 0; - clif_updatestatus(pl_sd, SP_STATUSPOINT); + clif_updatestatus(pl_sd, SP::STATUSPOINT); } // to add: remove status points from stats pl_sd->status.base_level += level; pl_sd->status.base_exp = 0; - clif_updatestatus(pl_sd, SP_BASELEVEL); - clif_updatestatus(pl_sd, SP_NEXTBASEEXP); - clif_updatestatus(pl_sd, SP_BASEEXP); + clif_updatestatus(pl_sd, SP::BASELEVEL); + clif_updatestatus(pl_sd, SP::NEXTBASEEXP); + clif_updatestatus(pl_sd, SP::BASEEXP); pc_calcstatus(pl_sd, 0); clif_displaymessage(fd, "Character's base level lowered."); } @@ -3557,10 +3491,10 @@ int atcommand_character_joblevel(const int fd, struct map_session_data *sd, if (pl_sd->status.job_level + level > max_level) level = max_level - pl_sd->status.job_level; pl_sd->status.job_level += level; - clif_updatestatus(pl_sd, SP_JOBLEVEL); - clif_updatestatus(pl_sd, SP_NEXTJOBEXP); + clif_updatestatus(pl_sd, SP::JOBLEVEL); + clif_updatestatus(pl_sd, SP::NEXTJOBEXP); pl_sd->status.skill_point += level; - clif_updatestatus(pl_sd, SP_SKILLPOINT); + clif_updatestatus(pl_sd, SP::SKILLPOINT); pc_calcstatus(pl_sd, 0); clif_misceffect(&pl_sd->bl, 1); clif_displaymessage(fd, "character's job level raised."); @@ -3575,14 +3509,14 @@ int atcommand_character_joblevel(const int fd, struct map_session_data *sd, if (pl_sd->status.job_level + level < 1) level = 1 - pl_sd->status.job_level; pl_sd->status.job_level += level; - clif_updatestatus(pl_sd, SP_JOBLEVEL); - clif_updatestatus(pl_sd, SP_NEXTJOBEXP); + clif_updatestatus(pl_sd, SP::JOBLEVEL); + clif_updatestatus(pl_sd, SP::NEXTJOBEXP); if (pl_sd->status.skill_point > 0) { pl_sd->status.skill_point += level; if (pl_sd->status.skill_point < 0) pl_sd->status.skill_point = 0; - clif_updatestatus(pl_sd, SP_SKILLPOINT); + clif_updatestatus(pl_sd, SP::SKILLPOINT); } // to add: remove status points from skills pc_calcstatus(pl_sd, 0); clif_displaymessage(fd, "Character's job level lowered."); @@ -3684,7 +3618,7 @@ int atcommand_questskill(const int fd, struct map_session_data *sd, SkillID skill_id = SkillID(skill_id_); - if (/*skill_id >= SkillID() &&*/ skill_id < MAX_SKILL_DB) + if (/*skill_id >= SkillID() &&*/ skill_id < SkillID::MAX_SKILL_DB) { if (skill_get_inf2(skill_id) & 0x01) { @@ -3738,7 +3672,7 @@ int atcommand_charquestskill(const int fd, struct map_session_data *, SkillID skill_id = SkillID(skill_id_); - if (/*skill_id >= SkillID() &&*/ skill_id < MAX_SKILL_DB) + if (/*skill_id >= SkillID() &&*/ skill_id < SkillID::MAX_SKILL_DB) { if (skill_get_inf2(skill_id) & 0x01) { @@ -4139,20 +4073,20 @@ int atcommand_char_wipe(const int fd, struct map_session_data *sd, // Reset base level pl_sd->status.base_level = 1; pl_sd->status.base_exp = 0; - clif_updatestatus(pl_sd, SP_BASELEVEL); - clif_updatestatus(pl_sd, SP_NEXTBASEEXP); - clif_updatestatus(pl_sd, SP_BASEEXP); + clif_updatestatus(pl_sd, SP::BASELEVEL); + clif_updatestatus(pl_sd, SP::NEXTBASEEXP); + clif_updatestatus(pl_sd, SP::BASEEXP); // Reset job level pl_sd->status.job_level = 1; pl_sd->status.job_exp = 0; - clif_updatestatus(pl_sd, SP_JOBLEVEL); - clif_updatestatus(pl_sd, SP_NEXTJOBEXP); - clif_updatestatus(pl_sd, SP_JOBEXP); + clif_updatestatus(pl_sd, SP::JOBLEVEL); + clif_updatestatus(pl_sd, SP::NEXTJOBEXP); + clif_updatestatus(pl_sd, SP::JOBEXP); // Zeny to 50 pl_sd->status.zeny = 50; - clif_updatestatus(pl_sd, SP_ZENY); + clif_updatestatus(pl_sd, SP::ZENY); // Clear inventory for (i = 0; i < MAX_INVENTORY; i++) @@ -4233,9 +4167,9 @@ int atcommand_charmodel(const int fd, struct map_session_data *, cloth_color >= MIN_CLOTH_COLOR && cloth_color <= MAX_CLOTH_COLOR) { { - pc_changelook(pl_sd, LOOK_HAIR, hair_style); - pc_changelook(pl_sd, LOOK_HAIR_COLOR, hair_color); - pc_changelook(pl_sd, LOOK_CLOTHES_COLOR, cloth_color); + pc_changelook(pl_sd, LOOK::HAIR, hair_style); + pc_changelook(pl_sd, LOOK::HAIR_COLOR, hair_color); + pc_changelook(pl_sd, LOOK::CLOTHES_COLOR, cloth_color); clif_displaymessage(fd, "Appearence changed."); } } @@ -4287,7 +4221,7 @@ int atcommand_charskpoint(const int fd, struct map_session_data *, if (new_skill_point != (int) pl_sd->status.skill_point) { pl_sd->status.skill_point = new_skill_point; - clif_updatestatus(pl_sd, SP_SKILLPOINT); + clif_updatestatus(pl_sd, SP::SKILLPOINT); clif_displaymessage(fd, "Character's number of skill points changed!"); } else @@ -4341,7 +4275,7 @@ int atcommand_charstpoint(const int fd, struct map_session_data *, if (new_status_point != (int) pl_sd->status.status_point) { pl_sd->status.status_point = new_status_point; - clif_updatestatus(pl_sd, SP_STATUSPOINT); + clif_updatestatus(pl_sd, SP::STATUSPOINT); clif_displaymessage(fd, "Character's number of status points changed!"); } else @@ -4393,7 +4327,7 @@ int atcommand_charzeny(const int fd, struct map_session_data *, if (new_zeny != pl_sd->status.zeny) { pl_sd->status.zeny = new_zeny; - clif_updatestatus(pl_sd, SP_ZENY); + clif_updatestatus(pl_sd, SP::ZENY); clif_displaymessage(fd, "Character's number of zenys changed!"); } else @@ -4445,7 +4379,7 @@ int atcommand_recallall(const int fd, struct map_session_data *sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) count++; else - pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2); + pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, BeingRemoveWhy::QUIT); } } @@ -4506,7 +4440,7 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd, && battle_config.any_warp_GM_min_level > pc_isGM(sd)) count++; else - pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, 2); + pc_setpos(pl_sd, sd->mapname, sd->bl.x, sd->bl.y, BeingRemoveWhy::QUIT); } } std::string output = STRPRINTF("All online characters of the %s party are near you.", p->name); @@ -4715,28 +4649,28 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, nd = map[m_id].npc[i]; switch (nd->dir) { - case DIR_S: + case DIR::S: direction = "North"; break; - case DIR_SW: + case DIR::SW: direction = "North West"; break; - case DIR_W: + case DIR::W: direction = "West"; break; - case DIR_NW: + case DIR::NW: direction = "South West"; break; - case DIR_N: + case DIR::N: direction = "South"; break; - case DIR_NE: + case DIR::NE: direction = "South East"; break; - case DIR_E: + case DIR::E: direction = "East"; break; - case DIR_SE: + case DIR::SE: direction = "North East"; break; #if 0 @@ -5123,7 +5057,7 @@ int atcommand_jail(const int fd, struct map_session_data *sd, y = 75; break; } - if (pc_setpos(pl_sd, "sec_pri.gat", x, y, 3) == 0) + if (pc_setpos(pl_sd, "sec_pri.gat", x, y, BeingRemoveWhy::WARPED) == 0) { pc_setsavepoint(pl_sd, "sec_pri.gat", x, y); // Save Char Respawn Point in the jail room [Lupus] clif_displaymessage(pl_sd->fd, "GM has send you in jails."); @@ -5179,7 +5113,7 @@ int atcommand_unjail(const int fd, struct map_session_data *sd, clif_displaymessage(fd, "This player is not in jails."); return -1; } - else if (pc_setpos(pl_sd, "prontera.gat", 156, 191, 3) == 0) + else if (pc_setpos(pl_sd, "prontera.gat", 156, 191, BeingRemoveWhy::WARPED) == 0) { pc_setsavepoint(pl_sd, "prontera.gat", 156, 191); // Save char respawn point in Prontera clif_displaymessage(pl_sd->fd, "GM has discharge you."); @@ -6529,9 +6463,9 @@ int atcommand_unmute(const int, struct map_session_data *sd, if ((pl_sd = map_nick2sd(message)) != NULL) { - if (pl_sd->sc_data[SC_NOCHAT].timer != -1) + if (pl_sd->sc_data[StatusChange::SC_NOCHAT].timer != -1) { - skill_status_change_end(&pl_sd->bl, SC_NOCHAT, -1); + skill_status_change_end(&pl_sd->bl, StatusChange::SC_NOCHAT, -1); clif_displaymessage(sd->fd, "Player unmuted"); } else @@ -6546,12 +6480,12 @@ int atcommand_unmute(const int, struct map_session_data *sd, static SkillID magic_skills[] = { - TMW_MAGIC, - TMW_MAGIC_LIFE, - TMW_MAGIC_WAR, - TMW_MAGIC_TRANSMUTE, - TMW_MAGIC_NATURE, - TMW_MAGIC_ETHER, + SkillID::TMW_MAGIC, + SkillID::TMW_MAGIC_LIFE, + SkillID::TMW_MAGIC_WAR, + SkillID::TMW_MAGIC_TRANSMUTE, + SkillID::TMW_MAGIC_NATURE, + SkillID::TMW_MAGIC_ETHER, }; constexpr @@ -6742,7 +6676,7 @@ int atcommand_jump_iterate(const int fd, struct map_session_data *sd, "You are not authorised to warp you from your actual map."); return -1; } - pc_setpos(sd, map[pl_sd->bl.m].name, pl_sd->bl.x, pl_sd->bl.y, 3); + pc_setpos(sd, map[pl_sd->bl.m].name, pl_sd->bl.x, pl_sd->bl.y, BeingRemoveWhy::WARPED); std::string output = STRPRINTF("Jump to %s", pl_sd->status.name); clif_displaymessage(fd, output); diff --git a/src/map/battle.cpp b/src/map/battle.cpp index b431662..605d637 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -29,10 +29,10 @@ int battle_counttargeted(struct block_list *bl, struct block_list *src, ATK target_lv) { nullpo_ret(bl); - if (bl->type == BL_PC) + if (bl->type == BL::PC) return pc_counttargeted((struct map_session_data *) bl, src, target_lv); - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) return mob_counttargeted((struct mob_data *) bl, src, target_lv); return 0; } @@ -45,9 +45,9 @@ int battle_counttargeted(struct block_list *bl, struct block_list *src, int battle_get_class(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) return ((struct mob_data *) bl)->mob_class; - else if (bl->type == BL_PC) + else if (bl->type == BL::PC) return 0; else return 0; @@ -60,13 +60,13 @@ int battle_get_class(struct block_list *bl) */ DIR battle_get_dir(struct block_list *bl) { - nullpo_retr(DIR_S, bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + nullpo_retr(DIR::S, bl); + if (bl->type == BL::MOB && (struct mob_data *) bl) return ((struct mob_data *) bl)->dir; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->dir; else - return DIR_S; + return DIR::S; } /*========================================== @@ -77,9 +77,9 @@ DIR battle_get_dir(struct block_list *bl) int battle_get_lv(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) - return ((struct mob_data *) bl)->stats[MOB_LV]; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) + return ((struct mob_data *) bl)->stats[mob_stat::LV]; + else if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->status.base_level; else return 0; @@ -93,9 +93,9 @@ int battle_get_lv(struct block_list *bl) int battle_get_range(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return mob_db[((struct mob_data *) bl)->mob_class].range; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->attackrange; else return 0; @@ -109,9 +109,9 @@ int battle_get_range(struct block_list *bl) int battle_get_hp(struct block_list *bl) { nullpo_retr(1, bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return ((struct mob_data *) bl)->hp; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->status.hp; else return 1; @@ -125,14 +125,14 @@ int battle_get_hp(struct block_list *bl) int battle_get_max_hp(struct block_list *bl) { nullpo_retr(1, bl); - if (bl->type == BL_PC && ((struct map_session_data *) bl)) + if (bl->type == BL::PC && ((struct map_session_data *) bl)) return ((struct map_session_data *) bl)->status.max_hp; else { int max_hp = 1; - if (bl->type == BL_MOB && ((struct mob_data *) bl)) + if (bl->type == BL::MOB && ((struct mob_data *) bl)) { - max_hp = ((struct mob_data *) bl)->stats[MOB_MAX_HP]; + max_hp = ((struct mob_data *) bl)->stats[mob_stat::MAX_HP]; if (mob_db[((struct mob_data *) bl)->mob_class].mexp > 0) { if (battle_config.mvp_hp_rate != 100) @@ -162,9 +162,9 @@ int battle_get_str(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && ((struct mob_data *) bl)) - str = ((struct mob_data *) bl)->stats[MOB_STR]; - else if (bl->type == BL_PC && ((struct map_session_data *) bl)) + if (bl->type == BL::MOB && ((struct mob_data *) bl)) + str = ((struct mob_data *) bl)->stats[mob_stat::STR]; + else if (bl->type == BL::PC && ((struct map_session_data *) bl)) return ((struct map_session_data *) bl)->paramc[ATTR::STR]; if (str < 0) @@ -185,9 +185,9 @@ int battle_get_agi(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) - agi = ((struct mob_data *) bl)->stats[MOB_AGI]; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) + agi = ((struct mob_data *) bl)->stats[mob_stat::AGI]; + else if (bl->type == BL::PC && (struct map_session_data *) bl) agi = ((struct map_session_data *) bl)->paramc[ATTR::AGI]; if (agi < 0) @@ -207,9 +207,9 @@ int battle_get_vit(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) - vit = ((struct mob_data *) bl)->stats[MOB_VIT]; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) + vit = ((struct mob_data *) bl)->stats[mob_stat::VIT]; + else if (bl->type == BL::PC && (struct map_session_data *) bl) vit = ((struct map_session_data *) bl)->paramc[ATTR::VIT]; if (vit < 0) @@ -229,9 +229,9 @@ int battle_get_int(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) - int_ = ((struct mob_data *) bl)->stats[MOB_INT]; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) + int_ = ((struct mob_data *) bl)->stats[mob_stat::INT]; + else if (bl->type == BL::PC && (struct map_session_data *) bl) int_ = ((struct map_session_data *) bl)->paramc[ATTR::INT]; if (int_ < 0) @@ -251,9 +251,9 @@ int battle_get_dex(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) - dex = ((struct mob_data *) bl)->stats[MOB_DEX]; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) + dex = ((struct mob_data *) bl)->stats[mob_stat::DEX]; + else if (bl->type == BL::PC && (struct map_session_data *) bl) dex = ((struct map_session_data *) bl)->paramc[ATTR::DEX]; if (dex < 0) @@ -273,14 +273,14 @@ int battle_get_luk(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) - luk = ((struct mob_data *) bl)->stats[MOB_LUK]; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) + luk = ((struct mob_data *) bl)->stats[mob_stat::LUK]; + else if (bl->type == BL::PC && (struct map_session_data *) bl) luk = ((struct map_session_data *) bl)->paramc[ATTR::LUK]; if (sc_data) { - if (sc_data[SC_CURSE].timer != -1) // 呪い + if (sc_data[StatusChange::SC_CURSE].timer != -1) // 呪い luk = 0; } if (luk < 0) @@ -301,19 +301,19 @@ int battle_get_flee(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) flee = ((struct map_session_data *) bl)->flee; else flee = battle_get_agi(bl) + battle_get_lv(bl); if (sc_data) { - if (sc_data[SC_BLIND].timer != -1 && bl->type != BL_PC) + if (sc_data[StatusChange::SC_BLIND].timer != -1 && bl->type != BL::PC) flee -= flee * 25 / 100; if (battle_is_unarmed(bl)) - flee += (skill_power_bl(bl, TMW_BRAWLING) >> 3); // +25 for 200 - flee += skill_power_bl(bl, TMW_SPEED) >> 3; + flee += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 3); // +25 for 200 + flee += skill_power_bl(bl, SkillID::TMW_SPEED) >> 3; } if (flee < 1) flee = 1; @@ -333,18 +333,18 @@ int battle_get_hit(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) hit = ((struct map_session_data *) bl)->hit; else hit = battle_get_dex(bl) + battle_get_lv(bl); if (sc_data) { - if (sc_data[SC_BLIND].timer != -1 && bl->type != BL_PC) // 呪い + if (sc_data[StatusChange::SC_BLIND].timer != -1 && bl->type != BL::PC) // 呪い hit -= hit * 25 / 100; if (battle_is_unarmed(bl)) - hit += (skill_power_bl(bl, TMW_BRAWLING) >> 4); // +12 for 200 + hit += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 4); // +12 for 200 } if (hit < 1) hit = 1; @@ -364,7 +364,7 @@ int battle_get_flee2(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) { flee2 = battle_get_luk(bl) + 10; flee2 += @@ -376,8 +376,8 @@ int battle_get_flee2(struct block_list *bl) { if (battle_is_unarmed(bl)) - flee2 += (skill_power_bl(bl, TMW_BRAWLING) >> 3); // +25 for 200 - flee2 += skill_power_bl(bl, TMW_SPEED) >> 3; + flee2 += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 3); // +25 for 200 + flee2 += skill_power_bl(bl, SkillID::TMW_SPEED) >> 3; } if (flee2 < 1) flee2 = 1; @@ -397,7 +397,7 @@ int battle_get_critical(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) { critical = battle_get_luk(bl) * 2 + 10; critical += @@ -425,7 +425,7 @@ int battle_get_baseatk(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) batk = ((struct map_session_data *) bl)->base_atk; //設定されているbase_atk else { //それ以外なら @@ -436,7 +436,7 @@ int battle_get_baseatk(struct block_list *bl) } if (sc_data) { //状態異常あり - if (sc_data[SC_CURSE].timer != -1) //呪われていたら + if (sc_data[StatusChange::SC_CURSE].timer != -1) //呪われていたら batk -= batk * 25 / 100; //base_atkが25%減少 } if (batk < 1) @@ -457,14 +457,14 @@ int battle_get_atk(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) atk = ((struct map_session_data *) bl)->watk; - else if (bl->type == BL_MOB && (struct mob_data *) bl) - atk = ((struct mob_data *) bl)->stats[MOB_ATK1]; + else if (bl->type == BL::MOB && (struct mob_data *) bl) + atk = ((struct mob_data *) bl)->stats[mob_stat::ATK1]; if (sc_data) { - if (sc_data[SC_CURSE].timer != -1) + if (sc_data[StatusChange::SC_CURSE].timer != -1) atk -= atk * 25 / 100; } if (atk < 0) @@ -481,11 +481,11 @@ static int battle_get_atk_(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) { int atk = ((struct map_session_data *) bl)->watk_; - if (((struct map_session_data *) bl)->sc_data[SC_CURSE].timer != -1) + if (((struct map_session_data *) bl)->sc_data[StatusChange::SC_CURSE].timer != -1) atk -= atk * 25 / 100; return atk; } @@ -502,17 +502,17 @@ static int battle_get_atk2(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->watk2; else { eptr sc_data = battle_get_sc_data(bl); int atk2 = 0; - if (bl->type == BL_MOB && (struct mob_data *) bl) - atk2 = ((struct mob_data *) bl)->stats[MOB_ATK2]; + if (bl->type == BL::MOB && (struct mob_data *) bl) + atk2 = ((struct mob_data *) bl)->stats[mob_stat::ATK2]; if (sc_data) { - if (sc_data[SC_CURSE].timer != -1) + if (sc_data[StatusChange::SC_CURSE].timer != -1) atk2 -= atk2 * 25 / 100; } @@ -531,7 +531,7 @@ static int battle_get_atk_2(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_PC) + if (bl->type == BL::PC) return ((struct map_session_data *) bl)->watk_2; else return 0; @@ -548,14 +548,14 @@ int battle_get_matk1(struct block_list *bl) eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) { int matk, int_ = battle_get_int(bl); matk = int_ + (int_ / 5) * (int_ / 5); return matk; } - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->matk1; else return 0; @@ -570,14 +570,14 @@ static int battle_get_matk2(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) { int matk, int_ = battle_get_int(bl); matk = int_ + (int_ / 7) * (int_ / 7); return matk; } - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->matk2; else return 0; @@ -595,13 +595,13 @@ int battle_get_def(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) { def = ((struct map_session_data *) bl)->def; } - else if (bl->type == BL_MOB && (struct mob_data *) bl) + else if (bl->type == BL::MOB && (struct mob_data *) bl) { - def = ((struct mob_data *) bl)->stats[MOB_DEF]; + def = ((struct mob_data *) bl)->stats[mob_stat::DEF]; } if (def < 1000000) @@ -609,12 +609,12 @@ int battle_get_def(struct block_list *bl) if (sc_data) { //毒にかかっている時は減算 - if (sc_data[SC_POISON].timer != -1 && bl->type != BL_PC) + if (sc_data[StatusChange::SC_POISON].timer != -1 && bl->type != BL::PC) def = def * 75 / 100; //凍結、石化時は右シフト - if (sc_data[SC_FREEZE].timer != -1 - || (sc_data[SC_STONE].timer != -1 - && sc_data[SC_STONE].val2 == 0)) + if (sc_data[StatusChange::SC_FREEZE].timer != -1 + || (sc_data[StatusChange::SC_STONE].timer != -1 + && sc_data[StatusChange::SC_STONE].val2 == 0)) def >>= 1; } } @@ -635,26 +635,26 @@ int battle_get_mdef(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) mdef = ((struct map_session_data *) bl)->mdef; - else if (bl->type == BL_MOB && (struct mob_data *) bl) - mdef = ((struct mob_data *) bl)->stats[MOB_MDEF]; + else if (bl->type == BL::MOB && (struct mob_data *) bl) + mdef = ((struct mob_data *) bl)->stats[mob_stat::MDEF]; if (mdef < 1000000) { if (sc_data) { //バリアー状態時はMDEF100 - if (mdef < 90 && sc_data[SC_MBARRIER].timer != -1) + if (mdef < 90 && sc_data[StatusChange::SC_MBARRIER].timer != -1) { - mdef += sc_data[SC_MBARRIER].val1; + mdef += sc_data[StatusChange::SC_MBARRIER].val1; if (mdef > 90) mdef = 90; } //凍結、石化時は1.25倍 - if (sc_data[SC_FREEZE].timer != -1 - || (sc_data[SC_STONE].timer != -1 - && sc_data[SC_STONE].val2 == 0)) + if (sc_data[StatusChange::SC_FREEZE].timer != -1 + || (sc_data[StatusChange::SC_STONE].timer != -1 + && sc_data[StatusChange::SC_STONE].val2 == 0)) mdef = mdef * 125 / 100; } } @@ -675,14 +675,14 @@ int battle_get_def2(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_PC) + if (bl->type == BL::PC) def2 = ((struct map_session_data *) bl)->def2; - else if (bl->type == BL_MOB) - def2 = ((struct mob_data *) bl)->stats[MOB_VIT]; + else if (bl->type == BL::MOB) + def2 = ((struct mob_data *) bl)->stats[mob_stat::VIT]; if (sc_data) { - if (sc_data[SC_POISON].timer != -1 && bl->type != BL_PC) + if (sc_data[StatusChange::SC_POISON].timer != -1 && bl->type != BL::PC) def2 = def2 * 75 / 100; } if (def2 < 1) @@ -700,11 +700,11 @@ int battle_get_mdef2(struct block_list *bl) int mdef2 = 0; nullpo_ret(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) mdef2 = - ((struct mob_data *) bl)->stats[MOB_INT] + - (((struct mob_data *) bl)->stats[MOB_VIT] >> 1); - else if (bl->type == BL_PC) + ((struct mob_data *) bl)->stats[mob_stat::INT] + + (((struct mob_data *) bl)->stats[mob_stat::VIT] >> 1); + else if (bl->type == BL::PC) mdef2 = ((struct map_session_data *) bl)->mdef2 + (((struct map_session_data *) bl)->paramc[ATTR::VIT] >> 1); @@ -723,18 +723,18 @@ int battle_get_mdef2(struct block_list *bl) int battle_get_speed(struct block_list *bl) { nullpo_retr(1000, bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->speed; else { eptr sc_data = battle_get_sc_data(bl); int speed = 1000; - if (bl->type == BL_MOB && (struct mob_data *) bl) - speed = ((struct mob_data *) bl)->stats[MOB_SPEED]; + if (bl->type == BL::MOB && (struct mob_data *) bl) + speed = ((struct mob_data *) bl)->stats[mob_stat::SPEED]; if (sc_data) { - if (sc_data[SC_CURSE].timer != -1) + if (sc_data[StatusChange::SC_CURSE].timer != -1) speed = speed + 450; } if (speed < 1) @@ -751,22 +751,22 @@ int battle_get_speed(struct block_list *bl) int battle_get_adelay(struct block_list *bl) { nullpo_retr(4000, bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) return (((struct map_session_data *) bl)->aspd << 1); else { eptr sc_data = battle_get_sc_data(bl); int adelay = 4000, aspd_rate = 100; - if (bl->type == BL_MOB && (struct mob_data *) bl) - adelay = ((struct mob_data *) bl)->stats[MOB_ADELAY]; + if (bl->type == BL::MOB && (struct mob_data *) bl) + adelay = ((struct mob_data *) bl)->stats[mob_stat::ADELAY]; if (sc_data) { - if (sc_data[SC_SPEEDPOTION0].timer != -1) - aspd_rate -= sc_data[SC_SPEEDPOTION0].val1; + if (sc_data[StatusChange::SC_SPEEDPOTION0].timer != -1) + aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1; // Fate's `haste' spell works the same as the above - if (sc_data[SC_HASTE].timer != -1) - aspd_rate -= sc_data[SC_HASTE].val1; + if (sc_data[StatusChange::SC_HASTE].timer != -1) + aspd_rate -= sc_data[StatusChange::SC_HASTE].val1; } if (aspd_rate != 100) @@ -780,21 +780,21 @@ int battle_get_adelay(struct block_list *bl) int battle_get_amotion(struct block_list *bl) { nullpo_retr(2000, bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->amotion; else { eptr sc_data = battle_get_sc_data(bl); int amotion = 2000, aspd_rate = 100; - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) amotion = mob_db[((struct mob_data *) bl)->mob_class].amotion; if (sc_data) { - if (sc_data[SC_SPEEDPOTION0].timer != -1) - aspd_rate -= sc_data[SC_SPEEDPOTION0].val1; - if (sc_data[SC_HASTE].timer != -1) - aspd_rate -= sc_data[SC_HASTE].val1; + if (sc_data[StatusChange::SC_SPEEDPOTION0].timer != -1) + aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1; + if (sc_data[StatusChange::SC_HASTE].timer != -1) + aspd_rate -= sc_data[StatusChange::SC_HASTE].val1; } if (aspd_rate != 100) @@ -812,13 +812,13 @@ int battle_get_dmotion(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) { ret = mob_db[((struct mob_data *) bl)->mob_class].dmotion; if (battle_config.monster_damage_delay_rate != 100) ret = ret * battle_config.monster_damage_delay_rate / 400; } - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) { ret = ((struct map_session_data *) bl)->dmotion; if (battle_config.pc_damage_delay_rate != 100) @@ -837,14 +837,14 @@ LevelElement battle_get_element(struct block_list *bl) nullpo_retr(ret, bl); sc_data = battle_get_sc_data(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) // 10の位=Lv*2、1の位=属性 + if (bl->type == BL::MOB && (struct mob_data *) bl) // 10の位=Lv*2、1の位=属性 ret = ((struct mob_data *) bl)->def_ele; if (sc_data) { - if (sc_data[SC_FREEZE].timer != -1) // 凍結 + if (sc_data[StatusChange::SC_FREEZE].timer != -1) // 凍結 ret = LevelElement{2, Element::water}; - if (sc_data[SC_STONE].timer != -1 && sc_data[SC_STONE].val2 == 0) + if (sc_data[StatusChange::SC_STONE].timer != -1 && sc_data[StatusChange::SC_STONE].val2 == 0) ret = LevelElement{2, Element::earth}; } @@ -854,9 +854,9 @@ LevelElement battle_get_element(struct block_list *bl) int battle_get_party_id(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_PC && (struct map_session_data *) bl) + if (bl->type == BL::PC && (struct map_session_data *) bl) return ((struct map_session_data *) bl)->status.party_id; - else if (bl->type == BL_MOB && (struct mob_data *) bl) + else if (bl->type == BL::MOB && (struct mob_data *) bl) { struct mob_data *md = (struct mob_data *) bl; if (md->master_id > 0) @@ -869,9 +869,9 @@ int battle_get_party_id(struct block_list *bl) Race battle_get_race(struct block_list *bl) { nullpo_retr(Race::formless, bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return mob_db[((struct mob_data *) bl)->mob_class].race; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return Race::demihuman; else return Race::formless; @@ -880,7 +880,7 @@ Race battle_get_race(struct block_list *bl) MobMode battle_get_mode(struct block_list *bl) { nullpo_retr(MobMode::CAN_MOVE, bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return mob_db[((struct mob_data *) bl)->mob_class].mode; // とりあえず動くということで1 return MobMode::CAN_MOVE; @@ -889,13 +889,13 @@ MobMode battle_get_mode(struct block_list *bl) int battle_get_mexp(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) { const struct mob_data *mob = (struct mob_data *) bl; const int retval = (mob_db[mob->mob_class].mexp * - (int)(mob->stats[MOB_XP_BONUS])) >> MOB_XP_BONUS_SHIFT; - FPRINTF(stderr, "Modifier of %x: -> %d\n", mob->stats[MOB_XP_BONUS], + (int)(mob->stats[mob_stat::XP_BONUS])) >> MOB_XP_BONUS_SHIFT; + FPRINTF(stderr, "Modifier of %x: -> %d\n", mob->stats[mob_stat::XP_BONUS], retval); return retval; } @@ -907,17 +907,17 @@ int battle_get_stat(SP stat_id, struct block_list *bl) { switch (stat_id) { - case SP_STR: + case SP::STR: return battle_get_str(bl); - case SP_AGI: + case SP::AGI: return battle_get_agi(bl); - case SP_DEX: + case SP::DEX: return battle_get_dex(bl); - case SP_VIT: + case SP::VIT: return battle_get_vit(bl); - case SP_INT: + case SP::INT: return battle_get_int(bl); - case SP_LUK: + case SP::LUK: return battle_get_luk(bl); default: return 0; @@ -931,9 +931,9 @@ eptr battle_get_sc_data(struct block_list *b switch (bl->type) { - case BL_MOB: + case BL::MOB: return ((struct mob_data *)(bl))->sc_data; - case BL_PC: + case BL::PC: return ((struct map_session_data *)(bl))->sc_data; } return nullptr; @@ -942,9 +942,9 @@ eptr battle_get_sc_data(struct block_list *b short *battle_get_sc_count(struct block_list *bl) { nullpo_retr(NULL, bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return &((struct mob_data *) bl)->sc_count; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return &((struct map_session_data *) bl)->sc_count; return NULL; } @@ -952,11 +952,11 @@ short *battle_get_sc_count(struct block_list *bl) Opt1 *battle_get_opt1(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return &((struct mob_data *) bl)->opt1; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return &((struct map_session_data *) bl)->opt1; - else if (bl->type == BL_NPC && (struct npc_data *) bl) + else if (bl->type == BL::NPC && (struct npc_data *) bl) return &((struct npc_data *) bl)->opt1; return 0; } @@ -964,11 +964,11 @@ Opt1 *battle_get_opt1(struct block_list *bl) Opt2 *battle_get_opt2(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return &((struct mob_data *) bl)->opt2; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return &((struct map_session_data *) bl)->opt2; - else if (bl->type == BL_NPC && (struct npc_data *) bl) + else if (bl->type == BL::NPC && (struct npc_data *) bl) return &((struct npc_data *) bl)->opt2; return 0; } @@ -976,11 +976,11 @@ Opt2 *battle_get_opt2(struct block_list *bl) Opt3 *battle_get_opt3(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return &((struct mob_data *) bl)->opt3; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return &((struct map_session_data *) bl)->opt3; - else if (bl->type == BL_NPC && (struct npc_data *) bl) + else if (bl->type == BL::NPC && (struct npc_data *) bl) return &((struct npc_data *) bl)->opt3; return 0; } @@ -988,11 +988,11 @@ Opt3 *battle_get_opt3(struct block_list *bl) Option *battle_get_option(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB && (struct mob_data *) bl) + if (bl->type == BL::MOB && (struct mob_data *) bl) return &((struct mob_data *) bl)->option; - else if (bl->type == BL_PC && (struct map_session_data *) bl) + else if (bl->type == BL::PC && (struct map_session_data *) bl) return &((struct map_session_data *) bl)->status.option; - else if (bl->type == BL_NPC && (struct npc_data *) bl) + else if (bl->type == BL::NPC && (struct npc_data *) bl) return &((struct npc_data *) bl)->option; return 0; } @@ -1035,22 +1035,22 @@ int battle_damage(struct block_list *bl, struct block_list *target, && *sc_count > 0) { // 凍結、石化、睡眠を消去 - if (sc_data[SC_FREEZE].timer != -1) - skill_status_change_end(target, SC_FREEZE, -1); - if (sc_data[SC_STONE].timer != -1 && sc_data[SC_STONE].val2 == 0) - skill_status_change_end(target, SC_STONE, -1); - if (sc_data[SC_SLEEP].timer != -1) - skill_status_change_end(target, SC_SLEEP, -1); + if (sc_data[StatusChange::SC_FREEZE].timer != -1) + skill_status_change_end(target, StatusChange::SC_FREEZE, -1); + if (sc_data[StatusChange::SC_STONE].timer != -1 && sc_data[StatusChange::SC_STONE].val2 == 0) + skill_status_change_end(target, StatusChange::SC_STONE, -1); + if (sc_data[StatusChange::SC_SLEEP].timer != -1) + skill_status_change_end(target, StatusChange::SC_SLEEP, -1); } - if (target->type == BL_MOB) + if (target->type == BL::MOB) { // MOB struct mob_data *md = (struct mob_data *) target; if (md && md->skilltimer != -1 && md->state.skillcastcancel) // 詠唱妨害 skill_castcancel(target, 0); return mob_damage(bl, md, damage, 0); } - else if (target->type == BL_PC) + else if (target->type == BL::PC) { // PC struct map_session_data *tsd = (struct map_session_data *) target; @@ -1066,7 +1066,7 @@ int battle_heal(struct block_list *bl, struct block_list *target, int hp, { nullpo_ret(target); //blはNULLで呼ばれることがあるので他でチェック - if (target->type == BL_PC + if (target->type == BL::PC && pc_isdead((struct map_session_data *) target)) return 0; if (hp == 0 && sp == 0) @@ -1075,9 +1075,9 @@ int battle_heal(struct block_list *bl, struct block_list *target, int hp, if (hp < 0) return battle_damage(bl, target, -hp, flag); - if (target->type == BL_MOB) + if (target->type == BL::MOB) return mob_heal((struct mob_data *) target, hp); - else if (target->type == BL_PC) + else if (target->type == BL::PC) return pc_heal((struct map_session_data *) target, hp, sp); return 0; } @@ -1086,9 +1086,9 @@ int battle_heal(struct block_list *bl, struct block_list *target, int hp, int battle_stopattack(struct block_list *bl) { nullpo_ret(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) return mob_stopattack((struct mob_data *) bl); - else if (bl->type == BL_PC) + else if (bl->type == BL::PC) return pc_stopattack((struct map_session_data *) bl); return 0; } @@ -1097,9 +1097,9 @@ int battle_stopattack(struct block_list *bl) int battle_stopwalking(struct block_list *bl, int type) { nullpo_ret(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) return mob_stop_walking((struct mob_data *) bl, type); - else if (bl->type == BL_PC) + else if (bl->type == BL::PC) return pc_stop_walking((struct map_session_data *) bl, type); return 0; } @@ -1117,11 +1117,11 @@ int battle_calc_damage(struct block_list *, struct block_list *bl, nullpo_ret(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) md = (struct mob_data *) bl; if (battle_config.skill_min_damage - || bool(flag & BF_MISC)) + || bool(flag & BF::MISC)) { if (div_ < 255) { @@ -1167,14 +1167,14 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, sc_data = battle_get_sc_data(src); // ターゲット - if (target->type == BL_PC) + if (target->type == BL::PC) tsd = (struct map_session_data *) target; - else if (target->type == BL_MOB) + else if (target->type == BL::MOB) tmd = (struct mob_data *) target; MobMode t_mode = battle_get_mode(target); t_sc_data = battle_get_sc_data(target); - flag = BF_SHORT | BF_WEAPON | BF_NORMAL; // 攻撃の種類の設定 + flag = BF::SHORT | BF::WEAPON | BF::NORMAL; // 攻撃の種類の設定 // 回避率計算、回避判定は後で flee = battle_get_flee(target); @@ -1217,7 +1217,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, atkmax = battle_get_atk2(src); } if (mob_db[md->mob_class].range > 3) - flag = (flag & ~BF_RANGEMASK) | BF_LONG; + flag = (flag & ~BF::RANGEMASK) | BF::LONG; if (atkmin > atkmax) atkmin = atkmax; @@ -1230,7 +1230,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, if (cri < 1) cri = 1; } - if (t_sc_data && t_sc_data[SC_SLEEP].timer != -1) // 睡眠中はクリティカルが倍に + if (t_sc_data && t_sc_data[StatusChange::SC_SLEEP].timer != -1) // 睡眠中はクリティカルが倍に cri <<= 1; if (ac_flag) @@ -1259,7 +1259,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, if (skill_num != SkillID::ZERO && skill_num != SkillID::NEGATIVE) { - flag = (flag & ~BF_SKILLMASK) | BF_SKILL; + flag = (flag & ~BF::SKILLMASK) | BF::SKILL; } { @@ -1350,18 +1350,18 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, if (hitrate < 1000000) hitrate = ((hitrate > 95) ? 95 : ((hitrate < 5) ? 5 : hitrate)); if (hitrate < 1000000 && // 必中攻撃 - (t_sc_data && (t_sc_data[SC_SLEEP].timer != -1 || // 睡眠は必中 - t_sc_data[SC_STAN].timer != -1 || // スタンは必中 - t_sc_data[SC_FREEZE].timer != -1 || (t_sc_data[SC_STONE].timer != -1 && t_sc_data[SC_STONE].val2 == 0)))) // 凍結は必中 + (t_sc_data && (t_sc_data[StatusChange::SC_SLEEP].timer != -1 || // 睡眠は必中 + t_sc_data[StatusChange::SC_STAN].timer != -1 || // スタンは必中 + t_sc_data[StatusChange::SC_FREEZE].timer != -1 || (t_sc_data[StatusChange::SC_STONE].timer != -1 && t_sc_data[StatusChange::SC_STONE].val2 == 0)))) // 凍結は必中 hitrate = 1000000; if (type == DamageType::NORMAL && MRAND(100) >= hitrate) { damage = damage2 = 0; - dmg_lv = ATK_FLEE; + dmg_lv = ATK::FLEE; } else { - dmg_lv = ATK_DEF; + dmg_lv = ATK::DEF; } if (damage < 0) @@ -1373,7 +1373,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, { damage = 0; type = DamageType::FLEE2; - dmg_lv = ATK_LUCKY; + dmg_lv = ATK::LUCKY; } if (battle_config.enemy_perfect_flee) @@ -1383,7 +1383,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, { damage = 0; type = DamageType::FLEE2; - dmg_lv = ATK_LUCKY; + dmg_lv = ATK::LUCKY; } } @@ -1409,12 +1409,12 @@ int battle_is_unarmed(struct block_list *bl) { if (!bl) return 0; - if (bl->type == BL_PC) + if (bl->type == BL::PC) { struct map_session_data *sd = (struct map_session_data *) bl; - return (sd->equip_index[EQUIP_SHIELD] == -1 - && sd->equip_index[EQUIP_WEAPON] == -1); + return (sd->equip_index[EQUIP::SHIELD] == -1 + && sd->equip_index[EQUIP::WEAPON] == -1); } else return 0; @@ -1460,17 +1460,17 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, // アタッカー sc_data = battle_get_sc_data(src); //ステータス異常 - sd->state.attack_type = BF_WEAPON; //攻撃タイプは武器攻撃 + sd->state.attack_type = BF::WEAPON; //攻撃タイプは武器攻撃 // ターゲット - if (target->type == BL_PC) //対象がPCなら + if (target->type == BL::PC) //対象がPCなら tsd = (struct map_session_data *) target; //tsdに代入(tmdはNULL) - else if (target->type == BL_MOB) //対象がMobなら + else if (target->type == BL::MOB) //対象がMobなら tmd = (struct mob_data *) target; //tmdに代入(tsdはNULL) MobMode t_mode = battle_get_mode(target); //対象のMode t_sc_data = battle_get_sc_data(target); //対象のステータス異常 - flag = BF_SHORT | BF_WEAPON | BF_NORMAL; // 攻撃の種類の設定 + flag = BF::SHORT | BF::WEAPON | BF::NORMAL; // 攻撃の種類の設定 // 回避率計算、回避判定は後で flee = battle_get_flee(target); @@ -1506,7 +1506,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, target_distance = max(dx, dy); malus_dist = - max(0, target_distance - (skill_power(sd, AC_OWL) / 75)); + max(0, target_distance - (skill_power(sd, SkillID::AC_OWL) / 75)); hitrate -= (malus_dist * (malus_dist + 1)); } @@ -1547,7 +1547,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, if (sd->status.weapon == 11) { //武器が弓矢の場合 atkmin = watk * ((atkmin < watk) ? atkmin : watk) / 100; //弓用最低ATK計算 - flag = (flag & ~BF_RANGEMASK) | BF_LONG; //遠距離攻撃フラグを有効 + flag = (flag & ~BF::RANGEMASK) | BF::LONG; //遠距離攻撃フラグを有効 sd->state.arrow_atk = 1; //arrow_atk有効化 } @@ -1581,7 +1581,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, // カタールの場合、クリティカルを倍に cri <<= 1; cri -= battle_get_luk(target) * 3; - if (t_sc_data && t_sc_data[SC_SLEEP].timer != -1) // 睡眠中はクリティカルが倍に + if (t_sc_data && t_sc_data[StatusChange::SC_SLEEP].timer != -1) // 睡眠中はクリティカルが倍に cri <<= 1; if (ac_flag) cri = 1000; @@ -1631,7 +1631,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, if (skill_num != SkillID::ZERO && skill_num != SkillID::NEGATIVE) { - flag = (flag & ~BF_SKILLMASK) | BF_SKILL; + flag = (flag & ~BF::SKILLMASK) | BF::SKILL; } { @@ -1764,18 +1764,18 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, // 回避修正 hitrate = (hitrate < 5) ? 5 : hitrate; if (hitrate < 1000000 && // 必中攻撃 - (t_sc_data && (t_sc_data[SC_SLEEP].timer != -1 || // 睡眠は必中 - t_sc_data[SC_STAN].timer != -1 || // スタンは必中 - t_sc_data[SC_FREEZE].timer != -1 || (t_sc_data[SC_STONE].timer != -1 && t_sc_data[SC_STONE].val2 == 0)))) // 凍結は必中 + (t_sc_data && (t_sc_data[StatusChange::SC_SLEEP].timer != -1 || // 睡眠は必中 + t_sc_data[StatusChange::SC_STAN].timer != -1 || // スタンは必中 + t_sc_data[StatusChange::SC_FREEZE].timer != -1 || (t_sc_data[StatusChange::SC_STONE].timer != -1 && t_sc_data[StatusChange::SC_STONE].val2 == 0)))) // 凍結は必中 hitrate = 1000000; if (type == DamageType::NORMAL && MRAND(100) >= hitrate) { damage = damage2 = 0; - dmg_lv = ATK_FLEE; + dmg_lv = ATK::FLEE; } else { - dmg_lv = ATK_DEF; + dmg_lv = ATK::DEF; } if (damage < 0) @@ -1839,7 +1839,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, { damage = damage2 = 0; type = DamageType::FLEE2; - dmg_lv = ATK_LUCKY; + dmg_lv = ATK::LUCKY; } // 対象が完全回避をする設定がONなら @@ -1850,7 +1850,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, { damage = damage2 = 0; type = DamageType::FLEE2; - dmg_lv = ATK_LUCKY; + dmg_lv = ATK::LUCKY; } } @@ -1913,12 +1913,12 @@ struct Damage battle_calc_weapon_attack(struct block_list *src, nullpo_retr(wd, src); nullpo_retr(wd, target); - if (src->type == BL_PC) + if (src->type == BL::PC) wd = battle_calc_pc_weapon_attack(src, target, skill_num, skill_lv, wflag); // weapon breaking [Valaris] - else if (src->type == BL_MOB) + else if (src->type == BL::MOB) wd = battle_calc_mob_weapon_attack(src, target, skill_num, skill_lv, wflag); - if (battle_config.equipment_breaking && src->type == BL_PC + if (battle_config.equipment_breaking && src->type == BL::PC && (wd.damage > 0 || wd.damage2 > 0)) { struct map_session_data *sd = (struct map_session_data *) src; @@ -1937,7 +1937,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src, } } - if (battle_config.equipment_breaking && target->type == BL_PC + if (battle_config.equipment_breaking && target->type == BL::PC && (wd.damage > 0 || wd.damage2 > 0)) { int breakrate = 1; @@ -1977,17 +1977,21 @@ struct Damage battle_calc_magic_attack(struct block_list *bl, matk2 = battle_get_matk2(bl); MobMode t_mode = battle_get_mode(target); -#define MATK_FIX( a,b ) { matk1=matk1*(a)/(b); matk2=matk2*(a)/(b); } +#define MATK_FIX(a, b) \ +{ \ + matk1 = matk1 * (a) / (b); \ + matk2 = matk2 * (a) / (b); \ +} - if (bl->type == BL_PC && (sd = (struct map_session_data *) bl)) + if (bl->type == BL::PC && (sd = (struct map_session_data *) bl)) { - sd->state.attack_type = BF_MAGIC; + sd->state.attack_type = BF::MAGIC; if (sd->matk_rate != 100) MATK_FIX(sd->matk_rate, 100); sd->state.arrow_atk = 0; } - BF aflag = BF_MAGIC | BF_LONG | BF_SKILL; + BF aflag = BF::MAGIC | BF::LONG | BF::SKILL; if (normalmagic_flag) { // 一般魔法ダメージ計算 @@ -2054,20 +2058,20 @@ struct Damage battle_calc_misc_attack(struct block_list *bl, struct Damage md {}; int damagefix = 1; - BF aflag = BF_MISC | BF_LONG | BF_SKILL; + BF aflag = BF::MISC | BF::LONG | BF::SKILL; nullpo_retr(md, bl); nullpo_retr(md, target); - if (bl->type == BL_PC && (sd = (struct map_session_data *) bl)) + if (bl->type == BL::PC && (sd = (struct map_session_data *) bl)) { - sd->state.attack_type = BF_MISC; + sd->state.attack_type = BF::MISC; sd->state.arrow_atk = 0; } switch (skill_num) { - case NPC_SELFDESTRUCTION: // 自爆 + case SkillID::NPC_SELFDESTRUCTION: // 自爆 damage = battle_get_hp(bl) - (bl == target ? 1 : 0); damagefix = 0; break; @@ -2118,13 +2122,13 @@ struct Damage battle_calc_attack(BF attack_type, switch (attack_type) { - case BF_WEAPON: + case BF::WEAPON: return battle_calc_weapon_attack(bl, target, skill_num, skill_lv, flag); - case BF_MAGIC: + case BF::MAGIC: return battle_calc_magic_attack(bl, target, skill_num, skill_lv, flag); - case BF_MISC: + case BF::MISC: return battle_calc_misc_attack(bl, target, skill_num, skill_lv, flag); default: @@ -2150,14 +2154,14 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, nullpo_retr(ATK::ZERO, src); nullpo_retr(ATK::ZERO, target); - if (src->type == BL_PC) + if (src->type == BL::PC) sd = (struct map_session_data *) src; if (src->prev == NULL || target->prev == NULL) return ATK::ZERO; - if (src->type == BL_PC && pc_isdead(sd)) + if (src->type == BL::PC && pc_isdead(sd)) return ATK::ZERO; - if (target->type == BL_PC + if (target->type == BL::PC && pc_isdead((struct map_session_data *) target)) return ATK::ZERO; @@ -2188,15 +2192,15 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, wd = battle_calc_weapon_attack(src, target, SkillID::ZERO, 0, 0); // significantly increase injuries for hasted characters - if (wd.damage > 0 && (t_sc_data[SC_HASTE].timer != -1)) + if (wd.damage > 0 && (t_sc_data[StatusChange::SC_HASTE].timer != -1)) { - wd.damage = (wd.damage * (16 + t_sc_data[SC_HASTE].val1)) >> 4; + wd.damage = (wd.damage * (16 + t_sc_data[StatusChange::SC_HASTE].val1)) >> 4; } if (wd.damage > 0 - && t_sc_data[SC_PHYS_SHIELD].timer != -1 && target->type == BL_PC) + && t_sc_data[StatusChange::SC_PHYS_SHIELD].timer != -1 && target->type == BL::PC) { - int reduction = t_sc_data[SC_PHYS_SHIELD].val1; + int reduction = t_sc_data[StatusChange::SC_PHYS_SHIELD].val1; if (reduction > wd.damage) reduction = wd.damage; @@ -2216,7 +2220,7 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, map_freeblock_lock(); - if (src->type == BL_PC) + if (src->type == BL::PC) { int weapon_index = sd->equip_index[EQUIP::WEAPON]; int weapon = 0; @@ -2226,21 +2230,21 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, MAP_LOG("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d", sd->status.char_id, src->m, src->x, src->y, - (target->type == BL_PC) ? "PC" : "MOB", + (target->type == BL::PC) ? "PC" : "MOB", (target->type == - BL_PC) ? ((struct map_session_data *) target)-> + BL::PC) ? ((struct map_session_data *) target)-> status.char_id : target->id, battle_get_class(target), wd.damage + wd.damage2, weapon); } - if (target->type == BL_PC) + if (target->type == BL::PC) { struct map_session_data *sd2 = (struct map_session_data *) target; MAP_LOG("PC%d %d:%d,%d WPNINJURY %s%d %d FOR %d", sd2->status.char_id, target->m, target->x, target->y, - (src->type == BL_PC) ? "PC" : "MOB", - (src->type == BL_PC) + (src->type == BL::PC) ? "PC" : "MOB", + (src->type == BL::PC) ? ((struct map_session_data *) src)->status.char_id : src->id, battle_get_class(src), @@ -2249,18 +2253,18 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, battle_damage(src, target, (wd.damage + wd.damage2), 0); if (target->prev != NULL && - (target->type != BL_PC - || (target->type == BL_PC + (target->type != BL::PC + || (target->type == BL::PC && !pc_isdead((struct map_session_data *) target)))) { if (wd.damage > 0 || wd.damage2 > 0) { - skill_additional_effect(src, target, SkillID::ZERO, 0, BF_WEAPON, tick); + skill_additional_effect(src, target, SkillID::ZERO, 0, BF::WEAPON, tick); } } if (sd) { - if (bool(wd.flag & BF_WEAPON) + if (bool(wd.flag & BF::WEAPON) && src != target && (wd.damage > 0 || wd.damage2 > 0)) { @@ -2339,18 +2343,18 @@ int battle_check_target(struct block_list *src, struct block_list *target, if (flag & BCT_ALL) { - if (target->type == BL_MOB || target->type == BL_PC) + if (target->type == BL::MOB || target->type == BL::PC) return 1; else return -1; } - if (target->type == BL_PC + if (target->type == BL::PC && ((struct map_session_data *) target)->invincible_timer != -1) return -1; // Mobでmaster_idがあってspecial_mob_aiなら、召喚主を求める - if (src->type == BL_MOB) + if (src->type == BL::MOB) { struct mob_data *md = (struct mob_data *) src; if (md && md->master_id > 0) @@ -2359,7 +2363,7 @@ int battle_check_target(struct block_list *src, struct block_list *target, return 1; if (md->state.special_mob_ai) { - if (target->type == BL_MOB) + if (target->type == BL::MOB) { //special_mob_aiで対象がMob struct mob_data *tmd = (struct mob_data *) target; if (tmd) @@ -2384,16 +2388,16 @@ int battle_check_target(struct block_list *src, struct block_list *target, if (src == target || ss == target) // 同じなら肯定 return 1; - if (target->type == BL_PC + if (target->type == BL::PC && pc_isinvisible((struct map_session_data *) target)) return -1; if (src->prev == NULL || // 死んでるならエラー - (src->type == BL_PC && pc_isdead((struct map_session_data *) src))) + (src->type == BL::PC && pc_isdead((struct map_session_data *) src))) return -1; - if ((ss->type == BL_PC && target->type == BL_MOB) || - (ss->type == BL_MOB && target->type == BL_PC)) + if ((ss->type == BL::PC && target->type == BL::MOB) || + (ss->type == BL::MOB && target->type == BL::PC)) return 0; // PCvsMOBなら否定 s_p = battle_get_party_id(ss); @@ -2411,7 +2415,7 @@ int battle_check_target(struct block_list *src, struct block_list *target, //PRINTF("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type); //PRINTF("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g); - if (ss->type == BL_PC && target->type == BL_PC) + if (ss->type == BL::PC && target->type == BL::PC) { // 両方PVPモードなら否定(敵) if (map[ss->m].flag.pvp || pc_iskiller((struct map_session_data *) ss, @@ -2579,11 +2583,11 @@ int battle_config_read(const char *cfgName) battle_config.agi_penaly_type = 0; battle_config.agi_penaly_count = 3; battle_config.agi_penaly_num = 0; - battle_config.agi_penaly_count_lv = int(ATK_FLEE); // FIXME + battle_config.agi_penaly_count_lv = int(ATK::FLEE); // FIXME battle_config.vit_penaly_type = 0; battle_config.vit_penaly_count = 3; battle_config.vit_penaly_num = 0; - battle_config.vit_penaly_count_lv = int(ATK_DEF); // FIXME + battle_config.vit_penaly_count_lv = int(ATK::DEF); // FIXME battle_config.player_defense_type = 0; battle_config.monster_defense_type = 0; battle_config.magic_defense_type = 0; diff --git a/src/map/battle.t.hpp b/src/map/battle.t.hpp index 94bdd50..e374298 100644 --- a/src/map/battle.t.hpp +++ b/src/map/battle.t.hpp @@ -11,25 +11,15 @@ enum class BF : uint16_t NEGATIVE_1 = 0xffff, WEAPON = 0x0001, -#define BF_WEAPON BF::WEAPON MAGIC = 0x0002, -#define BF_MAGIC BF::MAGIC MISC = 0x0004, -#define BF_MISC BF::MISC SHORT = 0x0010, -#define BF_SHORT BF::SHORT LONG = 0x0040, -#define BF_LONG BF::LONG SKILL = 0x0100, -#define BF_SKILL BF::SKILL NORMAL = 0x0200, -#define BF_NORMAL BF::NORMAL WEAPONMASK = 0x000f, -#define BF_WEAPONMASK BF::WEAPONMASK RANGEMASK = 0x00f0, -#define BF_RANGEMASK BF::RANGEMASK SKILLMASK = 0x0f00, -#define BF_SKILLMASK BF::SKILLMASK }; ENUM_BITWISE_OPERATORS(BF) } diff --git a/src/map/chat.cpp b/src/map/chat.cpp index 75b45e9..0d3bb95 100644 --- a/src/map/chat.cpp +++ b/src/map/chat.cpp @@ -45,16 +45,16 @@ int chat_leavechat(struct map_session_data *sd) cd->users--; pc_setchatid(sd, 0); - if (cd->users == 0 && (*cd->owner)->type == BL_PC) + if (cd->users == 0 && (*cd->owner)->type == BL::PC) { // 全員居なくなった&PCのチャットなので消す - map_delobject(cd->bl.id, BL_CHAT); // freeまでしてくれる + map_delobject(cd->bl.id, BL::CHAT); // freeまでしてくれる } else { for (i = leavechar; i < cd->users; i++) cd->usersd[i] = cd->usersd[i + 1]; - if (leavechar == 0 && (*cd->owner)->type == BL_PC) + if (leavechar == 0 && (*cd->owner)->type == BL::PC) { // PCのチャットなので所有者が抜けたので位置変更 cd->bl.x = cd->usersd[0]->bl.x; @@ -92,7 +92,7 @@ int chat_createnpcchat(struct npc_data *nd, int limit, int pub, int trigger, cd->bl.m = nd->bl.m; cd->bl.x = nd->bl.x; cd->bl.y = nd->bl.y; - cd->bl.type = BL_CHAT; + cd->bl.type = BL::CHAT; cd->owner_ = (struct block_list *) nd; cd->owner = &cd->owner_; memcpy(cd->npc_event, ev, sizeof(cd->npc_event)); @@ -121,7 +121,7 @@ int chat_deletenpcchat(struct npc_data *nd) nullpo_ret(cd); chat_npckickall(cd); - map_delobject(cd->bl.id, BL_CHAT); // freeまでしてくれる + map_delobject(cd->bl.id, BL::CHAT); // freeまでしてくれる nd->chat_id = 0; return 0; diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 302d04c..360c054 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -952,7 +952,7 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) switch (bl->type) { - case BL_PC: + case BL::PC: { struct map_session_data *pc = (struct map_session_data *) bl; struct storage *stor = account2storage2(pc->status.account_id); @@ -987,7 +987,7 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) break; } - case BL_MOB: + case BL::MOB: { struct mob_data *mob = (struct mob_data *) bl; int i; @@ -996,7 +996,7 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) break; } - case BL_ITEM: + case BL::ITEM: { struct flooritem_data *item = (struct flooritem_data *) bl; FIX(item->item_data); @@ -1021,7 +1021,7 @@ void ladmin_itemfrob(int fd) struct block_list *bl = (struct block_list *) map_get_first_session(); // flooritems - map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), BL_NUL /* any object */); + map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), BL::NUL /* any object */); // player characters (and, hopefully, mobs) while (bl->next) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index e719430..65b5246 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -32,7 +32,7 @@ #define DUMP_UNKNOWN_PACKET 1 -#define EMOTE_IGNORED 0x0e +constexpr int EMOTE_IGNORED = 0x0e; static const int packet_len_table[0x220] = { @@ -238,7 +238,7 @@ static int is_deaf(struct block_list *bl) { struct map_session_data *sd = (struct map_session_data *) bl; - if (!bl || bl->type != BL_PC) + if (!bl || bl->type != BL::PC) return 0; return sd->special_state.deaf; } @@ -271,7 +271,7 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, case AREA_CHAT_WOC: if (is_deaf(bl) - && !(bl->type == BL_PC + && !(bl->type == BL::PC && pc_isGM((struct map_session_data *) src_bl))) { clif_emotion_towards(src_bl, bl, EMOTE_IGNORED); @@ -328,7 +328,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) { nullpo_ret(bl); - if (bl->type == BL_PC) + if (bl->type == BL::PC) { struct map_session_data *sd2 = (struct map_session_data *) bl; if (bool(sd2->status.option & Option::INVISIBILITY)) @@ -389,22 +389,22 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) case AREA_WOSC: map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, type), bl->m, bl->x - AREA_SIZE, bl->y - AREA_SIZE, - bl->x + AREA_SIZE, bl->y + AREA_SIZE, BL_PC); + bl->x + AREA_SIZE, bl->y + AREA_SIZE, BL::PC); break; case AREA_CHAT_WOC: map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, AREA_CHAT_WOC), bl->m, bl->x - (AREA_SIZE), bl->y - (AREA_SIZE), - bl->x + (AREA_SIZE), bl->y + (AREA_SIZE), BL_PC); + bl->x + (AREA_SIZE), bl->y + (AREA_SIZE), BL::PC); break; case CHAT_: case CHAT_WOS: cd = (struct chat_data *) bl; - if (bl->type == BL_PC) + if (bl->type == BL::PC) { sd = (struct map_session_data *) bl; cd = (struct chat_data *) map_id2bl(sd->chatID); } - else if (bl->type != BL_CHAT) + else if (bl->type != BL::CHAT) break; if (cd == NULL) break; @@ -432,7 +432,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) case PARTY_WOS: // 自分以外の全パーティーメンバに送信 case PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信 case PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信 - if (bl->type == BL_PC) + if (bl->type == BL::PC) { sd = (struct map_session_data *) bl; if (sd->partyspy > 0) @@ -652,7 +652,7 @@ int clif_clearflooritem(struct flooritem_data *fitem, int fd) * *------------------------------------------ */ -int clif_clearchar(struct block_list *bl, int type) +int clif_clearchar(struct block_list *bl, BeingRemoveWhy type) { unsigned char buf[16]; @@ -660,16 +660,16 @@ int clif_clearchar(struct block_list *bl, int type) WBUFW(buf, 0) = 0x80; WBUFL(buf, 2) = bl->id; - if (type == 9) + if (type == BeingRemoveWhy::DISGUISE) { - WBUFB(buf, 6) = 0; + WBUFB(buf, 6) = static_cast(BeingRemoveWhy::GONE); clif_send(buf, packet_len_table[0x80], bl, AREA); } else { - WBUFB(buf, 6) = type; + WBUFB(buf, 6) = static_cast(type); clif_send(buf, packet_len_table[0x80], bl, - type == 1 ? AREA : AREA_WOS); + type == BeingRemoveWhy::DEAD ? AREA : AREA_WOS); } return 0; @@ -681,17 +681,17 @@ void clif_clearchar_delay_sub(timer_id, tick_t, custom_id_t id, { struct block_list *bl = (struct block_list *) id; - clif_clearchar(bl, data); + clif_clearchar(bl, static_cast(data)); map_freeblock(bl); } -int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) +int clif_clearchar_delay(unsigned int tick, struct block_list *bl, BeingRemoveWhy type) { struct block_list *tmpbl; CREATE(tmpbl, struct block_list, 1); memcpy(tmpbl, bl, sizeof(struct block_list)); - add_timer(tick, clif_clearchar_delay_sub, (custom_id_t) tmpbl, type); + add_timer(tick, clif_clearchar_delay_sub, (custom_id_t) tmpbl, static_cast(type)); return 0; } @@ -700,13 +700,13 @@ int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) * *------------------------------------------ */ -int clif_clearchar_id(int id, int type, int fd) +int clif_clearchar_id(int id, BeingRemoveWhy type, int fd) { unsigned char buf[16]; WBUFW(buf, 0) = 0x80; WBUFL(buf, 2) = id; - WBUFB(buf, 6) = type; + WBUFB(buf, 6) = static_cast(type); memcpy(WFIFOP(fd, 0), buf, 7); WFIFOSET(fd, packet_len_table[0x80]); @@ -1082,7 +1082,7 @@ int clif_spawnmob(struct mob_data *md) WBUFW(buf, 0) = 0x7c; WBUFL(buf, 2) = md->bl.id; - WBUFW(buf, 6) = md->stats[MOB_SPEED]; + WBUFW(buf, 6) = md->stats[mob_stat::SPEED]; WBUFW(buf, 8) = uint16_t(md->opt1); WBUFW(buf, 10) = uint16_t(md->opt2); WBUFW(buf, 12) = uint16_t(md->option); @@ -1152,7 +1152,7 @@ int clif_movechar(struct map_session_data *sd) clif_send(buf, len, &sd->bl, AREA_WOS); if (battle_config.save_clothcolor == 1 && sd->status.clothes_color > 0) - clif_changelook(&sd->bl, LOOK_CLOTHES_COLOR, + clif_changelook(&sd->bl, LOOK::CLOTHES_COLOR, sd->status.clothes_color); return 0; @@ -1867,121 +1867,121 @@ int clif_updatestatus(struct map_session_data *sd, SP type) switch (type) { // 00b0 - case SP_WEIGHT: + case SP::WEIGHT: pc_checkweighticon(sd); // is this because pc_checkweighticon can send other packets? WFIFOW(fd, 0) = 0xb0; WFIFOW(fd, 2) = uint16_t(type); WFIFOL(fd, 4) = sd->weight; break; - case SP_MAXWEIGHT: + case SP::MAXWEIGHT: WFIFOL(fd, 4) = sd->max_weight; break; - case SP_SPEED: + case SP::SPEED: WFIFOL(fd, 4) = sd->speed; break; - case SP_BASELEVEL: + case SP::BASELEVEL: WFIFOL(fd, 4) = sd->status.base_level; break; - case SP_JOBLEVEL: + case SP::JOBLEVEL: WFIFOL(fd, 4) = 0; break; - case SP_STATUSPOINT: + case SP::STATUSPOINT: WFIFOL(fd, 4) = sd->status.status_point; break; - case SP_SKILLPOINT: + case SP::SKILLPOINT: WFIFOL(fd, 4) = sd->status.skill_point; break; - case SP_HIT: + case SP::HIT: WFIFOL(fd, 4) = sd->hit; break; - case SP_FLEE1: + case SP::FLEE1: WFIFOL(fd, 4) = sd->flee; break; - case SP_FLEE2: + case SP::FLEE2: WFIFOL(fd, 4) = sd->flee2 / 10; break; - case SP_MAXHP: + case SP::MAXHP: WFIFOL(fd, 4) = sd->status.max_hp; break; - case SP_MAXSP: + case SP::MAXSP: WFIFOL(fd, 4) = sd->status.max_sp; break; - case SP_HP: + case SP::HP: WFIFOL(fd, 4) = sd->status.hp; break; - case SP_SP: + case SP::SP: WFIFOL(fd, 4) = sd->status.sp; break; - case SP_ASPD: + case SP::ASPD: WFIFOL(fd, 4) = sd->aspd; break; - case SP_ATK1: + case SP::ATK1: WFIFOL(fd, 4) = sd->base_atk + sd->watk; break; - case SP_DEF1: + case SP::DEF1: WFIFOL(fd, 4) = sd->def; break; - case SP_MDEF1: + case SP::MDEF1: WFIFOL(fd, 4) = sd->mdef; break; - case SP_ATK2: + case SP::ATK2: WFIFOL(fd, 4) = sd->watk2; break; - case SP_DEF2: + case SP::DEF2: WFIFOL(fd, 4) = sd->def2; break; - case SP_MDEF2: + case SP::MDEF2: WFIFOL(fd, 4) = sd->mdef2; break; - case SP_CRITICAL: + case SP::CRITICAL: WFIFOL(fd, 4) = sd->critical / 10; break; - case SP_MATK1: + case SP::MATK1: WFIFOL(fd, 4) = sd->matk1; break; - case SP_MATK2: + case SP::MATK2: WFIFOL(fd, 4) = sd->matk2; break; - case SP_ZENY: + case SP::ZENY: trade_verifyzeny(sd); WFIFOW(fd, 0) = 0xb1; if (sd->status.zeny < 0) sd->status.zeny = 0; WFIFOL(fd, 4) = sd->status.zeny; break; - case SP_BASEEXP: + case SP::BASEEXP: WFIFOW(fd, 0) = 0xb1; WFIFOL(fd, 4) = sd->status.base_exp; break; - case SP_JOBEXP: + case SP::JOBEXP: WFIFOW(fd, 0) = 0xb1; WFIFOL(fd, 4) = sd->status.job_exp; break; - case SP_NEXTBASEEXP: + case SP::NEXTBASEEXP: WFIFOW(fd, 0) = 0xb1; WFIFOL(fd, 4) = pc_nextbaseexp(sd); break; - case SP_NEXTJOBEXP: + case SP::NEXTJOBEXP: WFIFOW(fd, 0) = 0xb1; WFIFOL(fd, 4) = pc_nextjobexp(sd); break; // 00be 終了 - case SP_USTR: - case SP_UAGI: - case SP_UVIT: - case SP_UINT: - case SP_UDEX: - case SP_ULUK: + case SP::USTR: + case SP::UAGI: + case SP::UVIT: + case SP::UINT: + case SP::UDEX: + case SP::ULUK: WFIFOW(fd, 0) = 0xbe; WFIFOB(fd, 4) = pc_need_status_point(sd, usp_to_sp(type)); len = 5; break; // 013a 終了 - case SP_ATTACKRANGE: + case SP::ATTACKRANGE: WFIFOW(fd, 0) = 0x13a; WFIFOW(fd, 2) = (sd->attack_spell_override) ? sd->attack_spell_range : sd->attackrange; @@ -1989,12 +1989,12 @@ int clif_updatestatus(struct map_session_data *sd, SP type) break; // 0141 終了 - case SP_STR: - case SP_AGI: - case SP_VIT: - case SP_INT: - case SP_DEX: - case SP_LUK: + case SP::STR: + case SP::AGI: + case SP::VIT: + case SP::INT: + case SP::DEX: + case SP::LUK: { ATTR attr = sp_to_attr(type); WFIFOW(fd, 0) = 0x141; @@ -2005,7 +2005,7 @@ int clif_updatestatus(struct map_session_data *sd, SP type) } break; - case SP_GM: + case SP::GM: WFIFOL(fd, 4) = pc_isGM(sd); break; @@ -2037,18 +2037,18 @@ int clif_changelook_towards(struct block_list *bl, LOOK type, int val, nullpo_ret(bl); - if (bl->type == BL_PC) + if (bl->type == BL::PC) sd = (struct map_session_data *) bl; if (sd && bool(sd->status.option & Option::INVISIBILITY)) return 0; if (sd - && (type == LOOK_WEAPON || type == LOOK_SHIELD || type >= LOOK_SHOES)) + && (type == LOOK::WEAPON || type == LOOK::SHIELD || type >= LOOK::SHOES)) { WBUFW(buf, 0) = 0x1d7; WBUFL(buf, 2) = bl->id; - if (type >= LOOK_SHOES) + if (type >= LOOK::SHOES) { EQUIP equip_point = equip_points[type]; @@ -2139,17 +2139,17 @@ int clif_initialstatus(struct map_session_data *sd) WFIFOW(fd, 2) = sd->status.status_point; WFIFOB(fd, 4) = min(sd->status.attrs[ATTR::STR], 255); - WFIFOB(fd, 5) = pc_need_status_point(sd, SP_STR); + WFIFOB(fd, 5) = pc_need_status_point(sd, SP::STR); WFIFOB(fd, 6) = min(sd->status.attrs[ATTR::AGI], 255); - WFIFOB(fd, 7) = pc_need_status_point(sd, SP_AGI); + WFIFOB(fd, 7) = pc_need_status_point(sd, SP::AGI); WFIFOB(fd, 8) = min(sd->status.attrs[ATTR::VIT], 255); - WFIFOB(fd, 9) = pc_need_status_point(sd, SP_VIT); + WFIFOB(fd, 9) = pc_need_status_point(sd, SP::VIT); WFIFOB(fd, 10) = min(sd->status.attrs[ATTR::INT], 255); - WFIFOB(fd, 11) = pc_need_status_point(sd, SP_INT); + WFIFOB(fd, 11) = pc_need_status_point(sd, SP::INT); WFIFOB(fd, 12) = min(sd->status.attrs[ATTR::DEX], 255); - WFIFOB(fd, 13) = pc_need_status_point(sd, SP_DEX); + WFIFOB(fd, 13) = pc_need_status_point(sd, SP::DEX); WFIFOB(fd, 14) = min(sd->status.attrs[ATTR::LUK], 255); - WFIFOB(fd, 15) = pc_need_status_point(sd, SP_LUK); + WFIFOB(fd, 15) = pc_need_status_point(sd, SP::LUK); WFIFOW(fd, 16) = sd->base_atk + sd->watk; WFIFOW(fd, 18) = sd->watk2; //atk bonus @@ -2168,15 +2168,15 @@ int clif_initialstatus(struct map_session_data *sd) WFIFOSET(fd, packet_len_table[0xbd]); - clif_updatestatus(sd, SP_STR); - clif_updatestatus(sd, SP_AGI); - clif_updatestatus(sd, SP_VIT); - clif_updatestatus(sd, SP_INT); - clif_updatestatus(sd, SP_DEX); - clif_updatestatus(sd, SP_LUK); + clif_updatestatus(sd, SP::STR); + clif_updatestatus(sd, SP::AGI); + clif_updatestatus(sd, SP::VIT); + clif_updatestatus(sd, SP::INT); + clif_updatestatus(sd, SP::DEX); + clif_updatestatus(sd, SP::LUK); - clif_updatestatus(sd, SP_ATTACKRANGE); - clif_updatestatus(sd, SP_ASPD); + clif_updatestatus(sd, SP::ATTACKRANGE); + clif_updatestatus(sd, SP::ASPD); return 0; } @@ -2681,7 +2681,7 @@ int clif_storageclose(struct map_session_data *sd) void clif_changelook_accessories(struct block_list *bl, struct map_session_data *dest) { - for (LOOK i = LOOK_SHOES; i < LOOK::COUNT; i = LOOK(uint8_t(i) + 1)) + for (LOOK i = LOOK::SHOES; i < LOOK::COUNT; i = LOOK(uint8_t(i) + 1)) clif_changelook_towards(bl, i, 0, dest); } @@ -2716,7 +2716,7 @@ void clif_getareachar_pc(struct map_session_data *sd, } if (battle_config.save_clothcolor == 1 && dstsd->status.clothes_color > 0) - clif_changelook(&dstsd->bl, LOOK_CLOTHES_COLOR, + clif_changelook(&dstsd->bl, LOOK::CLOTHES_COLOR, dstsd->status.clothes_color); clif_changelook_accessories(&sd->bl, dstsd); @@ -2770,7 +2770,7 @@ int clif_fixmobpos(struct mob_data *md) nullpo_ret(md); - if (md->state.state == MS_WALK) + if (md->state.state == MS::WALK) { len = clif_mob007b(md, buf); clif_send(buf, len, &md->bl, AREA); @@ -2852,7 +2852,7 @@ void clif_getareachar_mob(struct map_session_data *sd, struct mob_data *md) nullpo_retv(sd); nullpo_retv(md); - if (md->state.state == MS_WALK) + if (md->state.state == MS::WALK) { len = clif_mob007b(md, static_cast(WFIFOP(sd->fd, 0))); WFIFOSET(sd->fd, len); @@ -2906,18 +2906,18 @@ void clif_getareachar(struct block_list *bl, struct map_session_data *sd) switch (bl->type) { - case BL_PC: + case BL::PC: if (sd == (struct map_session_data *) bl) break; clif_getareachar_pc(sd, (struct map_session_data *) bl); break; - case BL_NPC: + case BL::NPC: clif_getareachar_npc(sd, (struct npc_data *) bl); break; - case BL_MOB: + case BL::MOB: clif_getareachar_mob(sd, (struct mob_data *) bl); break; - case BL_ITEM: + case BL::ITEM: clif_getareachar_item(sd, (struct flooritem_data *) bl); break; default: @@ -2941,22 +2941,22 @@ void clif_pcoutsight(struct block_list *bl, struct map_session_data *sd) switch (bl->type) { - case BL_PC: + case BL::PC: dstsd = (struct map_session_data *) bl; if (sd != dstsd) { - clif_clearchar_id(dstsd->bl.id, 0, sd->fd); - clif_clearchar_id(sd->bl.id, 0, dstsd->fd); + clif_clearchar_id(dstsd->bl.id, BeingRemoveWhy::GONE, sd->fd); + clif_clearchar_id(sd->bl.id, BeingRemoveWhy::GONE, dstsd->fd); } break; - case BL_NPC: + case BL::NPC: if (((struct npc_data *) bl)->npc_class != INVISIBLE_CLASS) - clif_clearchar_id(bl->id, 0, sd->fd); + clif_clearchar_id(bl->id, BeingRemoveWhy::GONE, sd->fd); break; - case BL_MOB: - clif_clearchar_id(bl->id, 0, sd->fd); + case BL::MOB: + clif_clearchar_id(bl->id, BeingRemoveWhy::GONE, sd->fd); break; - case BL_ITEM: + case BL::ITEM: clif_clearflooritem((struct flooritem_data *) bl, sd->fd); break; } @@ -2975,7 +2975,7 @@ void clif_pcinsight(struct block_list *bl, struct map_session_data *sd) switch (bl->type) { - case BL_PC: + case BL::PC: dstsd = (struct map_session_data *) bl; if (sd != dstsd) { @@ -2983,13 +2983,13 @@ void clif_pcinsight(struct block_list *bl, struct map_session_data *sd) clif_getareachar_pc(dstsd, sd); } break; - case BL_NPC: + case BL::NPC: clif_getareachar_npc(sd, (struct npc_data *) bl); break; - case BL_MOB: + case BL::MOB: clif_getareachar_mob(sd, (struct mob_data *) bl); break; - case BL_ITEM: + case BL::ITEM: clif_getareachar_item(sd, (struct flooritem_data *) bl); break; } @@ -3006,9 +3006,9 @@ void clif_moboutsight(struct block_list *bl, struct mob_data *md) nullpo_retv(bl); nullpo_retv(md); - if (bl->type == BL_PC && (sd = (struct map_session_data *) bl)) + if (bl->type == BL::PC && (sd = (struct map_session_data *) bl)) { - clif_clearchar_id(md->bl.id, 0, sd->fd); + clif_clearchar_id(md->bl.id, BeingRemoveWhy::GONE, sd->fd); } } @@ -3023,7 +3023,7 @@ void clif_mobinsight(struct block_list *bl, struct mob_data *md) nullpo_retv(bl); nullpo_retv(md); - if (bl->type == BL_PC && (sd = (struct map_session_data *) bl)) + if (bl->type == BL::PC && (sd = (struct map_session_data *) bl)) { clif_getareachar_mob(sd, md); } @@ -3093,7 +3093,7 @@ int clif_skillinfoblock(struct map_session_data *sd) WFIFOW(fd, len + 2) = skill_get_inf(id); WFIFOW(fd, len + 4) = uint16_t( skill_db[i].poolflags - | (sd->status.skill[i].flags & SKILL_POOL_ACTIVATED)); + | (sd->status.skill[i].flags & SkillFlags::POOL_ACTIVATED)); WFIFOW(fd, len + 6) = sd->status.skill[i].lv; WFIFOW(fd, len + 8) = skill_get_sp(id, sd->status.skill[i].lv); range = skill_get_range(id, sd->status.skill[i].lv); @@ -3648,7 +3648,7 @@ void clif_emotion_towards(struct block_list *bl, nullpo_retv(bl); nullpo_retv(target); - if (target->type != BL_PC) + if (target->type != BL::PC) return; WBUFW(buf, 0) = 0xc0; @@ -3825,10 +3825,10 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd) // loadendack時 // next exp - clif_updatestatus(sd, SP_NEXTBASEEXP); - clif_updatestatus(sd, SP_NEXTJOBEXP); + clif_updatestatus(sd, SP::NEXTBASEEXP); + clif_updatestatus(sd, SP::NEXTJOBEXP); // skill point - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::SKILLPOINT); // item clif_itemlist(sd); clif_equiplist(sd); @@ -3848,8 +3848,8 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd) clif_spawnpc(sd); // spawn // weight max , now - clif_updatestatus(sd, SP_MAXWEIGHT); - clif_updatestatus(sd, SP_WEIGHT); + clif_updatestatus(sd, SP::MAXWEIGHT); + clif_updatestatus(sd, SP::WEIGHT); // pvp if (sd->pvp_timer != -1 && !battle_config.pk_mode) @@ -3874,13 +3874,13 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd) sd->state.connect_new = 0; // view equipment item - clif_changelook(&sd->bl, LOOK_WEAPON, 0); + clif_changelook(&sd->bl, LOOK::WEAPON, 0); if (battle_config.save_clothcolor == 1 && sd->status.clothes_color > 0) - clif_changelook(&sd->bl, LOOK_CLOTHES_COLOR, + clif_changelook(&sd->bl, LOOK::CLOTHES_COLOR, sd->status.clothes_color); if (battle_config.muting_players && sd->status.manner < 0) - skill_status_change_start(&sd->bl, SC_NOCHAT, 0, 0, 0, 0, 0, 0); + skill_status_change_start(&sd->bl, StatusChange::SC_NOCHAT, 0, 0, 0, 0, 0, 0); // option clif_changeoption(&sd->bl); @@ -3889,12 +3889,12 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd) if (bool(sd->status.inventory[i].equip) && bool(sd->status.inventory[i].equip & EPOS::WEAPON) && sd->status.inventory[i].broken == 1) - skill_status_change_start(&sd->bl, SC_BROKNWEAPON, 0, 0, 0, 0, 0, + skill_status_change_start(&sd->bl, StatusChange::SC_BROKNWEAPON, 0, 0, 0, 0, 0, 0); if (bool(sd->status.inventory[i].equip) && bool(sd->status.inventory[i].equip & EPOS::MISC1) && sd->status.inventory[i].broken == 1) - skill_status_change_start(&sd->bl, SC_BROKNARMOR, 0, 0, 0, 0, 0, + skill_status_change_start(&sd->bl, StatusChange::SC_BROKNARMOR, 0, 0, 0, 0, 0, 0); } @@ -3902,7 +3902,7 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd) map_foreachinarea(std::bind(clif_getareachar, ph::_1, sd), sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE, - sd->bl.y + AREA_SIZE, BL_NUL); + sd->bl.y + AREA_SIZE, BL::NUL); } /*========================================== @@ -3932,7 +3932,7 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } @@ -3946,9 +3946,7 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd) return; // ステータス異常やハイディング中(トンネルドライブ無)で動けない - if ((bool(sd->opt1) && sd->opt1 != (Opt1::_stone6)) - || sd->sc_data[SC_ANKLE].timer != -1 //アンクルスネア - ) + if (bool(sd->opt1) && sd->opt1 != (Opt1::_stone6)) return; if (sd->invincible_timer != -1) @@ -4021,7 +4019,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) switch (bl->type) { - case BL_PC: + case BL::PC: { struct map_session_data *ssd = (struct map_session_data *) bl; @@ -4073,7 +4071,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) } break; - case BL_NPC: + case BL::NPC: memcpy(WFIFOP(fd, 6), ((struct npc_data *) bl)->name, 24); { char *start = (char *)WFIFOP(fd, 6); @@ -4088,7 +4086,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) } WFIFOSET(fd, packet_len_table[0x95]); break; - case BL_MOB: + case BL::MOB: { struct mob_data *md = (struct mob_data *) bl; @@ -4131,7 +4129,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) } if (is_atcommand(fd, sd, message, 0) - || (sd->sc_data[SC_NOCHAT].timer != -1)) //チャット禁止 + || (sd->sc_data[StatusChange::SC_NOCHAT].timer != -1)) //チャット禁止 { free(buf); return; @@ -4228,7 +4226,7 @@ void clif_parse_Emotion(int fd, struct map_session_data *sd) nullpo_retv(sd); if (battle_config.basic_skill_check == 0 - || pc_checkskill(sd, NV_EMOTE) >= 1) + || pc_checkskill(sd, SkillID::NV_EMOTE) >= 1) { WBUFW(buf, 0) = 0xc0; WBUFL(buf, 2) = sd->bl.id; @@ -4266,7 +4264,7 @@ void clif_parse_ActionRequest(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } if (sd->npc_id != 0 @@ -4337,13 +4335,10 @@ void clif_parse_Restart(int fd, struct map_session_data *sd) pc_setrestartvalue(sd, 3); pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, - 2); + BeingRemoveWhy::QUIT); } break; case 0x01: - /*if (!pc_isdead(sd) && (sd->opt1 || (sd->opt2 && !(night_flag == 1 && sd->opt2 == Opt2::BLIND)))) - * return; */ - /* Rovert's Prevent logout option - Fixed [Valaris] */ if ((battle_config.prevent_logout && (gettick() - sd->canlog_tick) >= 10000) @@ -4389,7 +4384,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) } if (is_atcommand(fd, sd, message, 0) - || (sd->sc_data[SC_NOCHAT].timer != -1)) + || (sd->sc_data[StatusChange::SC_NOCHAT].timer != -1)) { free(buf); return; @@ -4472,13 +4467,13 @@ void clif_parse_TakeItem(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } if (sd->npc_id != 0 || sd->opt1 != Opt1::ZERO - || sd->sc_data[SC_NOCHAT].timer != -1) //会話禁止 + || sd->sc_data[StatusChange::SC_NOCHAT].timer != -1) //会話禁止 return; if (fitem == NULL || fitem->bl.m != sd->bl.m) @@ -4507,7 +4502,7 @@ void clif_parse_DropItem(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } if (map[sd->bl.m].flag.no_player_drops) @@ -4539,12 +4534,12 @@ void clif_parse_UseItem(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } if (sd->npc_id != 0 || sd->opt1 != Opt1::ZERO - || sd->sc_data[SC_NOCHAT].timer != -1) //会話禁止 + || sd->sc_data[StatusChange::SC_NOCHAT].timer != -1) //会話禁止 return; if (sd->invincible_timer != -1) @@ -4566,7 +4561,7 @@ void clif_parse_EquipItem(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } index = RFIFOW(fd, 2) - 2; @@ -4607,14 +4602,14 @@ void clif_parse_UnequipItem(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } index = RFIFOW(fd, 2) - 2; - if (sd->status.inventory[index].broken == 1 && sd->sc_data[SC_BROKNWEAPON].timer != -1) - skill_status_change_end(&sd->bl, SC_BROKNWEAPON, -1); - if (sd->status.inventory[index].broken == 1 && sd->sc_data[SC_BROKNARMOR].timer != -1) - skill_status_change_end(&sd->bl, SC_BROKNARMOR, -1); + if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNWEAPON].timer != -1) + skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, -1); + if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNARMOR].timer != -1) + skill_status_change_end(&sd->bl, StatusChange::SC_BROKNARMOR, -1); if (sd->npc_id != 0 || sd->opt1 != Opt1::ZERO) @@ -4633,7 +4628,7 @@ void clif_parse_NpcClicked(int fd, struct map_session_data *sd) if (pc_isdead(sd)) { - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); return; } if (sd->npc_id != 0) @@ -4697,7 +4692,7 @@ void clif_parse_TradeRequest(int, struct map_session_data *sd) nullpo_retv(sd); if (battle_config.basic_skill_check == 0 - || pc_checkskill(sd, NV_TRADE) >= 1) + || pc_checkskill(sd, SkillID::NV_TRADE) >= 1) { trade_traderequest(sd, RFIFOL(sd->fd, 2)); } @@ -4937,7 +4932,7 @@ static void clif_parse_CreateParty(int fd, struct map_session_data *sd) { if (battle_config.basic_skill_check == 0 - || pc_checkskill(sd, NV_PARTY) >= 2) + || pc_checkskill(sd, SkillID::NV_PARTY) >= 2) { party_create(sd, (const char *)RFIFOP(fd, 2)); } @@ -4969,7 +4964,7 @@ static void clif_parse_ReplyPartyInvite(int fd, struct map_session_data *sd) { if (battle_config.basic_skill_check == 0 - || pc_checkskill(sd, NV_PARTY) >= 1) + || pc_checkskill(sd, SkillID::NV_PARTY) >= 1) { party_reply_invite(sd, RFIFOL(fd, 2), RFIFOL(fd, 6)); } @@ -5034,7 +5029,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data *sd) } if (is_atcommand(fd, sd, message, 0) - || (sd->sc_data[SC_NOCHAT].timer != -1)) //チャット禁止 + || (sd->sc_data[StatusChange::SC_NOCHAT].timer != -1)) //チャット禁止 { free(buf); return; @@ -5741,9 +5736,12 @@ int clif_check_packet_flood(int fd, int cmd) return 0; } -#define WARN_MALFORMED_MSG(sd, msg) \ - PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed" \ - " message: %s.\n", sd->status.name, sd->status.account_id, msg) +inline +void WARN_MALFORMED_MSG(struct map_session_data *sd, const char *msg) +{ + PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed message: %s.\n", + sd->status.name, sd->status.account_id, msg); +} /** * Validate message integrity (inspired by upstream source (eAthena)). * diff --git a/src/map/clif.hpp b/src/map/clif.hpp index bfbca4d..dd061ad 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -1,6 +1,8 @@ #ifndef CLIF_HPP #define CLIF_HPP +#include "clif.t.hpp" + #include #include "../common/const_array.hpp" @@ -23,10 +25,9 @@ int clif_authfail_fd(int, int); int clif_charselectok(int); int clif_dropflooritem(struct flooritem_data *); int clif_clearflooritem(struct flooritem_data *, int); -int clif_clearchar(struct block_list *, int); // area or fd -int clif_clearchar_delay(unsigned int, struct block_list *, int); -#define clif_clearchar_area(bl,type) clif_clearchar(bl,type) -int clif_clearchar_id(int, int, int); +int clif_clearchar(struct block_list *, BeingRemoveWhy); // area or fd +int clif_clearchar_delay(unsigned int, struct block_list *, BeingRemoveWhy); +int clif_clearchar_id(int, BeingRemoveWhy, int); int clif_spawnpc(struct map_session_data *); //area int clif_spawnnpc(struct npc_data *); // area int clif_spawn_fake_npc_for_player(struct map_session_data *sd, @@ -55,7 +56,11 @@ int clif_additem(struct map_session_data *, int, int, PickupFail); //self int clif_delitem(struct map_session_data *, int, int); //self int clif_updatestatus(struct map_session_data *, SP); //self int clif_damage(struct block_list *, struct block_list *, unsigned int, int, int, int, int, DamageType, int); // area -#define clif_takeitem(src,dst) clif_damage(src,dst,0,0,0,0,0,DamageType::TAKEITEM,0) +inline +int clif_takeitem(struct block_list *src, struct block_list *dst) +{ + return clif_damage(src, dst, 0, 0, 0, 0, 0, DamageType::TAKEITEM, 0); +} int clif_changelook(struct block_list *, LOOK, int); // area void clif_changelook_accessories(struct block_list *bl, struct map_session_data *dst); // area or target; list gloves, boots etc. int clif_arrowequip(struct map_session_data *sd, int val); //self diff --git a/src/map/clif.t.hpp b/src/map/clif.t.hpp new file mode 100644 index 0000000..38394e9 --- /dev/null +++ b/src/map/clif.t.hpp @@ -0,0 +1,21 @@ +#ifndef CLIF_T_HPP +#define CLIF_T_HPP + +#include + +enum class BeingRemoveWhy : uint8_t +{ + // general disappearance + GONE = 0, + // only case handled specially in client + DEAD = 1, + QUIT = 2, + WARPED = 3, + // handled specially in clif_clearchar - sent as 0 over network + DISGUISE = 9, + + // handled speciall in mob_warp - not actually sent over network + NEGATIVE1 = 0xff, +}; + +#endif // CLIF_T_HPP diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 8a869e1..a2f75c5 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -30,7 +30,6 @@ const int packet_len_table[] = { 11, -1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -#define inter_fd char_fd // エイリアス //----------------------------------------------------------------- // inter serverへの送信 @@ -39,12 +38,12 @@ const int packet_len_table[] = { void intif_GMmessage(const_string mes, int flag) { int lp = (flag & 0x10) ? 8 : 4; - WFIFOW(inter_fd, 0) = 0x3000; - WFIFOW(inter_fd, 2) = lp + mes.size() + 1; - WFIFOL(inter_fd, 4) = 0x65756c62; - memcpy(WFIFOP(inter_fd, lp), mes.data(), mes.size()); - WFIFOB(inter_fd, lp + mes.size()) = '\0'; - WFIFOSET(inter_fd, WFIFOW(inter_fd, 2)); + WFIFOW(char_fd, 0) = 0x3000; + WFIFOW(char_fd, 2) = lp + mes.size() + 1; + WFIFOL(char_fd, 4) = 0x65756c62; + memcpy(WFIFOP(char_fd, lp), mes.data(), mes.size()); + WFIFOB(char_fd, lp + mes.size()) = '\0'; + WFIFOSET(char_fd, WFIFOW(char_fd, 2)); } // The transmission of Wisp/Page to inter-server (player not found on this server) @@ -53,12 +52,12 @@ int intif_wis_message(struct map_session_data *sd, const char *nick, const char { nullpo_ret(sd); - WFIFOW(inter_fd, 0) = 0x3001; - WFIFOW(inter_fd, 2) = mes_len + 52; - memcpy(WFIFOP(inter_fd, 4), sd->status.name, 24); - memcpy(WFIFOP(inter_fd, 28), nick, 24); - memcpy(WFIFOP(inter_fd, 52), mes, mes_len); - WFIFOSET(inter_fd, WFIFOW(inter_fd, 2)); + WFIFOW(char_fd, 0) = 0x3001; + WFIFOW(char_fd, 2) = mes_len + 52; + memcpy(WFIFOP(char_fd, 4), sd->status.name, 24); + memcpy(WFIFOP(char_fd, 28), nick, 24); + memcpy(WFIFOP(char_fd, 52), mes, mes_len); + WFIFOSET(char_fd, WFIFOW(char_fd, 2)); if (battle_config.etc_log) PRINTF("intif_wis_message from %s to %s (message: '%s')\n", @@ -71,10 +70,10 @@ int intif_wis_message(struct map_session_data *sd, const char *nick, const char static int intif_wis_replay(int id, int flag) { - WFIFOW(inter_fd, 0) = 0x3002; - WFIFOL(inter_fd, 2) = id; - WFIFOB(inter_fd, 6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target - WFIFOSET(inter_fd, 7); + WFIFOW(char_fd, 0) = 0x3002; + WFIFOL(char_fd, 2) = id; + WFIFOB(char_fd, 6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target + WFIFOSET(char_fd, 7); if (battle_config.etc_log) PRINTF("intif_wis_replay: id: %d, flag:%d\n", id, flag); @@ -86,12 +85,12 @@ int intif_wis_replay(int id, int flag) int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes, int mes_len) { - WFIFOW(inter_fd, 0) = 0x3003; - WFIFOW(inter_fd, 2) = mes_len + 30; - memcpy(WFIFOP(inter_fd, 4), Wisp_name, 24); - WFIFOW(inter_fd, 28) = (short) min_gm_level; - memcpy(WFIFOP(inter_fd, 30), mes, mes_len); - WFIFOSET(inter_fd, WFIFOW(inter_fd, 2)); + WFIFOW(char_fd, 0) = 0x3003; + WFIFOW(char_fd, 2) = mes_len + 30; + memcpy(WFIFOP(char_fd, 4), Wisp_name, 24); + WFIFOW(char_fd, 28) = (short) min_gm_level; + memcpy(WFIFOP(char_fd, 30), mes, mes_len); + WFIFOSET(char_fd, WFIFOW(char_fd, 2)); if (battle_config.etc_log) PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", @@ -107,15 +106,15 @@ int intif_saveaccountreg(struct map_session_data *sd) nullpo_ret(sd); - WFIFOW(inter_fd, 0) = 0x3004; - WFIFOL(inter_fd, 4) = sd->bl.id; + WFIFOW(char_fd, 0) = 0x3004; + WFIFOL(char_fd, 4) = sd->bl.id; for (j = 0, p = 8; j < sd->status.account_reg_num; j++, p += 36) { - memcpy(WFIFOP(inter_fd, p), sd->status.account_reg[j].str, 32); - WFIFOL(inter_fd, p + 32) = sd->status.account_reg[j].value; + memcpy(WFIFOP(char_fd, p), sd->status.account_reg[j].str, 32); + WFIFOL(char_fd, p + 32) = sd->status.account_reg[j].value; } - WFIFOW(inter_fd, 2) = p; - WFIFOSET(inter_fd, p); + WFIFOW(char_fd, 2) = p; + WFIFOSET(char_fd, p); return 0; } @@ -124,18 +123,18 @@ int intif_request_accountreg(struct map_session_data *sd) { nullpo_ret(sd); - WFIFOW(inter_fd, 0) = 0x3005; - WFIFOL(inter_fd, 2) = sd->bl.id; - WFIFOSET(inter_fd, 6); + WFIFOW(char_fd, 0) = 0x3005; + WFIFOL(char_fd, 2) = sd->bl.id; + WFIFOSET(char_fd, 6); return 0; } // 倉庫データ要求 int intif_request_storage(int account_id) { - WFIFOW(inter_fd, 0) = 0x3010; - WFIFOL(inter_fd, 2) = account_id; - WFIFOSET(inter_fd, 6); + WFIFOW(char_fd, 0) = 0x3010; + WFIFOL(char_fd, 2) = account_id; + WFIFOSET(char_fd, 6); return 0; } @@ -143,11 +142,11 @@ int intif_request_storage(int account_id) int intif_send_storage(struct storage *stor) { nullpo_ret(stor); - WFIFOW(inter_fd, 0) = 0x3011; - WFIFOW(inter_fd, 2) = sizeof(struct storage) + 8; - WFIFOL(inter_fd, 4) = stor->account_id; - memcpy(WFIFOP(inter_fd, 8), stor, sizeof(struct storage)); - WFIFOSET(inter_fd, WFIFOW(inter_fd, 2)); + WFIFOW(char_fd, 0) = 0x3011; + WFIFOW(char_fd, 2) = sizeof(struct storage) + 8; + WFIFOL(char_fd, 4) = stor->account_id; + memcpy(WFIFOP(char_fd, 8), stor, sizeof(struct storage)); + WFIFOSET(char_fd, WFIFOW(char_fd, 2)); return 0; } @@ -156,13 +155,13 @@ int intif_create_party(struct map_session_data *sd, const char *name) { nullpo_ret(sd); - WFIFOW(inter_fd, 0) = 0x3020; - WFIFOL(inter_fd, 2) = sd->status.account_id; - memcpy(WFIFOP(inter_fd, 6), name, 24); - memcpy(WFIFOP(inter_fd, 30), sd->status.name, 24); - memcpy(WFIFOP(inter_fd, 54), map[sd->bl.m].name, 16); - WFIFOW(inter_fd, 70) = sd->status.base_level; - WFIFOSET(inter_fd, 72); + WFIFOW(char_fd, 0) = 0x3020; + WFIFOL(char_fd, 2) = sd->status.account_id; + memcpy(WFIFOP(char_fd, 6), name, 24); + memcpy(WFIFOP(char_fd, 30), sd->status.name, 24); + memcpy(WFIFOP(char_fd, 54), map[sd->bl.m].name, 16); + WFIFOW(char_fd, 70) = sd->status.base_level; + WFIFOSET(char_fd, 72); // if(battle_config.etc_log) // PRINTF("intif: create party\n"); return 0; @@ -171,9 +170,9 @@ int intif_create_party(struct map_session_data *sd, const char *name) // パーティ情報要求 int intif_request_partyinfo(int party_id) { - WFIFOW(inter_fd, 0) = 0x3021; - WFIFOL(inter_fd, 2) = party_id; - WFIFOSET(inter_fd, 6); + WFIFOW(char_fd, 0) = 0x3021; + WFIFOL(char_fd, 2) = party_id; + WFIFOSET(char_fd, 6); // if(battle_config.etc_log) // PRINTF("intif: request party info\n"); return 0; @@ -188,13 +187,13 @@ int intif_party_addmember(int party_id, int account_id) // PRINTF("intif: party add member %d %d\n",party_id,account_id); if (sd != NULL) { - WFIFOW(inter_fd, 0) = 0x3022; - WFIFOL(inter_fd, 2) = party_id; - WFIFOL(inter_fd, 6) = account_id; - memcpy(WFIFOP(inter_fd, 10), sd->status.name, 24); - memcpy(WFIFOP(inter_fd, 34), map[sd->bl.m].name, 16); - WFIFOW(inter_fd, 50) = sd->status.base_level; - WFIFOSET(inter_fd, 52); + WFIFOW(char_fd, 0) = 0x3022; + WFIFOL(char_fd, 2) = party_id; + WFIFOL(char_fd, 6) = account_id; + memcpy(WFIFOP(char_fd, 10), sd->status.name, 24); + memcpy(WFIFOP(char_fd, 34), map[sd->bl.m].name, 16); + WFIFOW(char_fd, 50) = sd->status.base_level; + WFIFOSET(char_fd, 52); } return 0; } @@ -202,12 +201,12 @@ int intif_party_addmember(int party_id, int account_id) // パーティ設定変更 int intif_party_changeoption(int party_id, int account_id, int exp, int item) { - WFIFOW(inter_fd, 0) = 0x3023; - WFIFOL(inter_fd, 2) = party_id; - WFIFOL(inter_fd, 6) = account_id; - WFIFOW(inter_fd, 10) = exp; - WFIFOW(inter_fd, 12) = item; - WFIFOSET(inter_fd, 14); + WFIFOW(char_fd, 0) = 0x3023; + WFIFOL(char_fd, 2) = party_id; + WFIFOL(char_fd, 6) = account_id; + WFIFOW(char_fd, 10) = exp; + WFIFOW(char_fd, 12) = item; + WFIFOSET(char_fd, 14); return 0; } @@ -216,10 +215,10 @@ int intif_party_leave(int party_id, int account_id) { // if(battle_config.etc_log) // PRINTF("intif: party leave %d %d\n",party_id,account_id); - WFIFOW(inter_fd, 0) = 0x3024; - WFIFOL(inter_fd, 2) = party_id; - WFIFOL(inter_fd, 6) = account_id; - WFIFOSET(inter_fd, 10); + WFIFOW(char_fd, 0) = 0x3024; + WFIFOL(char_fd, 2) = party_id; + WFIFOL(char_fd, 6) = account_id; + WFIFOSET(char_fd, 10); return 0; } @@ -228,13 +227,13 @@ int intif_party_changemap(struct map_session_data *sd, int online) { if (sd != NULL) { - WFIFOW(inter_fd, 0) = 0x3025; - WFIFOL(inter_fd, 2) = sd->status.party_id; - WFIFOL(inter_fd, 6) = sd->status.account_id; - memcpy(WFIFOP(inter_fd, 10), map[sd->bl.m].name, 16); - WFIFOB(inter_fd, 26) = online; - WFIFOW(inter_fd, 27) = sd->status.base_level; - WFIFOSET(inter_fd, 29); + WFIFOW(char_fd, 0) = 0x3025; + WFIFOL(char_fd, 2) = sd->status.party_id; + WFIFOL(char_fd, 6) = sd->status.account_id; + memcpy(WFIFOP(char_fd, 10), map[sd->bl.m].name, 16); + WFIFOB(char_fd, 26) = online; + WFIFOW(char_fd, 27) = sd->status.base_level; + WFIFOSET(char_fd, 29); } // if(battle_config.etc_log) // PRINTF("party: change map\n"); @@ -246,23 +245,23 @@ int intif_party_message(int party_id, int account_id, const char *mes, int len) { // if(battle_config.etc_log) // PRINTF("intif_party_message: %s\n",mes); - WFIFOW(inter_fd, 0) = 0x3027; - WFIFOW(inter_fd, 2) = len + 12; - WFIFOL(inter_fd, 4) = party_id; - WFIFOL(inter_fd, 8) = account_id; - memcpy(WFIFOP(inter_fd, 12), mes, len); - WFIFOSET(inter_fd, len + 12); + WFIFOW(char_fd, 0) = 0x3027; + WFIFOW(char_fd, 2) = len + 12; + WFIFOL(char_fd, 4) = party_id; + WFIFOL(char_fd, 8) = account_id; + memcpy(WFIFOP(char_fd, 12), mes, len); + WFIFOSET(char_fd, len + 12); return 0; } // パーティ競合チェック要求 int intif_party_checkconflict(int party_id, int account_id, const char *nick) { - WFIFOW(inter_fd, 0) = 0x3028; - WFIFOL(inter_fd, 2) = party_id; - WFIFOL(inter_fd, 6) = account_id; - memcpy(WFIFOP(inter_fd, 10), nick, 24); - WFIFOSET(inter_fd, 34); + WFIFOW(char_fd, 0) = 0x3028; + WFIFOL(char_fd, 2) = party_id; + WFIFOL(char_fd, 6) = account_id; + memcpy(WFIFOP(char_fd, 10), nick, 24); + WFIFOSET(char_fd, 34); return 0; } diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index 62331f1..06b2873 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -11,7 +11,7 @@ #include "../poison.hpp" -#define MAX_RANDITEM 2000 +constexpr int MAX_RANDITEM = 2000; // ** ITEMDB_OVERRIDE_NAME_VERBOSE ** // 定義すると、itemdb.txtとgrfで名前が異なる場合、表示します. diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp index 540fced..688fac1 100644 --- a/src/map/itemdb.hpp +++ b/src/map/itemdb.hpp @@ -50,19 +50,60 @@ struct random_item_data struct item_data *itemdb_searchname(const char *name); struct item_data *itemdb_search(int nameid); struct item_data *itemdb_exists(int nameid); -#define itemdb_type(n) itemdb_search(n)->type -#define itemdb_look(n) itemdb_search(n)->look -#define itemdb_weight(n) itemdb_search(n)->weight -#define itemdb_equipscript(n) itemdb_search(n)->equip_script -#define itemdb_wlv(n) itemdb_search(n)->wlv -#define itemdb_available(n) (itemdb_exists(n) && itemdb_search(n)->flag.available) -#define itemdb_viewid(n) (itemdb_search(n)->view_id) + +inline +ItemType itemdb_type(int n) +{ + return itemdb_search(n)->type; +} +inline +int itemdb_look(int n) +{ + return itemdb_search(n)->look; +} +inline +int itemdb_weight(int n) +{ + return itemdb_search(n)->weight; +} +inline +const ScriptCode *itemdb_equipscript(int n) +{ + return itemdb_search(n)->equip_script; +} +inline +int itemdb_wlv(int n) +{ + return itemdb_search(n)->wlv; +} +inline +bool itemdb_available(int n) +{ + return itemdb_exists(n) && itemdb_search(n)->flag.available; +} +inline +int itemdb_viewid(int n) +{ + return itemdb_search(n)->view_id; +} int itemdb_searchrandomid(int flags); -#define itemdb_value_sell(n) itemdb_search(n)->value_sell -#define itemdb_value_notdc(n) itemdb_search(n)->flag.value_notdc -#define itemdb_value_notoc(n) itemdb_search(n)->flag.value_notoc +inline +int itemdb_value_sell(int n) +{ + return itemdb_search(n)->value_sell; +} +inline +int itemdb_value_notdc(int n) +{ + return itemdb_search(n)->flag.value_notdc; +} +inline +int itemdb_value_notoc(int n) +{ + return itemdb_search(n)->flag.value_notoc; +} int itemdb_isequip(int); int itemdb_isequip2(struct item_data *); diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp index 1c4e1d2..d6decd9 100644 --- a/src/map/magic-expr-eval.hpp +++ b/src/map/magic-expr-eval.hpp @@ -31,13 +31,13 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, #define RESULTSPELL result->v.v_spell #define RESULTINVOCATION result->v.v_invocation -#define TY(x) args[x].ty -#define ETY(x) ARGENTITY(x)->type +#define ARG_TYPE(x) args[x].ty +#define ENTITY_TYPE(x) ARGENTITY(x)->type #define ARGPC(x) ((struct map_session_data *)ARGENTITY(x)) #define ARGNPC(x) ((struct map_session_data *)ARGENTITY(x)) #define ARGMOB(x) ((struct map_session_data *)ARGENTITY(x)) -#define ARG_MAY_BE_AREA(x) (TY(x) == TY_AREA || TY(x) == TY_LOCATION) +#define ARG_MAY_BE_AREA(x) (ARG_TYPE(x) == TYPE::AREA || ARG_TYPE(x) == TYPE::LOCATION) #endif // MAGIC_EXPR_EVAL_HPP diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 9431ecb..2858064 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -14,15 +14,11 @@ #include "../poison.hpp" -#define IS_SOLID(c) ((c) == 1 || (c) == 5) - -int map_is_solid(int m, int x, int y) +bool map_is_solid(int m, int x, int y) { - return (IS_SOLID(map_getcell(m, x, y))); + return map_getcell(m, x, y) == 1; } -#undef IS_SOLID - static void free_area(area_t *area) { @@ -31,7 +27,7 @@ void free_area(area_t *area) switch (area->ty) { - case AREA_UNION: + case AREA::UNION: free_area(area->a.a_union[0]); free_area(area->a.a_union[1]); break; @@ -50,7 +46,7 @@ area_t *dup_area(area_t *area) switch (area->ty) { - case AREA_UNION: + case AREA::UNION: retval->a.a_union[0] = dup_area(retval->a.a_union[0]); retval->a.a_union[1] = dup_area(retval->a.a_union[1]); break; @@ -67,10 +63,10 @@ void magic_copy_var(val_t *dest, val_t *src) switch (dest->ty) { - case TY_STRING: + case TYPE::STRING: dest->v.v_string = strdup(dest->v.v_string); break; - case TY_AREA: + case TYPE::AREA: dest->v.v_area = dup_area(dest->v.v_area); break; default: @@ -83,10 +79,10 @@ void magic_clear_var(val_t *v) { switch (v->ty) { - case TY_STRING: + case TYPE::STRING: free(v->v.v_string); break; - case TY_AREA: + case TYPE::AREA: free_area(v->v.v_area); break; default: @@ -99,18 +95,18 @@ const char *show_entity(entity_t *entity) { switch (entity->type) { - case BL_PC: + case BL::PC: return ((struct map_session_data *) entity)->status.name; - case BL_NPC: + case BL::NPC: return ((struct npc_data *) entity)->name; - case BL_MOB: + case BL::MOB: return ((struct mob_data *) entity)->name; - case BL_ITEM: + case BL::ITEM: /* Sorry about this one... */ return ((struct item_data *) (&((struct flooritem_data *) entity)-> item_data))->name; - case BL_SPELL: + case BL::SPELL: return "%invocation(ERROR:this-should-not-be-an-entity)"; default: return "%unknown-entity"; @@ -131,42 +127,42 @@ void stringify(val_t *v, int within_op) switch (v->ty) { - case TY_UNDEF: + case TYPE::UNDEF: buf = "UNDEF"; break; - case TY_INT: + case TYPE::INT: buf = STRPRINTF("%i", v->v.v_int); break; - case TY_STRING: + case TYPE::STRING: return; - case TY_DIR: + case TYPE::DIR: buf = dirs[v->v.v_int]; break; - case TY_ENTITY: + case TYPE::ENTITY: buf = show_entity(v->v.v_entity); break; - case TY_LOCATION: + case TYPE::LOCATION: buf = STRPRINTF("<\"%s\", %d, %d>", map[v->v.v_location.m].name, v->v.v_location.x, v->v.v_location.y); break; - case TY_AREA: + case TYPE::AREA: buf = "%area"; free_area(v->v.v_area); break; - case TY_SPELL: + case TYPE::SPELL: buf = v->v.v_spell->name; break; - case TY_INVOCATION: + case TYPE::INVOCATION: { invocation_t *invocation = within_op ? v->v.v_invocation @@ -182,17 +178,17 @@ void stringify(val_t *v, int within_op) } v->v.v_string = strdup(buf.c_str()); - v->ty = TY_STRING; + v->ty = TYPE::STRING; } static void intify(val_t *v) { - if (v->ty == TY_INT) + if (v->ty == TYPE::INT) return; magic_clear_var(v); - v->ty = TY_INT; + v->ty = TYPE::INT; v->v.v_int = 1; } @@ -208,7 +204,7 @@ area_t *area_new(AREA ty) static area_t *area_union(area_t *area, area_t *other_area) { - area_t *retval = area_new(AREA_UNION); + area_t *retval = area_new(AREA::UNION); retval->a.a_union[0] = area; retval->a.a_union[1] = other_area; retval->size = area->size + other_area->size; /* Assume no overlap */ @@ -221,11 +217,11 @@ area_t *area_union(area_t *area, area_t *other_area) static void make_area(val_t *v) { - if (v->ty == TY_LOCATION) + if (v->ty == TYPE::LOCATION) { area_t *a = (area_t *)malloc(sizeof(area_t)); - v->ty = TY_AREA; - a->ty = AREA_LOCATION; + v->ty = TYPE::AREA; + a->ty = AREA::LOCATION; a->a.a_loc = v->v.v_location; v->v.v_area = a; } @@ -234,11 +230,11 @@ void make_area(val_t *v) static void make_location(val_t *v) { - if (v->ty == TY_AREA && v->v.v_area->ty == AREA_LOCATION) + if (v->ty == TYPE::AREA && v->v.v_area->ty == AREA::LOCATION) { location_t location = v->v.v_area->a.a_loc; free_area(v->v.v_area); - v->ty = TY_LOCATION; + v->ty = TYPE::LOCATION; v->v.v_location = location; } } @@ -246,14 +242,14 @@ void make_location(val_t *v) static void make_spell(val_t *v) { - if (v->ty == TY_INVOCATION) + if (v->ty == TYPE::INVOCATION) { invocation_t *invoc = v->v.v_invocation; //(invocation_t *) map_id2bl(v->v.v_int); if (!invoc) - v->ty = TY_FAIL; + v->ty = TYPE::FAIL; else { - v->ty = TY_SPELL; + v->ty = TYPE::SPELL; v->v.v_spell = invoc->spell; } } @@ -262,11 +258,11 @@ void make_spell(val_t *v) static int fun_add(env_t *, int, val_t *result, val_t *args) { - if (TY(0) == TY_INT && TY(1) == TY_INT) + if (ARG_TYPE(0) == TYPE::INT && ARG_TYPE(1) == TYPE::INT) { /* Integer addition */ RESULTINT = ARGINT(0) + ARGINT(1); - result->ty = TY_INT; + result->ty = TYPE::INT; } else if (ARG_MAY_BE_AREA(0) && ARG_MAY_BE_AREA(1)) { @@ -276,7 +272,7 @@ int fun_add(env_t *, int, val_t *result, val_t *args) RESULTAREA = area_union(ARGAREA(0), ARGAREA(1)); ARGAREA(0) = NULL; ARGAREA(1) = NULL; - result->ty = TY_AREA; + result->ty = TYPE::AREA; } else { @@ -288,7 +284,7 @@ int fun_add(env_t *, int, val_t *result, val_t *args) (char *) malloc(1 + strlen(ARGSTR(0)) + strlen(ARGSTR(1))); strcpy(RESULTSTR, ARGSTR(0)); strcat(RESULTSTR, ARGSTR(1)); - result->ty = TY_STRING; + result->ty = TYPE::STRING; } return 0; } @@ -356,7 +352,7 @@ int fun_neg(env_t *, int, val_t *result, val_t *args) static int fun_gte(env_t *, int, val_t *result, val_t *args) { - if (TY(0) == TY_STRING || TY(1) == TY_STRING) + if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); @@ -374,7 +370,7 @@ int fun_gte(env_t *, int, val_t *result, val_t *args) static int fun_gt(env_t *, int, val_t *result, val_t *args) { - if (TY(0) == TY_STRING || TY(1) == TY_STRING) + if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); @@ -392,25 +388,25 @@ int fun_gt(env_t *, int, val_t *result, val_t *args) static int fun_eq(env_t *, int, val_t *result, val_t *args) { - if (TY(0) == TY_STRING || TY(1) == TY_STRING) + if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { stringify(&args[0], 1); stringify(&args[1], 1); RESULTINT = strcmp(ARGSTR(0), ARGSTR(1)) == 0; } - else if (TY(0) == TY_DIR && TY(1) == TY_DIR) + else if (ARG_TYPE(0) == TYPE::DIR && ARG_TYPE(1) == TYPE::DIR) RESULTINT = ARGDIR(0) == ARGDIR(1); - else if (TY(0) == TY_ENTITY && TY(1) == TY_ENTITY) + else if (ARG_TYPE(0) == TYPE::ENTITY && ARG_TYPE(1) == TYPE::ENTITY) RESULTINT = ARGENTITY(0) == ARGENTITY(1); - else if (TY(0) == TY_LOCATION && TY(1) == TY_LOCATION) + else if (ARG_TYPE(0) == TYPE::LOCATION && ARG_TYPE(1) == TYPE::LOCATION) RESULTINT = (ARGLOCATION(0).x == ARGLOCATION(1).x && ARGLOCATION(0).y == ARGLOCATION(1).y && ARGLOCATION(0).m == ARGLOCATION(1).m); - else if (TY(0) == TY_AREA && TY(1) == TY_AREA) + else if (ARG_TYPE(0) == TYPE::AREA && ARG_TYPE(1) == TYPE::AREA) RESULTINT = ARGAREA(0) == ARGAREA(1); /* Probably not that great an idea... */ - else if (TY(0) == TY_SPELL && TY(1) == TY_SPELL) + else if (ARG_TYPE(0) == TYPE::SPELL && ARG_TYPE(1) == TYPE::SPELL) RESULTINT = ARGSPELL(0) == ARGSPELL(1); - else if (TY(0) == TY_INVOCATION && TY(1) == TY_INVOCATION) + else if (ARG_TYPE(0) == TYPE::INVOCATION && ARG_TYPE(1) == TYPE::INVOCATION) RESULTINT = ARGINVOCATION(0) == ARGINVOCATION(1); else { @@ -485,10 +481,10 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, { switch (area->ty) { - case AREA_UNION: + case AREA::UNION: break; - case AREA_LOCATION: + case AREA::LOCATION: *m = area->a.a_loc.m; *x = area->a.a_loc.x; *y = area->a.a_loc.y; @@ -496,7 +492,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, *height = 1; break; - case AREA_RECT: + case AREA::RECT: *m = area->a.a_rect.loc.m; *x = area->a.a_rect.loc.x; *y = area->a.a_rect.loc.y; @@ -504,7 +500,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, *height = area->a.a_rect.height; break; - case AREA_BAR: + case AREA::BAR: { int tx = area->a.a_bar.loc.x; int ty = area->a.a_bar.loc.y; @@ -514,28 +510,28 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, switch (area->a.a_bar.dir) { - case DIR_S: + case DIR::S: *x = tx - twidth; *y = ty; *width = twidth * 2 + 1; *height = tdepth; break; - case DIR_W: + case DIR::W: *x = tx - tdepth; *y = ty - twidth; *width = tdepth; *height = twidth * 2 + 1; break; - case DIR_N: + case DIR::N: *x = tx - twidth; *y = ty - tdepth; *width = twidth * 2 + 1; *height = tdepth; break; - case DIR_E: + case DIR::E: *x = tx; *y = ty - twidth; *width = tdepth; @@ -558,12 +554,12 @@ int magic_location_in_area(int m, int x, int y, area_t *area) { switch (area->ty) { - case AREA_UNION: + case AREA::UNION: return magic_location_in_area(m, x, y, area->a.a_union[0]) || magic_location_in_area(m, x, y, area->a.a_union[1]); - case AREA_LOCATION: - case AREA_RECT: - case AREA_BAR: + case AREA::LOCATION: + case AREA::RECT: + case AREA::BAR: { int am; int ax, ay, awidth, aheight; @@ -590,7 +586,7 @@ int fun_is_in(env_t *, int, val_t *result, val_t *args) static int fun_skill(env_t *, int, val_t *result, val_t *args) { - if (ETY(0) != BL_PC + if (ENTITY_TYPE(0) != BL::PC // don't convert to enum until after the range check || ARGINT(1) < 0 || ARGINT(1) >= uint16_t(MAX_SKILL) @@ -604,7 +600,7 @@ int fun_skill(env_t *, int, val_t *result, val_t *args) static int fun_has_shroud(env_t *, int, val_t *result, val_t *args) { - RESULTINT = (ETY(0) == BL_PC && ARGPC(0)->state.shroud_active); + RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->state.shroud_active); return 0; } @@ -638,7 +634,7 @@ int fun_get_dir(env_t *, int, val_t *result, val_t *args) static \ int fun_get_##name(env_t *, int, val_t *result, val_t *args) \ { \ - if (ETY(0) == BL_PC) \ + if (ENTITY_TYPE(0) == BL::PC) \ RESULTINT = ARGPC(0)->status.name; \ else \ RESULTINT = 0; \ @@ -651,17 +647,17 @@ MMO_GETTER(max_sp) static int fun_name_of(env_t *, int, val_t *result, val_t *args) { - if (TY(0) == TY_ENTITY) + if (ARG_TYPE(0) == TYPE::ENTITY) { RESULTSTR = strdup(show_entity(ARGENTITY(0))); return 0; } - else if (TY(0) == TY_SPELL) + else if (ARG_TYPE(0) == TYPE::SPELL) { RESULTSTR = strdup(ARGSPELL(0)->name); return 0; } - else if (TY(0) == TY_INVOCATION) + else if (ARG_TYPE(0) == TYPE::INVOCATION) { RESULTSTR = strdup(ARGINVOCATION(0)->spell->name); return 0; @@ -673,12 +669,27 @@ int fun_name_of(env_t *, int, val_t *result, val_t *args) static int fun_mob_id(env_t *, int, val_t *result, val_t *args) { - if (ETY(0) != BL_MOB) return 1; + if (ENTITY_TYPE(0) != BL::MOB) + return 1; RESULTINT = ((struct mob_data *)(ARGENTITY(0)))->mob_class; return 0; } -#define COPY_LOCATION(dest, src) (dest).x = (src).x;(dest).y = (src).y;(dest).m = (src).m; +inline +void COPY_LOCATION(entity_t& dest, location_t& src) +{ + dest.x = src.x; + dest.y = src.y; + dest.m = src.m; +} + +inline +void COPY_LOCATION(location_t& dest, entity_t& src) +{ + dest.x = src.x; + dest.y = src.y; + dest.m = src.m; +} static int fun_location(env_t *, int, val_t *result, val_t *args) @@ -728,9 +739,9 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable) struct item_data *item_data; int must_add_sequentially; - if (TY(index) == TY_INT) + if (ARG_TYPE(index) == TYPE::INT) item_data = itemdb_exists(ARGINT(index)); - else if (TY(index) == TY_STRING) + else if (ARG_TYPE(index) == TYPE::STRING) item_data = itemdb_searchname(ARGSTR(index)); else return -1; @@ -758,7 +769,7 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable) static int fun_count_item(env_t *, int, val_t *result, val_t *args) { - character_t *chr = (ETY(0) == BL_PC) ? ARGPC(0) : NULL; + character_t *chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; struct item item; @@ -774,7 +785,7 @@ int fun_count_item(env_t *, int, val_t *result, val_t *args) static int fun_is_equipped(env_t *, int, val_t *result, val_t *args) { - character_t *chr = (ETY(0) == BL_PC) ? ARGPC(0) : NULL; + character_t *chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; struct item item; bool retval = false; @@ -800,28 +811,28 @@ int fun_is_equipped(env_t *, int, val_t *result, val_t *args) static int fun_is_married(env_t *, int, val_t *result, val_t *args) { - RESULTINT = (ETY(0) == BL_PC && ARGPC(0)->status.partner_id); + RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id); return 0; } static int fun_is_dead(env_t *, int, val_t *result, val_t *args) { - RESULTINT = (ETY(0) == BL_PC && pc_isdead(ARGPC(0))); + RESULTINT = (ENTITY_TYPE(0) == BL::PC && pc_isdead(ARGPC(0))); return 0; } static int fun_is_pc(env_t *, int, val_t *result, val_t *args) { - RESULTINT = (ETY(0) == BL_PC); + RESULTINT = (ENTITY_TYPE(0) == BL::PC); return 0; } static int fun_partner(env_t *, int, val_t *result, val_t *args) { - if (ETY(0) == BL_PC && ARGPC(0)->status.partner_id) + if (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id) { RESULTENTITY = (entity_t *) @@ -852,7 +863,7 @@ int fun_awayfrom(env_t *, int, val_t *result, val_t *args) static int fun_failed(env_t *, int, val_t *result, val_t *args) { - RESULTINT = TY(0) == TY_FAIL; + RESULTINT = ARG_TYPE(0) == TYPE::FAIL; return 0; } @@ -906,7 +917,7 @@ int fun_anchor(env_t *env, int, val_t *result, val_t *args) magic_eval(env, result, anchor->location); make_area(result); - if (result->ty != TY_AREA) + if (result->ty != TYPE::AREA) { magic_clear_var(result); return 1; @@ -932,7 +943,7 @@ void magic_random_location(location_t *dest, area_t *area) { switch (area->ty) { - case AREA_UNION: + case AREA::UNION: { int rv = MRAND(area->size); if (rv < area->a.a_union[0]->size) @@ -942,9 +953,9 @@ void magic_random_location(location_t *dest, area_t *area) break; } - case AREA_LOCATION: - case AREA_RECT: - case AREA_BAR: + case AREA::LOCATION: + case AREA::RECT: + case AREA::BAR: { int m, x, y, w, h; magic_area_rect(&m, &x, &y, &w, &h, area); @@ -1010,7 +1021,7 @@ int fun_read_script_int(env_t *, int, val_t *result, val_t *args) entity_t *subject_p = ARGENTITY(0); char *var_name = ARGSTR(1); - if (subject_p->type != BL_PC) + if (subject_p->type != BL::PC) return 1; RESULTINT = pc_readglobalreg((character_t *) subject_p, var_name); @@ -1023,7 +1034,7 @@ int fun_rbox(env_t *, int, val_t *result, val_t *args) location_t loc = ARGLOCATION(0); int radius = ARGINT(1); - RESULTAREA = area_new(AREA_RECT); + RESULTAREA = area_new(AREA::RECT); RESULTAREA->a.a_rect.loc.m = loc.m; RESULTAREA->a.a_rect.loc.x = loc.x - radius; RESULTAREA->a.a_rect.loc.y = loc.y - radius; @@ -1037,7 +1048,7 @@ static int fun_running_status_update(env_t *, int, val_t *result, val_t *args) { - if (ETY(0) != BL_PC && ETY(0) != BL_MOB) + if (ENTITY_TYPE(0) != BL::PC && ENTITY_TYPE(0) != BL::MOB) return 1; StatusChange sc = StatusChange(ARGINT(1)); @@ -1222,7 +1233,7 @@ int fun_dir_towards(env_t *, int, val_t *result, val_t *args) static int fun_extract_healer_xp(env_t *, int, val_t *result, val_t *args) { - character_t *sd = (ETY(0) == BL_PC) ? ARGPC(0) : NULL; + character_t *sd = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!sd) RESULTINT = 0; @@ -1231,8 +1242,6 @@ int fun_extract_healer_xp(env_t *, int, val_t *result, val_t *args) return 0; } -#define BATTLE_RECORD2(sname, name) { sname, "e", 'i', fun_get_##name } -#define BATTLE_RECORD(name) BATTLE_RECORD2(#name, name) static fun_t functions[] = { {"+", "..", '.', fun_add}, @@ -1257,19 +1266,19 @@ fun_t functions[] = { {"is_in", "la", 'i', fun_is_in}, {"if_then_else", "i__", '_', fun_if_then_else}, {"skill", "ei", 'i', fun_skill}, - BATTLE_RECORD(str), - BATTLE_RECORD(agi), - BATTLE_RECORD(vit), - BATTLE_RECORD(dex), - BATTLE_RECORD(luk), - BATTLE_RECORD(int), - BATTLE_RECORD2("level", lv), - BATTLE_RECORD(mdef), - BATTLE_RECORD(def), - BATTLE_RECORD(hp), - BATTLE_RECORD(max_hp), - BATTLE_RECORD(sp), - BATTLE_RECORD(max_sp), + {"str", "e", 'i', fun_get_str}, + {"agi", "e", 'i', fun_get_agi}, + {"vit", "e", 'i', fun_get_vit}, + {"dex", "e", 'i', fun_get_dex}, + {"luk", "e", 'i', fun_get_luk}, + {"int", "e", 'i', fun_get_int}, + {"level", "e", 'i', fun_get_lv}, + {"mdef", "e", 'i', fun_get_mdef}, + {"def", "e", 'i', fun_get_def}, + {"hp", "e", 'i', fun_get_hp}, + {"max_hp", "e", 'i', fun_get_max_hp}, + {"sp", "e", 'i', fun_get_sp}, + {"max_sp", "e", 'i', fun_get_max_sp}, {"dir", "e", 'd', fun_get_dir}, {"name_of", ".", 's', fun_name_of}, {"mob_id", "e", 'i', fun_mob_id}, @@ -1360,8 +1369,8 @@ eval_location(env_t *env, location_t *dest, e_location_t *expr) magic_eval(env, &x, expr->x); magic_eval(env, &y, expr->y); - if (CHECK_TYPE(&m, TY_STRING) - && CHECK_TYPE(&x, TY_INT) && CHECK_TYPE(&y, TY_INT)) + if (CHECK_TYPE(&m, TYPE::STRING) + && CHECK_TYPE(&x, TYPE::INT) && CHECK_TYPE(&y, TYPE::INT)) { int map_id = map_mapname2mapid(m.v.v_string); magic_clear_var(&m); @@ -1389,7 +1398,7 @@ area_t *eval_area(env_t *env, e_area_t *expr) switch (expr->ty) { - case AREA_LOCATION: + case AREA::LOCATION: area->size = 1; if (eval_location(env, &area->a.a_loc, &expr->a.a_loc)) { @@ -1399,7 +1408,7 @@ area_t *eval_area(env_t *env, e_area_t *expr) else return area; - case AREA_UNION: + case AREA::UNION: { int i, fail = 0; for (i = 0; i < 2; i++) @@ -1423,7 +1432,7 @@ area_t *eval_area(env_t *env, e_area_t *expr) return area; } - case AREA_RECT: + case AREA::RECT: { val_t width, height; magic_eval(env, &width, expr->a.a_rect.width); @@ -1432,8 +1441,8 @@ area_t *eval_area(env_t *env, e_area_t *expr) area->a.a_rect.width = width.v.v_int; area->a.a_rect.height = height.v.v_int; - if (CHECK_TYPE(&width, TY_INT) - && CHECK_TYPE(&height, TY_INT) + if (CHECK_TYPE(&width, TYPE::INT) + && CHECK_TYPE(&height, TYPE::INT) && !eval_location(env, &(area->a.a_rect.loc), &expr->a.a_rect.loc)) { @@ -1451,7 +1460,7 @@ area_t *eval_area(env_t *env, e_area_t *expr) } } - case AREA_BAR: + case AREA::BAR: { val_t width, depth, dir; magic_eval(env, &width, expr->a.a_bar.width); @@ -1462,9 +1471,9 @@ area_t *eval_area(env_t *env, e_area_t *expr) area->a.a_bar.depth = depth.v.v_int; area->a.a_bar.dir = dir.v.v_dir; - if (CHECK_TYPE(&width, TY_INT) - && CHECK_TYPE(&depth, TY_INT) - && CHECK_TYPE(&dir, TY_DIR) + if (CHECK_TYPE(&width, TYPE::INT) + && CHECK_TYPE(&depth, TYPE::INT) + && CHECK_TYPE(&dir, TYPE::DIR) && !eval_location(env, &area->a.a_bar.loc, &expr->a.a_bar.loc)) { @@ -1494,28 +1503,28 @@ area_t *eval_area(env_t *env, e_area_t *expr) } static -TY type_key(char ty_key) +TYPE type_key(char ty_key) { switch (ty_key) { case 'i': - return TY_INT; + return TYPE::INT; case 'd': - return TY_DIR; + return TYPE::DIR; case 's': - return TY_STRING; + return TYPE::STRING; case 'e': - return TY_ENTITY; + return TYPE::ENTITY; case 'l': - return TY_LOCATION; + return TYPE::LOCATION; case 'a': - return TY_AREA; + return TYPE::AREA; case 'S': - return TY_SPELL; + return TYPE::SPELL; case 'I': - return TY_INVOCATION; + return TYPE::INVOCATION; default: - return TY::NEGATIVE_1; + return TYPE::NEGATIVE_1; } } @@ -1527,21 +1536,21 @@ int magic_signature_check(const char *opname, const char *funname, const char *s { val_t *arg = &args[i]; char ty_key = signature[i]; - TY ty = arg->ty; - TY desired_ty = type_key(ty_key); + TYPE ty = arg->ty; + TYPE desired_ty = type_key(ty_key); - if (ty == TY_ENTITY) + if (ty == TYPE::ENTITY) { /* Dereference entities in preparation for calling function */ arg->v.v_entity = map_id2bl(arg->v.v_int); if (!arg->v.v_entity) - ty = arg->ty = TY_FAIL; + ty = arg->ty = TYPE::FAIL; } - else if (ty == TY_INVOCATION) + else if (ty == TYPE::INVOCATION) { arg->v.v_invocation = (invocation_t *) map_id2bl(arg->v.v_int); if (!arg->v.v_entity) - ty = arg->ty = TY_FAIL; + ty = arg->ty = TYPE::FAIL; } if (!ty_key) @@ -1552,13 +1561,13 @@ int magic_signature_check(const char *opname, const char *funname, const char *s return 1; } - if (ty == TY_FAIL && ty_key != '_') + if (ty == TYPE::FAIL && ty_key != '_') return 1; /* Fail `in a sane way': This is a perfectly permissible error */ - if (ty == desired_ty || desired_ty == TY::NEGATIVE_1) + if (ty == desired_ty || desired_ty == TYPE::NEGATIVE_1) continue; - if (ty == TY_UNDEF) + if (ty == TYPE::UNDEF) { FPRINTF(stderr, "[magic-eval]: L%d:%d: Argument #%d to %s `%s' undefined\n", @@ -1569,19 +1578,19 @@ int magic_signature_check(const char *opname, const char *funname, const char *s /* If we are here, we have a type mismatch but no failure _yet_. Try to coerce. */ switch (desired_ty) { - case TY_INT: + case TYPE::INT: intify(arg); break; /* 100% success rate */ - case TY_STRING: + case TYPE::STRING: stringify(arg, 1); break; /* 100% success rate */ - case TY_AREA: + case TYPE::AREA: make_area(arg); break; /* Only works for locations */ - case TY_LOCATION: + case TYPE::LOCATION: make_location(arg); break; /* Only works for some areas */ - case TY_SPELL: + case TYPE::SPELL: make_spell(arg); break; /* Only works for still-active invocatoins */ default: @@ -1591,7 +1600,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s ty = arg->ty; if (ty != desired_ty) { /* Coercion failed? */ - if (ty != TY_FAIL) + if (ty != TYPE::FAIL) FPRINTF(stderr, "[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n", line, column, i + 1, opname, funname, @@ -1610,25 +1619,25 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr) #pragma GCC diagnostic pop switch (expr->ty) { - case EXPR_VAL: + case EXPR::VAL: magic_copy_var(dest, &expr->e.e_val); break; - case EXPR_LOCATION: + case EXPR::LOCATION: if (eval_location(env, &dest->v.v_location, &expr->e.e_location)) - dest->ty = TY_FAIL; + dest->ty = TYPE::FAIL; else - dest->ty = TY_LOCATION; + dest->ty = TYPE::LOCATION; break; - case EXPR_AREA: + case EXPR::AREA: if ((dest->v.v_area = eval_area(env, &expr->e.e_area))) - dest->ty = TY_AREA; + dest->ty = TYPE::AREA; else - dest->ty = TY_FAIL; + dest->ty = TYPE::FAIL; break; - case EXPR_FUNAPP: + case EXPR::FUNAPP: { val_t arguments[MAX_ARGS]; int args_nr = expr->e.e_funapp.args_nr; @@ -1640,20 +1649,20 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr) if (magic_signature_check("function", f->name, f->signature, args_nr, arguments, expr->e.e_funapp.line_nr, expr->e.e_funapp.column) || f->fun(env, args_nr, dest, arguments)) - dest->ty = TY_FAIL; + dest->ty = TYPE::FAIL; else { - TY dest_ty = type_key(f->ret_ty); - if (dest_ty != TY::NEGATIVE_1) + TYPE dest_ty = type_key(f->ret_ty); + if (dest_ty != TYPE::NEGATIVE_1) dest->ty = dest_ty; /* translate entity back into persistent int */ - if (dest->ty == TY_ENTITY) + if (dest->ty == TYPE::ENTITY) { if (dest->v.v_entity) dest->v.v_int = dest->v.v_entity->id; else - dest->ty = TY_FAIL; + dest->ty = TYPE::FAIL; } } @@ -1662,25 +1671,25 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr) break; } - case EXPR_ID: + case EXPR::ID: { val_t v = VAR(expr->e.e_id); magic_copy_var(dest, &v); break; } - case EXPR_SPELLFIELD: + case EXPR::SPELLFIELD: { val_t v; int id = expr->e.e_field.id; magic_eval(env, &v, expr->e.e_field.expr); - if (v.ty == TY_INVOCATION) + if (v.ty == TYPE::INVOCATION) { invocation_t *t = (invocation_t *) map_id2bl(v.v.v_int); if (!t) - dest->ty = TY_UNDEF; + dest->ty = TYPE::UNDEF; else { #pragma GCC diagnostic push @@ -1696,7 +1705,7 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr) FPRINTF(stderr, "[magic] Attempt to access field %s on non-spell\n", env->base_env->var_name[id]); - dest->ty = TY_FAIL; + dest->ty = TYPE::FAIL; } break; } @@ -1714,7 +1723,7 @@ int magic_eval_int(env_t *env, expr_t *expr) val_t result; magic_eval(env, &result, expr); - if (result.ty == TY_FAIL || result.ty == TY_UNDEF) + if (result.ty == TYPE::FAIL || result.ty == TYPE::UNDEF) return 0; intify(&result); @@ -1727,7 +1736,7 @@ char *magic_eval_str(env_t *env, expr_t *expr) val_t result; magic_eval(env, &result, expr); - if (result.ty == TY_FAIL || result.ty == TY_UNDEF) + if (result.ty == TYPE::FAIL || result.ty == TYPE::UNDEF) return strdup("?"); stringify(&result, 0); diff --git a/src/map/magic-expr.hpp b/src/map/magic-expr.hpp index 4d2ea3c..e7f27dc 100644 --- a/src/map/magic-expr.hpp +++ b/src/map/magic-expr.hpp @@ -60,7 +60,7 @@ int magic_eval_int(env_t *env, expr_t *expr); */ char *magic_eval_str(env_t *env, expr_t *expr); -int map_is_solid(int m, int x, int y); +bool map_is_solid(int m, int x, int y); expr_t *magic_new_expr(EXPR ty); @@ -70,14 +70,16 @@ void magic_copy_var(val_t *dest, val_t *src); void magic_random_location(location_t *dest, area_t *area); -int // ret -1: not a string, ret 1: no such item, ret 0: OK +// ret -1: not a string, ret 1: no such item, ret 0: OK +int magic_find_item(val_t *args, int index, struct item *item, int *stackable); - - - - magic_find_item(val_t *args, int index, struct item *item, int *stackable); - -#define GET_ARG_ITEM(index, dest, stackable) switch (magic_find_item(args, index, &dest, &stackable)) { case -1 : return 1; case 1 : return 0; } +#define GET_ARG_ITEM(index, dest, stackable) \ + switch (magic_find_item(args, index, &dest, &stackable)) \ + { \ + case -1: return 1; \ + case 1: return 0; \ + default: break; \ + } int magic_location_in_area(int m, int x, int y, area_t *area); diff --git a/src/map/magic-interpreter-aux.hpp b/src/map/magic-interpreter-aux.hpp index 983d3d6..4bb0a82 100644 --- a/src/map/magic-interpreter-aux.hpp +++ b/src/map/magic-interpreter-aux.hpp @@ -1,8 +1,18 @@ #ifndef MAGIC_INTERPRETER_AUX_HPP #define MAGIC_INTERPRETER_AUX_HPP -#define CHECK_TYPE(v, t) ((v)->ty == t) +#include "magic-interpreter.t.hpp" -#define VAR(i) ((!env->vars || env->vars[i].ty == TY_UNDEF)? env->base_env->vars[i] : env->vars[i]) +template +bool CHECK_TYPE(T *v, TYPE t) +{ + return v->ty == t; +} + +// FIXME: macro capture! +#define VAR(i) \ + ((!env->vars || env->vars[i].ty == TYPE::UNDEF) \ + ? env->base_env->vars[i] \ + : env->vars[i]) #endif // MAGIC_INTERPRETER_AUX_HPP diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index 0ddc4fd..ac885c2 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -10,7 +10,7 @@ #include "../poison.hpp" static -void set_int_p(val_t *v, int i, TY t) +void set_int_p(val_t *v, int i, TYPE t) { v->ty = t; v->v.v_int = i; @@ -19,30 +19,30 @@ void set_int_p(val_t *v, int i, TY t) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-macros" -#define set_int(v, i) set_int_p(v, i, TY_INT) -#define set_dir(v, i) set_int_p(v, i, TY_DIR) +#define set_int(v, i) set_int_p(v, i, TYPE::INT) +#define set_dir(v, i) set_int_p(v, i, TYPE::DIR) #define SETTER(tty, dyn_ty, field) (val_t *v, tty x) { v->ty = dyn_ty; v->v.field = x; } static -void set_string SETTER(char *, TY_STRING, v_string) +void set_string SETTER(char *, TYPE::STRING, v_string) static void set_entity(val_t *v, entity_t *e) { - v->ty = TY_ENTITY; + v->ty = TYPE::ENTITY; v->v.v_int = e->id; } static void set_invocation(val_t *v, invocation_t *i) { - v->ty = TY_INVOCATION; + v->ty = TYPE::INVOCATION; v->v.v_int = i->bl.id; } static -void set_spell SETTER(spell_t *, TY_SPELL, v_spell) +void set_spell SETTER(spell_t *, TYPE::SPELL, v_spell) #define setenv(f, v, x) f(&(env->vars[v]), x) @@ -198,11 +198,11 @@ env_t *spell_create_env(magic_conf_t *conf, spell_t *spell, switch (spell->spellarg_ty) { - case SPELLARG_STRING: + case SPELLARG::STRING: set_env_string(spell->arg, param); break; - case SPELLARG_PC: + case SPELLARG::PC: { character_t *subject = map_nick2sd(param); if (!subject) @@ -212,7 +212,7 @@ env_t *spell_create_env(magic_conf_t *conf, spell_t *spell, break; } - case SPELLARG_NONE: + case SPELLARG::NONE: free(param); break; @@ -338,7 +338,7 @@ int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster, { unsigned int casttime = (unsigned int) check->casttime; - if (VAR(VAR_MIN_CASTTIME).ty == TY_INT) + if (VAR(VAR_MIN_CASTTIME).ty == TYPE::INT) casttime = max(casttime, VAR(VAR_MIN_CASTTIME).v.v_int); caster->cast_tick = tick + casttime; /* Make sure not to cast too frequently */ @@ -361,20 +361,20 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check, switch (guard->ty) { - case SPELLGUARD_CONDITION: + case SPELLGUARD::CONDITION: if (!magic_eval_int(env, guard->s.s_condition)) return NULL; break; - case SPELLGUARD_COMPONENTS: + case SPELLGUARD::COMPONENTS: copy_components(&check->components, guard->s.s_components); break; - case SPELLGUARD_CATALYSTS: + case SPELLGUARD::CATALYSTS: copy_components(&check->catalysts, guard->s.s_catalysts); break; - case SPELLGUARD_CHOICE: + case SPELLGUARD::CHOICE: { spellguard_check_t altcheck = *check; effect_set_t *retval; @@ -397,15 +397,15 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check, env, near_miss); } - case SPELLGUARD_MANA: + case SPELLGUARD::MANA: check->mana += magic_eval_int(env, guard->s.s_mana); break; - case SPELLGUARD_CASTTIME: + case SPELLGUARD::CASTTIME: check->casttime += magic_eval_int(env, guard->s.s_mana); break; - case SPELLGUARD_EFFECT: + case SPELLGUARD::EFFECT: if (spellguard_can_satisfy(check, caster, env, near_miss)) return &guard->s.s_effect; else @@ -463,7 +463,7 @@ static void spell_set_location(invocation_t *invocation, entity_t *entity) { magic_clear_var(&invocation->env->vars[VAR_LOCATION]); - invocation->env->vars[VAR_LOCATION].ty = TY_LOCATION; + invocation->env->vars[VAR_LOCATION].ty = TYPE::LOCATION; invocation->env->vars[VAR_LOCATION].v.v_location.m = entity->m; invocation->env->vars[VAR_LOCATION].v.v_location.x = entity->x; invocation->env->vars[VAR_LOCATION].v.v_location.y = entity->y; @@ -471,7 +471,7 @@ void spell_set_location(invocation_t *invocation, entity_t *entity) void spell_update_location(invocation_t *invocation) { - if (bool(invocation->spell->flags & SPELL_FLAG_LOCAL)) + if (bool(invocation->spell->flags & SPELL_FLAG::LOCAL)) return; else { @@ -500,7 +500,7 @@ invocation_t *spell_instantiate(effect_set_t *effect_set, env_t *env) caster = map_id2bl(retval->caster); // must still exist retval->bl.id = map_addobject(&retval->bl); - retval->bl.type = BL_SPELL; + retval->bl.type = BL::SPELL; retval->bl.m = caster->m; retval->bl.x = caster->x; retval->bl.y = caster->y; @@ -545,9 +545,9 @@ void spell_bind(character_t *subject, invocation_t *invocation) { /* Only bind nonlocal spells */ - if (!bool(invocation->spell->flags & SPELL_FLAG_LOCAL)) + if (!bool(invocation->spell->flags & SPELL_FLAG::LOCAL)) { - if (bool(invocation->flags & INVOCATION_FLAG_BOUND) + if (bool(invocation->flags & INVOCATION_FLAG::BOUND) || invocation->subject || invocation->next_invocation) { int *i = NULL; @@ -560,7 +560,7 @@ void spell_bind(character_t *subject, invocation_t *invocation) invocation->next_invocation = subject->active_spells; subject->active_spells = invocation; - invocation->flags |= INVOCATION_FLAG_BOUND; + invocation->flags |= INVOCATION_FLAG::BOUND; invocation->subject = subject->bl.id; } @@ -577,7 +577,7 @@ int spell_unbind(character_t *subject, invocation_t *invocation) { *seeker = invocation->next_invocation; - invocation->flags &= ~INVOCATION_FLAG_BOUND; + invocation->flags &= ~INVOCATION_FLAG::BOUND; invocation->next_invocation = NULL; invocation->subject = 0; diff --git a/src/map/magic-interpreter-lexer.lpp b/src/map/magic-interpreter-lexer.lpp index ba3372e..96598a3 100644 --- a/src/map/magic-interpreter-lexer.lpp +++ b/src/map/magic-interpreter-lexer.lpp @@ -84,7 +84,7 @@ "SKIP" {FIXLOC; return SKIP;} "ABORT" {FIXLOC; return ABORT;} "BREAK" {FIXLOC; return BREAK;} -"EFFECT" {FIXLOC; return EFFECT;} +"EFFECT" {FIXLOC; return EFFECT_;} "ATEND" {FIXLOC; return ATEND;} "ATTRIGGER" {FIXLOC; return ATTRIGGER;} "CONST" {FIXLOC; return CONST;} diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp index b6486f1..a8db8a4 100644 --- a/src/map/magic-interpreter-parser.ypp +++ b/src/map/magic-interpreter-parser.ypp @@ -23,7 +23,14 @@ expr_t *fun_expr(const char *name, int args_nr, expr_t **args, int line, int col static expr_t *dot_expr(expr_t *lhs, int id); -#define BIN_EXPR(x, name, arg1, arg2, line, column) { expr_t *e[2]; e[0] = arg1; e[1] = arg2; x = fun_expr(name, 2, e, line, column); } +static +void BIN_EXPR(expr_t *& x, const char *name, expr_t *arg1, expr_t *arg2, int line, int column) +{ + expr_t *e[2]; + e[0] = arg1; + e[1] = arg2; + x = fun_expr(name, 2, e, line, column); +} static int failed_flag = 0; @@ -44,7 +51,7 @@ static spellguard_t *new_spellguard(SPELLGUARD ty); static -effect_t *new_effect(EFFECT_ ty); +effect_t *new_effect(EFFECT ty); static effect_t *set_effect_continuation(effect_t *src, effect_t *continuation); @@ -161,7 +168,7 @@ val_t *find_constant(char *name); %token SKIP %token ABORT %token BREAK -%token EFFECT +%token EFFECT_ %token ATEND %token ATTRIGGER %token PC_F @@ -308,24 +315,24 @@ spellconf_option : ID '=' expr spell_flags : /* empty */ { $$ = SPELL_FLAG::ZERO; } | LOCAL spell_flags - { if (bool($2 & SPELL_FLAG_LOCAL)) + { if (bool($2 & SPELL_FLAG::LOCAL)) fail(@1.first_line, @1.first_column, "`LOCAL' specified more than once"); - $$ = $2 | SPELL_FLAG_LOCAL; + $$ = $2 | SPELL_FLAG::LOCAL; } | NONMAGIC spell_flags - { if (bool($2 & SPELL_FLAG_NONMAGIC)) + { if (bool($2 & SPELL_FLAG::NONMAGIC)) fail(@1.first_line, @1.first_column, "`NONMAGIC' specified more than once"); - $$ = $2 | SPELL_FLAG_NONMAGIC; + $$ = $2 | SPELL_FLAG::NONMAGIC; } | SILENT spell_flags - { if (bool($2 & SPELL_FLAG_SILENT)) + { if (bool($2 & SPELL_FLAG::SILENT)) fail(@1.first_line, @1.first_column, "`SILENT' specified more than once"); - $$ = $2 | SPELL_FLAG_SILENT; + $$ = $2 | SPELL_FLAG::SILENT; } argopt : /* empty */ - { $$.ty = SPELLARG_NONE; } + { $$.ty = SPELLARG::NONE; } | '(' ID ':' arg_ty ')' { $$.id = intern_id($2); $$.ty = $4; } @@ -333,40 +340,40 @@ argopt : /* empty */ arg_ty : PC_F - { $$ = SPELLARG_PC; } + { $$ = SPELLARG::PC; } | STRING_TY - { $$ = SPELLARG_STRING; } + { $$ = SPELLARG::STRING; } ; value : DIR - { $$.ty = TY_DIR; + { $$.ty = TYPE::DIR; $$.v.v_int = $1; } | INT - { $$.ty = TY_INT; + { $$.ty = TYPE::INT; $$.v.v_int = $1; } | STRING - { $$.ty = TY_STRING; + { $$.ty = TYPE::STRING; $$.v.v_string = $1; } ; expr : value - { $$ = magic_new_expr(EXPR_VAL); + { $$ = magic_new_expr(EXPR::VAL); $$->e.e_val = $1; } | ID { val_t *val; if ((val = find_constant($1))) { - $$ = magic_new_expr(EXPR_VAL); + $$ = magic_new_expr(EXPR::VAL); $$->e.e_val = *val; } else { - $$ = magic_new_expr(EXPR_ID); + $$ = magic_new_expr(EXPR::ID); $$->e.e_id = intern_id($1); } } | area - { $$ = magic_new_expr(EXPR_AREA); + { $$ = magic_new_expr(EXPR::AREA); $$->e.e_area = $1; } | expr '+' expr { BIN_EXPR($$, "+", $1, $3, @1.first_line, @1.first_column); } @@ -442,17 +449,17 @@ location : '@' '(' expr ',' expr ',' expr ')' ; area : location - { $$.ty = AREA_LOCATION; + { $$.ty = AREA::LOCATION; $$.a.a_loc = $1; } | location '@' '+' '(' expr ',' expr ')' - { $$.ty = AREA_RECT; + { $$.ty = AREA::RECT; $$.a.a_rect.loc = $1; $$.a.a_rect.width = $5; $$.a.a_rect.height = $7; } | location TOWARDS expr ':' '(' expr ',' expr ')' - { $$.ty = AREA_BAR; + { $$.ty = AREA::BAR; $$.a.a_bar.loc = $1; $$.a.a_bar.width = $6; $$.a.a_bar.depth = $8; @@ -501,7 +508,7 @@ def : ID '=' expr spellbody_list : spellbody { $$ = $1; } | spellbody '|' spellbody_list - { spellguard_t *sg = new_spellguard(SPELLGUARD_CHOICE); + { spellguard_t *sg = new_spellguard(SPELLGUARD::CHOICE); sg->next = $1; sg->s.s_alt = $3; $$ = sg; @@ -513,8 +520,8 @@ spellbody : spellguard DARROW spellbody { $$ = spellguard_implication($1, $3); } | '(' spellbody_list ')' { $$ = $2; } - | EFFECT effect_list maybe_trigger maybe_end - { spellguard_t *sg = new_spellguard(SPELLGUARD_EFFECT); + | EFFECT_ effect_list maybe_trigger maybe_end + { spellguard_t *sg = new_spellguard(SPELLGUARD::EFFECT); sg->s.s_effect.effect = $2; sg->s.s_effect.at_trigger = $3; sg->s.s_effect.at_end = $4; @@ -540,7 +547,7 @@ maybe_end : /* empty */ spellguard : prereq { $$ = $1; } | spellguard OR spellguard - { spellguard_t *sg = new_spellguard(SPELLGUARD_CHOICE); + { spellguard_t *sg = new_spellguard(SPELLGUARD::CHOICE); sg->next = $1; sg->s.s_alt = $3; $$ = sg; @@ -558,23 +565,23 @@ spellguard_list : spellguard prereq : REQUIRE expr - { $$ = new_spellguard(SPELLGUARD_CONDITION); + { $$ = new_spellguard(SPELLGUARD::CONDITION); $$->s.s_condition = $2; } | CATALYSTS items - { $$ = new_spellguard(SPELLGUARD_CATALYSTS); + { $$ = new_spellguard(SPELLGUARD::CATALYSTS); $$->s.s_catalysts = $2; } | COMPONENTS items - { $$ = new_spellguard(SPELLGUARD_COMPONENTS); + { $$ = new_spellguard(SPELLGUARD::COMPONENTS); $$->s.s_components = $2; } | MANA expr - { $$ = new_spellguard(SPELLGUARD_MANA); + { $$ = new_spellguard(SPELLGUARD::MANA); $$->s.s_mana = $2; } | CASTTIME expr - { $$ = new_spellguard(SPELLGUARD_CASTTIME); + { $$ = new_spellguard(SPELLGUARD::CASTTIME); $$->s.s_casttime = $2; } ; @@ -618,69 +625,69 @@ item_name : STRING selection : PC_F - { $$ = FOREACH_FILTER_PC; } + { $$ = FOREACH_FILTER::PC; } | MOB_F - { $$ = FOREACH_FILTER_MOB; } + { $$ = FOREACH_FILTER::MOB; } | ENTITY_F - { $$ = FOREACH_FILTER_ENTITY; } + { $$ = FOREACH_FILTER::ENTITY; } | SPELL - { $$ = FOREACH_FILTER_SPELL; } + { $$ = FOREACH_FILTER::SPELL; } | TARGET_F - { $$ = FOREACH_FILTER_TARGET; } + { $$ = FOREACH_FILTER::TARGET; } | NPC_F - { $$ = FOREACH_FILTER_NPC; } + { $$ = FOREACH_FILTER::NPC; } ; effect : '(' effect_list ')' { $$ = $2; } | SKIP ';' - { $$ = new_effect(EFFECT_SKIP); } + { $$ = new_effect(EFFECT::SKIP); } | ABORT ';' - { $$ = new_effect(EFFECT_ABORT); } + { $$ = new_effect(EFFECT::ABORT); } | END ';' - { $$ = new_effect(EFFECT_END); } + { $$ = new_effect(EFFECT::END); } | BREAK ';' - { $$ = new_effect(EFFECT_BREAK); } + { $$ = new_effect(EFFECT::BREAK); } | ID '=' expr ';' { if (find_constant($1)) { fail(@1.first_line, @1.first_column, "Attempt to re-define constant `%s' in assignment.", $1); free($1); } else { - $$ = new_effect(EFFECT_ASSIGN); + $$ = new_effect(EFFECT::ASSIGN); $$->e.e_assign.id = intern_id($1); $$->e.e_assign.expr = $3; } } | FOREACH selection ID IN expr DO effect - { $$ = new_effect(EFFECT_FOREACH); + { $$ = new_effect(EFFECT::FOREACH); $$->e.e_foreach.id = intern_id($3); $$->e.e_foreach.area = $5; $$->e.e_foreach.body = $7; $$->e.e_foreach.filter = $2; } | FOR ID '=' expr TO expr DO effect - { $$ = new_effect(EFFECT_FOR); + { $$ = new_effect(EFFECT::FOR); $$->e.e_for.id = intern_id($2); $$->e.e_for.start = $4; $$->e.e_for.stop = $6; $$->e.e_for.body = $8; } | IF expr THEN effect ELSE effect - { $$ = new_effect(EFFECT_IF); + { $$ = new_effect(EFFECT::IF); $$->e.e_if.cond = $2; $$->e.e_if.true_branch = $4; $$->e.e_if.false_branch = $6; } | IF expr THEN effect - { $$ = new_effect(EFFECT_IF); + { $$ = new_effect(EFFECT::IF); $$->e.e_if.cond = $2; $$->e.e_if.true_branch = $4; - $$->e.e_if.false_branch = new_effect(EFFECT_SKIP); + $$->e.e_if.false_branch = new_effect(EFFECT::SKIP); } | SLEEP expr ';' - { $$ = new_effect(EFFECT_SLEEP); + { $$ = new_effect(EFFECT::SLEEP); $$->e.e_sleep = $2; } | ID '(' arg_list ')' ';' @@ -688,7 +695,7 @@ effect : '(' effect_list ')' free($1); } | SCRIPT_DATA - { $$ = new_effect(EFFECT_SCRIPT); + { $$ = new_effect(EFFECT::SCRIPT); $$->e.e_script = parse_script($1, @1.first_line); free($1); if ($$->e.e_script == NULL) @@ -701,7 +708,7 @@ effect : '(' effect_list ')' ; effect_list : /* empty */ - { $$ = new_effect(EFFECT_SKIP); } + { $$ = new_effect(EFFECT::SKIP); } | effect semicolons effect_list { $$ = set_effect_continuation($1, $3); } ; @@ -728,7 +735,7 @@ int intern_id(const char *id_name) RECREATE(magic_conf.var_name, const char *, magic_conf.vars_nr); magic_conf.var_name[i] = id_name; RECREATE(magic_conf.vars, val_t, magic_conf.vars_nr); - magic_conf.vars[i].ty = TY_UNDEF; + magic_conf.vars[i].ty = TYPE::UNDEF; return i; } @@ -795,7 +802,7 @@ void fail(int line, int column, const char *fmt, ...) static expr_t *dot_expr(expr_t *expr, int id) { - expr_t *retval = magic_new_expr(EXPR_SPELLFIELD); + expr_t *retval = magic_new_expr(EXPR::SPELLFIELD); retval->e.e_field.id = id; retval->e.e_field.expr = expr; @@ -819,7 +826,7 @@ expr_t *fun_expr(const char *name, int args_nr, expr_t **args, int line, int col if (fun) { int i; - expr = magic_new_expr(EXPR_FUNAPP); + expr = magic_new_expr(EXPR::FUNAPP); expr->e.e_funapp.line_nr = line; expr->e.e_funapp.column = column; expr->e.e_funapp.id = id; @@ -828,8 +835,8 @@ expr_t *fun_expr(const char *name, int args_nr, expr_t **args, int line, int col for (i = 0; i < args_nr; i++) expr->e.e_funapp.args[i] = args[i]; } else { /* failure */ - expr = magic_new_expr(EXPR_VAL); - expr->e.e_val.ty = TY_FAIL; + expr = magic_new_expr(EXPR::VAL); + expr->e.e_val.ty = TYPE::FAIL; } return expr; @@ -873,7 +880,7 @@ spellguard_t *spellguard_implication(spellguard_t *a, spellguard_t *b) return retval; /* If the premise is a disjunction, b is the continuation of _all_ branches */ - if (a->ty == SPELLGUARD_CHOICE) + if (a->ty == SPELLGUARD::CHOICE) spellguard_implication(a->s.s_alt, b); if (a->next) spellguard_implication(a->next, b); @@ -885,7 +892,7 @@ spellguard_t *spellguard_implication(spellguard_t *a, spellguard_t *b) } static -effect_t *new_effect(EFFECT_ ty) +effect_t *new_effect(EFFECT ty) { effect_t *effect = (effect_t *) calloc(1, sizeof(effect_t)); effect->ty = ty; @@ -903,7 +910,7 @@ effect_t *set_effect_continuation(effect_t *src, effect_t *continuation) /* For FOR and FOREACH, we use special stack handlers and thus don't have to set * the continuation. It's only IF that we need to handle in this fashion. */ - if (src->ty == EFFECT_IF) { + if (src->ty == EFFECT::IF) { set_effect_continuation(src->e.e_if.true_branch, continuation); set_effect_continuation(src->e.e_if.false_branch, continuation); } @@ -932,7 +939,7 @@ effect_t *op_effect(char *name, int args_nr, expr_t **args, int line, int column if (op) { int i; - effect = new_effect(EFFECT_OP); + effect = new_effect(EFFECT::OP); effect->e.e_op.line_nr = line; effect->e.e_op.column = column; effect->e.e_op.id = id; @@ -941,7 +948,7 @@ effect_t *op_effect(char *name, int args_nr, expr_t **args, int line, int column for (i = 0; i < args_nr; i++) effect->e.e_op.args[i] = args[i]; } else /* failure */ - effect = new_effect(EFFECT_SKIP); + effect = new_effect(EFFECT::SKIP); return effect; } @@ -978,15 +985,15 @@ effect_t *call_proc(char *name, int args_nr, expr_t **args, int line_nr, int col if (!p) { fail(line_nr, column, "Unknown procedure `%s'\n", name); - return new_effect(EFFECT_SKIP); + return new_effect(EFFECT::SKIP); } if (p->args_nr != args_nr) { fail(line_nr, column, "Procedure %s/%d invoked with %d parameters\n", name, p->args_nr, args_nr); - return new_effect(EFFECT_SKIP); + return new_effect(EFFECT::SKIP); } - retval = new_effect(EFFECT_CALL); + retval = new_effect(EFFECT::CALL); retval->e.e_call.body = p->body; retval->e.e_call.args_nr = args_nr; retval->e.e_call.formals = p->args; @@ -1036,8 +1043,16 @@ val_t *find_constant(char *name) - -#define INTERN_ASSERT(name, id) { int zid = intern_id(name); if (zid != id) FPRINTF(stderr, "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", name, zid, id); error_flag = 1; } +// FIXME: macro capture +#define INTERN_ASSERT(name, id) \ +{ \ + int zid = intern_id(name); \ + if (zid != id) \ + FPRINTF(stderr, \ + "[magic-conf] INTERNAL ERROR: Builtin special var %s interned to %d, not %d as it should be!\n", \ + name, zid, id); \ + error_flag = 1; \ +} extern FILE *magic_frontend_in; @@ -1077,10 +1092,10 @@ int magic_init(const char *conffile) } magic_frontend_parse(); - if (magic_conf.vars[VAR_MIN_CASTTIME].ty == TY_INT) + if (magic_conf.vars[VAR_MIN_CASTTIME].ty == TYPE::INT) magic_conf.min_casttime = magic_conf.vars[VAR_MIN_CASTTIME].v.v_int; - if (magic_conf.vars[VAR_OBSCURE_CHANCE].ty == TY_INT) + if (magic_conf.vars[VAR_OBSCURE_CHANCE].ty == TYPE::INT) magic_conf.obscure_chance = magic_conf.vars[VAR_OBSCURE_CHANCE].v.v_int; PRINTF("[magic-conf] Magic initialised; obscure at %d%%. %d spells, %d teleport anchors.\n", diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp index 9b7a035..35377bc 100644 --- a/src/map/magic-interpreter.hpp +++ b/src/map/magic-interpreter.hpp @@ -56,7 +56,7 @@ typedef struct val struct invocation *v_invocation; /* Used ONLY during operation/function invocation; otherwise we use v_int */ struct spell *v_spell; } v; - TY ty; + TYPE ty; } val_t; /* ----------- */ @@ -157,7 +157,7 @@ typedef struct effect struct effect *body; } e_call; } e; - EFFECT_ ty; + EFFECT ty; } effect_t; /* ---------- */ @@ -280,7 +280,7 @@ typedef struct cont_activation_record struct { int id; - TY ty; + TYPE ty; effect_t *body; int entities_nr; int *entities; diff --git a/src/map/magic-interpreter.t.hpp b/src/map/magic-interpreter.t.hpp index 26dc8d9..d5aa5e5 100644 --- a/src/map/magic-interpreter.t.hpp +++ b/src/map/magic-interpreter.t.hpp @@ -6,35 +6,22 @@ enum class SPELLARG : uint8_t { NONE, -#define SPELLARG_NONE SPELLARG::NONE PC, -#define SPELLARG_PC SPELLARG::PC STRING, -#define SPELLARG_STRING SPELLARG::STRING }; -enum class TY : uint8_t +enum class TYPE : uint8_t { UNDEF, -#define TY_UNDEF TY::UNDEF INT, -#define TY_INT TY::INT DIR, -#define TY_DIR TY::DIR STRING, -#define TY_STRING TY::STRING ENTITY, -#define TY_ENTITY TY::ENTITY LOCATION, -#define TY_LOCATION TY::LOCATION AREA, -#define TY_AREA TY::AREA SPELL, -#define TY_SPELL TY::SPELL INVOCATION, -#define TY_INVOCATION TY::INVOCATION FAIL = 127, -#define TY_FAIL TY::FAIL NEGATIVE_1 = 255, }; @@ -45,21 +32,13 @@ enum class TY : uint8_t enum class DIR : uint8_t { S = 0, -#define DIR_S DIR::S SW = 1, -#define DIR_SW DIR::SW W = 2, -#define DIR_W DIR::W NW = 3, -#define DIR_NW DIR::NW N = 4, -#define DIR_N DIR::N NE = 5, -#define DIR_NE DIR::NE E = 6, -#define DIR_E DIR::E SE = 7, -#define DIR_SE DIR::SE COUNT, }; @@ -82,94 +61,58 @@ bool dir_is_diagonal(DIR d) enum class AREA : uint8_t { LOCATION, -#define AREA_LOCATION AREA::LOCATION UNION, -#define AREA_UNION AREA::UNION RECT, -#define AREA_RECT AREA::RECT BAR, -#define AREA_BAR AREA::BAR }; enum class EXPR : uint8_t { VAL, -#define EXPR_VAL EXPR::VAL LOCATION, -#define EXPR_LOCATION EXPR::LOCATION AREA, -#define EXPR_AREA EXPR::AREA FUNAPP, -#define EXPR_FUNAPP EXPR::FUNAPP ID, -#define EXPR_ID EXPR::ID SPELLFIELD, -#define EXPR_SPELLFIELD EXPR::SPELLFIELD }; // temporary rename to avoid collision with enum value // in magic-interpreter-parser -enum class EFFECT_ : uint8_t +enum class EFFECT : uint8_t { SKIP, -#define EFFECT_SKIP EFFECT_::SKIP ABORT, -#define EFFECT_ABORT EFFECT_::ABORT ASSIGN, -#define EFFECT_ASSIGN EFFECT_::ASSIGN FOREACH, -#define EFFECT_FOREACH EFFECT_::FOREACH FOR, -#define EFFECT_FOR EFFECT_::FOR IF, -#define EFFECT_IF EFFECT_::IF SLEEP, -#define EFFECT_SLEEP EFFECT_::SLEEP - // temporary rename to avoid collision with NpcSubtype - SCRIPT_, -#define EFFECT_SCRIPT EFFECT_::SCRIPT_ + SCRIPT, BREAK, -#define EFFECT_BREAK EFFECT_::BREAK OP, -#define EFFECT_OP EFFECT_::OP END, -#define EFFECT_END EFFECT_::END CALL, -#define EFFECT_CALL EFFECT_::CALL }; enum class FOREACH_FILTER : uint8_t { MOB, -#define FOREACH_FILTER_MOB FOREACH_FILTER::MOB PC, -#define FOREACH_FILTER_PC FOREACH_FILTER::PC ENTITY, -#define FOREACH_FILTER_ENTITY FOREACH_FILTER::ENTITY TARGET, -#define FOREACH_FILTER_TARGET FOREACH_FILTER::TARGET SPELL, -#define FOREACH_FILTER_SPELL FOREACH_FILTER::SPELL NPC, -#define FOREACH_FILTER_NPC FOREACH_FILTER::NPC }; enum class SPELLGUARD : uint8_t { CONDITION, -#define SPELLGUARD_CONDITION SPELLGUARD::CONDITION COMPONENTS, -#define SPELLGUARD_COMPONENTS SPELLGUARD::COMPONENTS CATALYSTS, -#define SPELLGUARD_CATALYSTS SPELLGUARD::CATALYSTS CHOICE, -#define SPELLGUARD_CHOICE SPELLGUARD::CHOICE MANA, -#define SPELLGUARD_MANA SPELLGUARD::MANA CASTTIME, -#define SPELLGUARD_CASTTIME SPELLGUARD::CASTTIME EFFECT, -#define SPELLGUARD_EFFECT SPELLGUARD::EFFECT }; namespace e @@ -180,13 +123,10 @@ enum class SPELL_FLAG : uint8_t // spell associated not with caster but with place LOCAL = 1 << 0, -#define SPELL_FLAG_LOCAL SPELL_FLAG::LOCAL // spell invocation never uttered SILENT = 1 << 1, -#define SPELL_FLAG_SILENT SPELL_FLAG::SILENT // `magic word' only: don't require spellcasting ability NONMAGIC = 1 << 2, -#define SPELL_FLAG_NONMAGIC SPELL_FLAG::NONMAGIC }; ENUM_BITWISE_OPERATORS(SPELL_FLAG) } @@ -195,11 +135,8 @@ using e::SPELL_FLAG; enum class CONT_STACK : uint8_t { FOREACH, -#define CONT_STACK_FOREACH CONT_STACK::FOREACH FOR, -#define CONT_STACK_FOR CONT_STACK::FOR PROC, -#define CONT_STACK_PROC CONT_STACK::PROC }; namespace e @@ -210,13 +147,10 @@ enum class INVOCATION_FLAG : uint8_t // Bound directly to the caster (i.e., ignore its location) BOUND = 1 << 0, -#define INVOCATION_FLAG_BOUND INVOCATION_FLAG::BOUND // Used `abort' to terminate ABORTED = 1 << 1, -#define INVOCATION_FLAG_ABORTED INVOCATION_FLAG::ABORTED // On magical attacks: if we run out of steam, stop attacking altogether STOPATTACK = 1 << 2, -#define INVOCATION_FLAG_STOPATTACK INVOCATION_FLAG::STOPATTACK }; ENUM_BITWISE_OPERATORS(INVOCATION_FLAG) } diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index 65f6336..2061e71 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -14,7 +14,8 @@ #include "../poison.hpp" -#define INVISIBLE_NPC 127 /* used for local spell effects */ +/* used for local spell effects */ +constexpr int INVISIBLE_NPC = 127; //#define DEBUG @@ -24,16 +25,16 @@ void print_val(val_t *v) { switch (v->ty) { - case TY_UNDEF: + case TYPE::UNDEF: FPRINTF(stderr, "UNDEF"); break; - case TY_INT: + case TYPE::INT: FPRINTF(stderr, "%d", v->v.v_int); break; - case TY_DIR: + case TYPE::DIR: FPRINTF(stderr, "dir%d", v->v.v_int); break; - case TY_STRING: + case TYPE::STRING: FPRINTF(stderr, "`%s'", v->v.v_string); break; default: @@ -65,10 +66,10 @@ void clear_activation_record(cont_activation_record_t *ar) { switch (ar->ty) { - case CONT_STACK_FOREACH: + case CONT_STACK::FOREACH: free(ar->c.c_foreach.entities); break; - case CONT_STACK_PROC: + case CONT_STACK::PROC: free(ar->c.c_proc.old_actuals); break; } @@ -107,10 +108,10 @@ void spell_free_invocation(invocation_t *invocation) invocation->status_change_refs_nr = 0; } - if (bool(invocation->flags & INVOCATION_FLAG_BOUND)) + if (bool(invocation->flags & INVOCATION_FLAG::BOUND)) { entity_t *e = map_id2bl(invocation->subject); - if (e && e->type == BL_PC) + if (e && e->type == BL::PC) spell_unbind((character_t *) e, invocation); } @@ -122,7 +123,7 @@ void spell_free_invocation(invocation_t *invocation) magic_free_env(invocation->env); map_delblock(&invocation->bl); - map_delobject(invocation->bl.id, BL_SPELL); // also frees the object + map_delobject(invocation->bl.id, BL::SPELL); // also frees the object // free(invocation); } @@ -141,14 +142,14 @@ void char_set_weapon_icon(character_t *subject, int count, clif_fixpcpos(subject); if (count) { - clif_changelook(&subject->bl, LOOK_WEAPON, look); + clif_changelook(&subject->bl, LOOK::WEAPON, look); if (icon != StatusChange::ZERO) clif_status_change(&subject->bl, icon, 1); } else { /* Set it to `normal' */ - clif_changelook(&subject->bl, LOOK_WEAPON, subject->status.weapon); + clif_changelook(&subject->bl, LOOK::WEAPON, subject->status.weapon); } } @@ -161,21 +162,21 @@ void char_set_attack_info(character_t *subject, int speed, int range) if (speed == 0) { pc_calcstatus(subject, 1); - clif_updatestatus(subject, SP_ASPD); - clif_updatestatus(subject, SP_ATTACKRANGE); + clif_updatestatus(subject, SP::ASPD); + clif_updatestatus(subject, SP::ATTACKRANGE); } else { subject->aspd = speed; - clif_updatestatus(subject, SP_ASPD); - clif_updatestatus(subject, SP_ATTACKRANGE); + clif_updatestatus(subject, SP::ASPD); + clif_updatestatus(subject, SP::ATTACKRANGE); } } void magic_stop_completely(character_t *c) { // Zap all status change references to spells - for (StatusChange i : erange(StatusChange(), MAX_STATUSCHANGE)) + for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE)) c->sc_data[i].spell_invocation = 0; while (c->active_spells) @@ -223,7 +224,7 @@ int trigger_spell(int subject, int spell) spell_bind((character_t *) map_id2bl(subject), invocation); magic_clear_var(&invocation->env->vars[VAR_CASTER]); - invocation->env->vars[VAR_CASTER].ty = TY_ENTITY; + invocation->env->vars[VAR_CASTER].ty = TYPE::ENTITY; invocation->env->vars[VAR_CASTER].v.v_int = subject; return invocation->bl.id; @@ -292,11 +293,11 @@ int op_sfx(env_t *, int, val_t *args) { int delay = ARGINT(2); - if (TY(0) == TY_ENTITY) + if (ARG_TYPE(0) == TYPE::ENTITY) { entity_effect(ARGENTITY(0), ARGINT(1), delay); } - else if (TY(0) == TY_LOCATION) + else if (ARG_TYPE(0) == TYPE::LOCATION) { local_spell_effect(ARGLOCATION(0).m, ARGLOCATION(0).x, @@ -311,13 +312,13 @@ int op_sfx(env_t *, int, val_t *args) static int op_instaheal(env_t *env, int, val_t *args) { - entity_t *caster = (VAR(VAR_CASTER).ty == TY_ENTITY) + entity_t *caster = (VAR(VAR_CASTER).ty == TYPE::ENTITY) ? map_id2bl(VAR(VAR_CASTER).v.v_int) : NULL; entity_t *subject = ARGENTITY(0); if (!caster) caster = subject; - if (caster->type == BL_PC && subject->type == BL_PC) + if (caster->type == BL::PC && subject->type == BL::PC) { character_t *caster_pc = (character_t *) caster; character_t *subject_pc = (character_t *) subject; @@ -333,7 +334,7 @@ static int op_itemheal(env_t *env, int args_nr, val_t *args) { entity_t *subject = ARGENTITY(0); - if (subject->type == BL_PC) + if (subject->type == BL::PC) { pc_itemheal((struct map_session_data *) subject, ARGINT(1), ARGINT(2)); @@ -344,28 +345,37 @@ int op_itemheal(env_t *env, int args_nr, val_t *args) return 0; } -#define SHROUD_HIDE_NAME_TALKING_FLAG (1 << 0) -#define SHROUD_DISAPPEAR_ON_PICKUP_FLAG (1 << 1) -#define SHROUD_DISAPPEAR_ON_TALK_FLAG (1 << 2) +namespace e +{ +enum class Shroud +{ + HIDE_NAME_TALKING_FLAG = 1 << 0, + DISAPPEAR_ON_PICKUP_FLAG = 1 << 1, + DISAPPEAR_ON_TALK_FLAG = 1 << 2, +}; +ENUM_BITWISE_OPERATORS(Shroud) +} +using e::Shroud; -#define ARGCHAR(n) (ARGENTITY(n)->type == BL_PC) ? (character_t *)(ARGENTITY(n)) : NULL +// differs from ARGPC by checking +#define ARGCHAR(n) (ARGENTITY(n)->type == BL::PC) ? (character_t *)(ARGENTITY(n)) : NULL static int op_shroud(env_t *, int, val_t *args) { character_t *subject = ARGCHAR(0); - int arg = ARGINT(1); + Shroud arg = static_cast(ARGINT(1)); if (!subject) return 0; subject->state.shroud_active = 1; subject->state.shroud_hides_name_talking = - (arg & SHROUD_HIDE_NAME_TALKING_FLAG) != 0; + bool(arg & Shroud::HIDE_NAME_TALKING_FLAG); subject->state.shroud_disappears_on_pickup = - (arg & SHROUD_DISAPPEAR_ON_PICKUP_FLAG) != 0; + bool(arg & Shroud::DISAPPEAR_ON_PICKUP_FLAG); subject->state.shroud_disappears_on_talk = - (arg & SHROUD_DISAPPEAR_ON_TALK_FLAG) != 0; + bool(arg & Shroud::DISAPPEAR_ON_TALK_FLAG); return 0; } @@ -418,16 +428,16 @@ int op_messenger_npc(env_t *, int, val_t *args) static void entity_warp(entity_t *target, int destm, int destx, int desty) { - if (target->type == BL_PC || target->type == BL_MOB) + if (target->type == BL::PC || target->type == BL::MOB) { switch (target->type) { - case BL_PC: + case BL::PC: { character_t *character = (character_t *) target; char *map_name; - clif_clearchar_area(&character->bl, 3); + clif_clearchar(&character->bl, BeingRemoveWhy::WARPED); map_delblock(&character->bl); character->bl.x = destx; character->bl.y = desty; @@ -439,13 +449,13 @@ void entity_warp(entity_t *target, int destm, int destx, int desty) map_name = map[character->bl.m].name; // Warp part #1: update relevant data, interrupt trading etc.: - pc_setpos(character, map_name, character->bl.x, character->bl.y, 0); + pc_setpos(character, map_name, character->bl.x, character->bl.y, BeingRemoveWhy::GONE); // Warp part #2: now notify the client clif_changemap(character, map_name, character->bl.x, character->bl.y); break; } - case BL_MOB: + case BL::MOB: target->x = destx; target->y = desty; target->m = destm; @@ -486,12 +496,12 @@ int op_banish(env_t *, int, val_t *args) { entity_t *subject = ARGENTITY(0); - if (subject->type == BL_MOB) + if (subject->type == BL::MOB) { struct mob_data *mob = (struct mob_data *) subject; - if (bool(mob->mode & MOB_MODE_SUMMONED)) - mob_catch_delete(mob, 3); + if (bool(mob->mode & MobMode::SUMMONED)) + mob_catch_delete(mob, BeingRemoveWhy::WARPED); } return 0; @@ -516,7 +526,7 @@ static int op_status_change(env_t *env, int, val_t *args) { entity_t *subject = ARGENTITY(0); - int invocation_id = VAR(VAR_INVOCATION).ty == TY_INVOCATION + int invocation_id = VAR(VAR_INVOCATION).ty == TYPE::INVOCATION ? VAR(VAR_INVOCATION).v.v_int : 0; invocation_t *invocation = (invocation_t *) map_id2bl(invocation_id); @@ -524,7 +534,7 @@ int op_status_change(env_t *env, int, val_t *args) ARGINT(2), ARGINT(3), ARGINT(4), ARGINT(5), ARGINT(6), 0, invocation_id); - if (invocation && subject->type == BL_PC) + if (invocation && subject->type == BL::PC) record_status_change(invocation, subject->id, StatusChange(ARGINT(1))); return 0; @@ -553,7 +563,7 @@ int op_override_attack(env_t *env, int, val_t *args) int stopattack = ARGINT(6); character_t *subject; - if (psubject->type != BL_PC) + if (psubject->type != BL::PC) return 0; subject = (character_t *) psubject; @@ -575,7 +585,7 @@ int op_override_attack(env_t *env, int, val_t *args) invocation_t *attack_spell = (invocation_t *) map_id2bl(subject->attack_spell_override); if (attack_spell && stopattack) - attack_spell->flags |= INVOCATION_FLAG_STOPATTACK; + attack_spell->flags |= INVOCATION_FLAG::STOPATTACK; char_set_weapon_icon(subject, charges, icon, look); char_set_attack_info(subject, attack_delay, attack_range); @@ -595,7 +605,7 @@ int op_create_item(env_t *, int, val_t *args) if (count <= 0) return 0; - if (entity->type == BL_PC) + if (entity->type == BL::PC) subject = (character_t *) entity; else return 0; @@ -611,8 +621,16 @@ int op_create_item(env_t *, int, val_t *args) return 0; } -#define AGGRAVATION_MODE_ATTACKS_CASTER(n) ((n) == 0 || (n) == 2) -#define AGGRAVATION_MODE_MAKES_AGGRESSIVE(n) ((n) > 0) +inline +bool AGGRAVATION_MODE_ATTACKS_CASTER(int n) +{ + return n == 0 || n == 2; +} +inline +bool AGGRAVATION_MODE_MAKES_AGGRESSIVE(int n) +{ + return n > 0; +} static int op_aggravate(env_t *, int, val_t *args) @@ -622,7 +640,7 @@ int op_aggravate(env_t *, int, val_t *args) entity_t *target = ARGENTITY(0); struct mob_data *other; - if (target->type == BL_MOB) + if (target->type == BL::MOB) other = (struct mob_data *) target; else return 0; @@ -630,7 +648,7 @@ int op_aggravate(env_t *, int, val_t *args) mob_target(other, victim, battle_get_range(victim)); if (AGGRAVATION_MODE_MAKES_AGGRESSIVE(mode)) - other->mode = MobMode::war | (other->mode & MOB_SENSIBLE_MASK); + other->mode = MobMode::war | (other->mode & MobMode::SENSIBLE_MASK); if (AGGRAVATION_MODE_ATTACKS_CASTER(mode)) { @@ -641,10 +659,13 @@ int op_aggravate(env_t *, int, val_t *args) return 0; } -#define MONSTER_ATTITUDE_HOSTILE 0 -#define MONSTER_ATTITUDE_FRIENDLY 1 -#define MONSTER_ATTITUDE_SERVANT 2 -#define MONSTER_ATTITUDE_FROZEN 3 +enum class MonsterAttitude +{ + HOSTILE = 0, + FRIENDLY = 1, + SERVANT = 2, + FROZEN = 3, +}; static int op_spawn(env_t *, int, val_t *args) @@ -652,14 +673,15 @@ int op_spawn(env_t *, int, val_t *args) area_t *area = ARGAREA(0); entity_t *owner_e = ARGENTITY(1); int monster_id = ARGINT(2); - int monster_attitude = ARGINT(3); + MonsterAttitude monster_attitude = static_cast(ARGINT(3)); int monster_count = ARGINT(4); int monster_lifetime = ARGINT(5); int i; - character_t *owner = (monster_attitude == MONSTER_ATTITUDE_SERVANT - && owner_e->type == - BL_PC) ? (character_t *) owner_e : NULL; + character_t *owner = NULL; + if (monster_attitude == MonsterAttitude::SERVANT + && owner_e->type == BL::PC) + owner = (character_t *) owner_e; for (i = 0; i < monster_count; i++) { @@ -680,17 +702,16 @@ int op_spawn(env_t *, int, val_t *args) switch (monster_attitude) { - - case MONSTER_ATTITUDE_SERVANT: + case MonsterAttitude::SERVANT: mob->state.special_mob_ai = 1; mob->mode |= MobMode::AGGRESSIVE; break; - case MONSTER_ATTITUDE_FRIENDLY: + case MonsterAttitude::FRIENDLY: mob->mode = MobMode::CAN_ATTACK | (mob->mode & MobMode::CAN_MOVE); break; - case MONSTER_ATTITUDE_HOSTILE: + case MonsterAttitude::HOSTILE: mob->mode = MobMode::CAN_ATTACK | MobMode::AGGRESSIVE | (mob->mode & MobMode::CAN_MOVE); if (owner) { @@ -699,13 +720,13 @@ int op_spawn(env_t *, int, val_t *args) } break; - case MONSTER_ATTITUDE_FROZEN: + case MonsterAttitude::FROZEN: mob->mode = MobMode::ZERO; break; } mob->mode |= - MOB_MODE_SUMMONED | MOB_MODE_TURNS_AGAINST_BAD_MASTER; + MobMode::SUMMONED | MobMode::TURNS_AGAINST_BAD_MASTER; mob->deletetimer = add_timer(gettick() + monster_lifetime, mob_timer_delete, mob_id, 0); @@ -726,7 +747,7 @@ const char *get_invocation_name(env_t *env) { invocation_t *invocation; - if (VAR(VAR_INVOCATION).ty != TY_INVOCATION) + if (VAR(VAR_INVOCATION).ty != TYPE::INVOCATION) return "?"; invocation = (invocation_t *) map_id2bl(VAR(VAR_INVOCATION).v.v_int); @@ -746,7 +767,7 @@ int op_injure(env_t *env, int, val_t *args) int target_hp = battle_get_hp(target); int mdef = battle_get_mdef(target); - if (target->type == BL_PC && !map[target->m].flag.pvp && !((character_t *) target)->special_state.killable && (caster->type != BL_PC || !((character_t *) caster)->special_state.killer)) + if (target->type == BL::PC && !map[target->m].flag.pvp && !((character_t *) target)->special_state.killable && (caster->type != BL::PC || !((character_t *) caster)->special_state.killer)) return 0; /* Cannot damage other players outside of pvp */ if (target != caster) @@ -764,10 +785,10 @@ int op_injure(env_t *env, int, val_t *args) // display damage first, because dealing damage may deallocate the target. clif_damage(caster, target, gettick(), 0, 0, damage_caused, 0, DamageType::NORMAL, 0); - if (caster->type == BL_PC) + if (caster->type == BL::PC) { character_t *caster_pc = (character_t *) caster; - if (target->type == BL_MOB) + if (target->type == BL::MOB) { struct mob_data *mob = (struct mob_data *) target; @@ -794,7 +815,7 @@ int op_emote(env_t *, int, val_t *args) static int op_set_script_variable(env_t *, int, val_t *args) { - character_t *c = (ETY(0) == BL_PC) ? ARGPC(0) : NULL; + character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; @@ -807,12 +828,12 @@ int op_set_script_variable(env_t *, int, val_t *args) static int op_set_hair_colour(env_t *, int, val_t *args) { - character_t *c = (ETY(0) == BL_PC) ? ARGPC(0) : NULL; + character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; - pc_changelook(c, LOOK_HAIR_COLOR, ARGINT(1)); + pc_changelook(c, LOOK::HAIR_COLOR, ARGINT(1)); return 0; } @@ -820,12 +841,12 @@ int op_set_hair_colour(env_t *, int, val_t *args) static int op_set_hair_style(env_t *, int, val_t *args) { - character_t *c = (ETY(0) == BL_PC) ? ARGPC(0) : NULL; + character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; - pc_changelook(c, LOOK_HAIR, ARGINT(1)); + pc_changelook(c, LOOK::HAIR, ARGINT(1)); return 0; } @@ -838,7 +859,7 @@ int op_drop_item_for (env_t *, int args_nr, val_t *args) location_t *loc = &ARGLOCATION(0); int count = ARGINT(2); int time = ARGINT(3); - character_t *c = ((args_nr > 4) && (ETY(4) == BL_PC)) ? ARGPC(4) : NULL; + character_t *c = ((args_nr > 4) && (ENTITY_TYPE(4) == BL::PC)) ? ARGPC(4) : NULL; int delay = (args_nr > 5) ? ARGINT(5) : 0; int delaytime[3] = { delay, delay, delay }; character_t *owners[3] = { c, NULL, NULL }; @@ -859,7 +880,7 @@ int op_drop_item_for (env_t *, int args_nr, val_t *args) static int op_gain_exp(env_t *, int, val_t *args) { - character_t *c = (ETY(0) == BL_PC) ? ARGPC(0) : NULL; + character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; @@ -944,7 +965,7 @@ void spell_effect_report_termination(int invocation_id, int bl_id, int index = -1; invocation_t *invocation = (invocation_t *) map_id2bl(invocation_id); - if (!invocation || invocation->bl.type != BL_SPELL) + if (!invocation || invocation->bl.type != BL::SPELL) return; for (i = 0; i < invocation->status_change_refs_nr; i++) @@ -960,7 +981,7 @@ void spell_effect_report_termination(int invocation_id, int bl_id, if (index == -1) { entity_t *entity = map_id2bl(bl_id); - if (entity->type == BL_PC) + if (entity->type == BL::PC) FPRINTF(stderr, "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n", bl_id, sc_id); @@ -989,7 +1010,7 @@ effect_t *return_to_stack(invocation_t *invocation) switch (ar->ty) { - case CONT_STACK_PROC: + case CONT_STACK::PROC: { effect_t *ret = ar->return_location; int i; @@ -1008,7 +1029,7 @@ effect_t *return_to_stack(invocation_t *invocation) return ret; } - case CONT_STACK_FOREACH: + case CONT_STACK::FOREACH: { int entity_id; val_t *var = &invocation->env->vars[ar->c.c_foreach.id]; @@ -1035,7 +1056,7 @@ effect_t *return_to_stack(invocation_t *invocation) return ar->c.c_foreach.body; } - case CONT_STACK_FOR: + case CONT_STACK::FOR: if (ar->c.c_for.current > ar->c.c_for.stop) { effect_t *ret = ar->return_location; @@ -1045,7 +1066,7 @@ effect_t *return_to_stack(invocation_t *invocation) } magic_clear_var(&invocation->env->vars[ar->c.c_for.id]); - invocation->env->vars[ar->c.c_for.id].ty = TY_INT; + invocation->env->vars[ar->c.c_for.id].ty = TYPE::INT; invocation->env->vars[ar->c.c_for.id].v.v_int = ar->c.c_for.current++; @@ -1099,13 +1120,13 @@ void find_entities_in_area_c(entity_t *target, switch (target->type) { - case BL_PC: - if (filter == FOREACH_FILTER_PC - || filter == FOREACH_FILTER_ENTITY - || (filter == FOREACH_FILTER_TARGET + case BL::PC: + if (filter == FOREACH_FILTER::PC + || filter == FOREACH_FILTER::ENTITY + || (filter == FOREACH_FILTER::TARGET && map[target->m].flag.pvp)) break; - else if (filter == FOREACH_FILTER_SPELL) + else if (filter == FOREACH_FILTER::SPELL) { /* Check all spells bound to the caster */ invocation_t *invoc = ((character_t *) target)->active_spells; /* Add all spells locked onto thie PC */ @@ -1118,21 +1139,21 @@ void find_entities_in_area_c(entity_t *target, } return; - case BL_MOB: - if (filter == FOREACH_FILTER_MOB - || filter == FOREACH_FILTER_ENTITY - || filter == FOREACH_FILTER_TARGET) + case BL::MOB: + if (filter == FOREACH_FILTER::MOB + || filter == FOREACH_FILTER::ENTITY + || filter == FOREACH_FILTER::TARGET) break; else return; - case BL_SPELL: - if (filter == FOREACH_FILTER_SPELL) + case BL::SPELL: + if (filter == FOREACH_FILTER::SPELL) { invocation_t *invocation = (invocation_t *) target; - /* Check whether the spell is `bound'-- if so, we'll consider it iff we see the caster(case BL_PC). */ - if (bool(invocation->flags & INVOCATION_FLAG_BOUND)) + /* Check whether the spell is `bound'-- if so, we'll consider it iff we see the caster(case BL::PC). */ + if (bool(invocation->flags & INVOCATION_FLAG::BOUND)) return; else break; /* Add the spell */ @@ -1140,8 +1161,8 @@ void find_entities_in_area_c(entity_t *target, else return; - case BL_NPC: - if (filter == FOREACH_FILTER_NPC) + case BL::NPC: + if (filter == FOREACH_FILTER::NPC) break; else return; @@ -1160,7 +1181,7 @@ void find_entities_in_area(area_t *area, int *entities_allocd_p, { switch (area->ty) { - case AREA_UNION: + case AREA::UNION: find_entities_in_area(area->a.a_union[0], entities_allocd_p, entities_nr_p, entities_p, filter); find_entities_in_area(area->a.a_union[1], entities_allocd_p, @@ -1173,7 +1194,7 @@ void find_entities_in_area(area_t *area, int *entities_allocd_p, magic_area_rect(&m, &x, &y, &width, &height, area); map_foreachinarea(std::bind(find_entities_in_area_c, ph::_1, entities_allocd_p, entities_nr_p, entities_p, filter), m, x, y, x + width, y + height, - BL_NUL /* filter elsewhere */); + BL::NUL /* filter elsewhere */); } } } @@ -1189,7 +1210,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach, magic_eval(invocation->env, &area, foreach->e.e_foreach.area); - if (area.ty != TY_AREA) + if (area.ty != TYPE::AREA) { magic_clear_var(&area); FPRINTF(stderr, @@ -1200,7 +1221,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach, else { cont_activation_record_t *ar = - add_stack_entry(invocation, CONT_STACK_FOREACH, return_location); + add_stack_entry(invocation, CONT_STACK::FOREACH, return_location); int entities_allocd = 64; int *entities_collect; int *entities; @@ -1239,7 +1260,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach, ar->c.c_foreach.entities_nr = entities_nr; ar->c.c_foreach.entities = entities; ar->c.c_foreach.ty = - (filter == FOREACH_FILTER_SPELL) ? TY_INVOCATION : TY_ENTITY; + (filter == FOREACH_FILTER::SPELL) ? TYPE::INVOCATION : TYPE::ENTITY; magic_clear_var(&area); @@ -1259,7 +1280,7 @@ effect_t *run_for (invocation_t *invocation, effect_t *for_, magic_eval(invocation->env, &start, for_->e.e_for.start); magic_eval(invocation->env, &stop, for_->e.e_for.stop); - if (start.ty != TY_INT || stop.ty != TY_INT) + if (start.ty != TYPE::INT || stop.ty != TYPE::INT) { magic_clear_var(&start); magic_clear_var(&stop); @@ -1269,7 +1290,7 @@ effect_t *run_for (invocation_t *invocation, effect_t *for_, return return_location; } - ar = add_stack_entry(invocation, CONT_STACK_FOR, return_location); + ar = add_stack_entry(invocation, CONT_STACK::FOR, return_location); if (!ar) return return_location; @@ -1294,7 +1315,7 @@ effect_t *run_call(invocation_t *invocation, CREATE(old_actuals, val_t, args_nr); int i; - ar = add_stack_entry(invocation, CONT_STACK_PROC, return_location); + ar = add_stack_entry(invocation, CONT_STACK::PROC, return_location); ar->c.c_proc.args_nr = args_nr; ar->c.c_proc.formals = formals; ar->c.c_proc.old_actuals = old_actuals; @@ -1328,27 +1349,27 @@ void print_cfg(int i, effect_t *e) switch (e->ty) { - case EFFECT_SKIP: + case EFFECT::SKIP: puts("SKIP"); break; - case EFFECT_END: + case EFFECT::END: puts("END"); break; - case EFFECT_ABORT: + case EFFECT::ABORT: puts("ABORT"); break; - case EFFECT_ASSIGN: + case EFFECT::ASSIGN: puts("ASSIGN"); break; - case EFFECT_FOREACH: + case EFFECT::FOREACH: puts("FOREACH"); print_cfg(i + 1, e->e.e_foreach.body); break; - case EFFECT_FOR: + case EFFECT::FOR: puts("FOR"); print_cfg(i + 1, e->e.e_for.body); break; - case EFFECT_IF: + case EFFECT::IF: puts("IF"); for (j = 0; j < i; j++) PRINTF(" "); @@ -1359,16 +1380,16 @@ void print_cfg(int i, effect_t *e) puts("ELSE"); print_cfg(i + 1, e->e.e_if.false_branch); break; - case EFFECT_SLEEP: + case EFFECT::SLEEP: puts("SLEEP"); break; - case EFFECT_SCRIPT: - puts("SCRIPT"); + case EFFECT::SCRIPT: + puts("NpcSubtype::SCRIPT"); break; - case EFFECT_BREAK: + case EFFECT::BREAK: puts("BREAK"); break; - case EFFECT_OP: + case EFFECT::OP: puts("OP"); break; } @@ -1409,40 +1430,40 @@ int spell_run(invocation_t *invocation, int allow_delete) switch (e->ty) { - case EFFECT_SKIP: + case EFFECT::SKIP: break; - case EFFECT_ABORT: - invocation->flags |= INVOCATION_FLAG_ABORTED; + case EFFECT::ABORT: + invocation->flags |= INVOCATION_FLAG::ABORTED; invocation->end_effect = NULL; FALLTHROUGH; - case EFFECT_END: + case EFFECT::END: clear_stack(invocation); next = NULL; break; - case EFFECT_ASSIGN: + case EFFECT::ASSIGN: magic_eval(invocation->env, &invocation->env->vars[e->e.e_assign.id], e->e.e_assign.expr); break; - case EFFECT_FOREACH: + case EFFECT::FOREACH: next = run_foreach(invocation, e, next); break; - case EFFECT_FOR: + case EFFECT::FOR: next = run_for (invocation, e, next); break; - case EFFECT_IF: + case EFFECT::IF: if (magic_eval_int(invocation->env, e->e.e_if.cond)) next = e->e.e_if.true_branch; else next = e->e.e_if.false_branch; break; - case EFFECT_SLEEP: + case EFFECT::SLEEP: { int sleeptime = magic_eval_int(invocation->env, e->e.e_sleep); @@ -1452,7 +1473,7 @@ int spell_run(invocation_t *invocation, int allow_delete) break; } - case EFFECT_SCRIPT: + case EFFECT::SCRIPT: { character_t *caster = (character_t *) map_id2bl(invocation->caster); @@ -1461,7 +1482,7 @@ int spell_run(invocation_t *invocation, int allow_delete) env_t *env = invocation->env; argrec_t arg[] = { {"@target", VAR(VAR_TARGET).ty == - TY_ENTITY ? 0 : VAR(VAR_TARGET). + TYPE::ENTITY ? 0 : VAR(VAR_TARGET). v.v_int} , {"@caster", invocation->caster} @@ -1470,7 +1491,7 @@ int spell_run(invocation_t *invocation, int allow_delete) }; int message_recipient = VAR(VAR_SCRIPTTARGET).ty == - TY_ENTITY ? VAR(VAR_SCRIPTTARGET). + TYPE::ENTITY ? VAR(VAR_SCRIPTTARGET). v.v_int : invocation->caster; character_t *recipient = (character_t *) map_id2bl(message_recipient); @@ -1500,17 +1521,17 @@ int spell_run(invocation_t *invocation, int allow_delete) } else invocation->script_pos = 0; - clif_clearchar_id(invocation->bl.id, 1, caster->fd); + clif_clearchar_id(invocation->bl.id, BeingRemoveWhy::DEAD, caster->fd); } REFRESH_INVOCATION; // Script may have killed the caster break; } - case EFFECT_BREAK: + case EFFECT::BREAK: next = return_to_stack(invocation); break; - case EFFECT_OP: + case EFFECT::OP: { op_t *op = &operations[e->e.e_op.id]; val_t args[MAX_ARGS]; @@ -1531,7 +1552,7 @@ int spell_run(invocation_t *invocation, int allow_delete) break; } - case EFFECT_CALL: + case EFFECT::CALL: next = run_call(invocation, next); break; @@ -1604,17 +1625,17 @@ int spell_attack(int caster_id, int target_id) invocation = (invocation_t *) map_id2bl(caster->attack_spell_override); - if (invocation && bool(invocation->flags & INVOCATION_FLAG_STOPATTACK)) + if (invocation && bool(invocation->flags & INVOCATION_FLAG::STOPATTACK)) stop_attack = 1; if (invocation && caster->attack_spell_charges > 0) { magic_clear_var(&invocation->env->vars[VAR_TARGET]); - invocation->env->vars[VAR_TARGET].ty = TY_ENTITY; + invocation->env->vars[VAR_TARGET].ty = TYPE::ENTITY; invocation->env->vars[VAR_TARGET].v.v_int = target_id; invocation->current_effect = invocation->trigger_effect; - invocation->flags &= ~INVOCATION_FLAG_ABORTED; + invocation->flags &= ~INVOCATION_FLAG::ABORTED; spell_execute_d(invocation, 0 /* don't delete the invocation if done */ ); @@ -1622,7 +1643,7 @@ int spell_attack(int caster_id, int target_id) invocation = (invocation_t *) map_id2bl(caster->attack_spell_override); - if (invocation && !bool(invocation->flags & INVOCATION_FLAG_ABORTED)) // If we didn't abort: + if (invocation && !bool(invocation->flags & INVOCATION_FLAG::ABORTED)) // If we didn't abort: caster->attack_spell_charges--; } diff --git a/src/map/magic.cpp b/src/map/magic.cpp index 5e08d30..1377979 100644 --- a/src/map/magic.cpp +++ b/src/map/magic.cpp @@ -29,8 +29,6 @@ char *magic_preprocess_message(character_t *character, char *start, return end + 2; /* step past blank */ } -#define ISBLANK(c) ((c) == ' ') - /* Returns a dynamically allocated copy of `src'. * `*parameter' may point within that copy or be NULL. */ static @@ -39,7 +37,7 @@ char *magic_tokenise(char *src, char **parameter) char *retval = strdup(src); char *seeker = retval; - while (*seeker && !ISBLANK(*seeker)) + while (*seeker && *seeker != ' ') ++seeker; if (!*seeker) @@ -49,7 +47,7 @@ char *magic_tokenise(char *src, char **parameter) *seeker = 0; /* Terminate invocation */ ++seeker; - while (ISBLANK(*seeker)) + while (*seeker == ' ') ++seeker; *parameter = seeker; @@ -91,7 +89,7 @@ int magic_message(character_t *caster, char *spell_, size_t) spell_create_env(&magic_conf, spell, caster, power, parameter); effect_set_t *effects; - if (bool(spell->flags & SPELL_FLAG_NONMAGIC) || (power >= 1)) + if (bool(spell->flags & SPELL_FLAG::NONMAGIC) || (power >= 1)) effects = spell_trigger(spell, caster, env, &near_miss); else effects = NULL; @@ -113,7 +111,7 @@ int magic_message(character_t *caster, char *spell_, size_t) spell_bind(caster, invocation); spell_execute(invocation); - return bool(spell->flags & SPELL_FLAG_SILENT) ? -1 : 1; + return bool(spell->flags & SPELL_FLAG::SILENT) ? -1 : 1; } else magic_free_env(env); diff --git a/src/map/map.cpp b/src/map/map.cpp index 86737a2..aae2e44 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -52,13 +52,13 @@ struct block_list *object[MAX_FLOORITEM]; static int first_free_object_id = 0, last_object_id = 0; -#define block_free_max 1048576 +constexpr int block_free_max = 1048576; static void *block_free[block_free_max]; static int block_free_count = 0, block_free_lock = 0; -#define BL_LIST_MAX 1048576 +constexpr int BL_LIST_MAX = 1048576; static struct block_list *bl_list[BL_LIST_MAX]; static @@ -214,7 +214,7 @@ int map_addblock(struct block_list *bl) x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys) return 1; - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) { bl->next = map[m].block_mob[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs]; @@ -234,7 +234,7 @@ int map_addblock(struct block_list *bl) bl->next->prev = bl; map[m].block[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs] = bl; map[m].block_count[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs]++; - if (bl->type == BL_PC) + if (bl->type == BL::PC) map[m].users++; } @@ -265,7 +265,7 @@ int map_delblock(struct block_list *bl) b = bl->x / BLOCK_SIZE + (bl->y / BLOCK_SIZE) * map[bl->m].bxs; - if (bl->type == BL_PC) + if (bl->type == BL::PC) map[bl->m].users--; if (bl->next) @@ -273,7 +273,7 @@ int map_delblock(struct block_list *bl) if (bl->prev == &bl_head) { // リストの頭なので、map[]のblock_listを更新する - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) { map[bl->m].block_mob[b] = bl->next; if ((map[bl->m].block_mob_count[b]--) < 0) @@ -316,7 +316,7 @@ int map_count_oncell(int m, int x, int y) c = map[m].block_count[bx + by * map[m].bxs]; for (i = 0; i < c && bl; i++, bl = bl->next) { - if (bl->x == x && bl->y == y && bl->type == BL_PC) + if (bl->x == x && bl->y == y && bl->type == BL::PC) count++; } bl = map[m].block_mob[bx + by * map[m].bxs]; @@ -356,7 +356,7 @@ void map_foreachinarea(std::function func, x1 = map[m].xs - 1; if (y1 >= map[m].ys) y1 = map[m].ys - 1; - if (type == BL_NUL || type != BL_MOB) + if (type == BL::NUL || type != BL::MOB) for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { for (bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) @@ -365,7 +365,7 @@ void map_foreachinarea(std::function func, c = map[m].block_count[bx + by * map[m].bxs]; for (i = 0; i < c && bl; i++, bl = bl->next) { - if (bl && type != BL_NUL && bl->type != type) + if (bl && type != BL::NUL && bl->type != type) continue; if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0 && bl->y <= y1 && bl_list_count < BL_LIST_MAX) @@ -373,7 +373,7 @@ void map_foreachinarea(std::function func, } } } - if (type == BL_NUL || type == BL_MOB) + if (type == BL::NUL || type == BL::MOB) for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { for (bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) @@ -465,7 +465,7 @@ void map_foreachinmovearea(std::function func, c = map[m].block_count[bx + by * map[m].bxs]; for (i = 0; i < c && bl; i++, bl = bl->next) { - if (bl && type != BL_NUL && bl->type != type) + if (bl && type != BL::NUL && bl->type != type) continue; if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0 && bl->y <= y1 && bl_list_count < BL_LIST_MAX) @@ -475,7 +475,7 @@ void map_foreachinmovearea(std::function func, c = map[m].block_mob_count[bx + by * map[m].bxs]; for (i = 0; i < c && bl; i++, bl = bl->next) { - if (bl && type != BL_NUL && bl->type != type) + if (bl && type != BL::NUL && bl->type != type) continue; if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0 && bl->y <= y1 && bl_list_count < BL_LIST_MAX) @@ -504,7 +504,7 @@ void map_foreachinmovearea(std::function func, c = map[m].block_count[bx + by * map[m].bxs]; for (i = 0; i < c && bl; i++, bl = bl->next) { - if (bl && type != BL_NUL && bl->type != type) + if (bl && type != BL::NUL && bl->type != type) continue; if ((bl) && !(bl->x >= x0 && bl->x <= x1 && bl->y >= y0 @@ -523,7 +523,7 @@ void map_foreachinmovearea(std::function func, c = map[m].block_mob_count[bx + by * map[m].bxs]; for (i = 0; i < c && bl; i++, bl = bl->next) { - if (bl && type != BL_NUL && bl->type != type) + if (bl && type != BL::NUL && bl->type != type) continue; if ((bl) && !(bl->x >= x0 && bl->x <= x1 && bl->y >= y0 @@ -576,20 +576,20 @@ void map_foreachincell(std::function func, by = y / BLOCK_SIZE; bx = x / BLOCK_SIZE; - if (type == BL_NUL || type != BL_MOB) + if (type == BL::NUL || type != BL::MOB) { bl = map[m].block[bx + by * map[m].bxs]; c = map[m].block_count[bx + by * map[m].bxs]; for (i = 0; i < c && bl; i++, bl = bl->next) { - if (type != BL_NUL && bl && bl->type != type) + if (type != BL::NUL && bl && bl->type != type) continue; if (bl && bl->x == x && bl->y == y && bl_list_count < BL_LIST_MAX) bl_list[bl_list_count++] = bl; } } - if (type == BL_NUL || type == BL_MOB) + if (type == BL::NUL || type == BL::MOB) { bl = map[m].block_mob[bx + by * map[m].bxs]; c = map[m].block_mob_count[bx + by * map[m].bxs]; @@ -699,7 +699,7 @@ int map_delobject(int id, BL type) return 0; map_delobjectnofree(id, type); - if (obj->type == BL_PC) // [Fate] Not sure where else to put this... I'm not sure where delobject for PCs is called from + if (obj->type == BL::PC) // [Fate] Not sure where else to put this... I'm not sure where delobject for PCs is called from pc_cleanup((struct map_session_data *) obj); map_freeblock(obj); @@ -722,7 +722,7 @@ void map_foreachobject(std::function func, { if (object[i]) { - if (type != BL_NUL && object[i]->type != type) + if (type != BL::NUL && object[i]->type != type) continue; if (bl_list_count >= BL_LIST_MAX) { @@ -760,7 +760,7 @@ void map_clearflooritem_timer(timer_id tid, tick_t, custom_id_t id, custom_data_ struct flooritem_data *fitem = NULL; fitem = (struct flooritem_data *) object[id]; - if (fitem == NULL || fitem->bl.type != BL_ITEM + if (fitem == NULL || fitem->bl.type != BL::ITEM || (!data && fitem->cleartimer != tid)) { if (battle_config.error_log) @@ -770,7 +770,7 @@ void map_clearflooritem_timer(timer_id tid, tick_t, custom_id_t id, custom_data_ if (data) delete_timer(fitem->cleartimer, map_clearflooritem_timer); clif_clearflooritem(fitem, 0); - map_delobject(fitem->bl.id, BL_ITEM); + map_delobject(fitem->bl.id, BL::ITEM); } /*========================================== @@ -846,7 +846,7 @@ int map_addflooritem_any(struct item *item_data, int amount, int m, int x, r = mt_random(); CREATE(fitem, struct flooritem_data, 1); - fitem->bl.type = BL_ITEM; + fitem->bl.type = BL::ITEM; fitem->bl.prev = fitem->bl.next = NULL; fitem->bl.m = m; fitem->bl.x = xy & 0xffff; @@ -934,7 +934,7 @@ int map_addflooritem(struct item *item_data, int amount, int m, int x, int y, /* r=rand(); */ /* fitem = (struct flooritem_data *)aCalloc(1,sizeof(*fitem)); */ -/* fitem->bl.type=BL_ITEM; */ +/* fitem->bl.type=BL::ITEM; */ /* fitem->bl.prev = fitem->bl.next = NULL; */ /* fitem->bl.m=m; */ /* fitem->bl.x=xy&0xffff; */ @@ -1092,7 +1092,7 @@ int map_quit(struct map_session_data *sd) pc_calcstatus(sd, 4); - clif_clearchar_area(&sd->bl, 2); + clif_clearchar(&sd->bl, BeingRemoveWhy::QUIT); if (pc_isdead(sd)) pc_setrestartvalue(sd, 2); @@ -1133,7 +1133,7 @@ struct map_session_data *map_id2sd(int id) struct block_list *bl; bl=numdb_search(id_db,id); - if (bl && bl->type==BL_PC) + if (bl && bl->type==BL::PC) return (struct map_session_data*)bl; return NULL; */ @@ -1335,10 +1335,10 @@ void map_removenpc(void) { if (map[m].npc[i] != NULL) { - clif_clearchar_area(&map[m].npc[i]->bl, 2); + clif_clearchar(&map[m].npc[i]->bl, BeingRemoveWhy::QUIT); map_delblock(&map[m].npc[i]->bl); numdb_erase(id_db, map[m].npc[i]->bl.id); - if (map[m].npc[i]->bl.subtype == SCRIPT) + if (map[m].npc[i]->bl.subtype == NpcSubtype::SCRIPT) { // free(map[m].npc[i]->u.scr.script); // free(map[m].npc[i]->u.scr.label_list); @@ -1403,48 +1403,48 @@ bool map_check_dir(const DIR s_dir, const DIR t_dir) */ DIR map_calc_dir(struct block_list *src, int x, int y) { - DIR dir = DIR_S; + DIR dir = DIR::S; int dx, dy; - nullpo_retr(DIR_S, src); + nullpo_retr(DIR::S, src); dx = x - src->x; dy = y - src->y; if (dx == 0 && dy == 0) { - dir = DIR_S; + dir = DIR::S; } else if (dx >= 0 && dy >= 0) { - dir = DIR_SE; + dir = DIR::SE; if (dx * 3 - 1 < dy) - dir = DIR_S; + dir = DIR::S; if (dx > dy * 3) - dir = DIR_E; + dir = DIR::E; } else if (dx >= 0 && dy <= 0) { - dir = DIR_NE; + dir = DIR::NE; if (dx * 3 - 1 < -dy) - dir = DIR_N; + dir = DIR::N; if (dx > -dy * 3) - dir = DIR_E; + dir = DIR::E; } else if (dx <= 0 && dy <= 0) { - dir = DIR_NW; + dir = DIR::NW; if (dx * 3 + 1 > dy) - dir = DIR_N; + dir = DIR::N; if (dx < dy * 3) - dir = DIR_W; + dir = DIR::W; } else { - dir = DIR_SW; + dir = DIR::SW; if (-dx * 3 - 1 < dy) - dir = DIR_S; + dir = DIR::S; if (-dx > dy * 3) - dir = DIR_W; + dir = DIR::W; } return dir; } @@ -1707,7 +1707,7 @@ int map_delmap(const char *mapname) return 0; } -#define LOGFILE_SECONDS_PER_CHUNK_SHIFT 10 +constexpr int LOGFILE_SECONDS_PER_CHUNK_SHIFT = 10; static FILE *map_logfile = NULL; @@ -1906,19 +1906,19 @@ void cleanup_sub(struct block_list *bl) switch (bl->type) { - case BL_PC: + case BL::PC: map_delblock(bl); // There is something better... break; - case BL_NPC: + case BL::NPC: npc_delete((struct npc_data *) bl); break; - case BL_MOB: + case BL::MOB: mob_delete((struct mob_data *) bl); break; - case BL_ITEM: + case BL::ITEM: map_clearflooritem(bl->id); break; - case BL_SPELL: + case BL::SPELL: spell_free_invocation((struct invocation *) bl); break; } @@ -1939,7 +1939,7 @@ void term_func(void) if (map[map_id].m) map_foreachinarea(cleanup_sub, map_id, 0, 0, map[map_id].xs, map[map_id].ys, - BL_NUL); + BL::NUL); } for (i = 0; i < fd_max; i++) @@ -2061,9 +2061,9 @@ int map_scriptcont(struct map_session_data *sd, int id) switch (bl->type) { - case BL_NPC: + case BL::NPC: return npc_scriptcont(sd, id); - case BL_SPELL: + case BL::SPELL: spell_execute_script((struct invocation *) bl); break; } diff --git a/src/map/map.hpp b/src/map/map.hpp index eab75c4..9d033f4 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -16,27 +16,23 @@ #include "script.hpp" // change to script.t.hpp #include "skill.t.hpp" -#define MAX_NPC_PER_MAP 512 -#define BLOCK_SIZE 8 +constexpr int MAX_NPC_PER_MAP = 512; +constexpr int BLOCK_SIZE = 8; #define AREA_SIZE battle_config.area_size -#define LOCAL_REG_NUM 16 -#define LIFETIME_FLOORITEM 60 -#define DAMAGELOG_SIZE 30 -#define LOOTITEM_SIZE 10 -#define MAX_SKILL_LEVEL 100 -#define MAX_SKILLUNITGROUP 32 -#define MAX_MOBSKILLUNITGROUP 8 -#define MAX_SKILLUNITGROUPTICKSET 128 -#define MAX_MOBSKILL 32 -#define MAX_EVENTQUEUE 2 -#define MAX_EVENTTIMER 32 -#define NATURAL_HEAL_INTERVAL 500 -#define MAX_FLOORITEM 500000 -#define MAX_LEVEL 255 -#define MAX_WALKPATH 48 -#define MAX_DROP_PER_MAP 48 - -#define DEFAULT_AUTOSAVE_INTERVAL 60*1000 +constexpr int LIFETIME_FLOORITEM = 60; +constexpr int DAMAGELOG_SIZE = 30; +constexpr int LOOTITEM_SIZE = 10; +constexpr int MAX_SKILL_LEVEL = 100; +constexpr int MAX_MOBSKILL = 32; +constexpr int MAX_EVENTQUEUE = 2; +constexpr int MAX_EVENTTIMER = 32; +constexpr int NATURAL_HEAL_INTERVAL = 500; +constexpr int MAX_FLOORITEM = 500000; +constexpr int MAX_LEVEL = 255; +constexpr int MAX_WALKPATH = 48; +constexpr int MAX_DROP_PER_MAP = 48; + +constexpr int DEFAULT_AUTOSAVE_INTERVAL = 60 * 1000; struct block_list { @@ -84,8 +80,6 @@ struct quick_regeneration unsigned char tickdelay; // number of ticks to next update }; -#define VERSION_2_SKILLINFO 0x02 // client supports full skillinfo blocks - struct map_session_data { struct block_list bl; @@ -227,7 +221,7 @@ struct map_session_data int regstr_num; struct script_regstr *regstr; - earray sc_data; + earray sc_data; short sc_count; struct square dev; @@ -324,7 +318,7 @@ struct npc_data short x, y; char name[16]; } warp; - char *message; // for MESSAGE: only send this message + char *message; // for NpcSubtype::MESSAGE: only send this message } u; // ここにメンバを追加してはならない(shop_itemが可変長の為) @@ -333,8 +327,8 @@ struct npc_data short arenaflag; }; -#define MOB_XP_BONUS_BASE 1024 -#define MOB_XP_BONUS_SHIFT 10 +constexpr int MOB_XP_BONUS_BASE = 1024; +constexpr int MOB_XP_BONUS_SHIFT = 10; struct mob_data { @@ -378,7 +372,7 @@ struct mob_data struct item *lootitem; short lootitem_count; - earray sc_data; + earray sc_data; short sc_count; Opt1 opt1; Opt2 opt2; @@ -551,11 +545,17 @@ void map_log(const_string line); #define MAP_LOG(format, ...) \ map_log(static_cast(STRPRINTF(format, ## __VA_ARGS__))) -#define MAP_LOG_PC(sd, fmt, ...) MAP_LOG("PC%d %d:%d,%d " fmt, sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## __VA_ARGS__) +#define MAP_LOG_PC(sd, fmt, ...) \ + MAP_LOG("PC%d %d:%d,%d " fmt, \ + sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## __VA_ARGS__) // 床アイテム関連 void map_clearflooritem_timer(timer_id, tick_t, custom_id_t, custom_data_t); -#define map_clearflooritem(id) map_clearflooritem_timer(0,0,id,1) +inline +void map_clearflooritem(custom_id_t id) +{ + map_clearflooritem_timer(0, 0, id, 1); +} int map_addflooritem_any(struct item *, int amount, int m, int x, int y, struct map_session_data **owners, int *owner_protection, int lifetime, int dispersal); diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp index b7abc59..6b53015 100644 --- a/src/map/map.t.hpp +++ b/src/map/map.t.hpp @@ -68,86 +68,53 @@ using e::Opt3; enum class BL : uint8_t { NUL, -#define BL_NUL BL::NUL PC, -#define BL_PC BL::PC NPC, -#define BL_NPC BL::NPC MOB, -#define BL_MOB BL::MOB ITEM, -#define BL_ITEM BL::ITEM CHAT, -#define BL_CHAT BL::CHAT SPELL, -#define BL_SPELL BL::SPELL }; enum class NpcSubtype : uint8_t { WARP, -#define WARP NpcSubtype::WARP SHOP, -#define SHOP NpcSubtype::SHOP SCRIPT, -#define SCRIPT NpcSubtype::SCRIPT MONS, -#define MONS NpcSubtype::MONS MESSAGE, -#define MESSAGE NpcSubtype::MESSAGE }; enum class mob_stat { LV, -#define MOB_LV mob_stat::LV MAX_HP, -#define MOB_MAX_HP mob_stat::MAX_HP STR, -#define MOB_STR mob_stat::STR AGI, -#define MOB_AGI mob_stat::AGI VIT, -#define MOB_VIT mob_stat::VIT INT, -#define MOB_INT mob_stat::INT DEX, -#define MOB_DEX mob_stat::DEX LUK, -#define MOB_LUK mob_stat::LUK // low and high attacks ATK1, -#define MOB_ATK1 mob_stat::ATK1 ATK2, -#define MOB_ATK2 mob_stat::ATK2 // attack delay ADELAY, -#define MOB_ADELAY mob_stat::ADELAY DEF, -#define MOB_DEF mob_stat::DEF MDEF, -#define MOB_MDEF mob_stat::MDEF SPEED, -#define MOB_SPEED mob_stat::SPEED // These must come last: // [Fate] Encoded as base to 1024: 1024 means 100% XP_BONUS, -#define MOB_XP_BONUS mob_stat::XP_BONUS LAST, -#define MOB_LAST mob_stat::LAST }; enum class MS : uint8_t { IDLE, -#define MS_IDLE MS::IDLE WALK, -#define MS_WALK MS::WALK ATTACK, -#define MS_ATTACK MS::ATTACK DEAD, -#define MS_DEAD MS::DEAD DELAY, -#define MS_DELAY MS::DELAY }; enum class ATK @@ -155,383 +122,272 @@ enum class ATK ZERO = 0, LUCKY, -#define ATK_LUCKY ATK::LUCKY FLEE, -#define ATK_FLEE ATK::FLEE DEF, -#define ATK_DEF ATK::DEF }; enum class SP : uint16_t { // sent to client SPEED = 0, -#define SP_SPEED SP::SPEED // when used as "no stat" ZERO = 0, // sent to client BASEEXP = 1, -#define SP_BASEEXP SP::BASEEXP // sent to client JOBEXP = 2, -#define SP_JOBEXP SP::JOBEXP #if 0 KARMA = 3, -#define SP_KARMA SP::KARMA #endif // sent to client HP = 5, -#define SP_HP SP::HP // sent to client MAXHP = 6, -#define SP_MAXHP SP::MAXHP // sent to client SP = 7, -#define SP_SP SP::SP // sent to client MAXSP = 8, -#define SP_MAXSP SP::MAXSP // sent to client STATUSPOINT = 9, -#define SP_STATUSPOINT SP::STATUSPOINT // sent to client BASELEVEL = 11, -#define SP_BASELEVEL SP::BASELEVEL // sent to client SKILLPOINT = 12, -#define SP_SKILLPOINT SP::SKILLPOINT // sent to client STR = 13, -#define SP_STR SP::STR // sent to client AGI = 14, -#define SP_AGI SP::AGI // sent to client VIT = 15, -#define SP_VIT SP::VIT // sent to client INT = 16, -#define SP_INT SP::INT // sent to client DEX = 17, -#define SP_DEX SP::DEX // sent to client LUK = 18, -#define SP_LUK SP::LUK CLASS = 19, -#define SP_CLASS SP::CLASS // sent to client ZENY = 20, -#define SP_ZENY SP::ZENY SEX = 21, -#define SP_SEX SP::SEX // sent to client NEXTBASEEXP = 22, -#define SP_NEXTBASEEXP SP::NEXTBASEEXP // sent to client NEXTJOBEXP = 23, -#define SP_NEXTJOBEXP SP::NEXTJOBEXP // sent to client WEIGHT = 24, -#define SP_WEIGHT SP::WEIGHT // sent to client MAXWEIGHT = 25, -#define SP_MAXWEIGHT SP::MAXWEIGHT // sent to client USTR = 32, -#define SP_USTR SP::USTR // sent to client UAGI = 33, -#define SP_UAGI SP::UAGI // sent to client UVIT = 34, -#define SP_UVIT SP::UVIT // sent to client UINT = 35, -#define SP_UINT SP::UINT // sent to client UDEX = 36, -#define SP_UDEX SP::UDEX // sent to client ULUK = 37, -#define SP_ULUK SP::ULUK // sent to client ATK1 = 41, -#define SP_ATK1 SP::ATK1 // sent to client ATK2 = 42, -#define SP_ATK2 SP::ATK2 // sent to client MATK1 = 43, -#define SP_MATK1 SP::MATK1 // sent to client MATK2 = 44, -#define SP_MATK2 SP::MATK2 // sent to client DEF1 = 45, -#define SP_DEF1 SP::DEF1 // sent to client DEF2 = 46, -#define SP_DEF2 SP::DEF2 // sent to client MDEF1 = 47, -#define SP_MDEF1 SP::MDEF1 // sent to client MDEF2 = 48, -#define SP_MDEF2 SP::MDEF2 // sent to client HIT = 49, -#define SP_HIT SP::HIT // sent to client FLEE1 = 50, -#define SP_FLEE1 SP::FLEE1 // sent to client FLEE2 = 51, -#define SP_FLEE2 SP::FLEE2 // sent to client CRITICAL = 52, -#define SP_CRITICAL SP::CRITICAL // sent to client ASPD = 53, -#define SP_ASPD SP::ASPD // sent to client JOBLEVEL = 55, -#define SP_JOBLEVEL SP::JOBLEVEL #if 0 PARTNER = 57, -#define SP_PARTNER SP::PARTNER CART = 58, -#define SP_CART SP::CART FAME = 59, -#define SP_FAME SP::FAME UNBREAKABLE = 60, -#define SP_UNBREAKABLE SP::UNBREAKABLE #endif DEAF = 70, -#define SP_DEAF SP::DEAF // sent to client GM = 500, -#define SP_GM SP::GM // sent to client ATTACKRANGE = 1000, -#define SP_ATTACKRANGE SP::ATTACKRANGE #if 0 ATKELE = 1001, -#define SP_ATKELE SP::ATKELE #endif #if 0 DEFELE = 1002, -#define SP_DEFELE SP::DEFELE #endif #if 0 CASTRATE = 1003, -#define SP_CASTRATE SP::CASTRATE #endif MAXHPRATE = 1004, -#define SP_MAXHPRATE SP::MAXHPRATE #if 0 MAXSPRATE = 1005, -#define SP_MAXSPRATE SP::MAXSPRATE #endif #if 0 SPRATE = 1006, -#define SP_SPRATE SP::SPRATE #endif #if 0 ADDEFF = 1012, -#define SP_ADDEFF SP::ADDEFF #endif #if 0 RESEFF = 1013, -#define SP_RESEFF SP::RESEFF #endif BASE_ATK = 1014, -#define SP_BASE_ATK SP::BASE_ATK ASPD_RATE = 1015, -#define SP_ASPD_RATE SP::ASPD_RATE HP_RECOV_RATE = 1016, -#define SP_HP_RECOV_RATE SP::HP_RECOV_RATE #if 0 SP_RECOV_RATE = 1017, -#define SP_SP_RECOV_RATE SP::SP_RECOV_RATE #endif #if 0 SPEED_RATE = 1018, -#define SP_SPEED_RATE SP::SPEED_RATE #endif #if 0 CRITICAL_DEF = 1019, -#define SP_CRITICAL_DEF SP::CRITICAL_DEF #endif #if 0 NEAR_ATK_DEF = 1020, -#define SP_NEAR_ATK_DEF SP::NEAR_ATK_DEF #endif #if 0 LONG_ATK_DEF = 1021, -#define SP_LONG_ATK_DEF SP::LONG_ATK_DEF #endif #if 0 DOUBLE_RATE = 1022, -#define SP_DOUBLE_RATE SP::DOUBLE_RATE #endif DOUBLE_ADD_RATE = 1023, -#define SP_DOUBLE_ADD_RATE SP::DOUBLE_ADD_RATE #if 0 MATK = 1024, -#define SP_MATK SP::MATK #endif #if 0 MATK_RATE = 1025, -#define SP_MATK_RATE SP::MATK_RATE #endif #if 0 IGNORE_DEF_ELE = 1026, -#define SP_IGNORE_DEF_ELE SP::IGNORE_DEF_ELE #endif #if 0 IGNORE_DEF_RACE = 1027, -#define SP_IGNORE_DEF_RACE SP::IGNORE_DEF_RACE #endif #if 0 ATK_RATE = 1028, -#define SP_ATK_RATE SP::ATK_RATE #endif SPEED_ADDRATE = 1029, -#define SP_SPEED_ADDRATE SP::SPEED_ADDRATE #if 0 ASPD_ADDRATE = 1030, -#define SP_ASPD_ADDRATE SP::ASPD_ADDRATE #endif #if 0 MAGIC_ATK_DEF = 1031, -#define SP_MAGIC_ATK_DEF SP::MAGIC_ATK_DEF #endif #if 0 MISC_ATK_DEF = 1032, -#define SP_MISC_ATK_DEF SP::MISC_ATK_DEF #endif #if 0 IGNORE_MDEF_ELE = 1033, -#define SP_IGNORE_MDEF_ELE SP::IGNORE_MDEF_ELE #endif #if 0 IGNORE_MDEF_RACE = 1034, -#define SP_IGNORE_MDEF_RACE SP::IGNORE_MDEF_RACE #endif #if 0 PERFECT_HIT_RATE = 1038, -#define SP_PERFECT_HIT_RATE SP::PERFECT_HIT_RATE #endif #if 0 PERFECT_HIT_ADD_RATE = 1039, -#define SP_PERFECT_HIT_ADD_RATE SP::PERFECT_HIT_ADD_RATE #endif #if 0 CRITICAL_RATE = 1040, -#define SP_CRITICAL_RATE SP::CRITICAL_RATE #endif #if 0 GET_ZENY_NUM = 1041, -#define SP_GET_ZENY_NUM SP::GET_ZENY_NUM #endif #if 0 ADD_GET_ZENY_NUM = 1042, -#define SP_ADD_GET_ZENY_NUM SP::ADD_GET_ZENY_NUM #endif #if 0 ADD_MONSTER_DROP_ITEM = 1047, -#define SP_ADD_MONSTER_DROP_ITEM SP::ADD_MONSTER_DROP_ITEM #endif #if 0 DEF_RATIO_ATK_ELE = 1048, -#define SP_DEF_RATIO_ATK_ELE SP::DEF_RATIO_ATK_ELE #endif #if 0 DEF_RATIO_ATK_RACE = 1049, -#define SP_DEF_RATIO_ATK_RACE SP::DEF_RATIO_ATK_RACE #endif #if 0 ADD_SPEED = 1050, -#define SP_ADD_SPEED SP::ADD_SPEED #endif #if 0 HIT_RATE = 1051, -#define SP_HIT_RATE SP::HIT_RATE #endif #if 0 FLEE_RATE = 1052, -#define SP_FLEE_RATE SP::FLEE_RATE #endif #if 0 FLEE2_RATE = 1053, -#define SP_FLEE2_RATE SP::FLEE2_RATE #endif DEF_RATE = 1054, -#define SP_DEF_RATE SP::DEF_RATE DEF2_RATE = 1055, -#define SP_DEF2_RATE SP::DEF2_RATE #if 0 MDEF_RATE = 1056, -#define SP_MDEF_RATE SP::MDEF_RATE #endif #if 0 MDEF2_RATE = 1057, -#define SP_MDEF2_RATE SP::MDEF2_RATE #endif #if 0 SPLASH_RANGE = 1058, -#define SP_SPLASH_RANGE SP::SPLASH_RANGE #endif #if 0 SPLASH_ADD_RANGE = 1059, -#define SP_SPLASH_ADD_RANGE SP::SPLASH_ADD_RANGE #endif HP_DRAIN_RATE = 1061, -#define SP_HP_DRAIN_RATE SP::HP_DRAIN_RATE #if 0 SP_DRAIN_RATE = 1062, -#define SP_SP_DRAIN_RATE SP::SP_DRAIN_RATE #endif #if 0 SHORT_WEAPON_DAMAGE_RETURN = 1063, -#define SP_SHORT_WEAPON_DAMAGE_RETURN SP::SHORT_WEAPON_DAMAGE_RETURN #endif #if 0 LONG_WEAPON_DAMAGE_RETURN = 1064, -#define SP_LONG_WEAPON_DAMAGE_RETURN SP::LONG_WEAPON_DAMAGE_RETURN #endif #if 0 ADDEFF2 = 1067, -#define SP_ADDEFF2 SP::ADDEFF2 #endif BREAK_WEAPON_RATE = 1068, -#define SP_BREAK_WEAPON_RATE SP::BREAK_WEAPON_RATE BREAK_ARMOR_RATE = 1069, -#define SP_BREAK_ARMOR_RATE SP::BREAK_ARMOR_RATE ADD_STEAL_RATE = 1070, -#define SP_ADD_STEAL_RATE SP::ADD_STEAL_RATE MAGIC_DAMAGE_RETURN = 1071, -#define SP_MAGIC_DAMAGE_RETURN SP::MAGIC_DAMAGE_RETURN #if 0 RANDOM_ATTACK_INCREASE = 1072, -#define SP_RANDOM_ATTACK_INCREASE SP::RANDOM_ATTACK_INCREASE #endif }; @@ -575,33 +431,19 @@ SP usp_to_sp(SP sp) enum class LOOK : uint8_t { BASE = 0, -#define LOOK_BASE LOOK::BASE HAIR = 1, -#define LOOK_HAIR LOOK::HAIR WEAPON = 2, -#define LOOK_WEAPON LOOK::WEAPON HEAD_BOTTOM = 3, -#define LOOK_HEAD_BOTTOM LOOK::HEAD_BOTTOM HEAD_TOP = 4, -#define LOOK_HEAD_TOP LOOK::HEAD_TOP HEAD_MID = 5, -#define LOOK_HEAD_MID LOOK::HEAD_MID HAIR_COLOR = 6, -#define LOOK_HAIR_COLOR LOOK::HAIR_COLOR CLOTHES_COLOR = 7, -#define LOOK_CLOTHES_COLOR LOOK::CLOTHES_COLOR SHIELD = 8, -#define LOOK_SHIELD LOOK::SHIELD SHOES = 9, -#define LOOK_SHOES LOOK::SHOES GLOVES = 10, -#define LOOK_GLOVES LOOK::GLOVES CAPE = 11, -#define LOOK_CAPE LOOK::CAPE MISC1 = 12, -#define LOOK_MISC1 LOOK::MISC1 MISC2 = 13, -#define LOOK_MISC2 LOOK::MISC2 COUNT, }; @@ -618,9 +460,7 @@ enum class EQUIP HAT = 6, // also called "head top" MISC1 = 7, SHIELD = 8, -#define EQUIP_SHIELD EQUIP::SHIELD WEAPON = 9, -#define EQUIP_WEAPON EQUIP::WEAPON ARROW = 10, COUNT = 11, }; @@ -695,13 +535,10 @@ enum class MobMode : uint16_t war = CAN_MOVE | AGGRESSIVE | CAN_ATTACK, SUMMONED = 0x1000, -#define MOB_MODE_SUMMONED MobMode::SUMMONED TURNS_AGAINST_BAD_MASTER = 0x2000, -#define MOB_MODE_TURNS_AGAINST_BAD_MASTER MobMode::TURNS_AGAINST_BAD_MASTER // mob mode flags that Fate actually understood SENSIBLE_MASK = 0xf000, -#define MOB_SENSIBLE_MASK MobMode::SENSIBLE_MASK }; ENUM_BITWISE_OPERATORS(MobMode) diff --git a/src/map/mob.cpp b/src/map/mob.cpp index 47e3e16..b8339e4 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -20,10 +20,12 @@ #include "../poison.hpp" -#define MIN_MOBTHINKTIME 100 +constexpr int MIN_MOBTHINKTIME = 100; -#define MOB_LAZYMOVEPERC 50 // Move probability in the negligent mode MOB (rate of 1000 minute) -#define MOB_LAZYWARPPERC 20 // Warp probability in the negligent mode MOB (rate of 1000 minute) +// Move probability in the negligent mode MOB (rate of 1000 minute) +constexpr int MOB_LAZYMOVEPERC = 50; +// Warp probability in the negligent mode MOB (rate of 1000 minute) +constexpr int MOB_LAZYWARPPERC = 20; struct mob_db mob_db[2001]; @@ -115,43 +117,43 @@ int mob_spawn_dataset(struct mob_data *md, const char *mobname, int mob_class) // For one 256th of change, we give out that many 1024th fractions of XP change // (i.e., 1024 means a 100% XP increase for a single point of adjustment, 4 means 100% XP bonus for doubling the value) static -earray mutation_value //= +earray mutation_value //= {{ - 2, // MOB_LV - 3, // MOB_MAX_HP - 1, // MOB_STR - 2, // MOB_AGI - 1, // MOB_VIT - 0, // MOB_INT - 2, // MOB_DEX - 2, // MOB_LUK - 1, // MOB_ATK1 - 1, // MOB_ATK2 - 2, // MOB_ADELAY - 2, // MOB_DEF - 2, // MOB_MDEF - 2, // MOB_SPEED + 2, // mob_stat::LV + 3, // mob_stat::MAX_HP + 1, // mob_stat::STR + 2, // mob_stat::AGI + 1, // mob_stat::VIT + 0, // mob_stat::INT + 2, // mob_stat::DEX + 2, // mob_stat::LUK + 1, // mob_stat::ATK1 + 1, // mob_stat::ATK2 + 2, // mob_stat::ADELAY + 2, // mob_stat::DEF + 2, // mob_stat::MDEF + 2, // mob_stat::SPEED }}; // The mutation scale indicates how far `up' we can go, with 256 indicating 100% Note that this may stack with multiple // calls to `mutate'. static -earray mutation_scale //= +earray mutation_scale //= {{ - 16, // MOB_LV - 256, // MOB_MAX_HP - 32, // MOB_STR - 48, // MOB_AGI - 48, // MOB_VIT - 48, // MOB_INT - 48, // MOB_DEX - 64, // MOB_LUK - 48, // MOB_ATK1 - 48, // MOB_ATK2 - 80, // MOB_ADELAY - 48, // MOB_DEF - 48, // MOB_MDEF - 80, // MOB_SPEED + 16, // mob_stat::LV + 256, // mob_stat::MAX_HP + 32, // mob_stat::STR + 48, // mob_stat::AGI + 48, // mob_stat::VIT + 48, // mob_stat::INT + 48, // mob_stat::DEX + 64, // mob_stat::LUK + 48, // mob_stat::ATK1 + 48, // mob_stat::ATK2 + 80, // mob_stat::ADELAY + 48, // mob_stat::DEF + 48, // mob_stat::MDEF + 80, // mob_stat::SPEED }}; // The table below indicates the `average' value for each of the statistics, or -1 if there is none. @@ -162,22 +164,22 @@ earray mutation_scale //= // (3) third, compute the percentage stat change relative to mutation_base (p1) // (4) fourth, compute the XP mofication based on the smaller of (p0, p1). static -earray mutation_base //= +earray mutation_base //= {{ - 30, // MOB_LV - -1, // MOB_MAX_HP - 20, // MOB_STR - 20, // MOB_AGI - 20, // MOB_VIT - 20, // MOB_INT - 20, // MOB_DEX - 20, // MOB_LUK - -1, // MOB_ATK1 - -1, // MOB_ATK2 - -1, // MOB_ADELAY - -1, // MOB_DEF - 20, // MOB_MDEF - -1, // MOB_SPEED + 30, // mob_stat::LV + -1, // mob_stat::MAX_HP + 20, // mob_stat::STR + 20, // mob_stat::AGI + 20, // mob_stat::VIT + 20, // mob_stat::INT + 20, // mob_stat::DEX + 20, // mob_stat::LUK + -1, // mob_stat::ATK1 + -1, // mob_stat::ATK2 + -1, // mob_stat::ADELAY + -1, // mob_stat::DEF + 20, // mob_stat::MDEF + -1, // mob_stat::SPEED }}; /*======================================== @@ -194,7 +196,7 @@ void mob_mutate(struct mob_data *md, mob_stat stat, int intensity) const int mut_base = mutation_base[stat]; int sign = 1; - if (!md || stat >= MOB_XP_BONUS || intensity == 0) + if (!md || stat >= mob_stat::XP_BONUS || intensity == 0) return; while (intensity > mutation_scale[stat]) @@ -211,8 +213,8 @@ void mob_mutate(struct mob_data *md, mob_stat stat, int intensity) if (!intensity) return; - // MOB_ADELAY and MOB_SPEED are special because going DOWN is good here. - if (stat == MOB_ADELAY || stat == MOB_SPEED) + // mob_stat::ADELAY and mob_stat::SPEED are special because going DOWN is good here. + if (stat == mob_stat::ADELAY || stat == mob_stat::SPEED) sign = -1; // Now compute the new stat @@ -247,16 +249,16 @@ void mob_mutate(struct mob_data *md, mob_stat stat, int intensity) md->stats[stat] = new_stat; // Adjust XP value - md->stats[MOB_XP_BONUS] += mutation_value[stat] * real_intensity; - if (md->stats[MOB_XP_BONUS] <= 0) - md->stats[MOB_XP_BONUS] = 1; + md->stats[mob_stat::XP_BONUS] += mutation_value[stat] * real_intensity; + if (md->stats[mob_stat::XP_BONUS] <= 0) + md->stats[mob_stat::XP_BONUS] = 1; // Sanitise - if (md->stats[MOB_ATK1] > md->stats[MOB_ATK2]) + if (md->stats[mob_stat::ATK1] > md->stats[mob_stat::ATK2]) { - int swap = md->stats[MOB_ATK2]; - md->stats[MOB_ATK2] = md->stats[MOB_ATK1]; - md->stats[MOB_ATK1] = swap; + int swap = md->stats[mob_stat::ATK2]; + md->stats[mob_stat::ATK2] = md->stats[mob_stat::ATK1]; + md->stats[mob_stat::ATK1] = swap; } } @@ -304,30 +306,30 @@ void mob_init(struct mob_data *md) const int mutations_nr = mob_db[mob_class].mutations_nr; const int mutation_power = mob_db[mob_class].mutation_power; - md->stats[MOB_LV] = mob_db[mob_class].lv; - md->stats[MOB_MAX_HP] = mob_db[mob_class].max_hp; - md->stats[MOB_STR] = mob_db[mob_class].attrs[ATTR::STR]; - md->stats[MOB_AGI] = mob_db[mob_class].attrs[ATTR::AGI]; - md->stats[MOB_VIT] = mob_db[mob_class].attrs[ATTR::VIT]; - md->stats[MOB_INT] = mob_db[mob_class].attrs[ATTR::INT]; - md->stats[MOB_DEX] = mob_db[mob_class].attrs[ATTR::DEX]; - md->stats[MOB_LUK] = mob_db[mob_class].attrs[ATTR::LUK]; - md->stats[MOB_ATK1] = mob_db[mob_class].atk1; - md->stats[MOB_ATK2] = mob_db[mob_class].atk2; - md->stats[MOB_ADELAY] = mob_db[mob_class].adelay; - md->stats[MOB_DEF] = mob_db[mob_class].def; - md->stats[MOB_MDEF] = mob_db[mob_class].mdef; - md->stats[MOB_SPEED] = mob_db[mob_class].speed; - md->stats[MOB_XP_BONUS] = MOB_XP_BONUS_BASE; + md->stats[mob_stat::LV] = mob_db[mob_class].lv; + md->stats[mob_stat::MAX_HP] = mob_db[mob_class].max_hp; + md->stats[mob_stat::STR] = mob_db[mob_class].attrs[ATTR::STR]; + md->stats[mob_stat::AGI] = mob_db[mob_class].attrs[ATTR::AGI]; + md->stats[mob_stat::VIT] = mob_db[mob_class].attrs[ATTR::VIT]; + md->stats[mob_stat::INT] = mob_db[mob_class].attrs[ATTR::INT]; + md->stats[mob_stat::DEX] = mob_db[mob_class].attrs[ATTR::DEX]; + md->stats[mob_stat::LUK] = mob_db[mob_class].attrs[ATTR::LUK]; + md->stats[mob_stat::ATK1] = mob_db[mob_class].atk1; + md->stats[mob_stat::ATK2] = mob_db[mob_class].atk2; + md->stats[mob_stat::ADELAY] = mob_db[mob_class].adelay; + md->stats[mob_stat::DEF] = mob_db[mob_class].def; + md->stats[mob_stat::MDEF] = mob_db[mob_class].mdef; + md->stats[mob_stat::SPEED] = mob_db[mob_class].speed; + md->stats[mob_stat::XP_BONUS] = MOB_XP_BONUS_BASE; for (i = 0; i < mutations_nr; i++) { - mob_stat stat_nr = mob_stat(MRAND(unsigned(MOB_LAST))); + mob_stat stat_nr = mob_stat(MRAND(unsigned(mob_stat::LAST))); int strength; // double chance to modify hp - if (stat_nr == MOB_XP_BONUS) - stat_nr = MOB_MAX_HP; + if (stat_nr == mob_stat::XP_BONUS) + stat_nr = mob_stat::MAX_HP; strength = ((MRAND((mutation_power >> 1)) + @@ -432,7 +434,7 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname, memcpy(md->npc_event, event, sizeof(md->npc_event)); - md->bl.type = BL_MOB; + md->bl.type = BL::MOB; map_addiddb(&md->bl); mob_spawn(md->bl.id); } @@ -540,7 +542,7 @@ int mob_spawn_guardian(struct map_session_data *sd, const char *mapname, memcpy(md->npc_event, event, sizeof(md->npc_event)); - md->bl.type = BL_MOB; + md->bl.type = BL::MOB; map_addiddb(&md->bl); mob_spawn(md->bl.id); } @@ -611,9 +613,6 @@ int mob_can_move(struct mob_data *md) if (md->canmove_tick > gettick() || (bool(md->opt1) && md->opt1 != Opt1::_stone6)) return 0; - // アンクル中で動けないとか - if (md->sc_data[SC_ANKLE].timer != -1) - return 0; return 1; } @@ -650,7 +649,7 @@ int mob_walk(struct mob_data *md, unsigned int tick, int data) nullpo_ret(md); - md->state.state = MS_IDLE; + md->state.state = MS::IDLE; if (md->walkpath.path_pos >= md->walkpath.path_len || md->walkpath.path_pos != data) return 0; @@ -692,11 +691,11 @@ int mob_walk(struct mob_data *md, unsigned int tick, int data) moveblock = (x / BLOCK_SIZE != (x + dx) / BLOCK_SIZE || y / BLOCK_SIZE != (y + dy) / BLOCK_SIZE); - md->state.state = MS_WALK; + md->state.state = MS::WALK; map_foreachinmovearea(std::bind(clif_moboutsight, ph::_1, md), md->bl.m, x - AREA_SIZE, y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE, - dx, dy, BL_PC); + dx, dy, BL::PC); x += dx; y += dy; @@ -713,8 +712,8 @@ int mob_walk(struct mob_data *md, unsigned int tick, int data) map_foreachinmovearea(std::bind(clif_mobinsight, ph::_1, md), md->bl.m, x - AREA_SIZE, y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE, - -dx, -dy, BL_PC); - md->state.state = MS_IDLE; + -dx, -dy, BL::PC); + md->state.state = MS::IDLE; } if ((i = calc_next_walk_step(md)) > 0) { @@ -723,7 +722,7 @@ int mob_walk(struct mob_data *md, unsigned int tick, int data) i = 1; md->timer = add_timer(tick + i, mob_timer, md->bl.id, md->walkpath.path_pos); - md->state.state = MS_WALK; + md->state.state = MS::WALK; if (md->walkpath.path_pos >= md->walkpath.path_len) clif_fixmobpos(md); // When mob stops, retransmission current of a position. @@ -748,8 +747,8 @@ int mob_check_attack(struct mob_data *md) nullpo_ret(md); md->min_chase = 13; - md->state.state = MS_IDLE; - md->state.skillstate = MSS_IDLE; + md->state.state = MS::IDLE; + md->state.skillstate = MobSkillState::MSS_IDLE; if (md->skilltimer != -1) return 0; @@ -764,9 +763,9 @@ int mob_check_attack(struct mob_data *md) return 0; } - if (tbl->type == BL_PC) + if (tbl->type == BL::PC) tsd = (struct map_session_data *) tbl; - else if (tbl->type == BL_MOB) + else if (tbl->type == BL::MOB) tmd = (struct mob_data *) tbl; else return 0; @@ -855,7 +854,7 @@ int mob_attack(struct mob_data *md, unsigned int tick, int) //clif_fixmobpos(md); - md->state.skillstate = MSS_ATTACK; + md->state.skillstate = MobSkillState::MSS_ATTACK; if (mobskill_use(md, tick, MobSkillCondition::NEVER_EQUAL)) return 0; @@ -863,15 +862,15 @@ int mob_attack(struct mob_data *md, unsigned int tick, int) // If you are reading this, please note: // it is highly platform-specific that this even works at all. int radius = battle_config.mob_splash_radius; - if (radius >= 0 && tbl->type == BL_PC && !map[tbl->m].flag.town) + if (radius >= 0 && tbl->type == BL::PC && !map[tbl->m].flag.town) map_foreachinarea(std::bind(mob_ancillary_attack, ph::_1, &md->bl, tbl, tick), tbl->m, tbl->x - radius, tbl->y - radius, - tbl->x + radius, tbl->y + radius, BL_PC); + tbl->x + radius, tbl->y + radius, BL::PC); md->attackabletime = tick + battle_get_adelay(&md->bl); md->timer = add_timer(md->attackabletime, mob_timer, md->bl.id, 0); - md->state.state = MS_ATTACK; + md->state.state = MS::ATTACK; return 0; } @@ -908,7 +907,7 @@ int mob_changestate(struct mob_data *md, MS state, int type) switch (state) { - case MS_WALK: + case MS::WALK: if ((i = calc_next_walk_step(md)) > 0) { i = i >> 2; @@ -916,9 +915,9 @@ int mob_changestate(struct mob_data *md, MS state, int type) add_timer(gettick() + i, mob_timer, md->bl.id, 0); } else - md->state.state = MS_IDLE; + md->state.state = MS::IDLE; break; - case MS_ATTACK: + case MS::ATTACK: tick = gettick(); i = DIFF_TICK(md->attackabletime, tick); if (i > 0 && i < 2000) @@ -937,14 +936,14 @@ int mob_changestate(struct mob_data *md, MS state, int type) add_timer(md->attackabletime, mob_timer, md->bl.id, 0); } break; - case MS_DELAY: + case MS::DELAY: md->timer = add_timer(gettick() + type, mob_timer, md->bl.id, 0); break; - case MS_DEAD: + case MS::DEAD: skill_castcancel(&md->bl, 0); // mobskill_deltimer(md); - md->state.skillstate = MSS_DEAD; + md->state.skillstate = MobSkillState::MSS_DEAD; md->last_deadtime = gettick(); // Since it died, all aggressors' attack to this mob is stopped. clif_foreachclient(std::bind(mob_stopattacked, ph::_1, md->bl.id)); @@ -976,7 +975,7 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) return; } - if (bl->type == BL_NUL || bl->type != BL_MOB) + if (bl->type == BL::NUL || bl->type != BL::MOB) return; md = (struct mob_data *) bl; @@ -988,21 +987,21 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) return; } md->timer = -1; - if (md->bl.prev == NULL || md->state.state == MS_DEAD) + if (md->bl.prev == NULL || md->state.state == MS::DEAD) return; map_freeblock_lock(); switch (md->state.state) { - case MS_WALK: + case MS::WALK: mob_check_attack(md); mob_walk(md, tick, data); break; - case MS_ATTACK: + case MS::ATTACK: mob_attack(md, tick, data); break; - case MS_DELAY: - mob_changestate(md, MS_IDLE, 0); + case MS::DELAY: + mob_changestate(md, MS::IDLE, 0); break; default: if (battle_config.error_log == 1) @@ -1031,7 +1030,7 @@ int mob_walktoxy_sub(struct mob_data *md) memcpy(&md->walkpath, &wpd, sizeof(wpd)); md->state.change_walk_target = 0; - mob_changestate(md, MS_WALK, 0); + mob_changestate(md, MS::WALK, 0); clif_movemob(md); return 0; @@ -1048,14 +1047,14 @@ int mob_walktoxy(struct mob_data *md, int x, int y, int easy) nullpo_ret(md); - if (md->state.state == MS_WALK + if (md->state.state == MS::WALK && path_search(&wpd, md->bl.m, md->bl.x, md->bl.y, x, y, easy)) return 1; md->state.walk_easy = easy; md->to_x = x; md->to_y = y; - if (md->state.state == MS_WALK) + if (md->state.state == MS::WALK) { md->state.change_walk_target = 1; } @@ -1091,13 +1090,13 @@ int mob_setdelayspawn(int id) if ((bl = map_id2bl(id)) == NULL) return -1; - if (!bl || bl->type == BL_NUL || bl->type != BL_MOB) + if (!bl || bl->type == BL::NUL || bl->type != BL::MOB) return -1; md = (struct mob_data *) bl; nullpo_retr(-1, md); - if (!md || md->bl.type != BL_MOB) + if (!md || md->bl.type != BL::MOB) return -1; // Processing of MOB which is not revitalized @@ -1148,19 +1147,18 @@ int mob_spawn(int id) bl = map_id2bl(id); nullpo_retr(-1, bl); - if (!bl || bl->type == BL_NUL || bl->type != BL_MOB) + if (!bl || bl->type == BL::NUL || bl->type != BL::MOB) return -1; md = (struct mob_data *) bl; nullpo_retr(-1, md); - if (!md || md->bl.type == BL_NUL || md->bl.type != BL_MOB) + if (!md || md->bl.type == BL::NUL || md->bl.type != BL::MOB) return -1; md->last_spawntime = tick; if (md->bl.prev != NULL) { -// clif_clearchar_area(&md->bl,3); map_delblock(&md->bl); } @@ -1194,7 +1192,7 @@ int mob_spawn(int id) md->to_x = md->bl.x = x; md->to_y = md->bl.y = y; - md->dir = DIR_S; + md->dir = DIR::S; map_addblock(&md->bl); @@ -1204,14 +1202,14 @@ int mob_spawn(int id) md->move_fail_count = 0; mob_init(md); - if (!md->stats[MOB_SPEED]) - md->stats[MOB_SPEED] = mob_db[md->mob_class].speed; + if (!md->stats[mob_stat::SPEED]) + md->stats[mob_stat::SPEED] = mob_db[md->mob_class].speed; md->def_ele = mob_db[md->mob_class].element; md->master_id = 0; md->master_dist = 0; - md->state.state = MS_IDLE; - md->state.skillstate = MSS_IDLE; + md->state.state = MS::IDLE; + md->state.skillstate = MobSkillState::MSS_IDLE; md->timer = -1; md->last_thinktime = tick; md->next_walktime = tick + MPRAND(5000, 50); @@ -1232,7 +1230,7 @@ int mob_spawn(int id) memset(md->lootitem, 0, sizeof(*md->lootitem)); md->lootitem_count = 0; - for (StatusChange i : erange(StatusChange(), MAX_STATUSCHANGE)) + for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE)) { md->sc_data[i].timer = -1; md->sc_data[i].val1 = md->sc_data[i].val2 = md->sc_data[i].val3 = @@ -1290,7 +1288,7 @@ int mob_stop_walking(struct mob_data *md, int type) { nullpo_ret(md); - if (md->state.state == MS_WALK || md->state.state == MS_IDLE) + if (md->state.state == MS::WALK || md->state.state == MS::IDLE) { int dx = 0, dy = 0; @@ -1315,7 +1313,7 @@ int mob_stop_walking(struct mob_data *md, int type) mob_walktoxy_sub(md); return 0; } - mob_changestate(md, MS_IDLE, 0); + mob_changestate(md, MS::IDLE, 0); } if (type & 0x01) clif_fixmobpos(md); @@ -1347,7 +1345,7 @@ int mob_can_reach(struct mob_data *md, struct block_list *bl, int range) dx = abs(bl->x - md->bl.x); dy = abs(bl->y - md->bl.y); - if (bl && bl->type == BL_PC && battle_config.monsters_ignore_gm == 1) + if (bl && bl->type == BL::PC && battle_config.monsters_ignore_gm == 1) { // option to have monsters ignore GMs [Valaris] struct map_session_data *sd; if ((sd = (struct map_session_data *) bl) != NULL && pc_isGM(sd)) @@ -1371,7 +1369,7 @@ int mob_can_reach(struct mob_data *md, struct block_list *bl, int range) -1) return 1; - if (bl->type != BL_PC && bl->type != BL_MOB) + if (bl->type != BL::PC && bl->type != BL::MOB) return 0; // It judges whether it can adjoin or not. @@ -1429,7 +1427,7 @@ int mob_target(struct mob_data *md, struct block_list *bl, int dist) || race == Race::_insect || race == Race::_demon)) { - if (bl->type == BL_PC) + if (bl->type == BL::PC) { sd = (struct map_session_data *) bl; nullpo_ret(sd); @@ -1441,7 +1439,7 @@ int mob_target(struct mob_data *md, struct block_list *bl, int dist) } md->target_id = bl->id; // Since there was no disturbance, it locks on to target. - if (bl->type == BL_PC || bl->type == BL_MOB) + if (bl->type == BL::PC || bl->type == BL::MOB) md->state.attackable = true; else md->state.attackable = false; @@ -1469,9 +1467,9 @@ void mob_ai_sub_hard_activesearch(struct block_list *bl, nullpo_retv(smd); nullpo_retv(pcc); - if (bl->type == BL_PC) + if (bl->type == BL::PC) tsd = (struct map_session_data *) bl; - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) tmd = (struct mob_data *) bl; else return; @@ -1622,13 +1620,13 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick) mode = mob_db[md->mob_class].mode; // It is not main monster/leader. - if (!mmd || mmd->bl.type != BL_MOB || mmd->bl.id != md->master_id) + if (!mmd || mmd->bl.type != BL::MOB || mmd->bl.id != md->master_id) return 0; // Since it is in the map on which the master is not, teleport is carried out and it pursues. if (mmd->bl.m != md->bl.m) { - mob_warp(md, mmd->bl.m, mmd->bl.x, mmd->bl.y, 3); + mob_warp(md, mmd->bl.m, mmd->bl.x, mmd->bl.y, BeingRemoveWhy::WARPED); md->state.master_check = 1; return 0; } @@ -1640,7 +1638,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick) // Since the master was in near immediately before, teleport is carried out and it pursues. if (old_dist < 10 && md->master_dist > 18) { - mob_warp(md, -1, mmd->bl.x, mmd->bl.y, 3); + mob_warp(md, -1, mmd->bl.x, mmd->bl.y, BeingRemoveWhy::WARPED); md->state.master_check = 1; return 0; } @@ -1743,7 +1741,7 @@ int mob_unlocktarget(struct mob_data *md, int tick) md->target_id = 0; md->state.attackable = false; - md->state.skillstate = MSS_IDLE; + md->state.skillstate = MobSkillState::MSS_IDLE; md->next_walktime = tick + MPRAND(3000, 3000); return 0; } @@ -1800,7 +1798,7 @@ int mob_randomwalk(struct mob_data *md, int tick) c += speed; } md->next_walktime = tick + MPRAND(3000, 3000) + c; - md->state.skillstate = MSS_WALK; + md->state.skillstate = MobSkillState::MSS_WALK; return 1; } return 0; @@ -1844,7 +1842,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) // Abnormalities if ((bool(md->opt1) && md->opt1 != Opt1::_stone6) - || md->state.state == MS_DELAY) + || md->state.state == MS::DELAY) return; if (!bool(mode & MobMode::CAN_ATTACK) && md->target_id > 0) @@ -1859,7 +1857,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) { map_foreachinarea(std::bind(mob_ai_sub_hard_linksearch, ph::_1, md, &asd->bl), md->bl.m, md->bl.x - 13, md->bl.y - 13, - md->bl.x + 13, md->bl.y + 13, BL_MOB); + md->bl.x + 13, md->bl.y + 13, BL::MOB); } } } @@ -1873,7 +1871,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) struct map_session_data *asd = NULL; if (abl) { - if (abl->type == BL_PC) + if (abl->type == BL::PC) asd = (struct map_session_data *) abl; if (asd == NULL || md->bl.m != abl->m || abl->prev == NULL || asd->invincible_timer != -1 || pc_isinvisible(asd) @@ -1910,13 +1908,13 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) map_foreachinarea(std::bind(mob_ai_sub_hard_activesearch, ph::_1, md, &i), md->bl.m, md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2, md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, - BL_NUL); + BL::NUL); } else { map_foreachinarea(std::bind(mob_ai_sub_hard_activesearch, ph::_1, md, &i), md->bl.m, md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2, - md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, BL_PC); + md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, BL::PC); } } @@ -1928,7 +1926,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) i = 0; map_foreachinarea(std::bind(mob_ai_sub_hard_lootsearch, ph::_1, md, &i), md->bl.m, md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2, - md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, BL_ITEM); + md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, BL::ITEM); } // It will attack, if the candidate for an attack is. @@ -1936,9 +1934,9 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) { if ((tbl = map_id2bl(md->target_id))) { - if (tbl->type == BL_PC) + if (tbl->type == BL::PC) tsd = (struct map_session_data *) tbl; - else if (tbl->type == BL_MOB) + else if (tbl->type == BL::MOB) tmd = (struct mob_data *) tbl; if (tsd || tmd) { @@ -1962,10 +1960,10 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) } if (!mob_can_move(md)) // 動けない状態にある return; - md->state.skillstate = MSS_CHASE; // 突撃時スキル + md->state.skillstate = MobSkillState::MSS_CHASE; // 突撃時スキル mobskill_use(md, tick, MobSkillCondition::ANY); // if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tsd->bl.x,tsd->bl.y)<2) ) - if (md->timer != -1 && md->state.state != MS_ATTACK + if (md->timer != -1 && md->state.state != MS::ATTACK && (DIFF_TICK(md->next_walktime, tick) < 0 || distance(md->to_x, md->to_y, tbl->x, tbl->y) < 2)) @@ -2029,32 +2027,32 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) } else { // 攻撃射程範囲内 - md->state.skillstate = MSS_ATTACK; - if (md->state.state == MS_WALK) + md->state.skillstate = MobSkillState::MSS_ATTACK; + if (md->state.state == MS::WALK) mob_stop_walking(md, 1); // 歩行中なら停止 - if (md->state.state == MS_ATTACK) + if (md->state.state == MS::ATTACK) return; // 既に攻撃中 - mob_changestate(md, MS_ATTACK, attack_type); + mob_changestate(md, MS::ATTACK, attack_type); /* if (mode&0x08){ // リンクモンスター map_foreachinarea(mob_ai_sub_hard_linksearch,md->bl.m, md->bl.x-13,md->bl.y-13, md->bl.x+13,md->bl.y+13, - BL_MOB,md,&tsd->bl); + BL::MOB,md,&tsd->bl); }*/ } return; } else { // ルートモンスター処理 - if (tbl == NULL || tbl->type != BL_ITEM || tbl->m != md->bl.m + if (tbl == NULL || tbl->type != BL::ITEM || tbl->m != md->bl.m || (dist = distance(md->bl.x, md->bl.y, tbl->x, tbl->y)) >= md->min_chase || !md->lootitem) { // 遠すぎるかアイテムがなくなった mob_unlocktarget(md, tick); - if (md->state.state == MS_WALK) + if (md->state.state == MS::WALK) mob_stop_walking(md, 1); // 歩行中なら停止 } else if (dist) @@ -2066,10 +2064,10 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) } if (!mob_can_move(md)) // 動けない状態にある return; - md->state.skillstate = MSS_LOOT; // ルート時スキル使用 + md->state.skillstate = MobSkillState::MSS_LOOT; // ルート時スキル使用 mobskill_use(md, tick, MobSkillCondition::ANY); // if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tbl->x,tbl->y)<2) ) - if (md->timer != -1 && md->state.state != MS_ATTACK + if (md->timer != -1 && md->state.state != MS::ATTACK && (DIFF_TICK(md->next_walktime, tick) < 0 || distance(md->to_x, md->to_y, tbl->x, tbl->y) <= 0)) @@ -2087,9 +2085,9 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) } else { // アイテムまでたどり着いた - if (md->state.state == MS_ATTACK) + if (md->state.state == MS::ATTACK) return; // 攻撃中 - if (md->state.state == MS_WALK) + if (md->state.state == MS::WALK) mob_stop_walking(md, 1); // 歩行中なら停止 fitem = (struct flooritem_data *) tbl; if (md->lootitem_count < LOOTITEM_SIZE) @@ -2118,7 +2116,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) else { mob_unlocktarget(md, tick); - if (md->state.state == MS_WALK) + if (md->state.state == MS::WALK) mob_stop_walking(md, 4); // 歩行中なら停止 return; } @@ -2150,7 +2148,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick) // Since he has finished walking, it stands by. if (md->walkpath.path_len == 0 || md->walkpath.path_pos >= md->walkpath.path_len) - md->state.skillstate = MSS_IDLE; + md->state.skillstate = MobSkillState::MSS_IDLE; } /*========================================== @@ -2164,7 +2162,7 @@ void mob_ai_sub_foreachclient(struct map_session_data *sd, unsigned int tick) map_foreachinarea(std::bind(mob_ai_sub_hard, ph::_1, tick), sd->bl.m, sd->bl.x - AREA_SIZE * 2, sd->bl.y - AREA_SIZE * 2, - sd->bl.x + AREA_SIZE * 2, sd->bl.y + AREA_SIZE * 2, BL_MOB); + sd->bl.x + AREA_SIZE * 2, sd->bl.y + AREA_SIZE * 2, BL::MOB); } /*========================================== @@ -2191,7 +2189,7 @@ void mob_ai_sub_lazy(db_key_t, db_val_t data, unsigned int tick) if (md == NULL) return; - if (md->bl.type == BL_NUL || md->bl.type != BL_MOB) + if (md->bl.type == BL::NUL || md->bl.type != BL::MOB) return; if (DIFF_TICK(tick, md->last_thinktime) < MIN_MOBTHINKTIME * 10) @@ -2233,7 +2231,7 @@ void mob_ai_sub_lazy(db_key_t, db_val_t data, unsigned int tick) if (MRAND(1000) < MOB_LAZYWARPPERC && md->x0 <= 0 && md->master_id != 0 && mob_db[md->mob_class].mexp <= 0 && !bool(mob_db[md->mob_class].mode & MobMode::BOSS)) - mob_warp(md, -1, -1, -1, -1); + mob_warp(md, -1, -1, -1, BeingRemoveWhy::NEGATIVE1); } md->next_walktime = tick + MPRAND(5000, 10000); @@ -2358,22 +2356,22 @@ int mob_delete(struct mob_data *md) if (md->bl.prev == NULL) return 1; - mob_changestate(md, MS_DEAD, 0); - clif_clearchar_area(&md->bl, 1); + mob_changestate(md, MS::DEAD, 0); + clif_clearchar(&md->bl, BeingRemoveWhy::DEAD); map_delblock(&md->bl); mob_deleteslave(md); mob_setdelayspawn(md->bl.id); return 0; } -int mob_catch_delete(struct mob_data *md, int type) +int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type) { nullpo_retr(1, md); if (md->bl.prev == NULL) return 1; - mob_changestate(md, MS_DEAD, 0); - clif_clearchar_area(&md->bl, type); + mob_changestate(md, MS::DEAD, 0); + clif_clearchar(&md->bl, type); map_delblock(&md->bl); mob_setdelayspawn(md->bl.id); return 0; @@ -2387,7 +2385,7 @@ void mob_timer_delete(timer_id, tick_t, custom_id_t id, custom_data_t) nullpo_retv(bl); md = (struct mob_data *) bl; - mob_catch_delete(md, 3); + mob_catch_delete(md, BeingRemoveWhy::WARPED); } /*========================================== @@ -2416,12 +2414,15 @@ int mob_deleteslave(struct mob_data *md) map_foreachinarea(std::bind(mob_deleteslave_sub, ph::_1, md->bl.id), md->bl.m, 0, 0, - map[md->bl.m].xs, map[md->bl.m].ys, BL_MOB); + map[md->bl.m].xs, map[md->bl.m].ys, BL::MOB); return 0; } -#define DAMAGE_BONUS_COUNT 6 // max. number of players to account for -const static double damage_bonus_factor[DAMAGE_BONUS_COUNT + 1] = { +// max. number of players to account for +constexpr int DAMAGE_BONUS_COUNT = 6; +const static +double damage_bonus_factor[DAMAGE_BONUS_COUNT + 1] = +{ 1.0, 1.0, 2.0, 2.5, 2.75, 2.9, 3.0 }; @@ -2451,7 +2452,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, nullpo_ret(md); //srcはNULLで呼ばれる場合もあるので、他でチェック if (src && src->id == md->master_id - && bool(md->mode & MOB_MODE_TURNS_AGAINST_BAD_MASTER)) + && bool(md->mode & MobMode::TURNS_AGAINST_BAD_MASTER)) { /* If the master hits a monster, have the monster turn against him */ md->master_id = 0; @@ -2462,7 +2463,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, max_hp = battle_get_max_hp(&md->bl); - if (src && src->type == BL_PC) + if (src && src->type == BL::PC) { sd = (struct map_session_data *) src; mvp_sd = sd; @@ -2477,15 +2478,15 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, return 0; } - if (md->state.state == MS_DEAD || md->hp <= 0) + if (md->state.state == MS::DEAD || md->hp <= 0) { if (md->bl.prev != NULL) { - mob_changestate(md, MS_DEAD, 0); + mob_changestate(md, MS::DEAD, 0); // It is skill at the time of death. mobskill_use(md, tick, MobSkillCondition::ANY); - clif_clearchar_area(&md->bl, 1); + clif_clearchar(&md->bl, BeingRemoveWhy::DEAD); map_delblock(&md->bl); mob_setdelayspawn(md->bl.id); } @@ -2535,12 +2536,12 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, if (md->attacked_id <= 0 && md->state.special_mob_ai == 0) md->attacked_id = sd->bl.id; } - if (src && src->type == BL_MOB + if (src && src->type == BL::MOB && ((struct mob_data *) src)->state.special_mob_ai) { struct mob_data *md2 = (struct mob_data *) src; struct block_list *master_bl = map_id2bl(md2->master_id); - if (master_bl && master_bl->type == BL_PC) + if (master_bl && master_bl->type == BL::PC) { MAP_LOG_PC(((struct map_session_data *) master_bl), "MOB-TO-MOB-DMG FROM MOB%d %d TO MOB%d %d FOR %d", @@ -2592,7 +2593,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, // ----- ここから死亡処理 ----- map_freeblock_lock(); - mob_changestate(md, MS_DEAD, 0); + mob_changestate(md, MS::DEAD, 0); mobskill_use(md, tick, MobSkillCondition::ANY); memset(tmpsd, 0, sizeof(tmpsd)); @@ -2600,7 +2601,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, max_hp = battle_get_max_hp(&md->bl); - if (src && src->type == BL_MOB) + if (src && src->type == BL::MOB) mob_unlocktarget((struct mob_data *) src, tick); // map外に消えた人は計算から除くので @@ -2665,7 +2666,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, base_exp = ((mob_db[md->mob_class].base_exp * - md->stats[MOB_XP_BONUS]) >> MOB_XP_BONUS_SHIFT) * per / 256; + md->stats[mob_stat::XP_BONUS]) >> MOB_XP_BONUS_SHIFT) * per / 256; if (base_exp < 1) base_exp = 1; if (sd && md && battle_config.pk_mode == 1 @@ -2856,7 +2857,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, npc_event(sd, md->npc_event, 0); } - clif_clearchar_area(&md->bl, 1); + clif_clearchar(&md->bl, BeingRemoveWhy::DEAD); map_delblock(&md->bl); mob_deleteslave(md); mob_setdelayspawn(md->bl.id); @@ -2913,12 +2914,12 @@ int mob_class_change(struct mob_data *md, int *value) md->target_id = 0; md->move_fail_count = 0; - md->stats[MOB_SPEED] = mob_db[md->mob_class].speed; + md->stats[mob_stat::SPEED] = mob_db[md->mob_class].speed; md->def_ele = mob_db[md->mob_class].element; - mob_changestate(md, MS_IDLE, 0); + mob_changestate(md, MS::IDLE, 0); skill_castcancel(&md->bl, 0); - md->state.skillstate = MSS_IDLE; + md->state.skillstate = MobSkillState::MSS_IDLE; md->last_thinktime = tick; md->next_walktime = tick + MPRAND(5000, 50); md->attackabletime = tick; @@ -2935,7 +2936,7 @@ int mob_class_change(struct mob_data *md, int *value) md->lootitem = (struct item *) calloc(LOOTITEM_SIZE, sizeof(struct item)); - clif_clearchar_area(&md->bl, 0); + clif_clearchar(&md->bl, BeingRemoveWhy::GONE); clif_spawnmob(md); return 0; @@ -2969,7 +2970,7 @@ void mob_warpslave_sub(struct block_list *bl, int id, int x, int y) if (md->master_id == id) { - mob_warp(md, -1, x, y, 2); + mob_warp(md, -1, x, y, BeingRemoveWhy::QUIT); } } @@ -2983,7 +2984,7 @@ int mob_warpslave(struct mob_data *md, int x, int y) //PRINTF("warp slave\n"); map_foreachinarea(std::bind(mob_warpslave_sub, ph::_1, md->bl.id, md->bl.x, md->bl.y), md->bl.m, x - AREA_SIZE, y - AREA_SIZE, - x + AREA_SIZE, y + AREA_SIZE, BL_MOB); + x + AREA_SIZE, y + AREA_SIZE, BL::MOB); return 0; } @@ -2991,7 +2992,7 @@ int mob_warpslave(struct mob_data *md, int x, int y) * mobワープ *------------------------------------------ */ -int mob_warp(struct mob_data *md, int m, int x, int y, int type) +int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type) { int i = 0, c, xs = 0, ys = 0, bx = x, by = y; @@ -3003,11 +3004,11 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type) if (m < 0) m = md->bl.m; - if (type >= 0) + if (type != BeingRemoveWhy::NEGATIVE1) { if (map[md->bl.m].flag.monster_noteleport) return 0; - clif_clearchar_area(&md->bl, type); + clif_clearchar(&md->bl, type); } map_delblock(&md->bl); @@ -3030,7 +3031,7 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type) y = MPRAND(1, (map[m].ys - 2)); } } - md->dir = DIR_S; + md->dir = DIR::S; if (i < 1000) { md->bl.x = md->to_x = x; @@ -3046,10 +3047,11 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type) md->target_id = 0; // タゲを解除する md->state.attackable = false; md->attacked_id = 0; - md->state.skillstate = MSS_IDLE; - mob_changestate(md, MS_IDLE, 0); + md->state.skillstate = MobSkillState::MSS_IDLE; + mob_changestate(md, MS::IDLE, 0); - if (type > 0 && i == 1000) + if (type != BeingRemoveWhy::GONE && type != BeingRemoveWhy::NEGATIVE1 + && i == 1000) { if (battle_config.battle_log == 1) PRINTF("MOB %d warp to (%d,%d), mob_class = %d\n", md->bl.id, x, y, @@ -3057,7 +3059,7 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type) } map_addblock(&md->bl); - if (type > 0) + if (type != BeingRemoveWhy::GONE && type != BeingRemoveWhy::NEGATIVE1) { clif_spawnmob(md); mob_warpslave(md, md->bl.x, md->bl.y); @@ -3095,7 +3097,7 @@ int mob_countslave(struct mob_data *md) map_foreachinarea(std::bind(mob_countslave_sub, ph::_1, md->bl.id, &c), md->bl.m, 0, 0, - map[md->bl.m].xs - 1, map[md->bl.m].ys - 1, BL_MOB); + map[md->bl.m].xs - 1, map[md->bl.m].ys - 1, BL::MOB); return c; } @@ -3162,12 +3164,12 @@ int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag) md->y0 = y; md->xs = 0; md->ys = 0; - md->stats[MOB_SPEED] = md2->stats[MOB_SPEED]; + md->stats[mob_stat::SPEED] = md2->stats[mob_stat::SPEED]; md->spawndelay1 = -1; // 一度のみフラグ md->spawndelay2 = -1; // 一度のみフラグ memset(md->npc_event, 0, sizeof(md->npc_event)); - md->bl.type = BL_MOB; + md->bl.type = BL::MOB; map_addiddb(&md->bl); mob_spawn(md->bl.id); @@ -3191,18 +3193,18 @@ void mob_counttargeted_sub(struct block_list *bl, if (id == bl->id || (src && id == src->id)) return; - if (bl->type == BL_PC) + if (bl->type == BL::PC) { struct map_session_data *sd = (struct map_session_data *) bl; if (sd && sd->attacktarget == id && sd->attacktimer != -1 && sd->attacktarget_lv >= target_lv) (*c)++; } - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) { struct mob_data *md = (struct mob_data *) bl; if (md && md->target_id == id && md->timer != -1 - && md->state.state == MS_ATTACK && md->target_lv >= target_lv) + && md->state.state == MS::ATTACK && md->target_lv >= target_lv) (*c)++; } } @@ -3221,7 +3223,7 @@ int mob_counttargeted(struct mob_data *md, struct block_list *src, map_foreachinarea(std::bind(mob_counttargeted_sub, ph::_1, md->bl.id, &c, src, target_lv), md->bl.m, md->bl.x - AREA_SIZE, md->bl.y - AREA_SIZE, md->bl.x + AREA_SIZE, md->bl.y + AREA_SIZE, - BL_NUL); + BL::NUL); return c; } @@ -3247,7 +3249,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_ PRINTF("mobskill_castend_id nullpo mbl->id:%d\n", mbl->id); return; } - if (md->bl.type != BL_MOB || md->bl.prev == NULL) + if (md->bl.type != BL::MOB || md->bl.prev == NULL) return; if (md->skilltimer != tid) // タイマIDの確認 return; @@ -3257,7 +3259,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_ if (bool(md->opt1)) return; - if (md->skillid != NPC_EMOTION) + if (md->skillid != SkillID::NPC_EMOTION) md->last_thinktime = tick + battle_get_adelay(&md->bl); if ((bl = map_id2bl(md->skilltarget)) == NULL || bl->prev == NULL) @@ -3319,7 +3321,7 @@ void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data md = (struct mob_data *) bl; nullpo_retv(md); - if (md->bl.type != BL_MOB || md->bl.prev == NULL) + if (md->bl.type != BL::MOB || md->bl.prev == NULL) return; if (md->skilltimer != tid) // タイマIDの確認 @@ -3446,7 +3448,7 @@ int mobskill_use_pos(struct mob_data *md, return 0; // 射程と障害物チェック - bl.type = BL_NUL; + bl.type = BL::NUL; bl.m = md->bl.m; bl.x = skill_x; bl.y = skill_y; @@ -3513,7 +3515,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, if (md->state.special_mob_ai) return 0; - if (md->sc_data[SC_SELFDESTRUCTION].timer != -1) //自爆中はスキルを使わない + if (md->sc_data[StatusChange::SC_SELFDESTRUCTION].timer != -1) //自爆中はスキルを使わない return 0; for (int ii = 0; ii < mob_db[md->mob_class].maxskill; ii++) @@ -3534,19 +3536,19 @@ int mobskill_use(struct mob_data *md, unsigned int tick, { switch (ms[ii].cond1) { - case MSC_ALWAYS: + case MobSkillCondition::MSC_ALWAYS: flag = 1; break; - case MSC_MYHPLTMAXRATE: // HP< maxhp% + case MobSkillCondition::MSC_MYHPLTMAXRATE: // HP< maxhp% flag = (md->hp < max_hp * ms[ii].cond2i / 100); break; - case MSC_NOTINTOWN: // Only outside of towns. + case MobSkillCondition::MSC_NOTINTOWN: // Only outside of towns. flag = !map[md->bl.m].flag.town; break; - case MSC_SLAVELT: // slave < num + case MobSkillCondition::MSC_SLAVELT: // slave < num flag = (mob_countslave(md) < ms[ii].cond2i); break; - case MSC_SLAVELE: // slave <= num + case MobSkillCondition::MSC_SLAVELE: // slave <= num flag = (mob_countslave(md) <= ms[ii].cond2i); break; } @@ -3563,7 +3565,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int x = 0, y = 0; { { - bl = ms[ii].target == MST_TARGET + bl = ms[ii].target == MobSkillTarget::MST_TARGET ? map_id2bl(md->target_id) : &md->bl; } @@ -3583,7 +3585,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, { { struct block_list *bl = NULL; - bl = (ms[ii].target == MST_TARGET) + bl = (ms[ii].target == MobSkillTarget::MST_TARGET) ? map_id2bl(md->target_id) : &md->bl; if (bl && !mobskill_use_id(md, bl, ii)) @@ -3610,10 +3612,10 @@ int mobskill_event(struct mob_data *md, BF flag) if (flag == BF::NEGATIVE_1 && mobskill_use(md, gettick(), MobSkillCondition::ANY)) return 1; - if (bool(flag & BF_SHORT) + if (bool(flag & BF::SHORT) && mobskill_use(md, gettick(), MobSkillCondition::ANY)) return 1; - if (bool(flag & BF_LONG) + if (bool(flag & BF::LONG) && mobskill_use(md, gettick(), MobSkillCondition::ANY)) return 1; return 0; @@ -3933,11 +3935,11 @@ int mob_readskilldb(void) MobSkillCondition id; } cond1[] = { - {"always", MSC_ALWAYS}, - {"myhpltmaxrate", MSC_MYHPLTMAXRATE}, - {"notintown", MSC_NOTINTOWN}, - {"slavelt", MSC_SLAVELT}, - {"slavele", MSC_SLAVELE}, + {"always", MobSkillCondition::MSC_ALWAYS}, + {"myhpltmaxrate", MobSkillCondition::MSC_MYHPLTMAXRATE}, + {"notintown", MobSkillCondition::MSC_NOTINTOWN}, + {"slavelt", MobSkillCondition::MSC_SLAVELT}, + {"slavele", MobSkillCondition::MSC_SLAVELE}, }; const struct { @@ -3946,9 +3948,9 @@ int mob_readskilldb(void) } state[] = { {"any", MobSkillState::ANY}, - {"idle", MSS_IDLE}, - {"walk", MSS_WALK}, - {"attack", MSS_ATTACK}, + {"idle", MobSkillState::MSS_IDLE}, + {"walk", MobSkillState::MSS_WALK}, + {"attack", MobSkillState::MSS_ATTACK}, }; const struct { @@ -3956,8 +3958,8 @@ int mob_readskilldb(void) MobSkillTarget id; } target[] = { - {"target", MST_TARGET}, - {"self", MST_SELF}, + {"target", MobSkillTarget::MST_TARGET}, + {"self", MobSkillTarget::MST_SELF}, }; int x; diff --git a/src/map/mob.hpp b/src/map/mob.hpp index 2d51eb0..384c1b9 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -6,10 +6,11 @@ #include "../common/mmo.hpp" #include "../common/timer.hpp" +#include "clif.t.hpp" #include "map.hpp" #include "skill.t.hpp" -#define MAX_RANDOMMONSTER 3 +constexpr int MAX_RANDOMMONSTER = 3; struct mob_skill { @@ -96,7 +97,7 @@ int mob_get_equip(int); // mob equip [Valaris] int do_init_mob(void); int mob_delete(struct mob_data *md); -int mob_catch_delete(struct mob_data *md, int type); +int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type); void mob_timer_delete(timer_id, tick_t, custom_id_t, custom_data_t); int mob_deleteslave(struct mob_data *md); @@ -105,7 +106,7 @@ int mob_counttargeted(struct mob_data *md, struct block_list *src, ATK target_lv); int mob_class_change(struct mob_data *md, int *value); -int mob_warp(struct mob_data *md, int m, int x, int y, int type); +int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type); int mobskill_use(struct mob_data *md, unsigned int tick, MobSkillCondition event, SkillID skill=SkillID::ZERO); diff --git a/src/map/mob.t.hpp b/src/map/mob.t.hpp index 0fcd7f5..b112c69 100644 --- a/src/map/mob.t.hpp +++ b/src/map/mob.t.hpp @@ -6,9 +6,7 @@ enum class MobSkillTarget { MST_TARGET = 0, -#define MST_TARGET MobSkillTarget::MST_TARGET MST_SELF, -#define MST_SELF MobSkillTarget::MST_SELF }; /// Used as a condition when trying to apply the chosen mob skill. @@ -19,17 +17,12 @@ enum class MobSkillCondition : uint16_t ANY = 0xffff, MSC_ALWAYS = 0x0000, -#define MSC_ALWAYS MobSkillCondition::MSC_ALWAYS MSC_MYHPLTMAXRATE = 0x0001, -#define MSC_MYHPLTMAXRATE MobSkillCondition::MSC_MYHPLTMAXRATE MSC_NOTINTOWN = 0x0032, -#define MSC_NOTINTOWN MobSkillCondition::MSC_NOTINTOWN MSC_SLAVELT = 0x0110, -#define MSC_SLAVELT MobSkillCondition::MSC_SLAVELT MSC_SLAVELE = 0x0111, -#define MSC_SLAVELE MobSkillCondition::MSC_SLAVELE }; /// Used as a filter when trying to choose a mob skill to use. @@ -38,17 +31,11 @@ enum class MobSkillState : uint8_t ANY = 0xff, MSS_IDLE = 0, -#define MSS_IDLE MobSkillState::MSS_IDLE MSS_WALK, -#define MSS_WALK MobSkillState::MSS_WALK MSS_ATTACK, -#define MSS_ATTACK MobSkillState::MSS_ATTACK MSS_DEAD, -#define MSS_DEAD MobSkillState::MSS_DEAD MSS_LOOT, -#define MSS_LOOT MobSkillState::MSS_LOOT MSS_CHASE, -#define MSS_CHASE MobSkillState::MSS_CHASE }; #endif // MOB_T_HPP diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 8501dc7..f77bac1 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -66,7 +66,7 @@ void npc_enable_sub(struct block_list *bl, struct npc_data *nd) nullpo_retv(bl); - if (bl->type == BL_PC && (sd = (struct map_session_data *) bl)) + if (bl->type == BL::PC && (sd = (struct map_session_data *) bl)) { if (nd->flag & 1) // 無効化されている @@ -95,12 +95,12 @@ int npc_enable(const char *name, bool flag) else { // 無効化 nd->flag |= 1; - clif_clearchar(&nd->bl, 0); + clif_clearchar(&nd->bl, BeingRemoveWhy::GONE); } if (flag && (nd->u.scr.xs > 0 || nd->u.scr.ys > 0)) map_foreachinarea(std::bind(npc_enable_sub, ph::_1, nd), nd->bl.m, nd->bl.x - nd->u.scr.xs, nd->bl.y - nd->u.scr.ys, - nd->bl.x + nd->u.scr.xs, nd->bl.y + nd->u.scr.ys, BL_PC); + nd->bl.x + nd->u.scr.xs, nd->bl.y + nd->u.scr.ys, BL::PC); return 0; } @@ -149,7 +149,7 @@ int npc_delete(struct npc_data *nd) if (nd->bl.prev == NULL) return 1; - clif_clearchar_area(&nd->bl, 1); + clif_clearchar(&nd->bl, BeingRemoveWhy::DEAD); map_delblock(&nd->bl); return 0; } @@ -633,12 +633,12 @@ int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y) switch (map[m].npc[i]->bl.subtype) { - case WARP: + case NpcSubtype::WARP: xs = map[m].npc[i]->u.warp.xs; ys = map[m].npc[i]->u.warp.ys; break; - case MESSAGE: - case SCRIPT: + case NpcSubtype::MESSAGE: + case NpcSubtype::SCRIPT: xs = map[m].npc[i]->u.scr.xs; ys = map[m].npc[i]->u.scr.ys; break; @@ -662,13 +662,13 @@ int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y) } switch (map[m].npc[i]->bl.subtype) { - case WARP: + case NpcSubtype::WARP: skill_stop_dancing(&sd->bl, 0); pc_setpos(sd, map[m].npc[i]->u.warp.name, - map[m].npc[i]->u.warp.x, map[m].npc[i]->u.warp.y, 0); + map[m].npc[i]->u.warp.x, map[m].npc[i]->u.warp.y, BeingRemoveWhy::GONE); break; - case MESSAGE: - case SCRIPT: + case NpcSubtype::MESSAGE: + case NpcSubtype::SCRIPT: { char *name = (char *)malloc(50); @@ -697,7 +697,7 @@ int npc_checknear(struct map_session_data *sd, int id) nullpo_ret(sd); nd = (struct npc_data *) map_id2bl(id); - if (nd == NULL || nd->bl.type != BL_NPC) + if (nd == NULL || nd->bl.type != BL::NPC) { if (battle_config.error_log) PRINTF("no such npc : %d\n", id); @@ -748,14 +748,14 @@ int npc_click(struct map_session_data *sd, int id) sd->npc_id = id; switch (nd->bl.subtype) { - case SHOP: + case NpcSubtype::SHOP: clif_npcbuysell(sd, id); npc_event_dequeue(sd); break; - case SCRIPT: + case NpcSubtype::SCRIPT: sd->npc_pos = run_script(nd->u.scr.script, 0, sd->bl.id, id); break; - case MESSAGE: + case NpcSubtype::MESSAGE: if (nd->u.message) { clif_scriptmes(sd, id, nd->u.message); @@ -786,7 +786,7 @@ int npc_scriptcont(struct map_session_data *sd, int id) nd = (struct npc_data *) map_id2bl(id); - if (!nd /* NPC was disposed? */ || nd->bl.subtype == MESSAGE) + if (!nd /* NPC was disposed? */ || nd->bl.subtype == NpcSubtype::MESSAGE) { clif_scriptclose(sd, id); npc_event_dequeue(sd); @@ -812,7 +812,7 @@ int npc_buysellsel(struct map_session_data *sd, int id, int type) return 1; nd = (struct npc_data *) map_id2bl(id); - if (nd->bl.subtype != SHOP) + if (nd->bl.subtype != NpcSubtype::SHOP) { if (battle_config.error_log) PRINTF("no such shop npc : %d\n", id); @@ -852,7 +852,7 @@ int npc_buylist(struct map_session_data *sd, int n, return 3; nd = (struct npc_data *) map_id2bl(sd->npc_shopid); - if (nd->bl.subtype != SHOP) + if (nd->bl.subtype != NpcSubtype::SHOP) return 3; for (i = 0, w = 0, z = 0; i < n; i++) @@ -870,15 +870,15 @@ int npc_buylist(struct map_session_data *sd, int n, switch (pc_checkadditem(sd, item_list[i * 2 + 1], item_list[i * 2])) { - case ADDITEM_EXIST: + case ADDITEM::EXIST: break; - case ADDITEM_NEW: + case ADDITEM::NEW: if (itemdb_isequip(item_list[i * 2 + 1])) new_stacks += item_list[i * 2]; else new_stacks++; break; - case ADDITEM_OVERAMOUNT: + case ADDITEM::OVERAMOUNT: return 2; } @@ -1080,7 +1080,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) nd->bl.m = m; nd->bl.x = x; nd->bl.y = y; - nd->dir = DIR_S; + nd->dir = DIR::S; nd->flag = 0; memcpy(nd->name, w3, 24); memcpy(nd->exname, w3, 24); @@ -1117,8 +1117,8 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) // PRINTF("warp npc %s %d read done\n",mapname,nd->bl.id); npc_warp++; - nd->bl.type = BL_NPC; - nd->bl.subtype = WARP; + nd->bl.type = BL::NPC; + nd->bl.subtype = NpcSubtype::WARP; map_addblock(&nd->bl); clif_spawnnpc(nd); strdb_insert(npcname_db, nd->name, nd); @@ -1221,8 +1221,8 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) //PRINTF("shop npc %s %d read done\n",mapname,nd->bl.id); npc_shop++; - nd->bl.type = BL_NPC; - nd->bl.subtype = SHOP; + nd->bl.type = BL::NPC; + nd->bl.subtype = NpcSubtype::SHOP; nd->n = map_addnpc(m, nd); map_addblock(&nd->bl); clif_spawnnpc(nd); @@ -1278,7 +1278,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, const char *first_line, FILE * fp, int *lines) { int x, y; - DIR dir = DIR_S; + DIR dir = DIR::S; int m, xs = 0, ys = 0, npc_class = 0; // [Valaris] thanks to fov char mapname[24]; char *srcbuf = NULL; @@ -1470,8 +1470,8 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, //PRINTF("script npc %s %d %d read done\n",mapname,nd->bl.id,nd->class); npc_script++; - nd->bl.type = BL_NPC; - nd->bl.subtype = SCRIPT; + nd->bl.type = BL::NPC; + nd->bl.subtype = NpcSubtype::SCRIPT; if (m >= 0) { nd->n = map_addnpc(m, nd); @@ -1743,7 +1743,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4) else memset(md->npc_event, 0, 24); - md->bl.type = BL_MOB; + md->bl.type = BL::MOB; map_addiddb(&md->bl); mob_spawn(md->bl.id); @@ -1928,8 +1928,8 @@ struct npc_data *npc_spawn_text(int m, int x, int y, retval->bl.x = x; retval->bl.y = y; retval->bl.m = m; - retval->bl.type = BL_NPC; - retval->bl.subtype = MESSAGE; + retval->bl.type = BL::NPC; + retval->bl.subtype = NpcSubtype::MESSAGE; strncpy(retval->name, name, 23); strncpy(retval->exname, name, 23); @@ -1959,7 +1959,7 @@ void npc_free_internal(struct npc_data *nd) free(cd); cd = NULL; } - if (nd->bl.subtype == SCRIPT) + if (nd->bl.subtype == NpcSubtype::SCRIPT) { if (nd->u.scr.timer_event) free(nd->u.scr.timer_event); @@ -1977,7 +1977,7 @@ void npc_free_internal(struct npc_data *nd) } } } - else if (nd->bl.subtype == MESSAGE && nd->u.message) + else if (nd->bl.subtype == NpcSubtype::MESSAGE && nd->u.message) { free(nd->u.message); } @@ -1989,12 +1989,12 @@ void npc_propagate_update(struct npc_data *nd) { map_foreachinarea(std::bind(npc_enable_sub, ph::_1, nd), nd->bl.m, nd->bl.x - nd->u.scr.xs, nd->bl.y - nd->u.scr.ys, - nd->bl.x + nd->u.scr.xs, nd->bl.y + nd->u.scr.ys, BL_PC); + nd->bl.x + nd->u.scr.xs, nd->bl.y + nd->u.scr.ys, BL::PC); } void npc_free(struct npc_data *nd) { - clif_clearchar(&nd->bl, 0); + clif_clearchar(&nd->bl, BeingRemoveWhy::GONE); npc_propagate_update(nd); map_deliddb(&nd->bl); map_delblock(&nd->bl); diff --git a/src/map/npc.hpp b/src/map/npc.hpp index 09fb1dc..50cfaa5 100644 --- a/src/map/npc.hpp +++ b/src/map/npc.hpp @@ -1,13 +1,14 @@ #ifndef NPC_HPP #define NPC_HPP +#include #include -#define START_NPC_NUM 110000000 +constexpr int START_NPC_NUM = 110000000; -#define WARP_CLASS 45 -#define WARP_DEBUG_CLASS 722 -#define INVISIBLE_CLASS 32767 +constexpr int WARP_CLASS = 45; +constexpr int WARP_DEBUG_CLASS = 722; +constexpr int INVISIBLE_CLASS = 32767; int npc_event_dequeue(struct map_session_data *sd); int npc_event(struct map_session_data *sd, const char *npcname, int); @@ -49,8 +50,16 @@ int npc_event_doall_l(const char *name, int rid, int argc, struct argrec *argv); int npc_event_do_l(const char *name, int rid, int argc, struct argrec *argv); -#define npc_event_doall(name) npc_event_doall_l(name, 0, 0, NULL) -#define npc_event_do(name) npc_event_do_l(name, 0, 0, NULL) +inline +int npc_event_doall(const char *name) +{ + return npc_event_doall_l(name, 0, 0, NULL); +} +inline +int npc_event_do(const char *name) +{ + return npc_event_do_l(name, 0, 0, NULL); +} int npc_timerevent_start(struct npc_data *nd); int npc_timerevent_stop(struct npc_data *nd); diff --git a/src/map/party.cpp b/src/map/party.cpp index 609044a..b422e04 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -17,7 +17,8 @@ #include "../poison.hpp" -#define PARTY_SEND_XYHP_INVERVAL 1000 // 座標やHP送信の間隔 +// 座標やHP送信の間隔 +constexpr int PARTY_SEND_XYHP_INVERVAL = 1000; static struct dbt *party_db; @@ -240,7 +241,7 @@ int party_invite(struct map_session_data *sd, int account_id) { /* Disallow the invitation under these conditions. */ if (tsd->trade_partner || tsd->npc_id - || tsd->npc_shopid || pc_checkskill(tsd, NV_PARTY) < 1) + || tsd->npc_shopid || pc_checkskill(tsd, SkillID::NV_PARTY) < 1) { clif_party_inviteack(sd, tsd->status.name, 1); return 0; diff --git a/src/map/path.cpp b/src/map/path.cpp index b764e7f..c2ab8ca 100644 --- a/src/map/path.cpp +++ b/src/map/path.cpp @@ -8,14 +8,19 @@ //#define PATH_STANDALONETEST -#define MAX_HEAP 150 +constexpr int MAX_HEAP = 150; struct tmp_path { short x, y, dist, before, cost; DIR dir; char flag; }; -#define calc_index(x,y) (((x)+(y)*MAX_WALKPATH) & (MAX_WALKPATH*MAX_WALKPATH-1)) + +static +int calc_index(int x, int y) +{ + return (x + y * MAX_WALKPATH) & (MAX_WALKPATH * MAX_WALKPATH - 1); +} /*========================================== * 経路探索補助heap push @@ -301,22 +306,22 @@ int path_search(struct walkpath_data *wpd, int m, int x0, int y0, int x1, int y1 x += dx; y += dy; wpd->path[i++] = (dx < 0) - ? ((dy > 0) ? DIR_SW : DIR_NW) - : ((dy < 0) ? DIR_NE : DIR_SE); + ? ((dy > 0) ? DIR::SW : DIR::NW) + : ((dy < 0) ? DIR::NE : DIR::SE); } else if (x != x1) { if (!can_move(md, x, y, x + dx, y, flag)) break; x += dx; - wpd->path[i++] = (dx < 0) ? DIR_W : DIR_E; + wpd->path[i++] = (dx < 0) ? DIR::W : DIR::E; } else { // y!=y1 if (!can_move(md, x, y, x, y + dy, flag)) break; y += dy; - wpd->path[i++] = (dy > 0) ? DIR_S : DIR_N; + wpd->path[i++] = (dy > 0) ? DIR::S : DIR::N; } if (x == x1 && y == y1) { @@ -335,7 +340,7 @@ int path_search(struct walkpath_data *wpd, int m, int x0, int y0, int x1, int y1 tp[i].x = x0; tp[i].y = y0; tp[i].dist = 0; - tp[i].dir = DIR_S; + tp[i].dir = DIR::S; tp[i].before = 0; tp[i].cost = calc_cost(&tp[i], x1, y1); tp[i].flag = 0; @@ -367,24 +372,23 @@ int path_search(struct walkpath_data *wpd, int m, int x0, int y0, int x1, int y1 return 0; } if (can_move(md, x, y, x + 1, y - 1, flag)) - e += add_path(heap, tp, x + 1, y - 1, tp[rp].dist + 14, DIR_NE, rp, x1, y1); + e += add_path(heap, tp, x + 1, y - 1, tp[rp].dist + 14, DIR::NE, rp, x1, y1); if (can_move(md, x, y, x + 1, y, flag)) - e += add_path(heap, tp, x + 1, y, tp[rp].dist + 10, DIR_E, rp, x1, y1); + e += add_path(heap, tp, x + 1, y, tp[rp].dist + 10, DIR::E, rp, x1, y1); if (can_move(md, x, y, x + 1, y + 1, flag)) - e += add_path(heap, tp, x + 1, y + 1, tp[rp].dist + 14, DIR_SE, rp, x1, y1); + e += add_path(heap, tp, x + 1, y + 1, tp[rp].dist + 14, DIR::SE, rp, x1, y1); if (can_move(md, x, y, x, y + 1, flag)) - e += add_path(heap, tp, x, y + 1, tp[rp].dist + 10, DIR_S, rp, x1, y1); + e += add_path(heap, tp, x, y + 1, tp[rp].dist + 10, DIR::S, rp, x1, y1); if (can_move(md, x, y, x - 1, y + 1, flag)) - e += add_path(heap, tp, x - 1, y + 1, tp[rp].dist + 14, DIR_SW, rp, x1, y1); + e += add_path(heap, tp, x - 1, y + 1, tp[rp].dist + 14, DIR::SW, rp, x1, y1); if (can_move(md, x, y, x - 1, y, flag)) - e += add_path(heap, tp, x - 1, y, tp[rp].dist + 10, DIR_W, rp, x1, y1); + e += add_path(heap, tp, x - 1, y, tp[rp].dist + 10, DIR::W, rp, x1, y1); if (can_move(md, x, y, x - 1, y - 1, flag)) - e += add_path(heap, tp, x - 1, y - 1, tp[rp].dist + 14, DIR_NW, rp, x1, y1); + e += add_path(heap, tp, x - 1, y - 1, tp[rp].dist + 14, DIR::NW, rp, x1, y1); if (can_move(md, x, y, x, y - 1, flag)) - e += add_path(heap, tp, x, y - 1, tp[rp].dist + 10, DIR_N, rp, x1, y1); + e += add_path(heap, tp, x, y - 1, tp[rp].dist + 10, DIR::N, rp, x1, y1); tp[rp].flag = 1; if (e || heap[0] >= MAX_HEAP - 5) return -1; } - return -1; } diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 9826323..3c55b08 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -27,31 +27,40 @@ #include "../poison.hpp" -#define PVP_CALCRANK_INTERVAL 1000 // PVP順位計算の間隔 +// PVP順位計算の間隔 +constexpr int PVP_CALCRANK_INTERVAL = 1000; //define it here, since the ifdef only occurs in this file #define USE_ASTRAL_SOUL_SKILL #ifdef USE_ASTRAL_SOUL_SKILL -#define MAGIC_SKILL_THRESHOLD 200 // [fate] At this threshold, the Astral Soul skill kicks in +// [fate] At this threshold, the Astral Soul skill kicks in +constexpr int MAGIC_SKILL_THRESHOLD = 200; #endif #define MAP_LOG_STATS(sd, suffix) \ - MAP_LOG_PC(sd, "STAT %d %d %d %d %d %d " suffix, \ - sd->status.attrs[ATTR::STR], sd->status.attrs[ATTR::AGI], sd->status.attrs[ATTR::VIT], sd->status.attrs[ATTR::INT], sd->status.attrs[ATTR::DEX], sd->status.attrs[ATTR::LUK]) + MAP_LOG_PC(sd, "STAT %d %d %d %d %d %d " suffix, \ + sd->status.attrs[ATTR::STR], \ + sd->status.attrs[ATTR::AGI], \ + sd->status.attrs[ATTR::VIT], \ + sd->status.attrs[ATTR::INT], \ + sd->status.attrs[ATTR::DEX], \ + sd->status.attrs[ATTR::LUK]) #define MAP_LOG_XP(sd, suffix) \ - MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \ - sd->status.base_level, sd->status.base_exp, sd->status.job_level, sd->status.job_exp, sd->status.skill_point, sd->status.zeny, pc_readaccountreg(sd, "BankAccount")) + MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \ + sd->status.base_level, sd->status.base_exp, \ + sd->status.job_level, sd->status.job_exp, sd->status.skill_point, \ + sd->status.zeny, pc_readaccountreg(sd, "BankAccount")) #define MAP_LOG_MAGIC(sd, suffix) \ MAP_LOG_PC(sd, "MAGIC %d %d %d %d %d %d EXP %d %d " suffix, \ - sd->status.skill[TMW_MAGIC].lv, \ - sd->status.skill[TMW_MAGIC_LIFE].lv, \ - sd->status.skill[TMW_MAGIC_WAR].lv, \ - sd->status.skill[TMW_MAGIC_TRANSMUTE].lv, \ - sd->status.skill[TMW_MAGIC_NATURE].lv, \ - sd->status.skill[TMW_MAGIC_ETHER].lv, \ + sd->status.skill[SkillID::TMW_MAGIC].lv, \ + sd->status.skill[SkillID::TMW_MAGIC_LIFE].lv, \ + sd->status.skill[SkillID::TMW_MAGIC_WAR].lv, \ + sd->status.skill[SkillID::TMW_MAGIC_TRANSMUTE].lv, \ + sd->status.skill[SkillID::TMW_MAGIC_NATURE].lv, \ + sd->status.skill[SkillID::TMW_MAGIC_ETHER].lv, \ pc_readglobalreg(sd, "MAGIC_EXPERIENCE") & 0xffff, \ (pc_readglobalreg(sd, "MAGIC_EXPERIENCE") >> 24) & 0xff) @@ -244,12 +253,12 @@ int pc_iskiller(struct map_session_data *src, { nullpo_ret(src); - if (src->bl.type != BL_PC) + if (src->bl.type != BL::PC) return 0; if (src->special_state.killer) return 1; - if (target->bl.type != BL_PC) + if (target->bl.type != BL::PC) return 0; if (target->special_state.killable) return 1; @@ -292,7 +301,7 @@ void pc_invincible_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t) struct map_session_data *sd; if ((sd = map_id2sd(id)) == NULL - || sd->bl.type != BL_PC) + || sd->bl.type != BL::PC) return; if (sd->invincible_timer != tid) @@ -334,7 +343,7 @@ void pc_spiritball_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t) int i; if ((sd = map_id2sd(id)) == NULL - || sd->bl.type != BL_PC) + || sd->bl.type != BL::PC) return; if (sd->spirit_timer[0] != tid) @@ -449,9 +458,9 @@ int pc_setrestartvalue(struct map_session_data *sd, int type) } } if (type & 1) - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); if (type & 1) - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::SP); sd->heal_xp = 0; // [Fate] Set gainable xp for healing this player to 0 @@ -470,18 +479,18 @@ void pc_counttargeted_sub(struct block_list *bl, if (id == bl->id || (src && id == src->id)) return; - if (bl->type == BL_PC) + if (bl->type == BL::PC) { struct map_session_data *sd = (struct map_session_data *) bl; if (sd && sd->attacktarget == id && sd->attacktimer != -1 && sd->attacktarget_lv >= target_lv) (*c)++; } - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) { struct mob_data *md = (struct mob_data *) bl; if (md && md->target_id == id && md->timer != -1 - && md->state.state == MS_ATTACK && md->target_lv >= target_lv) + && md->state.state == MS::ATTACK && md->target_lv >= target_lv) (*c)++; //PRINTF("md->target_lv:%d, target_lv:%d\n",((struct mob_data *)bl)->target_lv,target_lv); @@ -494,7 +503,7 @@ int pc_counttargeted(struct map_session_data *sd, struct block_list *src, int c = 0; map_foreachinarea(std::bind(pc_counttargeted_sub, ph::_1, sd->bl.id, &c, src, target_lv), sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE, - sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, BL_NUL); + sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, BL::NUL); return c; } @@ -565,7 +574,7 @@ int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id, sd->client_tick = client_tick; sd->sex = sex; sd->state.auth = 0; - sd->bl.type = BL_PC; + sd->bl.type = BL::PC; sd->canact_tick = sd->canmove_tick = gettick(); sd->canlog_tick = gettick(); sd->state.waitingdisconnect = 0; @@ -735,7 +744,7 @@ int pc_breakweapon(struct map_session_data *sd) clif_emotion(&sd->bl, 23); clif_displaymessage(sd->fd, output); clif_equiplist(sd); - skill_status_change_start(&sd->bl, SC_BROKNWEAPON, 0, 0, 0, + skill_status_change_start(&sd->bl, StatusChange::SC_BROKNWEAPON, 0, 0, 0, 0, 0, 0); } } @@ -774,7 +783,7 @@ int pc_breakarmor(struct map_session_data *sd) clif_emotion(&sd->bl, 23); clif_displaymessage(sd->fd, output); clif_equiplist(sd); - skill_status_change_start(&sd->bl, SC_BROKNARMOR, 0, 0, 0, 0, + skill_status_change_start(&sd->bl, StatusChange::SC_BROKNARMOR, 0, 0, 0, 0, 0, 0); } } @@ -826,8 +835,8 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, sd->weapontype1 = sd->weapontype2 = 0; sd->speed = DEFAULT_WALK_SPEED; sd->state.dead_sit = 0; - sd->dir = DIR_S; - sd->head_dir = DIR_S; + sd->dir = DIR::S; + sd->head_dir = DIR::S; sd->state.auth = 1; sd->walktimer = -1; sd->attacktimer = -1; @@ -877,7 +886,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, pc_checkitem(sd); // ステータス異常の初期化 - for (StatusChange i : erange(StatusChange(), MAX_STATUSCHANGE)) + for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE)) { sd->sc_data[i].timer = -1; sd->sc_data[i].val1 = sd->sc_data[i].val2 = sd->sc_data[i].val3 = @@ -907,7 +916,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, // 位置の設定 pc_setpos(sd, sd->status.last_point.map, sd->status.last_point.x, - sd->status.last_point.y, 0); + sd->status.last_point.y, BeingRemoveWhy::GONE); // パーティ、ギルドデータの要求 if (sd->status.party_id > 0 @@ -945,7 +954,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, { PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n", sd->status.name, sd->status.account_id, pc_isGM(sd)); - clif_updatestatus(sd, SP_GM); + clif_updatestatus(sd, SP::GM); } else PRINTF("Connection accepted: Character '%s' (account: %d).\n", @@ -1044,8 +1053,8 @@ void pc_calc_skilltree(struct map_session_data *sd) // TODO - I *think* this can be removed // since the skill is worthless without a level - if (sd->status.skill[NV_EMOTE].id == SkillID::ZERO) - sd->status.skill[NV_EMOTE].id = NV_EMOTE; + if (sd->status.skill[SkillID::NV_EMOTE].id == SkillID::ZERO) + sd->status.skill[SkillID::NV_EMOTE].id = SkillID::NV_EMOTE; } /*========================================== @@ -1059,30 +1068,30 @@ int pc_checkweighticon(struct map_session_data *sd) nullpo_ret(sd); if (sd->weight * 2 >= sd->max_weight - && sd->sc_data[SC_FLYING_BACKPACK].timer == -1) + && sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer == -1) flag = 1; if (sd->weight * 10 >= sd->max_weight * 9) flag = 2; if (flag == 1) { - if (sd->sc_data[SC_WEIGHT50].timer == -1) - skill_status_change_start(&sd->bl, SC_WEIGHT50, 0, 0, 0, 0, 0, + if (sd->sc_data[StatusChange::SC_WEIGHT50].timer == -1) + skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT50, 0, 0, 0, 0, 0, 0); } else { - skill_status_change_end(&sd->bl, SC_WEIGHT50, -1); + skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT50, -1); } if (flag == 2) { - if (sd->sc_data[SC_WEIGHT90].timer == -1) - skill_status_change_start(&sd->bl, SC_WEIGHT90, 0, 0, 0, 0, 0, + if (sd->sc_data[StatusChange::SC_WEIGHT90].timer == -1) + skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT90, 0, 0, 0, 0, 0, 0); } else { - skill_status_change_end(&sd->bl, SC_WEIGHT90, -1); + skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT90, -1); } return 0; } @@ -1091,10 +1100,10 @@ static void pc_set_weapon_look(struct map_session_data *sd) { if (sd->attack_spell_override) - clif_changelook(&sd->bl, LOOK_WEAPON, + clif_changelook(&sd->bl, LOOK::WEAPON, sd->attack_spell_look_override); else - clif_changelook(&sd->bl, LOOK_WEAPON, sd->status.weapon); + clif_changelook(&sd->bl, LOOK::WEAPON, sd->status.weapon); } /*========================================== @@ -1311,7 +1320,7 @@ int pc_calcstatus(struct map_session_data *sd, int first) if (sd->spellpower_bonus_target < 0) sd->spellpower_bonus_target = (sd->spellpower_bonus_target * 256) / - (min(128 + skill_power(sd, TMW_ASTRAL_SOUL), 256)); + (min(128 + skill_power(sd, SkillID::TMW_ASTRAL_SOUL), 256)); #endif if (sd->spellpower_bonus_target < sd->spellpower_bonus_current) @@ -1406,10 +1415,10 @@ int pc_calcstatus(struct map_session_data *sd, int first) if (battle_is_unarmed(&sd->bl)) { - sd->watk += skill_power(sd, TMW_BRAWLING) / 3; // +66 for 200 - sd->watk2 += skill_power(sd, TMW_BRAWLING) >> 3; // +25 for 200 - sd->watk_ += skill_power(sd, TMW_BRAWLING) / 3; // +66 for 200 - sd->watk_2 += skill_power(sd, TMW_BRAWLING) >> 3; // +25 for 200 + sd->watk += skill_power(sd, SkillID::TMW_BRAWLING) / 3; // +66 for 200 + sd->watk2 += skill_power(sd, SkillID::TMW_BRAWLING) >> 3; // +25 for 200 + sd->watk_ += skill_power(sd, SkillID::TMW_BRAWLING) / 3; // +66 for 200 + sd->watk_2 += skill_power(sd, SkillID::TMW_BRAWLING) >> 3; // +25 for 200 } if (sd->equip_index[EQUIP::ARROW] >= 0) @@ -1446,8 +1455,8 @@ int pc_calcstatus(struct map_session_data *sd, int first) if (sd->aspd_add_rate != 100) sd->aspd_rate += sd->aspd_add_rate - 100; - sd->speed -= skill_power(sd, TMW_SPEED) >> 3; - sd->aspd_rate -= skill_power(sd, TMW_SPEED) / 10; + sd->speed -= skill_power(sd, SkillID::TMW_SPEED) >> 3; + sd->aspd_rate -= skill_power(sd, SkillID::TMW_SPEED) / 10; if (sd->aspd_rate < 20) sd->aspd_rate = 20; @@ -1485,7 +1494,7 @@ int pc_calcstatus(struct map_session_data *sd, int first) int bonus = sd->matk1 - MAGIC_SKILL_THRESHOLD; // Ok if you are above a certain threshold, you get only (1/8) of that matk1 // if you have Astral soul skill you can get the whole power again (and additionally the 1/8 added) - sd->matk1 = MAGIC_SKILL_THRESHOLD + (bonus>>3) + ((3*bonus*skill_power(sd, TMW_ASTRAL_SOUL))>>9); + sd->matk1 = MAGIC_SKILL_THRESHOLD + (bonus>>3) + ((3*bonus*skill_power(sd, SkillID::TMW_ASTRAL_SOUL))>>9); } #endif sd->matk2 = 0; @@ -1501,7 +1510,7 @@ int pc_calcstatus(struct map_session_data *sd, int first) // 200 is the maximum of the skill // def2 is the defence gained by vit, whereas "def", which is gained by armor, stays as is - int spbsk = skill_power(sd, TMW_RAGING); + int spbsk = skill_power(sd, SkillID::TMW_RAGING); if (spbsk != 0 && sd->attackrange <= 2) { sd->critical += sd->critical * spbsk / 100; @@ -1566,8 +1575,8 @@ int pc_calcstatus(struct map_session_data *sd, int first) if (sd->attackrange > 2) { // [fate] ranged weapon? - sd->attackrange += min(skill_power(sd, AC_OWL) / 60, 3); - sd->hit += skill_power(sd, AC_OWL) / 10; // 20 for 200 + sd->attackrange += min(skill_power(sd, SkillID::AC_OWL) / 60, 3); + sd->hit += skill_power(sd, SkillID::AC_OWL) / 10; // 20 for 200 } sd->max_weight += 1000; @@ -1622,38 +1631,38 @@ int pc_calcstatus(struct map_session_data *sd, int first) if (sd->sc_count) { // ATK/DEF変化形 - if (sd->sc_data[SC_POISON].timer != -1) // 毒状態 + if (sd->sc_data[StatusChange::SC_POISON].timer != -1) // 毒状態 sd->def2 = sd->def2 * 75 / 100; - if (sd->sc_data[SC_ATKPOT].timer != -1) - sd->watk += sd->sc_data[SC_ATKPOT].val1; - if (sd->sc_data[SC_MATKPOT].timer != -1) + if (sd->sc_data[StatusChange::SC_ATKPOT].timer != -1) + sd->watk += sd->sc_data[StatusChange::SC_ATKPOT].val1; + if (sd->sc_data[StatusChange::SC_MATKPOT].timer != -1) { - sd->matk1 += sd->sc_data[SC_MATKPOT].val1; - sd->matk2 += sd->sc_data[SC_MATKPOT].val1; + sd->matk1 += sd->sc_data[StatusChange::SC_MATKPOT].val1; + sd->matk2 += sd->sc_data[StatusChange::SC_MATKPOT].val1; } { - if (sd->sc_data[SC_SPEEDPOTION0].timer != -1) - aspd_rate -= sd->sc_data[SC_SPEEDPOTION0].val1; + if (sd->sc_data[StatusChange::SC_SPEEDPOTION0].timer != -1) + aspd_rate -= sd->sc_data[StatusChange::SC_SPEEDPOTION0].val1; } - if (sd->sc_data[SC_HASTE].timer != -1) - aspd_rate -= sd->sc_data[SC_HASTE].val1; + if (sd->sc_data[StatusChange::SC_HASTE].timer != -1) + aspd_rate -= sd->sc_data[StatusChange::SC_HASTE].val1; /* Slow down if protected */ - if (sd->sc_data[SC_PHYS_SHIELD].timer != -1) - aspd_rate += sd->sc_data[SC_PHYS_SHIELD].val1; + if (sd->sc_data[StatusChange::SC_PHYS_SHIELD].timer != -1) + aspd_rate += sd->sc_data[StatusChange::SC_PHYS_SHIELD].val1; // HIT/FLEE変化系 - if (sd->sc_data[SC_BLIND].timer != -1) + if (sd->sc_data[StatusChange::SC_BLIND].timer != -1) { // 暗黒 sd->hit -= sd->hit * 25 / 100; sd->flee -= sd->flee * 25 / 100; } - if (sd->sc_data[SC_CURSE].timer != -1) + if (sd->sc_data[StatusChange::SC_CURSE].timer != -1) sd->speed += 450; } @@ -1683,13 +1692,13 @@ int pc_calcstatus(struct map_session_data *sd, int first) return 0; if (first & 3) { - clif_updatestatus(sd, SP_SPEED); - clif_updatestatus(sd, SP_MAXHP); - clif_updatestatus(sd, SP_MAXSP); + clif_updatestatus(sd, SP::SPEED); + clif_updatestatus(sd, SP::MAXHP); + clif_updatestatus(sd, SP::MAXSP); if (first & 1) { - clif_updatestatus(sd, SP_HP); - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::HP); + clif_updatestatus(sd, SP::SP); } return 0; } @@ -1699,53 +1708,53 @@ int pc_calcstatus(struct map_session_data *sd, int first) clif_skillinfoblock(sd); // スキル送信 if (b_speed != sd->speed) - clif_updatestatus(sd, SP_SPEED); + clif_updatestatus(sd, SP::SPEED); if (b_weight != sd->weight) - clif_updatestatus(sd, SP_WEIGHT); + clif_updatestatus(sd, SP::WEIGHT); if (b_max_weight != sd->max_weight) { - clif_updatestatus(sd, SP_MAXWEIGHT); + clif_updatestatus(sd, SP::MAXWEIGHT); pc_checkweighticon(sd); } for (ATTR i : ATTRs) if (b_paramb[i] + b_parame[i] != sd->paramb[i] + sd->parame[i]) clif_updatestatus(sd, attr_to_sp(i)); if (b_hit != sd->hit) - clif_updatestatus(sd, SP_HIT); + clif_updatestatus(sd, SP::HIT); if (b_flee != sd->flee) - clif_updatestatus(sd, SP_FLEE1); + clif_updatestatus(sd, SP::FLEE1); if (b_aspd != sd->aspd) - clif_updatestatus(sd, SP_ASPD); + clif_updatestatus(sd, SP::ASPD); if (b_watk != sd->watk || b_base_atk != sd->base_atk) - clif_updatestatus(sd, SP_ATK1); + clif_updatestatus(sd, SP::ATK1); if (b_def != sd->def) - clif_updatestatus(sd, SP_DEF1); + clif_updatestatus(sd, SP::DEF1); if (b_watk2 != sd->watk2) - clif_updatestatus(sd, SP_ATK2); + clif_updatestatus(sd, SP::ATK2); if (b_def2 != sd->def2) - clif_updatestatus(sd, SP_DEF2); + clif_updatestatus(sd, SP::DEF2); if (b_flee2 != sd->flee2) - clif_updatestatus(sd, SP_FLEE2); + clif_updatestatus(sd, SP::FLEE2); if (b_critical != sd->critical) - clif_updatestatus(sd, SP_CRITICAL); + clif_updatestatus(sd, SP::CRITICAL); if (b_matk1 != sd->matk1) - clif_updatestatus(sd, SP_MATK1); + clif_updatestatus(sd, SP::MATK1); if (b_matk2 != sd->matk2) - clif_updatestatus(sd, SP_MATK2); + clif_updatestatus(sd, SP::MATK2); if (b_mdef != sd->mdef) - clif_updatestatus(sd, SP_MDEF1); + clif_updatestatus(sd, SP::MDEF1); if (b_mdef2 != sd->mdef2) - clif_updatestatus(sd, SP_MDEF2); + clif_updatestatus(sd, SP::MDEF2); if (b_attackrange != sd->attackrange) - clif_updatestatus(sd, SP_ATTACKRANGE); + clif_updatestatus(sd, SP::ATTACKRANGE); if (b_max_hp != sd->status.max_hp) - clif_updatestatus(sd, SP_MAXHP); + clif_updatestatus(sd, SP::MAXHP); if (b_max_sp != sd->status.max_sp) - clif_updatestatus(sd, SP_MAXSP); + clif_updatestatus(sd, SP::MAXSP); if (b_hp != sd->status.hp) - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); if (b_sp != sd->status.sp) - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::SP); return 0; } @@ -1760,17 +1769,17 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) switch (type) { - case SP_STR: - case SP_AGI: - case SP_VIT: - case SP_INT: - case SP_DEX: - case SP_LUK: + case SP::STR: + case SP::AGI: + case SP::VIT: + case SP::INT: + case SP::DEX: + case SP::LUK: if (sd->state.lr_flag != 2) sd->parame[sp_to_attr(type)] += val; break; #if 0 - case SP_ATK1: + case SP::ATK1: if (!sd->state.lr_flag) sd->watk += val; else if (sd->state.lr_flag == 1) @@ -1778,7 +1787,7 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) break; #endif #if 0 - case SP_ATK2: + case SP::ATK2: if (!sd->state.lr_flag) sd->watk2 += val; else if (sd->state.lr_flag == 1) @@ -1786,86 +1795,86 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) break; #endif #if 0 - case SP_BASE_ATK: + case SP::BASE_ATK: if (sd->state.lr_flag != 2) sd->base_atk += val; break; #endif #if 0 - case SP_MATK1: + case SP::MATK1: if (sd->state.lr_flag != 2) sd->matk1 += val; break; #endif #if 0 - case SP_MATK2: + case SP::MATK2: if (sd->state.lr_flag != 2) sd->matk2 += val; break; #endif #if 0 - case SP_DEF1: + case SP::DEF1: if (sd->state.lr_flag != 2) sd->def += val; break; #endif - case SP_MDEF1: + case SP::MDEF1: if (sd->state.lr_flag != 2) sd->mdef += val; break; #if 0 - case SP_MDEF2: + case SP::MDEF2: if (sd->state.lr_flag != 2) sd->mdef += val; break; #endif - case SP_HIT: + case SP::HIT: if (sd->state.lr_flag != 2) sd->hit += val; else sd->arrow_hit += val; break; - case SP_FLEE1: + case SP::FLEE1: if (sd->state.lr_flag != 2) sd->flee += val; break; #if 0 - case SP_FLEE2: + case SP::FLEE2: if (sd->state.lr_flag != 2) sd->flee2 += val * 10; break; #endif - case SP_CRITICAL: + case SP::CRITICAL: if (sd->state.lr_flag != 2) sd->critical += val * 10; else sd->arrow_cri += val * 10; break; - case SP_MAXHP: + case SP::MAXHP: if (sd->state.lr_flag != 2) sd->status.max_hp += val; break; - case SP_MAXSP: + case SP::MAXSP: if (sd->state.lr_flag != 2) sd->status.max_sp += val; break; - case SP_MAXHPRATE: + case SP::MAXHPRATE: if (sd->state.lr_flag != 2) sd->hprate += val; break; #if 0 - case SP_MAXSPRATE: + case SP::MAXSPRATE: if (sd->state.lr_flag != 2) sd->sprate += val; break; #endif #if 0 - case SP_SPRATE: + case SP::SPRATE: if (sd->state.lr_flag != 2) sd->dsprate += val; break; #endif - case SP_ATTACKRANGE: + case SP::ATTACKRANGE: if (!sd->state.lr_flag) sd->attackrange += val; else if (sd->state.lr_flag == 1) @@ -1874,13 +1883,13 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) sd->arrow_range += val; break; #if 0 - case SP_ADD_SPEED: + case SP::ADD_SPEED: if (sd->state.lr_flag != 2) sd->speed -= val; break; #endif #if 0 - case SP_SPEED_RATE: + case SP::SPEED_RATE: if (sd->state.lr_flag != 2) { if (sd->speed_rate > 100 - val) @@ -1888,17 +1897,17 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) } break; #endif - case SP_SPEED_ADDRATE: + case SP::SPEED_ADDRATE: if (sd->state.lr_flag != 2) sd->speed_add_rate = sd->speed_add_rate * (100 - val) / 100; break; #if 0 - case SP_ASPD: + case SP::ASPD: if (sd->state.lr_flag != 2) sd->aspd -= val * 10; break; #endif - case SP_ASPD_RATE: + case SP::ASPD_RATE: if (sd->state.lr_flag != 2) { if (sd->aspd_rate > 100 - val) @@ -1906,106 +1915,106 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) } break; #if 0 - case SP_ASPD_ADDRATE: + case SP::ASPD_ADDRATE: if (sd->state.lr_flag != 2) sd->aspd_add_rate = sd->aspd_add_rate * (100 - val) / 100; break; #endif - case SP_HP_RECOV_RATE: + case SP::HP_RECOV_RATE: if (sd->state.lr_flag != 2) sd->hprecov_rate += val; break; #if 0 - case SP_SP_RECOV_RATE: + case SP::SP_RECOV_RATE: if (sd->state.lr_flag != 2) sd->sprecov_rate += val; break; #endif #if 0 - case SP_CRITICAL_DEF: + case SP::CRITICAL_DEF: if (sd->state.lr_flag != 2) sd->critical_def += val; break; #endif #if 0 - case SP_DOUBLE_RATE: + case SP::DOUBLE_RATE: if (sd->state.lr_flag == 0 && sd->double_rate < val) sd->double_rate = val; break; #endif - case SP_DOUBLE_ADD_RATE: + case SP::DOUBLE_ADD_RATE: if (sd->state.lr_flag == 0) sd->double_add_rate += val; break; #if 0 - case SP_MATK_RATE: + case SP::MATK_RATE: if (sd->state.lr_flag != 2) sd->matk_rate += val; break; #endif #if 0 - case SP_ATK_RATE: + case SP::ATK_RATE: if (sd->state.lr_flag != 2) sd->atk_rate += val; break; #endif #if 0 - case SP_PERFECT_HIT_RATE: + case SP::PERFECT_HIT_RATE: if (sd->state.lr_flag != 2 && sd->perfect_hit < val) sd->perfect_hit = val; break; #endif #if 0 - case SP_PERFECT_HIT_ADD_RATE: + case SP::PERFECT_HIT_ADD_RATE: if (sd->state.lr_flag != 2) sd->perfect_hit_add += val; break; #endif #if 0 - case SP_CRITICAL_RATE: + case SP::CRITICAL_RATE: if (sd->state.lr_flag != 2) sd->critical_rate += val; break; #endif #if 0 - case SP_HIT_RATE: + case SP::HIT_RATE: if (sd->state.lr_flag != 2) sd->hit_rate += val; break; #endif #if 0 - case SP_FLEE_RATE: + case SP::FLEE_RATE: if (sd->state.lr_flag != 2) sd->flee_rate += val; break; #endif #if 0 - case SP_FLEE2_RATE: + case SP::FLEE2_RATE: if (sd->state.lr_flag != 2) sd->flee2_rate += val; break; #endif - case SP_DEF_RATE: + case SP::DEF_RATE: if (sd->state.lr_flag != 2) sd->def_rate += val; break; - case SP_DEF2_RATE: + case SP::DEF2_RATE: if (sd->state.lr_flag != 2) sd->def2_rate += val; break; #if 0 - case SP_MDEF_RATE: + case SP::MDEF_RATE: if (sd->state.lr_flag != 2) sd->mdef_rate += val; break; #endif #if 0 - case SP_MDEF2_RATE: + case SP::MDEF2_RATE: if (sd->state.lr_flag != 2) sd->mdef2_rate += val; break; #endif - case SP_DEAF: + case SP::DEAF: sd->special_state.deaf = 1; break; default: @@ -2027,7 +2036,7 @@ int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val) switch (type) { - case SP_HP_DRAIN_RATE: + case SP::HP_DRAIN_RATE: if (!sd->state.lr_flag) { sd->hp_drain_rate += type2; @@ -2040,7 +2049,7 @@ int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val) } break; #if 0 - case SP_SP_DRAIN_RATE: + case SP::SP_DRAIN_RATE: if (!sd->state.lr_flag) { sd->sp_drain_rate += type2; @@ -2104,21 +2113,21 @@ ADDITEM pc_checkadditem(struct map_session_data *sd, int nameid, int amount) nullpo_retr(ADDITEM::ZERO, sd); if (itemdb_isequip(nameid)) - return ADDITEM_NEW; + return ADDITEM::NEW; for (i = 0; i < MAX_INVENTORY; i++) { if (sd->status.inventory[i].nameid == nameid) { if (sd->status.inventory[i].amount + amount > MAX_AMOUNT) - return ADDITEM_OVERAMOUNT; - return ADDITEM_EXIST; + return ADDITEM::OVERAMOUNT; + return ADDITEM::EXIST; } } if (amount > MAX_AMOUNT) - return ADDITEM_OVERAMOUNT; - return ADDITEM_NEW; + return ADDITEM::OVERAMOUNT; + return ADDITEM::NEW; } /*========================================== @@ -2154,7 +2163,7 @@ int pc_payzeny(struct map_session_data *sd, int zeny) if (sd->status.zeny < zeny || z - (double) zeny > MAX_ZENY) return 1; sd->status.zeny -= zeny; - clif_updatestatus(sd, SP_ZENY); + clif_updatestatus(sd, SP::ZENY); return 0; } @@ -2176,7 +2185,7 @@ int pc_getzeny(struct map_session_data *sd, int zeny) sd->status.zeny = MAX_ZENY; } sd->status.zeny += zeny; - clif_updatestatus(sd, SP_ZENY); + clif_updatestatus(sd, SP::ZENY); return 0; } @@ -2304,7 +2313,7 @@ PickupFail pc_additem(struct map_session_data *sd, struct item *item_data, return PickupFail::INV_FULL; } sd->weight += w; - clif_updatestatus(sd, SP_WEIGHT); + clif_updatestatus(sd, SP::WEIGHT); return PickupFail::OKAY; } @@ -2338,7 +2347,7 @@ int pc_delitem(struct map_session_data *sd, int n, int amount, int type) if (!(type & 1)) clif_delitem(sd, n, amount); if (!(type & 2)) - clif_updatestatus(sd, SP_WEIGHT); + clif_updatestatus(sd, SP::WEIGHT); return 0; } @@ -2599,7 +2608,7 @@ void pc_show_steal(struct block_list *bl, //** pc.c: Small Steal Item fix by fritz int pc_steal_item(struct map_session_data *sd, struct block_list *bl) { - if (sd != NULL && bl != NULL && bl->type == BL_MOB) + if (sd != NULL && bl != NULL && bl->type == BL::MOB) { int i, skill, rate, itemid, count; struct mob_data *md; @@ -2607,8 +2616,8 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl) if (!md->state.steal_flag && mob_db[md->mob_class].mexp <= 0 && !bool(mob_db[md->mob_class].mode & MobMode::BOSS) - && md->sc_data[SC_STONE].timer == -1 - && md->sc_data[SC_FREEZE].timer == -1) + && md->sc_data[StatusChange::SC_STONE].timer == -1 + && md->sc_data[StatusChange::SC_FREEZE].timer == -1) { skill = sd->paramc[ATTR::DEX] - mob_db[md->mob_class].attrs[ATTR::DEX] + 10; @@ -2667,13 +2676,13 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl) */ int pc_steal_coin(struct map_session_data *sd, struct block_list *bl) { - if (sd != NULL && bl != NULL && bl->type == BL_MOB) + if (sd != NULL && bl != NULL && bl->type == BL::MOB) { int rate; struct mob_data *md = (struct mob_data *) bl; if (md && !md->state.steal_coin_flag - && md->sc_data[SC_STONE].timer == -1 - && md->sc_data[SC_FREEZE].timer == -1) + && md->sc_data[StatusChange::SC_STONE].timer == -1 + && md->sc_data[StatusChange::SC_FREEZE].timer == -1) { rate = (sd->status.base_level - mob_db[md->mob_class].lv) * 3 + sd->paramc[ATTR::DEX] * 2 + sd->paramc[ATTR::LUK] * 2; @@ -2697,7 +2706,7 @@ int pc_steal_coin(struct map_session_data *sd, struct block_list *bl) *------------------------------------------ */ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y, - int clrtype) + BeingRemoveWhy clrtype) { char mapname[24]; int m = 0, c = 0; @@ -2741,7 +2750,7 @@ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y if (map_mapname2ipport(mapname, &ip, &port) == 0) { skill_stop_dancing(&sd->bl, 1); - clif_clearchar_area(&sd->bl, clrtype & 0xffff); + clif_clearchar(&sd->bl, clrtype); skill_gangsterparadise(sd, 0); map_delblock(&sd->bl); memcpy(sd->mapname, mapname, 24); @@ -2785,7 +2794,7 @@ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y if (sd->mapname[0] && sd->bl.prev != NULL) { - clif_clearchar_area(&sd->bl, clrtype & 0xffff); + clif_clearchar(&sd->bl, clrtype); skill_gangsterparadise(sd, 0); map_delblock(&sd->bl); clif_changemap(sd, map[m].name, x, y); // [MouseJstr] @@ -2811,7 +2820,7 @@ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y * PCのランダムワープ *------------------------------------------ */ -int pc_randomwarp(struct map_session_data *sd, int type) +int pc_randomwarp(struct map_session_data *sd, BeingRemoveWhy type) { int x, y, c, i = 0; int m; @@ -2950,7 +2959,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) sd->bl.m, x - AREA_SIZE, y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE, dx, dy, - BL_NUL); + BL::NUL); x += dx; y += dy; @@ -2966,7 +2975,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) sd->bl.m, x - AREA_SIZE, y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE, -dx, -dy, - BL_NUL); + BL::NUL); sd->walktimer = -1; if (sd->status.party_id > 0) @@ -2979,7 +2988,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data) sd->bl.m, x - AREA_SIZE, y - AREA_SIZE, x + AREA_SIZE, y + AREA_SIZE, -dx, -dy, - BL_PC); + BL::PC); if (p_flag) sd->party_hp = -1; } @@ -3131,7 +3140,7 @@ int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y) sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, dx, dy, - BL_NUL); + BL::NUL); if (moveblock) map_delblock(&sd->bl); @@ -3144,7 +3153,7 @@ int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y) sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, -dx, -dy, - BL_NUL); + BL::NUL); if (sd->status.party_id > 0) { // パーティのHP情報通知検査 @@ -3156,7 +3165,7 @@ int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y) sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, -dx, -dy, - BL_PC); + BL::PC); if (flag) sd->party_hp = -1; } @@ -3232,7 +3241,7 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t) if (bl == NULL || bl->prev == NULL) return; - if (bl->type == BL_PC && pc_isdead((struct map_session_data *) bl)) + if (bl->type == BL::PC && pc_isdead((struct map_session_data *) bl)) return; // 同じmapでないなら攻撃しない @@ -3333,7 +3342,7 @@ int pc_attack(struct map_session_data *sd, int target_id, int type) if (bl == NULL) return 1; - if (bl->type == BL_NPC) + if (bl->type == BL::NPC) { // monster npcs [Valaris] npc_click(sd, RFIFOL(sd->fd, 2)); return 0; @@ -3394,9 +3403,9 @@ int pc_checkbaselevelup(struct map_session_data *sd) sd->status.base_level++; sd->status.status_point += (sd->status.base_level + 14) / 4; - clif_updatestatus(sd, SP_STATUSPOINT); - clif_updatestatus(sd, SP_BASELEVEL); - clif_updatestatus(sd, SP_NEXTBASEEXP); + clif_updatestatus(sd, SP::STATUSPOINT); + clif_updatestatus(sd, SP::BASELEVEL); + clif_updatestatus(sd, SP::NEXTBASEEXP); pc_calcstatus(sd, 0); pc_heal(sd, sd->status.max_hp, sd->status.max_sp); @@ -3411,6 +3420,12 @@ int pc_checkbaselevelup(struct map_session_data *sd) return 0; } +inline +int RAISE_COST(int x) +{ + return (x * (x - 1)) / 2; +} + /*======================================== * Compute the maximum for sd->skill_point, i.e., the max. number of skill points that can still be filled in *---------------------------------------- @@ -3420,15 +3435,12 @@ int pc_skillpt_potential(struct map_session_data *sd) { int potential = 0; -#define RAISE_COST(x) (((x)*((x)-1))>>1) - for (SkillID skill_id = SkillID(); skill_id < MAX_SKILL; skill_id = SkillID(uint16_t(skill_id) + 1)) if (sd->status.skill[skill_id].id != SkillID::ZERO && sd->status.skill[skill_id].lv < skill_db[skill_id].max_raise) potential += RAISE_COST(skill_db[skill_id].max_raise) - RAISE_COST(sd->status.skill[skill_id].lv); -#undef RAISE_COST return potential; } @@ -3452,9 +3464,9 @@ int pc_checkjoblevelup(struct map_session_data *sd) // job側レベルアップ処理 sd->status.job_exp -= next; - clif_updatestatus(sd, SP_NEXTJOBEXP); + clif_updatestatus(sd, SP::NEXTJOBEXP); sd->status.skill_point++; - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); MAP_LOG_PC(sd, "SKILLPOINTS-UP %d", sd->status.skill_point); @@ -3477,7 +3489,7 @@ int pc_checkjoblevelup(struct map_session_data *sd) int pc_gainexp(struct map_session_data *sd, int base_exp, int job_exp) { return pc_gainexp_reason(sd, base_exp, job_exp, - PC_GAINEXP_REASON_KILLING); + PC_GAINEXP_REASON::KILLING); } int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, @@ -3512,7 +3524,7 @@ int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, sd->status.base_exp += base_exp; // [Fate] Adjust experience points that healers can extract from this character - if (reason != PC_GAINEXP_REASON_HEALING) + if (reason != PC_GAINEXP_REASON::HEALING) { const int max_heal_xp = 20 + (sd->status.base_level * sd->status.base_level); @@ -3527,7 +3539,7 @@ int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, while (pc_checkbaselevelup(sd)); - clif_updatestatus(sd, SP_BASEEXP); + clif_updatestatus(sd, SP::BASEEXP); if (!battle_config.multi_level_up && pc_nextjobafter(sd)) { while (sd->status.job_exp + job_exp >= pc_nextjobafter(sd) @@ -3544,7 +3556,7 @@ int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, while (pc_checkjoblevelup(sd)); - clif_updatestatus(sd, SP_JOBEXP); + clif_updatestatus(sd, SP::JOBEXP); if (battle_config.disp_experience) { @@ -3637,7 +3649,7 @@ int pc_need_status_point(struct map_session_data *sd, SP type) nullpo_retr(-1, sd); - if (type < SP_STR || type > SP_LUK) + if (type < SP::STR || type > SP::LUK) return -1; val = sd->status.attrs[sp_to_attr(type)]; @@ -3654,16 +3666,16 @@ int pc_statusup(struct map_session_data *sd, SP type) nullpo_ret(sd); - if (SP_STR <= type && type <= SP_LUK) + if (SP::STR <= type && type <= SP::LUK) val = sd->status.attrs[sp_to_attr(type)]; need = pc_need_status_point(sd, type); - if (type < SP_STR || type > SP_LUK || need < 0 + if (type < SP::STR || type > SP::LUK || need < 0 || need > sd->status.status_point || val >= battle_config.max_parameter) { clif_statusupack(sd, type, 0, val); - clif_updatestatus(sd, SP_STATUSPOINT); + clif_updatestatus(sd, SP::STATUSPOINT); return 1; } val = ++sd->status.attrs[sp_to_attr(type)]; @@ -3672,7 +3684,7 @@ int pc_statusup(struct map_session_data *sd, SP type) { clif_updatestatus(sd, sp_to_usp(type)); } - clif_updatestatus(sd, SP_STATUSPOINT); + clif_updatestatus(sd, SP::STATUSPOINT); clif_updatestatus(sd, type); pc_calcstatus(sd, 0); clif_statusupack(sd, type, 1, val); @@ -3690,7 +3702,7 @@ int pc_statusup2(struct map_session_data *sd, SP type, int val) { nullpo_ret(sd); - if (type < SP_STR || type > SP_LUK) + if (type < SP::STR || type > SP::LUK) { clif_statusupack(sd, type, 0, 0); return 1; @@ -3725,7 +3737,7 @@ int pc_skillup(struct map_session_data *sd, SkillID skill_num) pc_calcstatus(sd, 0); clif_skillup(sd, skill_num); - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::SKILLPOINT); clif_skillinfoblock(sd); MAP_LOG_PC(sd, "SKILLUP %d %d %d", uint16_t(skill_num), sd->status.skill[skill_num].lv, skill_power(sd, skill_num)); @@ -3779,26 +3791,26 @@ int pc_resetlvl(struct map_session_data *sd, int type) sd->status.job_exp = 0; } - clif_updatestatus(sd, SP_STATUSPOINT); - clif_updatestatus(sd, SP_STR); - clif_updatestatus(sd, SP_AGI); - clif_updatestatus(sd, SP_VIT); - clif_updatestatus(sd, SP_INT); - clif_updatestatus(sd, SP_DEX); - clif_updatestatus(sd, SP_LUK); - clif_updatestatus(sd, SP_BASELEVEL); - clif_updatestatus(sd, SP_JOBLEVEL); - clif_updatestatus(sd, SP_STATUSPOINT); - clif_updatestatus(sd, SP_NEXTBASEEXP); - clif_updatestatus(sd, SP_NEXTJOBEXP); - clif_updatestatus(sd, SP_SKILLPOINT); - - clif_updatestatus(sd, SP_USTR); // Updates needed stat points - Valaris - clif_updatestatus(sd, SP_UAGI); - clif_updatestatus(sd, SP_UVIT); - clif_updatestatus(sd, SP_UINT); - clif_updatestatus(sd, SP_UDEX); - clif_updatestatus(sd, SP_ULUK); // End Addition + clif_updatestatus(sd, SP::STATUSPOINT); + clif_updatestatus(sd, SP::STR); + clif_updatestatus(sd, SP::AGI); + clif_updatestatus(sd, SP::VIT); + clif_updatestatus(sd, SP::INT); + clif_updatestatus(sd, SP::DEX); + clif_updatestatus(sd, SP::LUK); + clif_updatestatus(sd, SP::BASELEVEL); + clif_updatestatus(sd, SP::JOBLEVEL); + clif_updatestatus(sd, SP::STATUSPOINT); + clif_updatestatus(sd, SP::NEXTBASEEXP); + clif_updatestatus(sd, SP::NEXTJOBEXP); + clif_updatestatus(sd, SP::SKILLPOINT); + + clif_updatestatus(sd, SP::USTR); // Updates needed stat points - Valaris + clif_updatestatus(sd, SP::UAGI); + clif_updatestatus(sd, SP::UVIT); + clif_updatestatus(sd, SP::UINT); + clif_updatestatus(sd, SP::UDEX); + clif_updatestatus(sd, SP::ULUK); // End Addition for (EQUIP i : EQUIPs) { @@ -3830,7 +3842,7 @@ int pc_resetstate(struct map_session_data *sd) sd->status.status_point = stat_p[sd->status.base_level - 1]; - clif_updatestatus(sd, SP_STATUSPOINT); + clif_updatestatus(sd, SP::STATUSPOINT); for (ATTR attr : ATTRs) sd->status.attrs[attr] = 1; @@ -3863,7 +3875,7 @@ int pc_resetskill(struct map_session_data *sd) sd->status.skill[i].flags = SkillFlags::ZERO; } - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::SKILLPOINT); clif_skillinfoblock(sd); pc_calcstatus(sd, 0); @@ -3893,7 +3905,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, if (src) { - if (src->type == BL_PC) + if (src->type == BL::PC) { MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d", ((struct map_session_data *) src)->status.char_id, @@ -3917,7 +3929,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, if (sd->status.hp > 0) { // まだ生きているならHP更新 - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); sd->canlog_tick = gettick(); @@ -3945,10 +3957,10 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, pc_stop_walking(sd, 0); skill_castcancel(&sd->bl, 0); // 詠唱の中止 - clif_clearchar_area(&sd->bl, 1); + clif_clearchar(&sd->bl, BeingRemoveWhy::DEAD); pc_setglobalreg(sd, "PC_DIE_COUNTER", ++sd->die_counter); //死にカウンター書き込み skill_status_change_clear(&sd->bl, 0); // ステータス異常を解除する - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); pc_calcstatus(sd, 0); // [Fate] Reset magic sd->cast_tick = gettick(); @@ -3969,7 +3981,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, sd->status.base_exp -= (double) pc_nextbaseexp(sd) * (double) battle_config.death_penalty_base / 10000; - if (battle_config.pk_mode && src && src->type == BL_PC) + if (battle_config.pk_mode && src && src->type == BL::PC) sd->status.base_exp -= (double) pc_nextbaseexp(sd) * (double) battle_config.death_penalty_base / 10000; @@ -3980,21 +3992,21 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, sd->status.base_exp -= (double) sd->status.base_exp * (double) battle_config.death_penalty_base / 10000; - if (battle_config.pk_mode && src && src->type == BL_PC) + if (battle_config.pk_mode && src && src->type == BL::PC) sd->status.base_exp -= (double) sd->status.base_exp * (double) battle_config.death_penalty_base / 10000; } if (sd->status.base_exp < 0) sd->status.base_exp = 0; - clif_updatestatus(sd, SP_BASEEXP); + clif_updatestatus(sd, SP::BASEEXP); if (battle_config.death_penalty_type == 1 && battle_config.death_penalty_job > 0) sd->status.job_exp -= (double) pc_nextjobexp(sd) * (double) battle_config.death_penalty_job / 10000; - if (battle_config.pk_mode && src && src->type == BL_PC) + if (battle_config.pk_mode && src && src->type == BL::PC) sd->status.job_exp -= (double) pc_nextjobexp(sd) * (double) battle_config.death_penalty_job / 10000; @@ -4005,14 +4017,14 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, sd->status.job_exp -= (double) sd->status.job_exp * (double) battle_config.death_penalty_job / 10000; - if (battle_config.pk_mode && src && src->type == BL_PC) + if (battle_config.pk_mode && src && src->type == BL::PC) sd->status.job_exp -= (double) sd->status.job_exp * (double) battle_config.death_penalty_job / 10000; } if (sd->status.job_exp < 0) sd->status.job_exp = 0; - clif_updatestatus(sd, SP_JOBEXP); + clif_updatestatus(sd, SP::JOBEXP); } } //ナイトメアモードアイテムドロップ @@ -4086,7 +4098,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, if (!map[sd->bl.m].flag.pvp_nocalcrank) { sd->pvp_point -= 5; - if (src && src->type == BL_PC) + if (src && src->type == BL::PC) ((struct map_session_data *) src)->pvp_point++; //} //fixed wrong '{' placement by Lupus pc_setdead(sd); @@ -4098,11 +4110,11 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, pc_setstand(sd); pc_setrestartvalue(sd, 3); pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, - sd->status.save_point.y, 0); + sd->status.save_point.y, BeingRemoveWhy::GONE); } } - if (src && src->type == BL_PC) + if (src && src->type == BL::PC) { // [Fate] PK death, trigger scripts argrec_t arg[3]; @@ -4135,63 +4147,63 @@ int pc_readparam(struct map_session_data *sd, SP type) switch (type) { - case SP_SKILLPOINT: + case SP::SKILLPOINT: val = sd->status.skill_point; break; - case SP_STATUSPOINT: + case SP::STATUSPOINT: val = sd->status.status_point; break; - case SP_ZENY: + case SP::ZENY: val = sd->status.zeny; break; - case SP_BASELEVEL: + case SP::BASELEVEL: val = sd->status.base_level; break; - case SP_JOBLEVEL: + case SP::JOBLEVEL: val = sd->status.job_level; break; - case SP_CLASS: + case SP::CLASS: val = sd->status.species; break; - case SP_SEX: + case SP::SEX: val = sd->sex; break; - case SP_WEIGHT: + case SP::WEIGHT: val = sd->weight; break; - case SP_MAXWEIGHT: + case SP::MAXWEIGHT: val = sd->max_weight; break; - case SP_BASEEXP: + case SP::BASEEXP: val = sd->status.base_exp; break; - case SP_JOBEXP: + case SP::JOBEXP: val = sd->status.job_exp; break; - case SP_NEXTBASEEXP: + case SP::NEXTBASEEXP: val = pc_nextbaseexp(sd); break; - case SP_NEXTJOBEXP: + case SP::NEXTJOBEXP: val = pc_nextjobexp(sd); break; - case SP_HP: + case SP::HP: val = sd->status.hp; break; - case SP_MAXHP: + case SP::MAXHP: val = sd->status.max_hp; break; - case SP_SP: + case SP::SP: val = sd->status.sp; break; - case SP_MAXSP: + case SP::MAXSP: val = sd->status.max_sp; break; - case SP_STR: - case SP_AGI: - case SP_VIT: - case SP_INT: - case SP_DEX: - case SP_LUK: + case SP::STR: + case SP::AGI: + case SP::VIT: + case SP::INT: + case SP::DEX: + case SP::LUK: val = sd->status.attrs[sp_to_attr(type)]; break; } @@ -4211,7 +4223,7 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) switch (type) { - case SP_BASELEVEL: + case SP::BASELEVEL: if (val > sd->status.base_level) { for (i = 1; i <= (val - sd->status.base_level); i++) @@ -4220,14 +4232,14 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) } sd->status.base_level = val; sd->status.base_exp = 0; - clif_updatestatus(sd, SP_BASELEVEL); - clif_updatestatus(sd, SP_NEXTBASEEXP); - clif_updatestatus(sd, SP_STATUSPOINT); - clif_updatestatus(sd, SP_BASEEXP); + clif_updatestatus(sd, SP::BASELEVEL); + clif_updatestatus(sd, SP::NEXTBASEEXP); + clif_updatestatus(sd, SP::STATUSPOINT); + clif_updatestatus(sd, SP::BASEEXP); pc_calcstatus(sd, 0); pc_heal(sd, sd->status.max_hp, sd->status.max_sp); break; - case SP_JOBLEVEL: + case SP::JOBLEVEL: up_level -= 40; if (val >= sd->status.job_level) { @@ -4236,10 +4248,10 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) sd->status.skill_point += (val - sd->status.job_level); sd->status.job_level = val; sd->status.job_exp = 0; - clif_updatestatus(sd, SP_JOBLEVEL); - clif_updatestatus(sd, SP_NEXTJOBEXP); - clif_updatestatus(sd, SP_JOBEXP); - clif_updatestatus(sd, SP_SKILLPOINT); + clif_updatestatus(sd, SP::JOBLEVEL); + clif_updatestatus(sd, SP::NEXTJOBEXP); + clif_updatestatus(sd, SP::JOBEXP); + clif_updatestatus(sd, SP::SKILLPOINT); pc_calcstatus(sd, 0); clif_misceffect(&sd->bl, 1); } @@ -4247,23 +4259,23 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) { sd->status.job_level = val; sd->status.job_exp = 0; - clif_updatestatus(sd, SP_JOBLEVEL); - clif_updatestatus(sd, SP_NEXTJOBEXP); - clif_updatestatus(sd, SP_JOBEXP); + clif_updatestatus(sd, SP::JOBLEVEL); + clif_updatestatus(sd, SP::NEXTJOBEXP); + clif_updatestatus(sd, SP::JOBEXP); pc_calcstatus(sd, 0); } clif_updatestatus(sd, type); break; - case SP_SKILLPOINT: + case SP::SKILLPOINT: sd->status.skill_point = val; break; - case SP_STATUSPOINT: + case SP::STATUSPOINT: sd->status.status_point = val; break; - case SP_ZENY: + case SP::ZENY: sd->status.zeny = val; break; - case SP_BASEEXP: + case SP::BASEEXP: if (pc_nextbaseexp(sd) > 0) { sd->status.base_exp = val; @@ -4272,7 +4284,7 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) pc_checkbaselevelup(sd); } break; - case SP_JOBEXP: + case SP::JOBEXP: if (pc_nextjobexp(sd) > 0) { sd->status.job_exp = val; @@ -4281,33 +4293,33 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) pc_checkjoblevelup(sd); } break; - case SP_SEX: + case SP::SEX: sd->sex = val; break; - case SP_WEIGHT: + case SP::WEIGHT: sd->weight = val; break; - case SP_MAXWEIGHT: + case SP::MAXWEIGHT: sd->max_weight = val; break; - case SP_HP: + case SP::HP: sd->status.hp = val; break; - case SP_MAXHP: + case SP::MAXHP: sd->status.max_hp = val; break; - case SP_SP: + case SP::SP: sd->status.sp = val; break; - case SP_MAXSP: + case SP::MAXSP: sd->status.max_sp = val; break; - case SP_STR: - case SP_AGI: - case SP_VIT: - case SP_INT: - case SP_DEX: - case SP_LUK: + case SP::STR: + case SP::AGI: + case SP::VIT: + case SP::INT: + case SP::DEX: + case SP::LUK: sd->status.attrs[sp_to_attr(type)] = val; break; } @@ -4353,9 +4365,9 @@ int pc_heal(struct map_session_data *sd, int hp, int sp) if (sd->status.sp <= 0) sd->status.sp = 0; if (hp) - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); if (sp) - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::SP); if (sd->status.party_id > 0) { // on-the-fly party hp updates [Valaris] @@ -4481,9 +4493,9 @@ int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp) if (sd->status.sp <= 0) sd->status.sp = 0; if (hp) - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); if (sp) - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::SP); return 0; } @@ -4550,9 +4562,9 @@ int pc_percentheal(struct map_session_data *sd, int hp, int sp) } } if (hp) - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); if (sp) - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::SP); return 0; } @@ -4567,31 +4579,31 @@ int pc_changelook(struct map_session_data *sd, LOOK type, int val) switch (type) { - case LOOK_HAIR: + case LOOK::HAIR: sd->status.hair = val; break; - case LOOK_WEAPON: + case LOOK::WEAPON: sd->status.weapon = val; break; - case LOOK_HEAD_BOTTOM: + case LOOK::HEAD_BOTTOM: sd->status.head_bottom = val; break; - case LOOK_HEAD_TOP: + case LOOK::HEAD_TOP: sd->status.head_top = val; break; - case LOOK_HEAD_MID: + case LOOK::HEAD_MID: sd->status.head_mid = val; break; - case LOOK_HAIR_COLOR: + case LOOK::HAIR_COLOR: sd->status.hair_color = val; break; - case LOOK_CLOTHES_COLOR: + case LOOK::CLOTHES_COLOR: sd->status.clothes_color = val; break; - case LOOK_SHIELD: + case LOOK::SHIELD: sd->status.shield = val; break; - case LOOK_SHOES: + case LOOK::SHOES: break; } clif_changelook(&sd->bl, type, val); @@ -5047,15 +5059,15 @@ static int pc_signal_advanced_equipment_change(struct map_session_data *sd, int n) { if (bool(sd->status.inventory[n].equip & EPOS::SHOES)) - clif_changelook(&sd->bl, LOOK_SHOES, 0); + clif_changelook(&sd->bl, LOOK::SHOES, 0); if (bool(sd->status.inventory[n].equip & EPOS::GLOVES)) - clif_changelook(&sd->bl, LOOK_GLOVES, 0); + clif_changelook(&sd->bl, LOOK::GLOVES, 0); if (bool(sd->status.inventory[n].equip & EPOS::CAPE)) - clif_changelook(&sd->bl, LOOK_CAPE, 0); + clif_changelook(&sd->bl, LOOK::CAPE, 0); if (bool(sd->status.inventory[n].equip & EPOS::MISC1)) - clif_changelook(&sd->bl, LOOK_MISC1, 0); + clif_changelook(&sd->bl, LOOK::MISC1, 0); if (bool(sd->status.inventory[n].equip & EPOS::MISC2)) - clif_changelook(&sd->bl, LOOK_MISC2, 0); + clif_changelook(&sd->bl, LOOK::MISC2, 0); return 0; } @@ -5168,22 +5180,22 @@ int pc_equipitem(struct map_session_data *sd, int n, EPOS) else sd->status.shield = sd->weapontype2 = 0; pc_calcweapontype(sd); - clif_changelook(&sd->bl, LOOK_SHIELD, sd->status.shield); + clif_changelook(&sd->bl, LOOK::SHIELD, sd->status.shield); } if (bool(sd->status.inventory[n].equip & EPOS::LEGS)) { sd->status.head_bottom = view; - clif_changelook(&sd->bl, LOOK_HEAD_BOTTOM, sd->status.head_bottom); + clif_changelook(&sd->bl, LOOK::HEAD_BOTTOM, sd->status.head_bottom); } if (bool(sd->status.inventory[n].equip & EPOS::HAT)) { sd->status.head_top = view; - clif_changelook(&sd->bl, LOOK_HEAD_TOP, sd->status.head_top); + clif_changelook(&sd->bl, LOOK::HEAD_TOP, sd->status.head_top); } if (bool(sd->status.inventory[n].equip & EPOS::TORSO)) { sd->status.head_mid = view; - clif_changelook(&sd->bl, LOOK_HEAD_MID, sd->status.head_mid); + clif_changelook(&sd->bl, LOOK::HEAD_MID, sd->status.head_mid); } pc_signal_advanced_equipment_change(sd, n); @@ -5229,30 +5241,30 @@ int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type) { sd->status.shield = sd->weapontype2 = 0; pc_calcweapontype(sd); - clif_changelook(&sd->bl, LOOK_SHIELD, sd->status.shield); + clif_changelook(&sd->bl, LOOK::SHIELD, sd->status.shield); } if (bool(sd->status.inventory[n].equip & EPOS::LEGS)) { sd->status.head_bottom = 0; - clif_changelook(&sd->bl, LOOK_HEAD_BOTTOM, + clif_changelook(&sd->bl, LOOK::HEAD_BOTTOM, sd->status.head_bottom); } if (bool(sd->status.inventory[n].equip & EPOS::HAT)) { sd->status.head_top = 0; - clif_changelook(&sd->bl, LOOK_HEAD_TOP, sd->status.head_top); + clif_changelook(&sd->bl, LOOK::HEAD_TOP, sd->status.head_top); } if (bool(sd->status.inventory[n].equip & EPOS::TORSO)) { sd->status.head_mid = 0; - clif_changelook(&sd->bl, LOOK_HEAD_MID, sd->status.head_mid); + clif_changelook(&sd->bl, LOOK::HEAD_MID, sd->status.head_mid); } pc_signal_advanced_equipment_change(sd, n); - if (sd->sc_data[SC_BROKNWEAPON].timer != -1 + if (sd->sc_data[StatusChange::SC_BROKNWEAPON].timer != -1 && bool(sd->status.inventory[n].equip & EPOS::WEAPON) && sd->status.inventory[n].broken == 1) - skill_status_change_end(&sd->bl, SC_BROKNWEAPON, -1); + skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, -1); clif_unequipitemack(sd, n, sd->status.inventory[n].equip, 1); sd->status.inventory[n].equip = EPOS::ZERO; @@ -5391,7 +5403,7 @@ int pc_checkoverhp(struct map_session_data *sd) if (sd->status.hp > sd->status.max_hp) { sd->status.hp = sd->status.max_hp; - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); return 2; } @@ -5407,7 +5419,7 @@ int pc_checkoversp(struct map_session_data *sd) if (sd->status.sp > sd->status.max_sp) { sd->status.sp = sd->status.max_sp; - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::SP); return 2; } @@ -5448,7 +5460,7 @@ int pc_calc_pvprank(struct map_session_data *sd) sd->pvp_rank = 1; map_foreachinarea(std::bind(pc_calc_pvprank_sub, ph::_1, sd), sd->bl.m, 0, 0, m->xs, m->ys, - BL_PC); + BL::PC); return sd->pvp_rank; } @@ -5643,7 +5655,7 @@ int pc_natural_heal_hp(struct map_session_data *sd) } } if (bhp != sd->status.hp) - clif_updatestatus(sd, SP_HP); + clif_updatestatus(sd, SP::HP); if (sd->nshealhp > 0) { @@ -5713,7 +5725,7 @@ int pc_natural_heal_sp(struct map_session_data *sd) } if (bsp != sd->status.sp) - clif_updatestatus(sd, SP_SP); + clif_updatestatus(sd, SP::SP); if (sd->nshealsp > 0) { @@ -5797,13 +5809,13 @@ void pc_natural_heal_sub(struct map_session_data *sd) pc_calcstatus(sd, 0); } - if (sd->sc_data[SC_HALT_REGENERATE].timer != -1) + if (sd->sc_data[StatusChange::SC_HALT_REGENERATE].timer != -1) return; if (sd->quick_regeneration_hp.amount || sd->quick_regeneration_sp.amount) { int hp_bonus = pc_quickregenerate_effect(&sd->quick_regeneration_hp, - (sd->sc_data[SC_POISON].timer == -1 || sd->sc_data[SC_SLOWPOISON].timer != -1) ? sd->nhealhp : 1); // [fate] slow down when poisoned + (sd->sc_data[StatusChange::SC_POISON].timer == -1 || sd->sc_data[StatusChange::SC_SLOWPOISON].timer != -1) ? sd->nhealhp : 1); // [fate] slow down when poisoned int sp_bonus = pc_quickregenerate_effect(&sd->quick_regeneration_sp, sd->nhealsp); @@ -5812,11 +5824,11 @@ void pc_natural_heal_sub(struct map_session_data *sd) skill_update_heal_animation(sd); // if needed. // -- moonsoul (if conditions below altered to disallow natural healing if under berserk status) - if ((sd->sc_data[SC_FLYING_BACKPACK].timer != -1 + if ((sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer != -1 || battle_config.natural_heal_weight_rate > 100 || sd->weight * 100 / sd->max_weight < battle_config.natural_heal_weight_rate) && !pc_isdead(sd) - && sd->sc_data[SC_POISON].timer == -1) + && sd->sc_data[StatusChange::SC_POISON].timer == -1) { pc_natural_heal_hp(sd); pc_natural_heal_sp(sd); @@ -6068,15 +6080,15 @@ void pc_invisibility(struct map_session_data *sd, int enabled) { if (enabled && !bool(sd->status.option & Option::INVISIBILITY)) { - clif_clearchar_area(&sd->bl, 3); + clif_clearchar(&sd->bl, BeingRemoveWhy::WARPED); sd->status.option |= Option::INVISIBILITY; - clif_status_change(&sd->bl, CLIF_OPTION_SC_INVISIBILITY, 1); + clif_status_change(&sd->bl, StatusChange::CLIF_OPTION_SC_INVISIBILITY, 1); } else if (!enabled) { sd->status.option &= ~Option::INVISIBILITY; - clif_status_change(&sd->bl, CLIF_OPTION_SC_INVISIBILITY, 0); - pc_setpos(sd, map[sd->bl.m].name, sd->bl.x, sd->bl.y, 3); + clif_status_change(&sd->bl, StatusChange::CLIF_OPTION_SC_INVISIBILITY, 0); + pc_setpos(sd, map[sd->bl.m].name, sd->bl.x, sd->bl.y, BeingRemoveWhy::WARPED); } } @@ -6085,7 +6097,7 @@ int pc_logout(struct map_session_data *sd) // [fate] Player logs out if (!sd) return 0; - if (sd->sc_data[SC_POISON].timer != -1) + if (sd->sc_data[StatusChange::SC_POISON].timer != -1) sd->status.hp = 1; // Logging out while poisoned -> bad /* diff --git a/src/map/pc.hpp b/src/map/pc.hpp index 9b0f4ef..bc565ab 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -3,6 +3,7 @@ #include "pc.t.hpp" +#include "clif.t.hpp" #include "map.hpp" inline @@ -69,9 +70,9 @@ int pc_checkequip(struct map_session_data *sd, EPOS pos); int pc_walktoxy(struct map_session_data *, int, int); int pc_stop_walking(struct map_session_data *, int); int pc_movepos(struct map_session_data *, int, int); -int pc_setpos(struct map_session_data *, const char *, int, int, int); +int pc_setpos(struct map_session_data *, const char *, int, int, BeingRemoveWhy); int pc_setsavepoint(struct map_session_data *, const char *, int, int); -int pc_randomwarp(struct map_session_data *sd, int type); +int pc_randomwarp(struct map_session_data *sd, BeingRemoveWhy type); ADDITEM pc_checkadditem(struct map_session_data *, int, int); int pc_inventoryblank(struct map_session_data *); diff --git a/src/map/pc.t.hpp b/src/map/pc.t.hpp index 3a21691..26e4d94 100644 --- a/src/map/pc.t.hpp +++ b/src/map/pc.t.hpp @@ -6,12 +6,8 @@ enum class PC_GAINEXP_REASON { KILLING = 0, -#define PC_GAINEXP_REASON_KILLING PC_GAINEXP_REASON::KILLING HEALING = 1, -#define PC_GAINEXP_REASON_HEALING PC_GAINEXP_REASON::HEALING - // temporary rename to avoid collision with npc subtypes - SCRIPT_ = 2, -#define PC_GAINEXP_REASON_SCRIPT PC_GAINEXP_REASON::SCRIPT_ + SCRIPT = 2, COUNT, }; @@ -19,11 +15,8 @@ enum class PC_GAINEXP_REASON enum class ADDITEM { EXIST, -#define ADDITEM_EXIST ADDITEM::EXIST NEW, -#define ADDITEM_NEW ADDITEM::NEW OVERAMOUNT, -#define ADDITEM_OVERAMOUNT ADDITEM::OVERAMOUNT // when used as error in nullpo_retr ZERO = 0, diff --git a/src/map/script.cpp b/src/map/script.cpp index c7bd9cd..3228160 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -37,7 +37,7 @@ //#define DEBUG_DISP //#define DEBUG_RUN -#define SCRIPT_BLOCK_SIZE 256 +constexpr int SCRIPT_BLOCK_SIZE = 256; enum { LABEL_NEXTLINE = 1, LABEL_START }; static @@ -72,7 +72,7 @@ struct dbt *mapregstr_db = NULL; static int mapreg_dirty = -1; char mapreg_txt[256] = "save/mapreg.txt"; -#define MAPREG_AUTOSAVE_INTERVAL (10*1000) +constexpr int MAPREG_AUTOSAVE_INTERVAL = 10 * 1000; static struct dbt *scriptlabel_db = NULL; @@ -1625,14 +1625,14 @@ void builtin_warp(ScriptState *st) x = conv_num(st, &(st->stack->stack_data[st->start + 3])); y = conv_num(st, &(st->stack->stack_data[st->start + 4])); if (strcmp(str, "Random") == 0) - pc_randomwarp(sd, 3); + pc_randomwarp(sd, BeingRemoveWhy::WARPED); else if (strcmp(str, "SavePoint") == 0) { if (map[sd->bl.m].flag.noreturn) // 蝶禁止 return; pc_setpos(sd, sd->status.save_point.map, - sd->status.save_point.x, sd->status.save_point.y, 3); + sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::WARPED); } else if (strcmp(str, "Save") == 0) { @@ -1640,10 +1640,10 @@ void builtin_warp(ScriptState *st) return; pc_setpos(sd, sd->status.save_point.map, - sd->status.save_point.x, sd->status.save_point.y, 3); + sd->status.save_point.x, sd->status.save_point.y, BeingRemoveWhy::WARPED); } else - pc_setpos(sd, str, x, y, 0); + pc_setpos(sd, str, x, y, BeingRemoveWhy::GONE); } /*========================================== @@ -1654,9 +1654,9 @@ static void builtin_areawarp_sub(struct block_list *bl, const char *mapname, int x, int y) { if (strcmp(mapname, "Random") == 0) - pc_randomwarp((struct map_session_data *) bl, 3); + pc_randomwarp((struct map_session_data *) bl, BeingRemoveWhy::WARPED); else - pc_setpos((struct map_session_data *) bl, mapname, x, y, 0); + pc_setpos((struct map_session_data *) bl, mapname, x, y, BeingRemoveWhy::GONE); } static @@ -1678,7 +1678,7 @@ void builtin_areawarp(ScriptState *st) return; map_foreachinarea(std::bind(builtin_areawarp_sub, ph::_1, str, x, y), - m, x0, y0, x1, y1, BL_PC); + m, x0, y0, x1, y1, BL::PC); } /*========================================== @@ -2770,7 +2770,7 @@ void builtin_getexp(ScriptState *st) if (base < 0 || job < 0) return; if (sd) - pc_gainexp_reason(sd, base, job, PC_GAINEXP_REASON_SCRIPT); + pc_gainexp_reason(sd, base, job, PC_GAINEXP_REASON::SCRIPT); } @@ -2856,7 +2856,7 @@ void builtin_killmonster(ScriptState *st) if ((m = map_mapname2mapid(mapname)) < 0) return; map_foreachinarea(std::bind(builtin_killmonster_sub, ph::_1, event, allflag), - m, 0, 0, map[m].xs, map[m].ys, BL_MOB); + m, 0, 0, map[m].xs, map[m].ys, BL::MOB); } static @@ -2874,7 +2874,7 @@ void builtin_killmonsterall(ScriptState *st) if ((m = map_mapname2mapid(mapname)) < 0) return; map_foreachinarea(builtin_killmonsterall_sub, - m, 0, 0, map[m].xs, map[m].ys, BL_MOB); + m, 0, 0, map[m].xs, map[m].ys, BL::MOB); } /*========================================== @@ -3041,7 +3041,7 @@ void builtin_mapannounce(ScriptState *st) if ((m = map_mapname2mapid(mapname)) < 0) return; map_foreachinarea(std::bind(builtin_mapannounce_sub, ph::_1, str, flag & 0x10), - m, 0, 0, map[m].xs, map[m].ys, BL_PC); + m, 0, 0, map[m].xs, map[m].ys, BL::PC); } /*========================================== @@ -3121,7 +3121,7 @@ void builtin_getareausers(ScriptState *st) return; } map_foreachinarea(std::bind(living ? builtin_getareausers_living_sub: builtin_getareausers_sub, ph::_1, &users), - m, x0, y0, x1, y1, BL_PC); + m, x0, y0, x1, y1, BL::PC); push_val(st->stack, ScriptCode::INT, users); } @@ -3186,10 +3186,10 @@ void builtin_getareadropitem(ScriptState *st) } if (delitems) map_foreachinarea(std::bind(builtin_getareadropitem_sub_anddelete, ph::_1, item, &amount), - m, x0, y0, x1, y1, BL_ITEM); + m, x0, y0, x1, y1, BL::ITEM); else map_foreachinarea(std::bind(builtin_getareadropitem_sub, ph::_1, item, &amount), - m, x0, y0, x1, y1, BL_ITEM); + m, x0, y0, x1, y1, BL::ITEM); push_val(st->stack, ScriptCode::INT, amount); } @@ -3663,7 +3663,7 @@ void builtin_mapwarp(ScriptState *st) // Added by RoVeRT return; map_foreachinarea(std::bind(builtin_areawarp_sub, ph::_1, str, x, y), - m, x0, y0, x1, y1, BL_PC); + m, x0, y0, x1, y1, BL::PC); } static @@ -3695,7 +3695,7 @@ void builtin_mobcount(ScriptState *st) // Added by RoVeRT return; } map_foreachinarea(std::bind(builtin_mobcount_sub, ph::_1, event, &c), - m, 0, 0, map[m].xs, map[m].ys, BL_MOB); + m, 0, 0, map[m].xs, map[m].ys, BL::MOB); push_val(st->stack, ScriptCode::INT, (c - 1)); @@ -3876,7 +3876,7 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st) SkillID skill_id = skill_pool_skills[i]; if (sd->status.skill[skill_id].id == skill_id - && !bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)) + && !bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { pc_setreg(sd, add_str("@skilllist_id") + (count << 24), uint16_t(sd->status.skill[skill_id].id)); @@ -4157,31 +4157,31 @@ void builtin_getlook(ScriptState *st) int val = -1; switch (type) { - case LOOK_HAIR: //1 + case LOOK::HAIR: //1 val = sd->status.hair; break; - case LOOK_WEAPON: //2 + case LOOK::WEAPON: //2 val = sd->status.weapon; break; - case LOOK_HEAD_BOTTOM: //3 + case LOOK::HEAD_BOTTOM: //3 val = sd->status.head_bottom; break; - case LOOK_HEAD_TOP: //4 + case LOOK::HEAD_TOP: //4 val = sd->status.head_top; break; - case LOOK_HEAD_MID: //5 + case LOOK::HEAD_MID: //5 val = sd->status.head_mid; break; - case LOOK_HAIR_COLOR: //6 + case LOOK::HAIR_COLOR: //6 val = sd->status.hair_color; break; - case LOOK_CLOTHES_COLOR: //7 + case LOOK::CLOTHES_COLOR: //7 val = sd->status.clothes_color; break; - case LOOK_SHIELD: //8 + case LOOK::SHIELD: //8 val = sd->status.shield; break; - case LOOK_SHOES: //9 + case LOOK::SHOES: //9 break; } @@ -4249,7 +4249,7 @@ void builtin_areatimer(ScriptState *st) return; map_foreachinarea(std::bind(builtin_areatimer_sub, ph::_1, tick, event), - m, x0, y0, x1, y1, BL_PC); + m, x0, y0, x1, y1, BL::PC); } /*========================================== @@ -4379,7 +4379,12 @@ int pop_val(ScriptState *st) return 0; } -#define isstr(c) ((c).type==ScriptCode::STR || (c).type==ScriptCode::CONSTSTR) +static +bool isstr(struct script_data& c) +{ + return c.type == ScriptCode::STR + || c.type == ScriptCode::CONSTSTR; +} /*========================================== * 加算演算子 diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp index 78d3f34..9c0ea8b 100644 --- a/src/map/skill-pools.cpp +++ b/src/map/skill-pools.cpp @@ -29,7 +29,7 @@ int skill_pool(struct map_session_data *sd, SkillID *skills) for (i = 0; count < MAX_SKILL_POOL && i < skill_pool_skills_size; i++) { SkillID skill_id = skill_pool_skills[i]; - if (bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)) + if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { if (skills) skills[count] = skill_id; @@ -47,17 +47,17 @@ int skill_pool_size(struct map_session_data *sd) int skill_pool_max(struct map_session_data *sd) { - return sd->status.skill[TMW_SKILLPOOL].lv; + return sd->status.skill[SkillID::TMW_SKILLPOOL].lv; } int skill_pool_activate(struct map_session_data *sd, SkillID skill_id) { - if (bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)) + if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) return 0; // Already there else if (sd->status.skill[skill_id].id == skill_id // knows the skill && (skill_pool_size(sd) < skill_pool_max(sd))) { - sd->status.skill[skill_id].flags |= SKILL_POOL_ACTIVATED; + sd->status.skill[skill_id].flags |= SkillFlags::POOL_ACTIVATED; pc_calcstatus(sd, 0); MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d", uint16_t(skill_id), sd->status.skill[skill_id].lv, @@ -70,14 +70,14 @@ int skill_pool_activate(struct map_session_data *sd, SkillID skill_id) bool skill_pool_is_activated(struct map_session_data *sd, SkillID skill_id) { - return bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED); + return bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED); } int skill_pool_deactivate(struct map_session_data *sd, SkillID skill_id) { - if (bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)) + if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { - sd->status.skill[skill_id].flags &= ~SKILL_POOL_ACTIVATED; + sd->status.skill[skill_id].flags &= ~SkillFlags::POOL_ACTIVATED; MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d", uint16_t(skill_id)); pc_calcstatus(sd, 0); return 0; @@ -87,7 +87,7 @@ int skill_pool_deactivate(struct map_session_data *sd, SkillID skill_id) } // Yields the stat associated with a skill. -// Returns zero if none, or SP_STR, SP_VIT, ... otherwise +// Returns zero if none, or SP::STR, SP::VIT, ... otherwise static SP skill_stat(SkillID skill_id) { @@ -118,7 +118,7 @@ int skill_power(struct map_session_data *sd, SkillID skill_id) int skill_power_bl(struct block_list *bl, SkillID skill) { - if (bl->type == BL_PC) + if (bl->type == BL::PC) return skill_power((struct map_session_data *) bl, skill); else return 0; diff --git a/src/map/skill.cpp b/src/map/skill.cpp index a93f375..ed9e551 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -20,37 +20,37 @@ struct skill_name_db skill_names[] = { - {AC_OWL, "OWL", "Owl's_Eye"}, - - {NPC_EMOTION, "EMOTION", "NPC_EMOTION"}, - {NPC_POISON, "POISON", "NPC_POISON"}, - {NPC_SELFDESTRUCTION, "SELFDESTRUCTION", "Kabooooom!"}, - {NPC_SUMMONSLAVE, "SUMMONSLAVE", "NPC_SUMMONSLAVE"}, - - {NV_EMOTE, "EMOTE", "Emote_Skill"}, - {NV_TRADE, "TRADE", "Trade_Skill"}, - {NV_PARTY, "PARTY", "Party_Skill"}, - - {TMW_MAGIC, "MAGIC", "General Magic"}, - {TMW_MAGIC_LIFE, "MAGIC_LIFE", "Life Magic"}, - {TMW_MAGIC_WAR, "MAGIC_WAR", "War Magic"}, - {TMW_MAGIC_TRANSMUTE, "MAGIC_TRANSMUTE", "Transmutation Magic"}, - {TMW_MAGIC_NATURE, "MAGIC_NATURE", "Nature Magic"}, - {TMW_MAGIC_ETHER, "MAGIC_ETHER", "Astral Magic"}, - {TMW_MAGIC_DARK, "MAGIC_DARK", "Dark Magic"}, - {TMW_MAGIC_LIGHT, "MAGIC_LIGHT", "Light Magic"}, - - {TMW_BRAWLING, "BRAWLING", "Brawling"}, - {TMW_LUCKY_COUNTER, "LUCKY_COUNTER", "Lucky Counter"}, - {TMW_SPEED, "SPEED", "Speed"}, - {TMW_RESIST_POISON, "RESIST_POISON", "Resist Poison"}, - {TMW_ASTRAL_SOUL, "ASTRAL_SOUL", "Astral Soul"}, - {TMW_RAGING, "RAGING", "Raging"}, + {SkillID::AC_OWL, "OWL", "Owl's_Eye"}, + + {SkillID::NPC_EMOTION, "EMOTION", "NPC_EMOTION"}, + {SkillID::NPC_POISON, "POISON", "NPC_POISON"}, + {SkillID::NPC_SELFDESTRUCTION, "SELFDESTRUCTION", "Kabooooom!"}, + {SkillID::NPC_SUMMONSLAVE, "SUMMONSLAVE", "NPC_SUMMONSLAVE"}, + + {SkillID::NV_EMOTE, "EMOTE", "Emote_Skill"}, + {SkillID::NV_TRADE, "TRADE", "Trade_Skill"}, + {SkillID::NV_PARTY, "PARTY", "Party_Skill"}, + + {SkillID::TMW_MAGIC, "MAGIC", "General Magic"}, + {SkillID::TMW_MAGIC_LIFE, "MAGIC_LIFE", "Life Magic"}, + {SkillID::TMW_MAGIC_WAR, "MAGIC_WAR", "War Magic"}, + {SkillID::TMW_MAGIC_TRANSMUTE, "MAGIC_TRANSMUTE", "Transmutation Magic"}, + {SkillID::TMW_MAGIC_NATURE, "MAGIC_NATURE", "Nature Magic"}, + {SkillID::TMW_MAGIC_ETHER, "MAGIC_ETHER", "Astral Magic"}, + {SkillID::TMW_MAGIC_DARK, "MAGIC_DARK", "Dark Magic"}, + {SkillID::TMW_MAGIC_LIGHT, "MAGIC_LIGHT", "Light Magic"}, + + {SkillID::TMW_BRAWLING, "BRAWLING", "Brawling"}, + {SkillID::TMW_LUCKY_COUNTER, "LUCKY_COUNTER", "Lucky Counter"}, + {SkillID::TMW_SPEED, "SPEED", "Speed"}, + {SkillID::TMW_RESIST_POISON, "RESIST_POISON", "Resist Poison"}, + {SkillID::TMW_ASTRAL_SOUL, "ASTRAL_SOUL", "Astral Soul"}, + {SkillID::TMW_RAGING, "RAGING", "Raging"}, {SkillID::ZERO, nullptr, nullptr} }; -earray skill_db; +earray skill_db; static @@ -162,21 +162,21 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl, if (skilllv < 0) return 0; - if (src->type == BL_PC) + if (src->type == BL::PC) { sd = (struct map_session_data *) src; nullpo_ret(sd); } - else if (src->type == BL_MOB) + else if (src->type == BL::MOB) { md = (struct mob_data *) src; nullpo_ret(md); //未使用? } sc_def_phys_shield_spell = 0; - if (battle_get_sc_data(bl)[SC_PHYS_SHIELD].timer != -1) + if (battle_get_sc_data(bl)[StatusChange::SC_PHYS_SHIELD].timer != -1) sc_def_phys_shield_spell = - battle_get_sc_data(bl)[SC_PHYS_SHIELD].val1; + battle_get_sc_data(bl)[StatusChange::SC_PHYS_SHIELD].val1; //対象の耐性 luk = battle_get_luk(bl); @@ -187,7 +187,7 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl, //自分の耐性 luk = battle_get_luk(src); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) { if (sc_def_mdef > 50) sc_def_mdef = 50; @@ -207,11 +207,11 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl, switch (skillid) { - case NPC_POISON: + case SkillID::NPC_POISON: if (MRAND(100) < 50 - (sc_def_vit >> 2) - (sc_def_phys_shield_spell) + (skilllv >> 2)) - skill_status_change_start(bl, SC_POISON, + skill_status_change_start(bl, StatusChange::SC_POISON, skilllv, 0, 0, 0, skilllv, 0); break; } @@ -250,15 +250,15 @@ int skill_attack(BF attack_type, struct block_list *src, return 0; if (src->prev == NULL || dsrc->prev == NULL || bl->prev == NULL) //prevよくわからない※ return 0; - if (src->type == BL_PC && pc_isdead((struct map_session_data *) src)) //術者?がPCですでに死んでいたら何もしない + if (src->type == BL::PC && pc_isdead((struct map_session_data *) src)) //術者?がPCですでに死んでいたら何もしない return 0; - if (dsrc->type == BL_PC && pc_isdead((struct map_session_data *) dsrc)) //術者?がPCですでに死んでいたら何もしない + if (dsrc->type == BL::PC && pc_isdead((struct map_session_data *) dsrc)) //術者?がPCですでに死んでいたら何もしない return 0; - if (bl->type == BL_PC && pc_isdead((struct map_session_data *) bl)) //対象がPCですでに死んでいたら何もしない + if (bl->type == BL::PC && pc_isdead((struct map_session_data *) bl)) //対象がPCですでに死んでいたら何もしない return 0; - if (src->type == BL_PC && ((struct map_session_data *) src)->chatID) //術者がPCでチャット中なら何もしない + if (src->type == BL::PC && ((struct map_session_data *) src)->chatID) //術者がPCでチャット中なら何もしない return 0; - if (dsrc->type == BL_PC && ((struct map_session_data *) dsrc)->chatID) //術者がPCでチャット中なら何もしない + if (dsrc->type == BL::PC && ((struct map_session_data *) dsrc)->chatID) //術者がPCでチャット中なら何もしない return 0; //何もしない判定ここまで @@ -277,7 +277,7 @@ int skill_attack(BF attack_type, struct block_list *src, switch (skillid) { - case NPC_SELFDESTRUCTION: + case SkillID::NPC_SELFDESTRUCTION: break; default: clif_skill_damage(dsrc, bl, tick, dmg.amotion, dmg.dmotion, @@ -295,12 +295,12 @@ int skill_attack(BF attack_type, struct block_list *src, { struct map_session_data *sd = (struct map_session_data *) bl; nullpo_ret(sd); - if (bl->type != BL_PC || (sd && !pc_isdead(sd))) + if (bl->type != BL::PC || (sd && !pc_isdead(sd))) { if (damage > 0) skill_additional_effect(src, bl, skillid, skilllv, attack_type, tick); - if (bl->type == BL_MOB && src != bl) /* スキル使用条件のMOBスキル */ + if (bl->type == BL::MOB && src != bl) /* スキル使用条件のMOBスキル */ { struct mob_data *md = (struct mob_data *) bl; nullpo_ret(md); @@ -308,7 +308,7 @@ int skill_attack(BF attack_type, struct block_list *src, { int target; target = md->target_id; - if (src->type == BL_PC) + if (src->type == BL::PC) md->target_id = src->id; mobskill_use(md, tick, MobSkillCondition::ANY, skillid); md->target_id = target; @@ -319,8 +319,8 @@ int skill_attack(BF attack_type, struct block_list *src, } } - if (src->type == BL_PC - && bool(dmg.flag & BF_WEAPON) + if (src->type == BL::PC + && bool(dmg.flag & BF::WEAPON) && src != bl && src == dsrc && damage > 0) @@ -368,7 +368,7 @@ void skill_area_sub(struct block_list *bl, { nullpo_retv(bl); - if (bl->type != BL_PC && bl->type != BL_MOB) + if (bl->type != BL::PC && bl->type != BL::MOB) return; if (battle_check_target(src, bl, flag) > 0) @@ -398,35 +398,35 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl, nullpo_retr(1, src); nullpo_retr(1, bl); - if (src->type == BL_PC) + if (src->type == BL::PC) sd = (struct map_session_data *) src; if (sd && pc_isdead(sd)) return 1; if (bl->prev == NULL) return 1; - if (bl->type == BL_PC && pc_isdead((struct map_session_data *) bl)) + if (bl->type == BL::PC && pc_isdead((struct map_session_data *) bl)) return 1; map_freeblock_lock(); switch (skillid) { - case NPC_POISON: - skill_attack(BF_WEAPON, src, src, bl, skillid, skilllv, tick, + case SkillID::NPC_POISON: + skill_attack(BF::WEAPON, src, src, bl, skillid, skilllv, tick, flag); break; - case NPC_SELFDESTRUCTION: /* 自爆 */ + case SkillID::NPC_SELFDESTRUCTION: /* 自爆 */ if (flag.lo & 1) { /* 個別にダメージを与える */ - if (src->type == BL_MOB) + if (src->type == BL::MOB) { struct mob_data *mb = (struct mob_data *) src; nullpo_retr(1, mb); mb->hp = skill_area_temp_hp; if (bl->id != skill_area_temp_id) - skill_attack(BF_MISC, src, src, bl, - NPC_SELFDESTRUCTION, skilllv, tick, + skill_attack(BF::MISC, src, src, bl, + SkillID::NPC_SELFDESTRUCTION, skilllv, tick, flag); mb->hp = 1; } @@ -440,7 +440,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl, skill_area_temp_hp = battle_get_hp(src); map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id), bl->m, bl->x - 5, bl->y - 5, - bl->x + 5, bl->y + 5, BL_NUL); + bl->x + 5, bl->y + 5, BL::NUL); battle_damage(src, src, md->hp, 0); } } @@ -453,7 +453,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl, if (flag.lo & 3) { if (bl->id != skill_area_temp_id) - skill_attack(BF_WEAPON, src, src, bl, skillid, + skill_attack(BF::WEAPON, src, src, bl, skillid, skilllv, tick, BCT_mid_x05); } else @@ -462,7 +462,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl, skill_area_temp_id = bl->id; map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id), bl->m, bl->x - 0, bl->y - 0, - bl->x + 0, bl->y + 0, BL_NUL); + bl->x + 0, bl->y + 0, BL::NUL); } } break; @@ -481,7 +481,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl, *------------------------------------------ */ // skillid.nk == 1 -// so skillid in (NPC_SUMMONSLAVE, NPC_EMOTION) +// so skillid in (SkillID::NPC_SUMMONSLAVE, SkillID::NPC_EMOTION) int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, SkillID skillid, int skilllv, unsigned int, BCT) @@ -495,9 +495,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, nullpo_retr(1, src); nullpo_retr(1, bl); - if (src->type == BL_PC) + if (src->type == BL::PC) sd = (struct map_session_data *) src; - else if (src->type == BL_MOB) + else if (src->type == BL::MOB) md = (struct mob_data *) src; sc_def_vit = 100 - (3 + battle_get_vit(bl) + battle_get_luk(bl) / 3); @@ -505,12 +505,12 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, sc_def_mdef = 100 - (3 + battle_get_mdef(bl) + battle_get_luk(bl) / 3); strip_fix = battle_get_dex(src) - battle_get_dex(bl); - if (bl->type == BL_PC) + if (bl->type == BL::PC) { dstsd = (struct map_session_data *) bl; nullpo_retr(1, dstsd); } - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) { dstmd = (struct mob_data *) bl; nullpo_retr(1, dstmd); @@ -536,17 +536,17 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, map_freeblock_lock(); switch (skillid) { - case NPC_SUMMONSLAVE: + case SkillID::NPC_SUMMONSLAVE: if (md && !md->master_id) { mob_summonslave(md, mob_db[md->mob_class].skill[md->skillidx].val, skilllv, - (true) ? 1 : 0); + 1); } break; - case NPC_EMOTION: + case SkillID::NPC_EMOTION: if (md) clif_emotion(&md->bl, mob_db[md->mob_class].skill[md->skillidx].val[0]); @@ -572,7 +572,7 @@ int skill_castfix(struct block_list *bl, int time) nullpo_ret(bl); - if (bl->type == BL_MOB) + if (bl->type == BL::MOB) { // Crash fix [Valaris] md = (struct mob_data *) bl; skill = md->skillid; @@ -587,16 +587,16 @@ int skill_castfix(struct block_list *bl, int time) sc_data = battle_get_sc_data(bl); dex = battle_get_dex(bl); - if (skill > MAX_SKILL_DB /*|| skill < SkillID()*/) + if (skill > SkillID::MAX_SKILL_DB /*|| skill < SkillID()*/) return 0; castnodex = skill_get_castnodex(skill, lv); if (time == 0) return 0; - if (castnodex > 0 && bl->type == BL_PC) + if (castnodex > 0 && bl->type == BL::PC) castrate = 100; - else if (castnodex <= 0 && bl->type == BL_PC) + else if (castnodex <= 0 && bl->type == BL::PC) { castrate = 100; time = @@ -623,7 +623,7 @@ int skill_delayfix(struct block_list *bl, int time) if (time <= 0) return 0; - if (bl->type == BL_PC) + if (bl->type == BL::PC) { if (battle_config.delay_dependon_dex) /* dexの影響を計算する */ time = @@ -646,7 +646,7 @@ int skill_castcancel(struct block_list *bl, int) nullpo_ret(bl); - if (bl->type == BL_PC) + if (bl->type == BL::PC) { struct map_session_data *sd = (struct map_session_data *) bl; unsigned long tick = gettick(); @@ -656,7 +656,7 @@ int skill_castcancel(struct block_list *bl, int) return 0; } - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) { struct mob_data *md = (struct mob_data *) bl; nullpo_ret(md); @@ -754,7 +754,7 @@ int skill_status_change_active(struct block_list *bl, StatusChange type) eptr sc_data; nullpo_ret(bl); - if (bl->type != BL_PC && bl->type != BL_MOB) + if (bl->type != BL::PC && bl->type != BL::MOB) { if (battle_config.error_log) PRINTF("skill_status_change_active: neither MOB nor PC !\n"); @@ -779,7 +779,7 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid) Opt3 *opt3; nullpo_ret(bl); - if (bl->type != BL_PC && bl->type != BL_MOB) + if (bl->type != BL::PC && bl->type != BL::MOB) { if (battle_config.error_log) PRINTF("skill_status_change_end: neither MOB nor PC !\n"); @@ -812,91 +812,84 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid) switch (type) { /* 異常の種類ごとの処理 */ - case SC_SPEEDPOTION0: /* 増速ポーション */ - case SC_ATKPOT: /* attack potion [Valaris] */ - case SC_MATKPOT: /* magic attack potion [Valaris] */ - case SC_PHYS_SHIELD: - case SC_HASTE: + case StatusChange::SC_SPEEDPOTION0: /* 増速ポーション */ + case StatusChange::SC_ATKPOT: /* attack potion [Valaris] */ + case StatusChange::SC_MATKPOT: /* magic attack potion [Valaris] */ + case StatusChange::SC_PHYS_SHIELD: + case StatusChange::SC_HASTE: calc_flag = 1; break; - { - struct map_session_data *md = map_id2sd(sc_data[type].val1); - sc_data[type].val1 = sc_data[type].val2 = 0; - skill_devotion(md, bl->id); - calc_flag = 1; - } - break; - case SC_NOCHAT: //チャット禁止状態 + case StatusChange::SC_NOCHAT: //チャット禁止状態 break; - case SC_SELFDESTRUCTION: /* 自爆 */ + case StatusChange::SC_SELFDESTRUCTION: /* 自爆 */ { //自分のダメージは0にして struct mob_data *md = NULL; - if (bl->type == BL_MOB && (md = (struct mob_data *) bl)) + if (bl->type == BL::MOB && (md = (struct mob_data *) bl)) skill_castend_damage_id(bl, bl, static_cast(sc_data[type].val2), sc_data[type].val1, gettick(), BCT_ZERO); } break; /* option1 */ - case SC_FREEZE: + case StatusChange::SC_FREEZE: sc_data[type].val3 = 0; break; /* option2 */ - case SC_POISON: /* 毒 */ - case SC_BLIND: /* 暗黒 */ - case SC_CURSE: + case StatusChange::SC_POISON: /* 毒 */ + case StatusChange::SC_BLIND: /* 暗黒 */ + case StatusChange::SC_CURSE: calc_flag = 1; break; } - if (bl->type == BL_PC && type < SC_SENDMAX) + if (bl->type == BL::PC && type < StatusChange::SC_SENDMAX) clif_status_change(bl, type, 0); /* アイコン消去 */ switch (type) { /* 正常に戻るときなにか処理が必要 */ - case SC_STONE: - case SC_FREEZE: - case SC_STAN: - case SC_SLEEP: + case StatusChange::SC_STONE: + case StatusChange::SC_FREEZE: + case StatusChange::SC_STAN: + case StatusChange::SC_SLEEP: *opt1 = Opt1::ZERO; opt_flag = 1; break; - case SC_POISON: + case StatusChange::SC_POISON: *opt2 &= ~Opt2::_poison; opt_flag = 1; break; - case SC_CURSE: + case StatusChange::SC_CURSE: *opt2 &= ~Opt2::_curse; opt_flag = 1; break; - case SC_SILENCE: + case StatusChange::SC_SILENCE: *opt2 &= ~Opt2::_silence; opt_flag = 1; break; - case SC_BLIND: + case StatusChange::SC_BLIND: *opt2 &= ~Opt2::BLIND; opt_flag = 1; break; - case SC_SLOWPOISON: - if (sc_data[SC_POISON].timer != -1) + case StatusChange::SC_SLOWPOISON: + if (sc_data[StatusChange::SC_POISON].timer != -1) *opt2 |= Opt2::_poison; *opt2 &= ~Opt2::_slowpoison; opt_flag = 1; break; - case SC_SPEEDPOTION0: + case StatusChange::SC_SPEEDPOTION0: *opt2 &= ~Opt2::_speedpotion0; opt_flag = 1; break; - case SC_ATKPOT: + case StatusChange::SC_ATKPOT: *opt2 &= ~Opt2::_atkpot; opt_flag = 1; break; @@ -904,7 +897,7 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid) if (night_flag == 1 && !bool(*opt2 & Opt2::BLIND) - && bl->type == BL_PC) + && bl->type == BL::PC) { // by [Yor] *opt2 |= Opt2::BLIND; opt_flag = 1; @@ -913,7 +906,7 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid) if (opt_flag) /* optionの変更を伝える */ clif_changeoption(bl); - if (bl->type == BL_PC && calc_flag) + if (bl->type == BL::PC && calc_flag) pc_calcstatus((struct map_session_data *) bl, 0); /* ステータス再計算 */ } @@ -958,7 +951,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom if (not sc_data) return; - if (bl->type == BL_PC) + if (bl->type == BL::PC) sd = (struct map_session_data *) bl; //sc_count=battle_get_sc_count(bl); //使ってない? @@ -979,7 +972,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom switch (type) { /* 特殊な処理になる場合 */ - case SC_STONE: + case StatusChange::SC_STONE: if (sc_data[type].val2 != 0) { Opt1 *opt1 = battle_get_opt1(bl); @@ -1005,9 +998,9 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom hp = hp / 100; if (hp < 1) hp = 1; - if (bl->type == BL_PC) + if (bl->type == BL::PC) pc_heal((struct map_session_data *) bl, -hp, 0); - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) { struct mob_data *md; if ((md = ((struct mob_data *) bl)) == NULL) @@ -1021,11 +1014,11 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom return; } break; - case SC_POISON: - if (sc_data[SC_SLOWPOISON].timer == -1) + case StatusChange::SC_POISON: + if (sc_data[StatusChange::SC_SLOWPOISON].timer == -1) { const int resist_poison = - skill_power_bl(bl, TMW_RESIST_POISON) >> 3; + skill_power_bl(bl, SkillID::TMW_RESIST_POISON) >> 3; if (resist_poison) sc_data[type].val1 -= MRAND(resist_poison + 1); @@ -1035,12 +1028,12 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom int hp = battle_get_max_hp(bl); if (battle_get_hp(bl) > hp >> 4) { - if (bl->type == BL_PC) + if (bl->type == BL::PC) { hp = 3 + hp * 3 / 200; pc_heal((struct map_session_data *) bl, -hp, 0); } - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) { struct mob_data *md; if ((md = ((struct mob_data *) bl)) == NULL) @@ -1061,17 +1054,17 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom break; /* 時間切れ無し?? */ - case SC_WEIGHT50: - case SC_WEIGHT90: - case SC_BROKNWEAPON: - case SC_BROKNARMOR: + case StatusChange::SC_WEIGHT50: + case StatusChange::SC_WEIGHT90: + case StatusChange::SC_BROKNWEAPON: + case StatusChange::SC_BROKNARMOR: if (sc_data[type].timer == tid) sc_data[type].timer = add_timer(1000 * 600 + tick, skill_status_change_timer, bl->id, data); return; - case SC_NOCHAT: //チャット禁止状態 + case StatusChange::SC_NOCHAT: //チャット禁止状態 if (sd && battle_config.muting_players) { time_t timer; @@ -1087,14 +1080,14 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom } } break; - case SC_SELFDESTRUCTION: /* 自爆 */ + case StatusChange::SC_SELFDESTRUCTION: /* 自爆 */ if (--sc_data[type].val3 > 0) { struct mob_data *md; - if (bl->type == BL_MOB && (md = (struct mob_data *) bl) - && md->stats[MOB_SPEED] > 250) + if (bl->type == BL::MOB && (md = (struct mob_data *) bl) + && md->stats[mob_stat::SPEED] > 250) { - md->stats[MOB_SPEED] -= 250; + md->stats[mob_stat::SPEED] -= 250; md->next_walktime = tick; } sc_data[type].timer = add_timer( /* タイマー再設定 */ @@ -1105,8 +1098,8 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom } break; - case SC_FLYING_BACKPACK: - clif_updatestatus(sd, SP_WEIGHT); + case StatusChange::SC_FLYING_BACKPACK: + clif_updatestatus(sd, SP::WEIGHT); break; } @@ -1164,34 +1157,34 @@ int skill_status_effect(struct block_list *bl, StatusChange type, switch (type) { - case SC_STONE: - case SC_FREEZE: + case StatusChange::SC_STONE: + case StatusChange::SC_FREEZE: scdef = 3 + battle_get_mdef(bl) + battle_get_luk(bl) / 3; break; - case SC_STAN: - case SC_SILENCE: - case SC_POISON: + case StatusChange::SC_STAN: + case StatusChange::SC_SILENCE: + case StatusChange::SC_POISON: scdef = 3 + battle_get_vit(bl) + battle_get_luk(bl) / 3; break; - case SC_SLEEP: - case SC_BLIND: + case StatusChange::SC_SLEEP: + case StatusChange::SC_BLIND: scdef = 3 + battle_get_int(bl) + battle_get_luk(bl) / 3; break; - case SC_CURSE: + case StatusChange::SC_CURSE: scdef = 3 + battle_get_luk(bl); break; -// case SC_CONFUSION: +// case StatusChange::SC_CONFUSION: default: scdef = 0; } if (scdef >= 100) return 0; - if (bl->type == BL_PC) + if (bl->type == BL::PC) { sd = (struct map_session_data *) bl; } - else if (bl->type == BL_MOB) + else if (bl->type == BL::MOB) { } else @@ -1201,32 +1194,32 @@ int skill_status_effect(struct block_list *bl, StatusChange type, return 0; } - if (type == SC_FREEZE && undead_flag && !(flag & 1)) + if (type == StatusChange::SC_FREEZE && undead_flag && !(flag & 1)) return 0; if (bool(mode & MobMode::BOSS) - && (type == SC_STONE - || type == SC_FREEZE - || type == SC_STAN - || type == SC_SLEEP - || type == SC_SILENCE + && (type == StatusChange::SC_STONE + || type == StatusChange::SC_FREEZE + || type == StatusChange::SC_STAN + || type == StatusChange::SC_SLEEP + || type == StatusChange::SC_SILENCE ) && !(flag & 1)) { /* ボスには効かない(ただしカードによる効果は適用される) */ return 0; } - if (type == SC_FREEZE || type == SC_STAN || type == SC_SLEEP) + if (type == StatusChange::SC_FREEZE || type == StatusChange::SC_STAN || type == StatusChange::SC_SLEEP) battle_stopwalking(bl, 1); if (sc_data[type].timer != -1) { /* すでに同じ異常になっている場合タイマ解除 */ if (sc_data[type].val1 > val1 - && type != SC_SPEEDPOTION0 - && type != SC_ATKPOT - && type != SC_MATKPOT) // added atk and matk potions [Valaris] + && type != StatusChange::SC_SPEEDPOTION0 + && type != StatusChange::SC_ATKPOT + && type != StatusChange::SC_MATKPOT) // added atk and matk potions [Valaris] return 0; - if (type >= SC_STAN && type <= SC_BLIND) + if (type >= StatusChange::SC_STAN && type <= StatusChange::SC_BLIND) return 0; /* 継ぎ足しができない状態異常である時は状態異常を行わない */ { (*sc_count)--; @@ -1237,28 +1230,28 @@ int skill_status_effect(struct block_list *bl, StatusChange type, switch (type) { /* 異常の種類ごとの処理 */ - case SC_SLOWPOISON: - if (sc_data[SC_POISON].timer == -1) + case StatusChange::SC_SLOWPOISON: + if (sc_data[StatusChange::SC_POISON].timer == -1) return 0; break; - case SC_SPEEDPOTION0: /* 増速ポーション */ + case StatusChange::SC_SPEEDPOTION0: /* 増速ポーション */ *opt2 |= Opt2::_speedpotion0; calc_flag = 1; tick = 1000 * tick; -// val2 = 5*(2+type-SC_SPEEDPOTION0); +// val2 = 5*(2+type-StatusChange::SC_SPEEDPOTION0); break; /* atk & matk potions [Valaris] */ - case SC_ATKPOT: + case StatusChange::SC_ATKPOT: *opt2 |= Opt2::_atkpot; FALLTHROUGH; - case SC_MATKPOT: + case StatusChange::SC_MATKPOT: calc_flag = 1; tick = 1000 * tick; break; - case SC_NOCHAT: //チャット禁止状態 + case StatusChange::SC_NOCHAT: //チャット禁止状態 { time_t timer; @@ -1271,13 +1264,13 @@ int skill_status_effect(struct block_list *bl, StatusChange type, // updateflag = SP_MANNER; } break; - case SC_SELFDESTRUCTION: //自爆 + case StatusChange::SC_SELFDESTRUCTION: //自爆 val3 = tick / 1000; tick = 1000; break; /* option1 */ - case SC_STONE: /* 石化 */ + case StatusChange::SC_STONE: /* 石化 */ if (!(flag & 2)) { int sc_def = battle_get_mdef(bl) * 200; @@ -1289,7 +1282,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, tick = 5000; val2 = 1; break; - case SC_SLEEP: /* 睡眠 */ + case StatusChange::SC_SLEEP: /* 睡眠 */ if (!(flag & 2)) { // int sc_def = 100 - (battle_get_int(bl) + battle_get_luk(bl)/3); @@ -1298,14 +1291,14 @@ int skill_status_effect(struct block_list *bl, StatusChange type, tick = 30000; //睡眠はステータス耐性に関わらず30秒 } break; - case SC_FREEZE: /* 凍結 */ + case StatusChange::SC_FREEZE: /* 凍結 */ if (!(flag & 2)) { int sc_def = 100 - battle_get_mdef(bl); tick = tick * sc_def / 100; } break; - case SC_STAN: /* スタン(val2にミリ秒セット) */ + case StatusChange::SC_STAN: /* スタン(val2にミリ秒セット) */ if (!(flag & 2)) { int sc_def = @@ -1315,7 +1308,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, break; /* option2 */ - case SC_POISON: /* 毒 */ + case StatusChange::SC_POISON: /* 毒 */ calc_flag = 1; if (!(flag & 2)) { @@ -1328,14 +1321,14 @@ int skill_status_effect(struct block_list *bl, StatusChange type, val3 = 1; tick = 1000; break; - case SC_SILENCE: /* 沈黙(レックスデビーナ) */ + case StatusChange::SC_SILENCE: /* 沈黙(レックスデビーナ) */ if (!(flag & 2)) { int sc_def = 100 - battle_get_vit(bl); tick = tick * sc_def / 100; } break; - case SC_BLIND: /* 暗黒 */ + case StatusChange::SC_BLIND: /* 暗黒 */ calc_flag = 1; if (!(flag & 2)) { @@ -1344,7 +1337,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, tick = 30000 - sc_def; } break; - case SC_CURSE: + case StatusChange::SC_CURSE: calc_flag = 1; if (!(flag & 2)) { @@ -1353,23 +1346,23 @@ int skill_status_effect(struct block_list *bl, StatusChange type, } break; - case SC_WEIGHT50: - case SC_WEIGHT90: - case SC_BROKNWEAPON: - case SC_BROKNARMOR: + case StatusChange::SC_WEIGHT50: + case StatusChange::SC_WEIGHT90: + case StatusChange::SC_BROKNWEAPON: + case StatusChange::SC_BROKNARMOR: tick = 600 * 1000; break; - case SC_HASTE: + case StatusChange::SC_HASTE: calc_flag = 1; break; - case SC_PHYS_SHIELD: - case SC_MBARRIER: - case SC_HALT_REGENERATE: - case SC_HIDE: + case StatusChange::SC_PHYS_SHIELD: + case StatusChange::SC_MBARRIER: + case StatusChange::SC_HALT_REGENERATE: + case StatusChange::SC_HIDE: break; - case SC_FLYING_BACKPACK: - updateflag = SP_WEIGHT; + case StatusChange::SC_FLYING_BACKPACK: + updateflag = SP::WEIGHT; break; default: if (battle_config.error_log) @@ -1377,16 +1370,16 @@ int skill_status_effect(struct block_list *bl, StatusChange type, return 0; } - if (bl->type == BL_PC && type < SC_SENDMAX) + if (bl->type == BL::PC && type < StatusChange::SC_SENDMAX) clif_status_change(bl, type, 1); /* アイコン表示 */ /* optionの変更 */ switch (type) { - case SC_STONE: - case SC_FREEZE: - case SC_STAN: - case SC_SLEEP: + case StatusChange::SC_STONE: + case StatusChange::SC_FREEZE: + case StatusChange::SC_STAN: + case StatusChange::SC_SLEEP: battle_stopattack(bl); /* 攻撃停止 */ skill_stop_dancing(bl, 0); /* 演奏/ダンスの中断 */ /* 同時に掛からないステータス異常を解除 */ @@ -1402,35 +1395,35 @@ int skill_status_effect(struct block_list *bl, StatusChange type, } switch (type) { - case SC_STONE: *opt1 = Opt1::_stone6; break; - case SC_FREEZE: *opt1 = Opt1::_freeze; break; - case SC_STAN: *opt1 = Opt1::_stan; break; - case SC_SLEEP: *opt1 = Opt1::_sleep; break; + case StatusChange::SC_STONE: *opt1 = Opt1::_stone6; break; + case StatusChange::SC_FREEZE: *opt1 = Opt1::_freeze; break; + case StatusChange::SC_STAN: *opt1 = Opt1::_stan; break; + case StatusChange::SC_SLEEP: *opt1 = Opt1::_sleep; break; } opt_flag = 1; break; - case SC_POISON: - if (sc_data[SC_SLOWPOISON].timer == -1) + case StatusChange::SC_POISON: + if (sc_data[StatusChange::SC_SLOWPOISON].timer == -1) { *opt2 |= Opt2::_poison; opt_flag = 1; } break; - case SC_CURSE: + case StatusChange::SC_CURSE: *opt2 |= Opt2::_curse; opt_flag = 1; break; - case SC_SILENCE: + case StatusChange::SC_SILENCE: *opt2 |= Opt2::_silence; opt_flag = 1; break; - case SC_BLIND: + case StatusChange::SC_BLIND: *opt2 |= Opt2::BLIND; opt_flag = 1; break; - case SC_SLOWPOISON: + case StatusChange::SC_SLOWPOISON: *opt2 &= ~Opt2::_poison; *opt2 |= Opt2::_slowpoison; opt_flag = 1; @@ -1457,10 +1450,10 @@ int skill_status_effect(struct block_list *bl, StatusChange type, add_timer(gettick() + tick, skill_status_change_timer, bl->id, custom_data_t(type)); - if (bl->type == BL_PC && calc_flag) + if (bl->type == BL::PC && calc_flag) pc_calcstatus(sd, 0); /* ステータス再計算 */ - if (bl->type == BL_PC && updateflag != SP::ZERO) + if (bl->type == BL::PC && updateflag != SP::ZERO) clif_updatestatus(sd, updateflag); /* ステータスをクライアントに送る */ return 0; @@ -1496,7 +1489,7 @@ int skill_status_change_clear(struct block_list *bl, int type) if (*sc_count == 0) return 0; - for (StatusChange i : erange(StatusChange(), MAX_STATUSCHANGE)) + for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE)) { if (sc_data[i].timer != -1) { @@ -1551,17 +1544,17 @@ static SP scan_stat(char *statname) { if (!strcasecmp(statname, "str")) - return SP_STR; + return SP::STR; if (!strcasecmp(statname, "dex")) - return SP_DEX; + return SP::DEX; if (!strcasecmp(statname, "agi")) - return SP_AGI; + return SP::AGI; if (!strcasecmp(statname, "vit")) - return SP_VIT; + return SP::VIT; if (!strcasecmp(statname, "int")) - return SP_INT; + return SP::INT; if (!strcasecmp(statname, "luk")) - return SP_LUK; + return SP::LUK; if (!strcasecmp(statname, "none")) return SP::ZERO; @@ -1612,7 +1605,7 @@ int skill_readdb(void) } SkillID i = SkillID(atoi(split[0])); - if (/*i < SkillID() ||*/ i > MAX_SKILL_DB) + if (/*i < SkillID() ||*/ i > SkillID::MAX_SKILL_DB) continue; memset(split2, 0, sizeof(split2)); @@ -1652,19 +1645,19 @@ int skill_readdb(void) skill_db[i].cast_def_rate = atoi(split[10]); skill_db[i].inf2 = atoi(split[11]); skill_db[i].maxcount = atoi(split[12]); - // split[13] was one of: BF_WEAPON, BF_MAGIC, BF_MISC, BF::ZERO + // split[13] was one of: BF::WEAPON, BF::MAGIC, BF::MISC, BF::ZERO memset(split2, 0, sizeof(split2)); // split[14] was colon-separated blow counts. if (!strcasecmp(split[15], "passive")) { skill_pool_register(i); - skill_db[i].poolflags = SKILL_POOL_FLAG; + skill_db[i].poolflags = SkillFlags::POOL_FLAG; } else if (!strcasecmp(split[15], "active")) { skill_pool_register(i); - skill_db[i].poolflags = SKILL_POOL_FLAG | SKILL_POOL_ACTIVE; + skill_db[i].poolflags = SkillFlags::POOL_FLAG | SkillFlags::POOL_ACTIVE; } else skill_db[i].poolflags = SkillFlags::ZERO; diff --git a/src/map/skill.hpp b/src/map/skill.hpp index 7ecdd37..9fb95a2 100644 --- a/src/map/skill.hpp +++ b/src/map/skill.hpp @@ -5,9 +5,9 @@ #include "map.hpp" -#define MAX_SKILL_PRODUCE_DB 150 -#define MAX_SKILL_ARROW_DB 150 -#define MAX_SKILL_ABRA_DB 350 +constexpr int MAX_SKILL_PRODUCE_DB = 150; +constexpr int MAX_SKILL_ARROW_DB = 150; +constexpr int MAX_SKILL_ABRA_DB = 350; // スキルデータベース struct skill_db @@ -29,7 +29,7 @@ struct skill_db int itemid[10], amount[10]; int castnodex[MAX_SKILL_LEVEL]; }; -extern earray skill_db; +extern earray skill_db; struct skill_name_db { @@ -105,9 +105,9 @@ void skill_reload(void); // [Fate] Skill pools API // Max. # of active entries in the skill pool -#define MAX_SKILL_POOL 3 +constexpr int MAX_SKILL_POOL = 3; // Max. # of skills that may be classified as pool skills in db/skill_db.txt -#define MAX_POOL_SKILLS 128 +constexpr int MAX_POOL_SKILLS = 128; extern SkillID skill_pool_skills[MAX_POOL_SKILLS]; // All pool skills extern int skill_pool_skills_size; // Number of entries in skill_pool_skills diff --git a/src/map/skill.t.hpp b/src/map/skill.t.hpp index 69dab85..9dcb119 100644 --- a/src/map/skill.t.hpp +++ b/src/map/skill.t.hpp @@ -10,7 +10,6 @@ enum class StatusChange : uint16_t { // indices into (map_session_data).status_change SC_SENDMAX = 256, -#define SC_SENDMAX StatusChange::SC_SENDMAX // sometimes means "none", sometimes not NEGATIVE1 = 0xffff, @@ -23,107 +22,69 @@ enum class StatusChange : uint16_t ATTACK_ICON_SHEARING = 2001, CART = 0x0c, CLIF_OPTION_SC_INVISIBILITY = 0x1000, -#define CLIF_OPTION_SC_INVISIBILITY StatusChange::CLIF_OPTION_SC_INVISIBILITY CLIF_OPTION_SC_SCRIBE = 0x1001, -#define CLIF_OPTION_SC_SCRIBE StatusChange::CLIF_OPTION_SC_SCRIBE // the rest are the normal effects SC_SLOWPOISON = 14, // item script -#define SC_SLOWPOISON StatusChange::SC_SLOWPOISON SC_BROKNARMOR = 32, // ? -#define SC_BROKNARMOR StatusChange::SC_BROKNARMOR SC_BROKNWEAPON = 33, // ? -#define SC_BROKNWEAPON StatusChange::SC_BROKNWEAPON SC_WEIGHT50 = 35, // ? sort of used -#define SC_WEIGHT50 StatusChange::SC_WEIGHT50 SC_WEIGHT90 = 36, // definitely used -#define SC_WEIGHT90 StatusChange::SC_WEIGHT90 SC_SPEEDPOTION0 = 37, // item script -#define SC_SPEEDPOTION0 StatusChange::SC_SPEEDPOTION0 SC_HEALING = 70, // item script -#define SC_HEALING StatusChange::SC_HEALING SC_STONE = 128, // ?bad -#define SC_STONE StatusChange::SC_STONE SC_FREEZE = 129, // ?bad -#define SC_FREEZE StatusChange::SC_FREEZE SC_STAN = 130, // ?bad -#define SC_STAN StatusChange::SC_STAN SC_SLEEP = 131, // ?bad -#define SC_SLEEP StatusChange::SC_SLEEP SC_POISON = 132, // bad; actually used -#define SC_POISON StatusChange::SC_POISON SC_CURSE = 133, // ?bad -#define SC_CURSE StatusChange::SC_CURSE SC_SILENCE = 134, // ?bad -#define SC_SILENCE StatusChange::SC_SILENCE SC_CONFUSION = 135, // ?bad -#define SC_CONFUSION StatusChange::SC_CONFUSION SC_BLIND = 136, // ?bad -#define SC_BLIND StatusChange::SC_BLIND - - SC_SAFETYWALL = 140, // ?skill.cpp skill_unit thingies -#define SC_SAFETYWALL StatusChange::SC_SAFETYWALL - SC_PNEUMA = 141, // ?skill.cpp skill_unit thingies -#define SC_PNEUMA StatusChange::SC_PNEUMA - - SC_ANKLE = 143, // ?skill.cpp skill_unit thingies -#define SC_ANKLE StatusChange::SC_ANKLE SC_ATKPOT = 185, // item script -#define SC_ATKPOT StatusChange::SC_ATKPOT SC_MATKPOT = 186, // unused, but kept for parallel -#define SC_MATKPOT StatusChange::SC_MATKPOT SC_NOCHAT = 188, // ? something with manner -#define SC_NOCHAT StatusChange::SC_NOCHAT SC_SELFDESTRUCTION = 190, // see table - maybe used, maybe not -#define SC_SELFDESTRUCTION StatusChange::SC_SELFDESTRUCTION // Added for Fate's spells SC_HIDE = 194, // Hide from `detect' magic (PCs only) -#define SC_HIDE StatusChange::SC_HIDE SC_SHEARED = 194, // Has been sheared (mobs only) -#define SC_SHEARED StatusChange::SC_SHEARED SC_HALT_REGENERATE = 195, // Suspend regeneration -#define SC_HALT_REGENERATE StatusChange::SC_HALT_REGENERATE SC_FLYING_BACKPACK = 196, // Flying backpack -#define SC_FLYING_BACKPACK StatusChange::SC_FLYING_BACKPACK SC_MBARRIER = 197, // Magical barrier, magic resistance (val1 : power (%)) -#define SC_MBARRIER StatusChange::SC_MBARRIER SC_HASTE = 198, // `Haste' spell (val1 : power) -#define SC_HASTE StatusChange::SC_HASTE SC_PHYS_SHIELD = 199, // `Protect' spell, reduce damage (val1: power) -#define SC_PHYS_SHIELD StatusChange::SC_PHYS_SHIELD MAX_STATUSCHANGE = 200, -#define MAX_STATUSCHANGE StatusChange::MAX_STATUSCHANGE }; constexpr StatusChange MAJOR_STATUS_EFFECTS[] = { - SC_STONE, - SC_FREEZE, - SC_STAN, - SC_SLEEP, - SC_POISON, - SC_CURSE, - SC_SILENCE, - SC_CONFUSION, - SC_BLIND, + StatusChange::SC_STONE, + StatusChange::SC_FREEZE, + StatusChange::SC_STAN, + StatusChange::SC_SLEEP, + StatusChange::SC_POISON, + StatusChange::SC_CURSE, + StatusChange::SC_SILENCE, + StatusChange::SC_CONFUSION, + StatusChange::SC_BLIND, }; constexpr StatusChange MAJOR_STATUS_EFFECTS_1[] = { - SC_STONE, - SC_FREEZE, - SC_STAN, - SC_SLEEP, + StatusChange::SC_STONE, + StatusChange::SC_FREEZE, + StatusChange::SC_STAN, + StatusChange::SC_SLEEP, }; // needed to work around some subtractative indexing @@ -147,13 +108,13 @@ enum class BadSC constexpr StatusChange BadSC_to_SC(BadSC bsc) { - return StatusChange(uint16_t(SC_STONE) + int(bsc)); + return StatusChange(uint16_t(StatusChange::SC_STONE) + int(bsc)); } constexpr BadSC BadSC_from_SC(StatusChange sc) { - return BadSC(uint16_t(sc) - uint16_t(SC_STONE)); + return BadSC(uint16_t(sc) - uint16_t(StatusChange::SC_STONE)); } // TODO remove most of these @@ -167,80 +128,53 @@ enum class SkillID : uint16_t // Basic skills. // These should probably be made unconditional. NV_EMOTE = 1, // -#define NV_EMOTE SkillID::NV_EMOTE NV_TRADE = 2, // -#define NV_TRADE SkillID::NV_TRADE NV_PARTY = 3, // -#define NV_PARTY SkillID::NV_PARTY AC_OWL = 45, // Mallard's Eye -#define AC_OWL SkillID::AC_OWL NPC_SELFDESTRUCTION = 175, // -#define NPC_SELFDESTRUCTION SkillID::NPC_SELFDESTRUCTION NPC_POISON = 178, // -#define NPC_POISON SkillID::NPC_POISON NPC_SUMMONSLAVE = 198, // -#define NPC_SUMMONSLAVE SkillID::NPC_SUMMONSLAVE NPC_EMOTION = 199, // -#define NPC_EMOTION SkillID::NPC_EMOTION TMW_SKILLPOOL = 339, // skill pool size -#define TMW_SKILLPOOL SkillID::TMW_SKILLPOOL // magic skills TMW_MAGIC = 340, // -#define TMW_MAGIC SkillID::TMW_MAGIC TMW_MAGIC_LIFE = 341, // -#define TMW_MAGIC_LIFE SkillID::TMW_MAGIC_LIFE TMW_MAGIC_WAR = 342, // -#define TMW_MAGIC_WAR SkillID::TMW_MAGIC_WAR TMW_MAGIC_TRANSMUTE = 343, // -#define TMW_MAGIC_TRANSMUTE SkillID::TMW_MAGIC_TRANSMUTE TMW_MAGIC_NATURE = 344, // -#define TMW_MAGIC_NATURE SkillID::TMW_MAGIC_NATURE TMW_MAGIC_ETHER = 345, // -#define TMW_MAGIC_ETHER SkillID::TMW_MAGIC_ETHER TMW_MAGIC_DARK = 346, // -#define TMW_MAGIC_DARK SkillID::TMW_MAGIC_DARK TMW_MAGIC_LIGHT = 347, // -#define TMW_MAGIC_LIGHT SkillID::TMW_MAGIC_LIGHT // focusable skills TMW_BRAWLING = 350, // -#define TMW_BRAWLING SkillID::TMW_BRAWLING TMW_LUCKY_COUNTER = 351, // -#define TMW_LUCKY_COUNTER SkillID::TMW_LUCKY_COUNTER TMW_SPEED = 352, // -#define TMW_SPEED SkillID::TMW_SPEED TMW_RESIST_POISON = 353, // -#define TMW_RESIST_POISON SkillID::TMW_RESIST_POISON TMW_ASTRAL_SOUL = 354, // -#define TMW_ASTRAL_SOUL SkillID::TMW_ASTRAL_SOUL TMW_RAGING = 355, // -#define TMW_RAGING SkillID::TMW_RAGING // Note: this value is also hard-coded in common/mmo.hpp MAX_SKILL_DB = 474, // not 450 -#define MAX_SKILL_DB SkillID::MAX_SKILL_DB }; namespace e { enum class SkillFlags : uint16_t { - ZERO = 0x00, + ZERO = 0x00, // is a pool skill - FLAG = 0x01, -#define SKILL_POOL_FLAG SkillFlags::FLAG + POOL_FLAG = 0x01, // is an active pool skill - ACTIVE = 0x02, -#define SKILL_POOL_ACTIVE SkillFlags::ACTIVE + POOL_ACTIVE = 0x02, // pool skill has been activated (used for clif) - ACTIVATED = 0x04, -#define SKILL_POOL_ACTIVATED SkillFlags::ACTIVATED + POOL_ACTIVATED = 0x04, }; ENUM_BITWISE_OPERATORS(SkillFlags) } diff --git a/src/map/trade.cpp b/src/map/trade.cpp index b255298..6e81602 100644 --- a/src/map/trade.cpp +++ b/src/map/trade.cpp @@ -292,11 +292,11 @@ void trade_tradecancel(struct map_session_data *sd) if (sd->deal_zeny) { sd->deal_zeny = 0; - clif_updatestatus(sd, SP_ZENY); + clif_updatestatus(sd, SP::ZENY); } if (target_sd->deal_zeny) { - clif_updatestatus(target_sd, SP_ZENY); + clif_updatestatus(target_sd, SP::ZENY); target_sd->deal_zeny = 0; } sd->deal_locked = 0; @@ -390,18 +390,18 @@ void trade_tradecommit(struct map_session_data *sd) int deal = sd->deal_zeny; sd->deal_zeny = 0; sd->status.zeny -= deal; - clif_updatestatus(sd, SP_ZENY); + clif_updatestatus(sd, SP::ZENY); target_sd->status.zeny += deal; - clif_updatestatus(target_sd, SP_ZENY); + clif_updatestatus(target_sd, SP::ZENY); } if (target_sd->deal_zeny) { int deal = target_sd->deal_zeny; target_sd->deal_zeny = 0; target_sd->status.zeny -= deal; - clif_updatestatus(target_sd, SP_ZENY); + clif_updatestatus(target_sd, SP::ZENY); sd->status.zeny += deal; - clif_updatestatus(sd, SP_ZENY); + clif_updatestatus(sd, SP::ZENY); } sd->deal_locked = 0; target_sd->deal_locked = 0; -- cgit v1.2.3-60-g2f50