diff options
Diffstat (limited to 'src/map/magic-stmt.cpp')
-rw-r--r-- | src/map/magic-stmt.cpp | 270 |
1 files changed, 139 insertions, 131 deletions
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index ba99409..9aca511 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -30,15 +30,15 @@ #include "../io/cxxstdio.hpp" -#include "../mmo/timer.hpp" +#include "../net/timer.hpp" +#include "battle.hpp" +#include "clif.hpp" +#include "magic.hpp" #include "magic-expr.hpp" #include "magic-expr-eval.hpp" #include "magic-interpreter.hpp" -#include "magic-interpreter-aux.hpp" - -#include "battle.hpp" -#include "clif.hpp" +#include "magic-interpreter-base.hpp" #include "mob.hpp" #include "npc.hpp" #include "pc.hpp" @@ -46,8 +46,11 @@ #include "../poison.hpp" + +namespace tmwa +{ /* used for local spell effects */ -constexpr int INVISIBLE_NPC = 127; +constexpr Species INVISIBLE_NPC = wrap<Species>(127); //#define DEBUG @@ -58,19 +61,19 @@ void print_val(val_t *v) switch (v->ty) { case TYPE::UNDEF: - FPRINTF(stderr, "UNDEF"); + FPRINTF(stderr, "UNDEF"_fmt); break; case TYPE::INT: - FPRINTF(stderr, "%d", v->v.v_int); + FPRINTF(stderr, "%d"_fmt, v->v.v_int); break; case TYPE::DIR: - FPRINTF(stderr, "dir%d", v->v.v_int); + FPRINTF(stderr, "dir%d"_fmt, v->v.v_int); break; case TYPE::STRING: - FPRINTF(stderr, "`%s'", v->v.v_string); + FPRINTF(stderr, "`%s'"_fmt, v->v.v_string); break; default: - FPRINTF(stderr, "ty%d", v->ty); + FPRINTF(stderr, "ty%d"_fmt, v->ty); break; } } @@ -84,11 +87,11 @@ void dump_env(env_t *env) val_t *v = &env->vars[i]; val_t *bv = &env->base_env->vars[i]; - FPRINTF(stderr, "%02x %30s ", i, env->base_env->var_name[i]); + FPRINTF(stderr, "%02x %30s "_fmt, i, env->base_env->var_name[i]); print_val(v); - FPRINTF(stderr, "\t("); + FPRINTF(stderr, "\t("_fmt); print_val(bv); - FPRINTF(stderr, ")\n"); + FPRINTF(stderr, ")\n"_fmt); } } #endif @@ -108,7 +111,7 @@ void clear_activation_record(cont_activation_record_t *ar) } static -void invocation_timer_callback(TimerData *, tick_t, int id) +void invocation_timer_callback(TimerData *, tick_t, BlockId id) { dumb_ptr<invocation> invocation = map_id_is_spell(id); @@ -153,7 +156,7 @@ void spell_free_invocation(dumb_ptr<invocation> invocation_) static void char_set_weapon_icon(dumb_ptr<map_session_data> subject, int count, - StatusChange icon, int look) + StatusChange icon, ItemNameId look) { const StatusChange old_icon = subject->attack_spell_icon_override; @@ -166,7 +169,7 @@ void char_set_weapon_icon(dumb_ptr<map_session_data> subject, int count, clif_fixpcpos(subject); if (count) { - clif_changelook(subject, LOOK::WEAPON, look); + clif_changelook(subject, LOOK::WEAPON, unwrap<ItemNameId>(look)); if (icon != StatusChange::ZERO) clif_status_change(subject, icon, 1); } @@ -202,7 +205,7 @@ void magic_stop_completely(dumb_ptr<map_session_data> c) { // Zap all status change references to spells for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE)) - c->sc_data[i].spell_invocation = 0; + c->sc_data[i].spell_invocation = BlockId(); while (c->active_spells) spell_free_invocation(c->active_spells); @@ -212,8 +215,8 @@ void magic_stop_completely(dumb_ptr<map_session_data> c) dumb_ptr<invocation> attack_spell = map_id_is_spell(c->attack_spell_override); if (attack_spell) spell_free_invocation(attack_spell); - c->attack_spell_override = 0; - char_set_weapon_icon(c, 0, StatusChange::ZERO, 0); + c->attack_spell_override = BlockId(); + char_set_weapon_icon(c, 0, StatusChange::ZERO, ItemNameId()); char_set_attack_info(c, interval_t::zero(), 0); } } @@ -228,7 +231,7 @@ void try_to_finish_invocation(dumb_ptr<invocation> invocation) { clear_stack(invocation); invocation->current_effect = invocation->end_effect; - invocation->end_effect = NULL; + invocation->end_effect = nullptr; spell_execute(invocation); } else @@ -237,19 +240,19 @@ void try_to_finish_invocation(dumb_ptr<invocation> invocation) } static -int trigger_spell(int subject, int spell) +BlockId trigger_spell(BlockId subject, BlockId spell) { dumb_ptr<invocation> invocation_ = map_id_is_spell(spell); if (!invocation_) - return 0; + return BlockId(); invocation_ = spell_clone_effect(invocation_); spell_bind(map_id_is_player(subject), invocation_); magic_clear_var(&invocation_->env->varu[VAR_CASTER]); invocation_->env->varu[VAR_CASTER].ty = TYPE::ENTITY; - invocation_->env->varu[VAR_CASTER].v.v_int = subject; + invocation_->env->varu[VAR_CASTER].v.v_int = static_cast<int32_t>(unwrap<BlockId>(subject)); return invocation_->bl_id; } @@ -265,7 +268,7 @@ void char_update(dumb_ptr<map_session_data> character) } static -void timer_callback_effect(TimerData *, tick_t, int id, int data) +void timer_callback_effect(TimerData *, tick_t, BlockId id, int data) { dumb_ptr<block_list> target = map_id2bl(id); if (target) @@ -286,12 +289,12 @@ void magic_unshroud(dumb_ptr<map_session_data> other_char) other_char->state.shroud_active = 0; // Now warp the caster out of and back into here to refresh everyone's display char_update(other_char); - clif_displaymessage(other_char->sess, "Your shroud has been dispelled!"); + clif_displaymessage(other_char->sess, "Your shroud has been dispelled!"_s); // entity_effect(other_char, MAGIC_EFFECT_REVEAL); } static -void timer_callback_effect_npc_delete(TimerData *, tick_t, int npc_id) +void timer_callback_effect_npc_delete(TimerData *, tick_t, BlockId npc_id) { dumb_ptr<npc_data> effect_npc = map_id_is_npc(npc_id); npc_free(effect_npc); @@ -302,10 +305,10 @@ dumb_ptr<npc_data> local_spell_effect(map_local *m, int x, int y, int effect, interval_t tdelay) { /* 1 minute should be enough for all interesting spell effects, I hope */ - std::chrono::seconds delay = std::chrono::seconds(30); + std::chrono::seconds delay = 30_s; dumb_ptr<npc_data> effect_npc = npc_spawn_text(m, x, y, - INVISIBLE_NPC, NpcName(), "?"); - int effect_npc_id = effect_npc->bl_id; + INVISIBLE_NPC, NpcName(), "?"_s); + BlockId effect_npc_id = effect_npc->bl_id; entity_effect(effect_npc, effect, tdelay); Timer(gettick() + delay, @@ -341,7 +344,7 @@ static int op_instaheal(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<block_list> caster = (env->VAR(VAR_CASTER).ty == TYPE::ENTITY) - ? map_id2bl(env->VAR(VAR_CASTER).v.v_int) : NULL; + ? map_id2bl(wrap<BlockId>(static_cast<uint32_t>(env->VAR(VAR_CASTER).v.v_int))) : nullptr; dumb_ptr<block_list> subject = ARGENTITY(0); if (!caster) caster = subject; @@ -350,8 +353,8 @@ int op_instaheal(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<map_session_data> caster_pc = caster->is_player(); dumb_ptr<map_session_data> subject_pc = subject->is_player(); - MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d", - subject_pc->status_key.char_id, ARGINT(1)); + MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d"_fmt, + subject_pc->status_key.char_id, ARGINT(1)); } battle_heal(caster, subject, ARGINT(1), ARGINT(2), 0); @@ -430,7 +433,7 @@ int op_message(dumb_ptr<env_t>, Slice<val_t> args) } static -void timer_callback_kill_npc(TimerData *, tick_t, int npc_id) +void timer_callback_kill_npc(TimerData *, tick_t, BlockId npc_id) { dumb_ptr<npc_data> npc = map_id_is_npc(npc_id); if (npc) @@ -445,7 +448,7 @@ int op_messenger_npc(dumb_ptr<env_t>, Slice<val_t> args) NpcName npcname = stringish<NpcName>(ARGSTR(2)); npc = npc_spawn_text(loc->m, loc->x, loc->y, - ARGINT(1), npcname, ARGSTR(3)); + wrap<Species>(static_cast<uint16_t>(ARGINT(1))), npcname, ARGSTR(3)); Timer(gettick() + static_cast<interval_t>(ARGINT(4)), std::bind(timer_callback_kill_npc, ph::_1, ph::_2, @@ -537,7 +540,7 @@ int op_banish(dumb_ptr<env_t>, Slice<val_t> args) } static -void record_status_change(dumb_ptr<invocation> invocation_, int bl_id, +void record_status_change(dumb_ptr<invocation> invocation_, BlockId bl_id, StatusChange sc_id) { status_change_ref_t cr {}; @@ -551,8 +554,8 @@ static int op_status_change(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<block_list> subject = ARGENTITY(0); - int invocation_id = env->VAR(VAR_INVOCATION).ty == TYPE::INVOCATION - ? env->VAR(VAR_INVOCATION).v.v_int : 0; + BlockId invocation_id = env->VAR(VAR_INVOCATION).ty == TYPE::INVOCATION + ? wrap<BlockId>(static_cast<uint32_t>(env->VAR(VAR_INVOCATION).v.v_int)) : BlockId(); dumb_ptr<invocation> invocation_ = map_id_is_spell(invocation_id); assert (!ARGINT(3)); @@ -563,7 +566,7 @@ int op_status_change(dumb_ptr<env_t> env, Slice<val_t> args) static_cast<interval_t>(ARGINT(6)), invocation_id); if (invocation_ && subject->bl_type == BL::PC) - record_status_change(invocation_, subject->bl_id, StatusChange(ARGINT(1))); + record_status_change(invocation_, subject->bl_id, static_cast<StatusChange>(ARGINT(1))); return 0; } @@ -587,7 +590,7 @@ int op_override_attack(dumb_ptr<env_t> env, Slice<val_t> args) interval_t attack_delay = static_cast<interval_t>(ARGINT(2)); int attack_range = ARGINT(3); StatusChange icon = StatusChange(ARGINT(4)); - int look = ARGINT(5); + ItemNameId look = wrap<ItemNameId>(static_cast<uint16_t>(ARGINT(5))); int stopattack = ARGINT(6); dumb_ptr<map_session_data> subject; @@ -604,7 +607,7 @@ int op_override_attack(dumb_ptr<env_t> env, Slice<val_t> args) } subject->attack_spell_override = - trigger_spell(subject->bl_id, env->VAR(VAR_INVOCATION).v.v_int); + trigger_spell(subject->bl_id, wrap<BlockId>(static_cast<uint32_t>(env->VAR(VAR_INVOCATION).v.v_int))); subject->attack_spell_charges = charges; if (subject->attack_spell_override) @@ -623,7 +626,7 @@ int op_override_attack(dumb_ptr<env_t> env, Slice<val_t> args) static int op_create_item(dumb_ptr<env_t>, Slice<val_t> args) { - struct item item; + Item item; dumb_ptr<block_list> entity = ARGENTITY(0); dumb_ptr<map_session_data> subject; int stackable; @@ -698,13 +701,13 @@ int op_spawn(dumb_ptr<env_t>, Slice<val_t> args) { dumb_ptr<area_t> area = ARGAREA(0); dumb_ptr<block_list> owner_e = ARGENTITY(1); - int monster_id = ARGINT(2); + Species monster_id = wrap<Species>(ARGINT(2)); MonsterAttitude monster_attitude = static_cast<MonsterAttitude>(ARGINT(3)); int monster_count = ARGINT(4); interval_t monster_lifetime = static_cast<interval_t>(ARGINT(5)); int i; - dumb_ptr<map_session_data> owner = NULL; + dumb_ptr<map_session_data> owner = nullptr; if (monster_attitude == MonsterAttitude::SERVANT && owner_e->bl_type == BL::PC) owner = owner_e->is_player(); @@ -714,7 +717,7 @@ int op_spawn(dumb_ptr<env_t>, Slice<val_t> args) location_t loc; magic_random_location(&loc, area); - int mob_id; + BlockId mob_id; dumb_ptr<mob_data> mob; mob_id = mob_once_spawn(owner, loc.m->name_, loc.x, loc.y, JAPANESE_NAME, // Is that needed? @@ -724,7 +727,7 @@ int op_spawn(dumb_ptr<env_t>, Slice<val_t> args) if (mob) { - mob->mode = mob_db[monster_id].mode; + mob->mode = get_mob_db(monster_id).mode; switch (monster_attitude) { @@ -770,18 +773,18 @@ int op_spawn(dumb_ptr<env_t>, Slice<val_t> args) } static -const char *get_invocation_name(dumb_ptr<env_t> env) +ZString get_invocation_name(dumb_ptr<env_t> env) { dumb_ptr<invocation> invocation_; if (env->VAR(VAR_INVOCATION).ty != TYPE::INVOCATION) - return "?"; - invocation_ = map_id_is_spell(env->VAR(VAR_INVOCATION).v.v_int); + return "?"_s; + invocation_ = map_id_is_spell(wrap<BlockId>(static_cast<uint32_t>(env->VAR(VAR_INVOCATION).v.v_int))); if (invocation_) - return invocation_->spell->name.c_str(); + return invocation_->spell->name; else - return "??"; + return "??"_s; } static @@ -824,9 +827,9 @@ int op_injure(dumb_ptr<env_t> env, Slice<val_t> args) { dumb_ptr<mob_data> mob = target->is_mob(); - MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s", - mob->bl_id, mob->mob_class, damage_caused, - get_invocation_name(env)); + MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s"_fmt, + mob->bl_id, mob->mob_class, damage_caused, + get_invocation_name(env)); } } battle_damage(caster, target, damage_caused, mp_damage); @@ -847,7 +850,7 @@ int op_emote(dumb_ptr<env_t>, Slice<val_t> args) static int op_set_script_variable(dumb_ptr<env_t>, Slice<val_t> args) { - dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : nullptr; VarName varname = stringish<VarName>(ARGSTR(1)); int array_index = 0; @@ -862,7 +865,7 @@ int op_set_script_variable(dumb_ptr<env_t>, Slice<val_t> args) static int op_set_script_str(dumb_ptr<env_t>, Slice<val_t> args) { - dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : nullptr; VarName varname = stringish<VarName>(ARGSTR(1)); int array_index = 0; @@ -877,7 +880,7 @@ int op_set_script_str(dumb_ptr<env_t>, Slice<val_t> args) static int op_set_hair_colour(dumb_ptr<env_t>, Slice<val_t> args) { - dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : nullptr; if (!c) return 1; @@ -890,7 +893,7 @@ int op_set_hair_colour(dumb_ptr<env_t>, Slice<val_t> args) static int op_set_hair_style(dumb_ptr<env_t>, Slice<val_t> args) { - dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : nullptr; if (!c) return 1; @@ -903,25 +906,29 @@ int op_set_hair_style(dumb_ptr<env_t>, Slice<val_t> args) static int op_drop_item_for (dumb_ptr<env_t>, Slice<val_t> args) { - struct item item; + Item item; int stackable; location_t *loc = &ARGLOCATION(0); int count = ARGINT(2); interval_t interval = static_cast<interval_t>(ARGINT(3)); - dumb_ptr<map_session_data> c = ((args.size() > 4) && (ENTITY_TYPE(4) == BL::PC)) ? ARGPC(4) : NULL; + dumb_ptr<map_session_data> c = ((args.size() > 4) && (ENTITY_TYPE(4) == BL::PC)) ? ARGPC(4) : nullptr; interval_t delay = (args.size() > 5) ? static_cast<interval_t>(ARGINT(5)) : interval_t::zero(); interval_t delaytime[3] = { delay, delay, delay }; - dumb_ptr<map_session_data> owners[3] = { c, NULL, NULL }; + dumb_ptr<map_session_data> owners[3] = { c, nullptr, nullptr }; GET_ARG_ITEM(1, item, stackable); if (stackable) + { map_addflooritem_any(&item, count, loc->m, loc->x, loc->y, owners, delaytime, interval, 0); + } else + { while (count-- > 0) map_addflooritem_any(&item, 1, loc->m, loc->x, loc->y, owners, delaytime, interval, 0); + } return 0; } @@ -929,7 +936,7 @@ int op_drop_item_for (dumb_ptr<env_t>, Slice<val_t> args) static int op_gain_exp(dumb_ptr<env_t>, Slice<val_t> args) { - dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : nullptr; if (!c) return 1; @@ -940,35 +947,35 @@ int op_gain_exp(dumb_ptr<env_t>, Slice<val_t> args) } #define MAGIC_OPERATION(name, args, impl) {{name}, {{name}, {args}, impl}} -#define MAGIC_OPERATION1(name, args) MAGIC_OPERATION(#name, args, op_##name) +#define MAGIC_OPERATION1(name, args) MAGIC_OPERATION(#name##_s, args, op_##name) static std::map<ZString, op_t> operations = { - MAGIC_OPERATION1(sfx, ".ii"), - MAGIC_OPERATION1(instaheal, "eii"), - MAGIC_OPERATION1(itemheal, "eii"), - MAGIC_OPERATION1(shroud, "ei"), - MAGIC_OPERATION("unshroud", "e", op_reveal), - MAGIC_OPERATION1(message, "es"), - MAGIC_OPERATION1(messenger_npc, "lissi"), - MAGIC_OPERATION1(move, "ed"), - MAGIC_OPERATION1(warp, "el"), - MAGIC_OPERATION1(banish, "e"), - MAGIC_OPERATION1(status_change, "eiiiiii"), - MAGIC_OPERATION1(stop_status_change, "ei"), - MAGIC_OPERATION1(override_attack, "eiiiiii"), - MAGIC_OPERATION1(create_item, "e.i"), - MAGIC_OPERATION1(aggravate, "eie"), - MAGIC_OPERATION1(spawn, "aeiiii"), - MAGIC_OPERATION1(injure, "eeii"), - MAGIC_OPERATION1(emote, "ei"), - MAGIC_OPERATION1(set_script_variable, "esi"), - MAGIC_OPERATION1(set_script_str, "ess"), - MAGIC_OPERATION1(set_hair_colour, "ei"), - MAGIC_OPERATION1(set_hair_style, "ei"), - MAGIC_OPERATION("drop_item", "l.ii", op_drop_item_for), - MAGIC_OPERATION1(drop_item_for, "l.iiei"), - MAGIC_OPERATION("gain_experience", "eiii", op_gain_exp), + MAGIC_OPERATION1(sfx, ".ii"_s), + MAGIC_OPERATION1(instaheal, "eii"_s), + MAGIC_OPERATION1(itemheal, "eii"_s), + MAGIC_OPERATION1(shroud, "ei"_s), + MAGIC_OPERATION("unshroud"_s, "e"_s, op_reveal), + MAGIC_OPERATION1(message, "es"_s), + MAGIC_OPERATION1(messenger_npc, "lissi"_s), + MAGIC_OPERATION1(move, "ed"_s), + MAGIC_OPERATION1(warp, "el"_s), + MAGIC_OPERATION1(banish, "e"_s), + MAGIC_OPERATION1(status_change, "eiiiiii"_s), + MAGIC_OPERATION1(stop_status_change, "ei"_s), + MAGIC_OPERATION1(override_attack, "eiiiiii"_s), + MAGIC_OPERATION1(create_item, "e.i"_s), + MAGIC_OPERATION1(aggravate, "eie"_s), + MAGIC_OPERATION1(spawn, "aeiiii"_s), + MAGIC_OPERATION1(injure, "eeii"_s), + MAGIC_OPERATION1(emote, "ei"_s), + MAGIC_OPERATION1(set_script_variable, "esi"_s), + MAGIC_OPERATION1(set_script_str, "ess"_s), + MAGIC_OPERATION1(set_hair_colour, "ei"_s), + MAGIC_OPERATION1(set_hair_style, "ei"_s), + MAGIC_OPERATION("drop_item"_s, "l.ii"_s, op_drop_item_for), + MAGIC_OPERATION1(drop_item_for, "l.iiei"_s), + MAGIC_OPERATION("gain_experience"_s, "eiii"_s, op_gain_exp), }; op_t *magic_get_op(ZString name) @@ -979,7 +986,7 @@ op_t *magic_get_op(ZString name) return &it->second; } -void spell_effect_report_termination(int invocation_id, int bl_id, +void spell_effect_report_termination(BlockId invocation_id, BlockId bl_id, StatusChange sc_id, int) { dumb_ptr<invocation> invocation_ = map_id_is_spell(invocation_id); @@ -1004,8 +1011,8 @@ void spell_effect_report_termination(int invocation_id, int bl_id, dumb_ptr<block_list> entity = map_id2bl(bl_id); if (entity->bl_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); + "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n"_fmt, + bl_id, sc_id); return; } @@ -1015,7 +1022,7 @@ static dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_) { if (!invocation_->stack_size) - return NULL; + return nullptr; else { cont_activation_record_t *ar = @@ -1042,7 +1049,7 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_) case CONT_STACK::FOREACH: { - int entity_id; + BlockId entity_id; val_t *var = &invocation_->env->varu[ar->c.c_foreach.id]; do @@ -1065,7 +1072,7 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_) magic_clear_var(var); var->ty = ar->c.c_foreach.ty; - var->v.v_int = entity_id; + var->v.v_int = static_cast<int32_t>(unwrap<BlockId>(entity_id)); return ar->c.c_foreach.body; } @@ -1089,9 +1096,9 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n", - invocation_->spell->name); - return NULL; + "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n"_fmt, + invocation_->spell->name); + return nullptr; } } } @@ -1105,10 +1112,10 @@ cont_activation_record_t *add_stack_entry(dumb_ptr<invocation> invocation_, if (invocation_->stack_size >= MAX_STACK_SIZE) { FPRINTF(stderr, - "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n", - invocation_->spell->name); + "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n"_fmt, + invocation_->spell->name); invocation_->stack_size--; - return NULL; + return nullptr; } ar->ty = ty; @@ -1118,7 +1125,7 @@ cont_activation_record_t *add_stack_entry(dumb_ptr<invocation> invocation_, static void find_entities_in_area_c(dumb_ptr<block_list> target, - std::vector<int> *entities_vp, + std::vector<BlockId> *entities_vp, FOREACH_FILTER filter) { switch (target->bl_type) @@ -1180,7 +1187,7 @@ void find_entities_in_area_c(dumb_ptr<block_list> target, static void find_entities_in_area(area_t& area_, - std::vector<int> *entities_vp, + std::vector<BlockId> *entities_vp, FOREACH_FILTER filter) { area_t *area = &area_; // temporary hack to "keep diff small". Heh. @@ -1221,8 +1228,8 @@ dumb_ptr<effect_t> run_foreach(dumb_ptr<invocation> invocation, { magic_clear_var(&area); FPRINTF(stderr, - "[magic] Error in spell `%s': FOREACH loop over non-area\n", - invocation->spell->name.c_str()); + "[magic] Error in spell `%s': FOREACH loop over non-area\n"_fmt, + invocation->spell->name); return return_location; } else @@ -1233,7 +1240,7 @@ dumb_ptr<effect_t> run_foreach(dumb_ptr<invocation> invocation, if (!ar) return return_location; - std::vector<int> entities_v; + std::vector<BlockId> entities_v; find_entities_in_area(*area.v.v_area, &entities_v, filter); entities_v.shrink_to_fit(); @@ -1271,8 +1278,8 @@ dumb_ptr<effect_t> run_for (dumb_ptr<invocation> invocation, magic_clear_var(&start); magic_clear_var(&stop); FPRINTF(stderr, - "[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n", - invocation->spell->name); + "[magic] Error in spell `%s': FOR loop start or stop point is not an integer\n"_fmt, + invocation->spell->name); return return_location; } @@ -1319,9 +1326,9 @@ void print_cfg(int i, effect_t *e) { int j; for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); - PRINTF("%p: ", e); + PRINTF("%p: "_fmt, e); if (!e) { @@ -1354,11 +1361,11 @@ void print_cfg(int i, effect_t *e) case EFFECT::IF: puts("IF"); for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); puts("THEN"); print_cfg(i + 1, e->e.e_if.true_branch); for (j = 0; j < i; j++) - PRINTF(" "); + PRINTF(" "_fmt); puts("ELSE"); print_cfg(i + 1, e->e.e_if.false_branch); break; @@ -1391,12 +1398,12 @@ void print_cfg(int i, effect_t *e) static interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) { - const int invocation_id = invocation_->bl_id; + const BlockId invocation_id = invocation_->bl_id; #define REFRESH_INVOCATION invocation_ = map_id_is_spell(invocation_id); if (!invocation_) return interval_t::zero(); #ifdef DEBUG - FPRINTF(stderr, "Resuming execution: invocation of `%s'\n", - invocation_->spell->name); + FPRINTF(stderr, "Resuming execution: invocation of `%s'\n"_fmt, + invocation_->spell->name); print_cfg(1, invocation_->current_effect); #endif while (invocation_->current_effect) @@ -1406,7 +1413,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) int i; #ifdef DEBUG - FPRINTF(stderr, "Next step of type %d\n", e->ty); + FPRINTF(stderr, "Next step of type %d\n"_fmt, e->ty); dump_env(invocation_->env); #endif @@ -1417,11 +1424,11 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) case EFFECT::ABORT: invocation_->flags |= INVOCATION_FLAG::ABORTED; - invocation_->end_effect = NULL; + invocation_->end_effect = nullptr; FALLTHROUGH; case EFFECT::END: clear_stack(invocation_); - next = NULL; + next = nullptr; break; case EFFECT::ASSIGN: @@ -1464,14 +1471,14 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) ZString caster_name = (caster ? caster->status_key.name : CharName()).to__actual(); argrec_t arg[3] = { - {"@target", env->VAR(VAR_TARGET).ty == TYPE::ENTITY ? 0 : env->VAR(VAR_TARGET).v.v_int}, - {"@caster", invocation_->caster}, - {"@caster_name$", caster_name}, + {"@target"_s, env->VAR(VAR_TARGET).ty == TYPE::ENTITY ? 0 : env->VAR(VAR_TARGET).v.v_int}, + {"@caster"_s, static_cast<int32_t>(unwrap<BlockId>(invocation_->caster))}, + {"@caster_name$"_s, caster_name}, }; - int message_recipient = - env->VAR(VAR_SCRIPTTARGET).ty == - TYPE::ENTITY ? env->VAR(VAR_SCRIPTTARGET). - v.v_int : invocation_->caster; + BlockId message_recipient = + env->VAR(VAR_SCRIPTTARGET).ty == TYPE::ENTITY + ? wrap<BlockId>(static_cast<uint32_t>(env->VAR(VAR_SCRIPTTARGET).v.v_int)) + : invocation_->caster; dumb_ptr<map_session_data> recipient = map_id_is_player(message_recipient); if (recipient->npc_id @@ -1516,7 +1523,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) for (i = 0; i < e->e.e_op.args_nr; i++) magic_eval(invocation_->env, &args[i], e->e.e_op.args[i]); - if (!magic_signature_check("effect", op->name, op->signature, + if (!magic_signature_check("effect"_s, op->name, op->signature, Slice<val_t>(args, e->e.e_op.args_nr), e->e.e_op.line_nr, e->e.e_op.column)) @@ -1535,8 +1542,8 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) default: FPRINTF(stderr, - "[magic] INTERNAL ERROR: Unknown effect %d\n", - e->ty); + "[magic] INTERNAL ERROR: Unknown effect %d\n"_fmt, + e->ty); } if (!next) @@ -1583,7 +1590,7 @@ void spell_execute_script(dumb_ptr<invocation> invocation) * running the same spell twice! */ } -int spell_attack(int caster_id, int target_id) +int spell_attack(BlockId caster_id, BlockId target_id) { dumb_ptr<map_session_data> caster = map_id_is_player(caster_id); dumb_ptr<invocation> invocation_; @@ -1601,7 +1608,7 @@ int spell_attack(int caster_id, int target_id) { magic_clear_var(&invocation_->env->varu[VAR_TARGET]); invocation_->env->varu[VAR_TARGET].ty = TYPE::ENTITY; - invocation_->env->varu[VAR_TARGET].v.v_int = target_id; + invocation_->env->varu[VAR_TARGET].v.v_int = static_cast<int32_t>(unwrap<BlockId>(target_id)); invocation_->current_effect = invocation_->trigger_effect; invocation_->flags &= ~INVOCATION_FLAG::ABORTED; @@ -1622,8 +1629,8 @@ int spell_attack(int caster_id, int target_id) } else if (!invocation_ || caster->attack_spell_charges <= 0) { - caster->attack_spell_override = 0; - char_set_weapon_icon(caster, 0, StatusChange::ZERO, 0); + caster->attack_spell_override = BlockId(); + char_set_weapon_icon(caster, 0, StatusChange::ZERO, ItemNameId()); char_set_attack_info(caster, interval_t::zero(), 0); if (stop_attack) @@ -1635,3 +1642,4 @@ int spell_attack(int caster_id, int target_id) return 1; } +} // namespace tmwa |