summaryrefslogtreecommitdiff
path: root/src/map/magic-interpreter-base.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/magic-interpreter-base.cpp')
-rw-r--r--src/map/magic-interpreter-base.cpp92
1 files changed, 48 insertions, 44 deletions
diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp
index d86f595..768a7df 100644
--- a/src/map/magic-interpreter-base.cpp
+++ b/src/map/magic-interpreter-base.cpp
@@ -19,22 +19,25 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include "magic-interpreter-aux.hpp"
-#include "magic-interpreter.hpp"
+#include <algorithm>
#include "../strings/astring.hpp"
#include "../strings/xstring.hpp"
#include "../io/cxxstdio.hpp"
-#include "../mmo/timer.hpp"
+#include "../net/timer.hpp"
+#include "magic.hpp"
#include "magic-expr.hpp"
-
+#include "magic-interpreter.hpp"
#include "pc.hpp"
#include "../poison.hpp"
+
+namespace tmwa
+{
static
void set_int_p(val_t *v, int i, TYPE t)
{
@@ -43,8 +46,8 @@ void set_int_p(val_t *v, int i, TYPE t)
}
#warning "This code should die"
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-macros"
+DIAG_PUSH();
+DIAG_I(unused_macros);
#define set_int(v, i) set_int_p(v, i, TYPE::INT)
#define set_dir(v, i) set_int_p(v, i, TYPE::DIR)
@@ -58,14 +61,14 @@ static
void set_entity(val_t *v, dumb_ptr<block_list> e)
{
v->ty = TYPE::ENTITY;
- v->v.v_int = e->bl_id;
+ v->v.v_int = static_cast<int32_t>(unwrap<BlockId>(e->bl_id));
}
static
void set_invocation(val_t *v, dumb_ptr<invocation> i)
{
v->ty = TYPE::INVOCATION;
- v->v.v_int = i->bl_id;
+ v->v.v_int = static_cast<int32_t>(unwrap<BlockId>(i->bl_id));
}
static
@@ -82,10 +85,10 @@ void set_spell SETTER(dumb_ptr<spell_t>, TYPE::SPELL, v_spell)
#define set_env_invocation(v, x) setenv(set_invocation, v, x)
#define set_env_spell(v, x) setenv(set_spell, v, x)
-#pragma GCC diagnostic pop
+DIAG_POP();
magic_conf_t magic_conf; /* Global magic conf */
-env_t magic_default_env = { &magic_conf, NULL };
+env_t magic_default_env = { &magic_conf, nullptr };
AString magic_find_invocation(XString spellname)
{
@@ -102,7 +105,7 @@ dumb_ptr<spell_t> magic_find_spell(XString invocation)
if (it != magic_conf.spells_by_invocation.end())
return it->second;
- return NULL;
+ return nullptr;
}
/* -------------------------------------------------------------------------------- */
@@ -125,7 +128,7 @@ dumb_ptr<teleport_anchor_t> magic_find_anchor(XString name)
if (it != magic_conf.anchors_by_invocation.end())
return it->second;
- return NULL;
+ return nullptr;
}
/* -------------------------------------------------------------------------------- */
@@ -187,8 +190,8 @@ dumb_ptr<env_t> spell_create_env(magic_conf_t *conf, dumb_ptr<spell_t> spell,
break;
default:
- FPRINTF(stderr, "Unexpected spellarg type %d\n",
- spell->spellarg_ty);
+ FPRINTF(stderr, "Unexpected spellarg type %d\n"_fmt,
+ spell->spellarg_ty);
}
set_env_entity(VAR_CASTER, caster);
@@ -201,22 +204,22 @@ dumb_ptr<env_t> spell_create_env(magic_conf_t *conf, dumb_ptr<spell_t> spell,
static
void free_components(dumb_ptr<component_t> *component_holder)
{
- if (*component_holder == NULL)
+ if (*component_holder == nullptr)
return;
free_components(&(*component_holder)->next);
(*component_holder).delete_();
- *component_holder = NULL;
+ *component_holder = nullptr;
}
-void magic_add_component(dumb_ptr<component_t> *component_holder, int id, int count)
+void magic_add_component(dumb_ptr<component_t> *component_holder, ItemNameId id, int count)
{
if (count <= 0)
return;
- if (*component_holder == NULL)
+ if (*component_holder == nullptr)
{
auto component = dumb_ptr<component_t>::make();
- component->next = NULL;
+ component->next = nullptr;
component->item_id = id;
component->count = count;
*component_holder = component;
@@ -238,7 +241,7 @@ void magic_add_component(dumb_ptr<component_t> *component_holder, int id, int co
static
void copy_components(dumb_ptr<component_t> *component_holder, dumb_ptr<component_t> component)
{
- if (component == NULL)
+ if (component == nullptr)
return;
magic_add_component(component_holder, component->item_id, component->count);
@@ -296,7 +299,7 @@ int spellguard_can_satisfy(spellguard_check_t *check, dumb_ptr<map_session_data>
interval_t casttime = check->casttime;
if (env->VAR(VAR_MIN_CASTTIME).ty == TYPE::INT)
- casttime = max(casttime, static_cast<interval_t>(env->VAR(VAR_MIN_CASTTIME).v.v_int));
+ casttime = std::max(casttime, static_cast<interval_t>(env->VAR(VAR_MIN_CASTTIME).v.v_int));
caster->cast_tick = tick + casttime; /* Make sure not to cast too frequently */
@@ -314,14 +317,14 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check,
dumb_ptr<env_t> env,
int *near_miss)
{
- if (guard == NULL)
- return NULL;
+ if (guard == nullptr)
+ return nullptr;
switch (guard->ty)
{
case SPELLGUARD::CONDITION:
if (!magic_eval_int(env, guard->s.s_condition))
- return NULL;
+ return nullptr;
break;
case SPELLGUARD::COMPONENTS:
@@ -337,8 +340,8 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check,
spellguard_check_t altcheck = *check;
effect_set_t *retval;
- altcheck.components = NULL;
- altcheck.catalysts = NULL;
+ altcheck.components = nullptr;
+ altcheck.catalysts = nullptr;
copy_components(&altcheck.catalysts, check->catalysts);
copy_components(&altcheck.components, check->components);
@@ -367,12 +370,12 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check,
if (spellguard_can_satisfy(check, caster, env, near_miss))
return &guard->s.s_effect;
else
- return NULL;
+ return nullptr;
default:
- FPRINTF(stderr, "Unexpected spellguard type %d\n",
+ FPRINTF(stderr, "Unexpected spellguard type %d\n"_fmt,
guard->ty);
- return NULL;
+ return nullptr;
}
return spellguard_check_sub(check, guard->next, caster, env, near_miss);
@@ -385,8 +388,8 @@ effect_set_t *check_spellguard(dumb_ptr<spellguard_t> guard,
{
spellguard_check_t check;
effect_set_t *retval;
- check.catalysts = NULL;
- check.components = NULL;
+ check.catalysts = nullptr;
+ check.components = nullptr;
check.mana = 0;
check.casttime = interval_t::zero();
@@ -449,7 +452,7 @@ dumb_ptr<invocation> spell_instantiate(effect_set_t *effect_set, dumb_ptr<env_t>
retval->env = env;
- retval->caster = env->VAR(VAR_CASTER).v.v_int;
+ retval->caster = wrap<BlockId>(static_cast<uint32_t>(env->VAR(VAR_CASTER).v.v_int));
retval->spell = env->VAR(VAR_SPELL).v.v_spell;
retval->stack_size = 0;
retval->current_effect = effect_set->effect;
@@ -478,12 +481,12 @@ dumb_ptr<invocation> spell_clone_effect(dumb_ptr<invocation> base)
// since this is the only call site, it is expanded here
//*retval = *base;
- retval->next_invocation = NULL;
+ retval->next_invocation = nullptr;
retval->flags = INVOCATION_FLAG::ZERO;
dumb_ptr<env_t> env = retval->env = clone_env(base->env);
retval->spell = base->spell;
retval->caster = base->caster;
- retval->subject = 0;
+ retval->subject = BlockId();
// retval->timer = 0;
retval->stack_size = 0;
// retval->stack = undef;
@@ -491,12 +494,12 @@ dumb_ptr<invocation> spell_clone_effect(dumb_ptr<invocation> base)
// huh?
retval->current_effect = base->trigger_effect;
retval->trigger_effect = base->trigger_effect;
- retval->end_effect = NULL;
- // retval->status_change_refs = NULL;
+ retval->end_effect = nullptr;
+ // retval->status_change_refs = nullptr;
- retval->bl_id = 0;
- retval->bl_prev = NULL;
- retval->bl_next = NULL;
+ retval->bl_id = BlockId();
+ retval->bl_prev = nullptr;
+ retval->bl_next = nullptr;
retval->bl_m = base->bl_m;
retval->bl_x = base->bl_x;
retval->bl_y = base->bl_y;
@@ -517,10 +520,10 @@ void spell_bind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invocat
if (bool(invocation->flags & INVOCATION_FLAG::BOUND)
|| invocation->subject || invocation->next_invocation)
{
- int *i = NULL;
+ int *i = nullptr;
FPRINTF(stderr,
- "[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n",
- invocation->spell->name);
+ "[magic] INTERNAL ERROR: Attempt to re-bind spell invocation `%s'\n"_fmt,
+ invocation->spell->name);
*i = 1;
return;
}
@@ -545,8 +548,8 @@ int spell_unbind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invoca
*seeker = invocation_->next_invocation;
invocation_->flags &= ~INVOCATION_FLAG::BOUND;
- invocation_->next_invocation = NULL;
- invocation_->subject = 0;
+ invocation_->next_invocation = nullptr;
+ invocation_->subject = BlockId();
return 0;
}
@@ -555,3 +558,4 @@ int spell_unbind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invoca
return 1;
}
+} // namespace tmwa