summaryrefslogtreecommitdiff
path: root/src/map/magic-stmt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/magic-stmt.cpp')
-rw-r--r--src/map/magic-stmt.cpp85
1 files changed, 46 insertions, 39 deletions
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp
index 2a657fa..4d8330a 100644
--- a/src/map/magic-stmt.cpp
+++ b/src/map/magic-stmt.cpp
@@ -29,7 +29,8 @@
#include "../generic/random2.hpp"
#include "../io/cxxstdio.hpp"
-#include "../io/cxxstdio_enums.hpp"
+
+#include "../mmo/cxxstdio_enums.hpp"
#include "../net/timer.hpp"
@@ -42,7 +43,9 @@
#include "magic-interpreter-base.hpp"
#include "mob.hpp"
#include "npc.hpp"
+#include "npc-parse.hpp"
#include "pc.hpp"
+#include "script-call.hpp"
#include "skill.hpp"
#include "../poison.hpp"
@@ -50,6 +53,8 @@
namespace tmwa
{
+namespace map
+{
namespace magic
{
/* used for local spell effects */
@@ -58,17 +63,18 @@ constexpr Species INVISIBLE_NPC = wrap<Species>(127);
static
void clear_activation_record(cont_activation_record_t *ar)
{
- MATCH (*ar)
+ MATCH_BEGIN (*ar)
{
- CASE (CarForEach&, c_foreach)
+ MATCH_CASE (CarForEach&, c_foreach)
{
c_foreach.entities_vp.delete_();
}
- CASE (CarProc&, c_proc)
+ MATCH_CASE (CarProc&, c_proc)
{
c_proc.old_actualpa.delete_();
}
}
+ MATCH_END ();
}
static
@@ -218,7 +224,7 @@ BlockId trigger_spell(BlockId subject, BlockId spell)
}
static
-void entity_warp(dumb_ptr<block_list> target, map_local *destm, int destx, int desty);
+void entity_warp(dumb_ptr<block_list> target, Borrowed<map_local> destm, int destx, int desty);
static
void char_update(dumb_ptr<map_session_data> character)
@@ -261,7 +267,7 @@ void timer_callback_effect_npc_delete(TimerData *, tick_t, BlockId npc_id)
}
static
-dumb_ptr<npc_data> local_spell_effect(map_local *m, int x, int y, int effect,
+dumb_ptr<npc_data> local_spell_effect(Borrowed<map_local> m, int x, int y, int effect,
interval_t tdelay)
{
/* 1 minute should be enough for all interesting spell effects, I hope */
@@ -421,7 +427,7 @@ int op_messenger_npc(dumb_ptr<env_t>, Slice<val_t> args)
}
static
-void entity_warp(dumb_ptr<block_list> target, map_local *destm, int destx, int desty)
+void entity_warp(dumb_ptr<block_list> target, Borrowed<map_local> destm, int destx, int desty)
{
if (target->bl_type == BL::PC || target->bl_type == BL::MOB)
{
@@ -767,8 +773,8 @@ int op_injure(dumb_ptr<env_t> env, Slice<val_t> args)
if (target->bl_type == BL::PC
&& !target->bl_m->flag.get(MapFlag::PVP)
- && !target->is_player()->special_state.killable
- && (caster->bl_type != BL::PC || !caster->is_player()->special_state.killer))
+ && (caster->bl_type == BL::PC)
+ && ((caster->is_player()->state.pvpchannel > 1) && (target->is_player()->state.pvpchannel != caster->is_player()->state.pvpchannel)))
return 0; /* Cannot damage other players outside of pvp */
if (target != caster)
@@ -786,7 +792,7 @@ int op_injure(dumb_ptr<env_t> env, Slice<val_t> args)
// display damage first, because dealing damage may deallocate the target.
clif_damage(caster, target,
gettick(), interval_t::zero(), interval_t::zero(),
- damage_caused, 0, DamageType::NORMAL, 0);
+ damage_caused, 0, DamageType::NORMAL);
if (caster->bl_type == BL::PC)
{
@@ -995,9 +1001,9 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_)
{
cont_activation_record_t *ar =
&invocation_->stack.back();
- MATCH (*ar)
+ MATCH_BEGIN (*ar)
{
- CASE (const CarProc&, c_proc)
+ MATCH_CASE (const CarProc&, c_proc)
{
dumb_ptr<effect_t> ret = ar->return_location;
for (int i = 0; i < c_proc.args_nr; i++)
@@ -1014,7 +1020,7 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_)
return ret;
}
- CASE (CarForEach&, c_foreach)
+ MATCH_CASE (CarForEach&, c_foreach)
{
BlockId entity_id;
val_t *var = &invocation_->env->varu[c_foreach.id];
@@ -1045,7 +1051,7 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_)
return c_foreach.body;
}
- CASE (CarFor&, c_for)
+ MATCH_CASE (CarFor&, c_for)
{
if (c_for.current > c_for.stop)
{
@@ -1062,6 +1068,7 @@ dumb_ptr<effect_t> return_to_stack(dumb_ptr<invocation> invocation_)
return c_for.body;
}
}
+ MATCH_END ();
abort();
}
}
@@ -1133,46 +1140,43 @@ void find_entities_in_area(area_t& area_,
std::vector<BlockId> *entities_vp,
FOREACH_FILTER filter)
{
- MATCH (area_)
+ MATCH_BEGIN (area_)
{
- CASE (const AreaUnion&, a)
+ MATCH_CASE (const AreaUnion&, a)
{
find_entities_in_area(*a.a_union[0], entities_vp, filter);
find_entities_in_area(*a.a_union[1], entities_vp, filter);
}
- CASE (const location_t&, a_loc)
+ MATCH_CASE (const location_t&, a_loc)
{
(void)a_loc;
// TODO this can be simplified
- map_local *m;
int x, y, width, height;
- magic_area_rect(&m, &x, &y, &width, &height, area_);
+ Borrowed<map_local> m = magic_area_rect(&x, &y, &width, &height, area_);
map_foreachinarea(std::bind(find_entities_in_area_c, ph::_1, entities_vp, filter),
m,
x, y,
x + width, y + height,
BL::NUL /* filter elsewhere */);
}
- CASE (const AreaRect&, a_rect)
+ MATCH_CASE (const AreaRect&, a_rect)
{
(void)a_rect;
// TODO this can be simplified
- map_local *m;
int x, y, width, height;
- magic_area_rect(&m, &x, &y, &width, &height, area_);
+ Borrowed<map_local> m = magic_area_rect(&x, &y, &width, &height, area_);
map_foreachinarea(std::bind(find_entities_in_area_c, ph::_1, entities_vp, filter),
m,
x, y,
x + width, y + height,
BL::NUL /* filter elsewhere */);
}
- CASE (const AreaBar&, a_bar)
+ MATCH_CASE (const AreaBar&, a_bar)
{
(void)a_bar;
// TODO this is wrong
- map_local *m;
int x, y, width, height;
- magic_area_rect(&m, &x, &y, &width, &height, area_);
+ Borrowed<map_local> m = magic_area_rect(&x, &y, &width, &height, area_);
map_foreachinarea(std::bind(find_entities_in_area_c, ph::_1, entities_vp, filter),
m,
x, y,
@@ -1180,6 +1184,7 @@ void find_entities_in_area(area_t& area_,
BL::NUL /* filter elsewhere */);
}
}
+ MATCH_END ();
}
static
@@ -1312,13 +1317,13 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete)
dumb_ptr<effect_t> next = e->next;
int i;
- MATCH (*e)
+ MATCH_BEGIN (*e)
{
- CASE (const EffectSkip&, e_)
+ MATCH_CASE (const EffectSkip&, e_)
{
(void)e_;
}
- CASE (const EffectAbort&, e_)
+ MATCH_CASE (const EffectAbort&, e_)
{
(void)e_;
invocation_->flags |= INVOCATION_FLAG::ABORTED;
@@ -1326,34 +1331,34 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete)
clear_stack(invocation_);
next = nullptr;
}
- CASE (const EffectEnd&, e_)
+ MATCH_CASE (const EffectEnd&, e_)
{
(void)e_;
clear_stack(invocation_);
next = nullptr;
}
- CASE (const EffectAssign&, e_assign)
+ MATCH_CASE (const EffectAssign&, e_assign)
{
magic_eval(invocation_->env,
&invocation_->env->varu[e_assign.id],
e_assign.expr);
}
- CASE (const EffectForEach&, e_foreach)
+ MATCH_CASE (const EffectForEach&, e_foreach)
{
next = run_foreach(invocation_, &e_foreach, next);
}
- CASE (const EffectFor&, e_for)
+ MATCH_CASE (const EffectFor&, e_for)
{
next = run_for (invocation_, &e_for, next);
}
- CASE (const EffectIf&, e_if)
+ MATCH_CASE (const EffectIf&, e_if)
{
if (magic_eval_int(invocation_->env, e_if.cond))
next = e_if.true_branch;
else
next = e_if.false_branch;
}
- CASE (const EffectSleep&, e_)
+ MATCH_CASE (const EffectSleep&, e_)
{
interval_t sleeptime = static_cast<interval_t>(
magic_eval_int(invocation_->env, e_.e_sleep));
@@ -1361,7 +1366,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete)
if (sleeptime > interval_t::zero())
return sleeptime;
}
- CASE (const EffectScript&, e_)
+ MATCH_CASE (const EffectScript&, e_)
{
dumb_ptr<map_session_data> caster = map_id_is_player(invocation_->caster);
if (caster)
@@ -1391,7 +1396,7 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete)
// dealing with an NPC
int newpos = run_script_l(
- ScriptPointer(&*e_.e_script, invocation_->script_pos),
+ ScriptPointer(borrow(*e_.e_script), invocation_->script_pos),
message_recipient, invocation_->bl_id,
arg);
/* Returns the new script position, or -1 once the script is finished */
@@ -1408,12 +1413,12 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete)
}
REFRESH_INVOCATION; // Script may have killed the caster
}
- CASE (const EffectBreak&, e_)
+ MATCH_CASE (const EffectBreak&, e_)
{
(void)e_;
next = return_to_stack(invocation_);
}
- CASE (const EffectOp&, e_op)
+ MATCH_CASE (const EffectOp&, e_op)
{
op_t *op = e_op.opp;
val_t args[MAX_ARGS];
@@ -1432,11 +1437,12 @@ interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete)
REFRESH_INVOCATION; // Effect may have killed the caster
}
- CASE (const EffectCall&, e_call)
+ MATCH_CASE (const EffectCall&, e_call)
{
next = run_call(invocation_, &e_call, next);
}
}
+ MATCH_END ();
break_match:
if (!next)
@@ -1535,4 +1541,5 @@ int spell_attack(BlockId caster_id, BlockId target_id)
return 1;
}
} // namespace magic
+} // namespace map
} // namespace tmwa