From dc0762c547cab250d4fe081706930582a27c0b46 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 24 Apr 2014 22:09:54 -0700 Subject: Conform magic headers to the decl/def rule --- Makefile.in | 4 +-- src/map/clif.cpp | 1 + src/map/fwd.hpp | 5 +++ src/map/magic-expr-eval.hpp | 11 ------ src/map/magic-expr.cpp | 19 +++++++---- src/map/magic-expr.hpp | 26 ++++++--------- src/map/magic-interpreter-aux.cpp | 21 ------------ src/map/magic-interpreter-aux.hpp | 33 ------------------ src/map/magic-interpreter-base.cpp | 6 ++-- src/map/magic-interpreter-base.hpp | 64 +++++++++++++++++++++++++++++++++-- src/map/magic-interpreter.hpp | 42 +---------------------- src/map/magic-stmt.cpp | 8 ++--- src/map/magic-stmt.hpp | 68 ++++++++++++++++++++++++++++++++++++-- src/map/magic-v2.cpp | 2 ++ src/map/magic.cpp | 10 +++--- src/map/magic.hpp | 57 -------------------------------- src/map/map.cpp | 2 +- src/map/pc.cpp | 2 +- src/map/script.cpp | 2 +- src/map/skill.cpp | 2 +- 20 files changed, 175 insertions(+), 210 deletions(-) delete mode 100644 src/map/magic-interpreter-aux.cpp delete mode 100644 src/map/magic-interpreter-aux.hpp diff --git a/Makefile.in b/Makefile.in index af9100b..99fbf0c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -311,9 +311,9 @@ gen-clean: ; ifndef MAKE_RESTARTS obj/%.d: src/%.cpp $(MKDIR_FIRST) - ${CXX} ${CPPFLAGS} -DGENERATING_DEPENDENCIES ${CXXFLAGS} -MG -MM $< \ + $c ${CXX} ${CPPFLAGS} -DGENERATING_DEPENDENCIES ${CXXFLAGS} -MG -MM \ -MT '$(patsubst obj/%.d,%,$@) := ' \ - > $@ + -MF $@ $< endif # the above SRC_DIR replacement is not really safe, but it works okayish. obj/%.ii: src/%.cpp diff --git a/src/map/clif.cpp b/src/map/clif.cpp index b19c7eb..0a6406b 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -51,6 +51,7 @@ #include "intif.hpp" #include "itemdb.hpp" #include "magic.hpp" +#include "magic-stmt.hpp" #include "map.hpp" #include "npc.hpp" #include "party.hpp" diff --git a/src/map/fwd.hpp b/src/map/fwd.hpp index b4ced2d..13d5f54 100644 --- a/src/map/fwd.hpp +++ b/src/map/fwd.hpp @@ -47,5 +47,10 @@ struct location_t; struct area_t; struct spell_t; struct invocation; +struct teleport_anchor_t; +struct env_t; +struct magic_conf_t; +struct component_t; +struct effect_set_t; #endif // TMWA_MAP_FWD_HPP diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp index ae86774..8500fc0 100644 --- a/src/map/magic-expr-eval.hpp +++ b/src/map/magic-expr-eval.hpp @@ -22,21 +22,10 @@ # include "fwd.hpp" -# include "../range/slice.hpp" - -# include "../strings/fwd.hpp" # include "../strings/zstring.hpp" # include "magic-interpreter.t.hpp" -/* Helper definitions for dealing with functions and operations */ - -int magic_signature_check(ZString opname, ZString funname, ZString signature, - Slice args, int line, int column); - -void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, - area_t& area); - // TODO kill this like I killed VAR # define ARGINT(x) args[x].v.v_int # define ARGDIR(x) args[x].v.v_dir diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 9f3f63e..ee422c1 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -1,6 +1,4 @@ -#include "magic-expr-eval.hpp" #include "magic-expr.hpp" -#include "magic-interpreter-aux.hpp" // magic-expr.cpp - Pure functions for the old magic backend. // // Copyright © 2004-2011 The Mana World Development Team @@ -38,14 +36,21 @@ #include "../mmo/dumb_ptr.hpp" #include "battle.hpp" -#include "npc.hpp" -#include "pc.hpp" #include "itemdb.hpp" - +#include "magic-expr-eval.hpp" #include "magic-interpreter.hpp" +#include "magic-interpreter-base.hpp" +#include "npc.hpp" +#include "pc.hpp" #include "../poison.hpp" +template +bool CHECK_TYPE(T *v, TYPE t) +{ + return v->ty == t; +} + static void free_area(dumb_ptr area) { @@ -791,8 +796,8 @@ int fun_hash_entity(dumb_ptr, val_t *result, Slice args) return 0; } -int // ret -1: not a string, ret 1: no such item, ret 0: OK -magic_find_item(Slice args, int index, struct item *item_, int *stackable) +// ret -1: not a string, ret 1: no such item, ret 0: OK +int magic_find_item(Slice args, int index, struct item *item_, int *stackable) { struct item_data *item_data; int must_add_sequentially; diff --git a/src/map/magic-expr.hpp b/src/map/magic-expr.hpp index 007491c..7276fd2 100644 --- a/src/map/magic-expr.hpp +++ b/src/map/magic-expr.hpp @@ -22,8 +22,6 @@ # include "fwd.hpp" -# include "magic-interpreter.hpp" - # include "../mmo/dumb_ptr.hpp" # include "../range/fwd.hpp" @@ -31,6 +29,8 @@ # include "../strings/zstring.hpp" # include "../strings/literal.hpp" +# include "magic-interpreter.t.hpp" + /* * Argument types: * i : int @@ -52,13 +52,6 @@ struct fun_t int (*fun)(dumb_ptr env, val_t *result, Slice arga); }; -struct op_t -{ - ZString name; - ZString signature; - int (*op)(dumb_ptr env, Slice arga); -}; - /** * Retrieves a function by name * @param name The name to look up @@ -66,13 +59,6 @@ struct op_t */ fun_t *magic_get_fun(ZString name); -/** - * Retrieves an operation by name - * @param name The name to look up - * @return An operation of that name, or NULL, and a function index - */ -op_t *magic_get_op(ZString name); - /** * Evaluates an expression and stores the result in `dest' */ @@ -109,4 +95,12 @@ int magic_find_item(Slice args, int index, struct item *item, int *stacka int magic_location_in_area(map_local *m, int x, int y, dumb_ptr area); +/* Helper definitions for dealing with functions and operations */ + +int magic_signature_check(ZString opname, ZString funname, ZString signature, + Slice args, int line, int column); + +void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, + area_t& area); + #endif // TMWA_MAP_MAGIC_EXPR_HPP diff --git a/src/map/magic-interpreter-aux.cpp b/src/map/magic-interpreter-aux.cpp deleted file mode 100644 index 10a376b..0000000 --- a/src/map/magic-interpreter-aux.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "magic-interpreter-aux.hpp" -// magic-interpreter-aux.cpp - Edge of the magic system. -// -// Copyright © 2014 Ben Longbons -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "../poison.hpp" diff --git a/src/map/magic-interpreter-aux.hpp b/src/map/magic-interpreter-aux.hpp deleted file mode 100644 index 0b78b58..0000000 --- a/src/map/magic-interpreter-aux.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef TMWA_MAP_MAGIC_INTERPRETER_AUX_HPP -#define TMWA_MAP_MAGIC_INTERPRETER_AUX_HPP -// magic-interpreter-aux.hpp - Edge of the magic system. -// -// Copyright © 2004-2011 The Mana World Development Team -// Copyright © 2011-2014 Ben Longbons -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -# include "fwd.hpp" - -# include "magic-interpreter.t.hpp" - -template -bool CHECK_TYPE(T *v, TYPE t) -{ - return v->ty == t; -} - -#endif // TMWA_MAP_MAGIC_INTERPRETER_AUX_HPP diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index a7c5496..baec6fb 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -1,5 +1,4 @@ #include "magic-interpreter-base.hpp" -#include "magic.hpp" // magic-interpreter-base.cpp - Core of the old magic system. // // Copyright © 2004-2011 The Mana World Development Team @@ -22,8 +21,6 @@ #include -#include "magic-interpreter.hpp" - #include "../strings/astring.hpp" #include "../strings/xstring.hpp" @@ -31,8 +28,9 @@ #include "../mmo/timer.hpp" +#include "magic.hpp" #include "magic-expr.hpp" - +#include "magic-interpreter.hpp" #include "pc.hpp" #include "../poison.hpp" diff --git a/src/map/magic-interpreter-base.hpp b/src/map/magic-interpreter-base.hpp index 780ada4..1baefc6 100644 --- a/src/map/magic-interpreter-base.hpp +++ b/src/map/magic-interpreter-base.hpp @@ -1,8 +1,9 @@ #ifndef TMWA_MAP_MAGIC_INTERPRETER_BASE_HPP #define TMWA_MAP_MAGIC_INTERPRETER_BASE_HPP -// magic-interpreter-base.hpp - dummy header to make Make dependencies work. +// magic-interpreter-base.hpp - Core of the old magic system. // -// Copyright © 2013 Ben Longbons +// Copyright © 2004-2011 The Mana World Development Team +// Copyright © 2011-2014 Ben Longbons // // This file is part of The Mana World (Athena server) // @@ -21,4 +22,63 @@ # include "fwd.hpp" +# include "../strings/fwd.hpp" + +# include "../mmo/dumb_ptr.hpp" + +extern magic_conf_t magic_conf; /* Global magic conf */ +extern env_t magic_default_env; /* Fake default environment */ + +/** + * Adds a component selection to a component holder (which may initially be NULL) + */ +void magic_add_component(dumb_ptr *component_holder, ItemNameId id, int count); + +/** + * Identifies the invocation used to trigger a spell + * + * Returns empty string if not found + */ +AString magic_find_invocation(XString spellname); + +/** + * Identifies the invocation used to denote a teleport location + * + * Returns empty string if not found + */ +AString magic_find_anchor_invocation(XString teleport_location); + +dumb_ptr magic_find_anchor(XString name); + +dumb_ptr spell_create_env(magic_conf_t *conf, dumb_ptr spell, + dumb_ptr caster, int spellpower, XString param); + +void magic_free_env(dumb_ptr env); + +/** + * near_miss is set to nonzero iff the spell only failed due to ephemereal issues (spell delay in effect, out of mana, out of components) + */ +effect_set_t *spell_trigger(dumb_ptr spell, + dumb_ptr caster, + dumb_ptr env, int *near_miss); + +dumb_ptr spell_instantiate(effect_set_t *effect, dumb_ptr env); + +/** + * Bind a spell to a subject (this is a no-op for `local' spells). + */ +void spell_bind(dumb_ptr subject, dumb_ptr invocation); + +// 1 on failure +int spell_unbind(dumb_ptr subject, dumb_ptr invocation); + +/** + * Clones a spell to run the at_effect field + */ +dumb_ptr spell_clone_effect(dumb_ptr source); + +dumb_ptr magic_find_spell(XString invocation); + +void spell_update_location(dumb_ptr invocation); + #endif // TMWA_MAP_MAGIC_INTERPRETER_BASE_HPP diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp index 16fc447..8861e92 100644 --- a/src/map/magic-interpreter.hpp +++ b/src/map/magic-interpreter.hpp @@ -400,48 +400,10 @@ struct invocation : block_list }; +// inlines for map.hpp inline dumb_ptr block_list::as_spell() { return dumb_ptr(static_cast(this)); } inline dumb_ptr block_list::is_spell() { return bl_type == BL::SPELL ? as_spell() : nullptr; } -extern magic_conf_t magic_conf; /* Global magic conf */ -extern env_t magic_default_env; /* Fake default environment */ - -/** - * Adds a component selection to a component holder (which may initially be NULL) - */ -void magic_add_component(dumb_ptr *component_holder, ItemNameId id, int count); - -dumb_ptr magic_find_anchor(XString name); - -dumb_ptr spell_create_env(magic_conf_t *conf, dumb_ptr spell, - dumb_ptr caster, int spellpower, XString param); - -void magic_free_env(dumb_ptr env); - -/** - * near_miss is set to nonzero iff the spell only failed due to ephemereal issues (spell delay in effect, out of mana, out of components) - */ -effect_set_t *spell_trigger(dumb_ptr spell, - dumb_ptr caster, - dumb_ptr env, int *near_miss); - -dumb_ptr spell_instantiate(effect_set_t *effect, dumb_ptr env); - -/** - * Bind a spell to a subject (this is a no-op for `local' spells). - */ -void spell_bind(dumb_ptr subject, dumb_ptr invocation); - -// 1 on failure -int spell_unbind(dumb_ptr subject, dumb_ptr invocation); - -/** - * Clones a spell to run the at_effect field - */ -dumb_ptr spell_clone_effect(dumb_ptr source); - -dumb_ptr magic_find_spell(XString invocation); - /* The following is used only by the parser: */ struct args_rec_t { @@ -461,6 +423,4 @@ struct proc_t {} }; -void spell_update_location(dumb_ptr invocation); - #endif // TMWA_MAP_MAGIC_INTERPRETER_HPP diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index 5710828..98cdb7e 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -1,5 +1,4 @@ #include "magic-stmt.hpp" -#include "magic.hpp" // magic-stmt.cpp - Imperative commands for the magic backend. // // Copyright © 2004-2011 The Mana World Development Team @@ -33,12 +32,13 @@ #include "../mmo/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 "battle.hpp" -#include "clif.hpp" +#include "magic-interpreter-base.hpp" #include "mob.hpp" #include "npc.hpp" #include "pc.hpp" diff --git a/src/map/magic-stmt.hpp b/src/map/magic-stmt.hpp index 0e687a6..08c2b28 100644 --- a/src/map/magic-stmt.hpp +++ b/src/map/magic-stmt.hpp @@ -1,8 +1,9 @@ #ifndef TMWA_MAP_MAGIC_STMT_HPP #define TMWA_MAP_MAGIC_STMT_HPP -// magic-stmt.hpp - dummy header to make Make dependencies work. +// magic-stmt.hpp - Imperative commands for the magic backend. // -// Copyright © 2013 Ben Longbons +// Copyright © 2004-2011 The Mana World Development Team +// Copyright © 2011-2014 Ben Longbons // // This file is part of The Mana World (Athena server) // @@ -21,4 +22,67 @@ # include "fwd.hpp" +# include "../range/fwd.hpp" + +# include "../mmo/dumb_ptr.hpp" + +# include "skill.t.hpp" + +struct op_t +{ + ZString name; + ZString signature; + int (*op)(dumb_ptr env, Slice arga); +}; + +/** + * Retrieves an operation by name + * @param name The name to look up + * @return An operation of that name, or NULL, and a function index + */ +op_t *magic_get_op(ZString name); + +/** + * Removes the shroud from a character + * + * \param character The character to remove the shroud from + */ +void magic_unshroud(dumb_ptr character); + +/** + * Notifies a running spell that a status_change timer triggered by the spell has expired + * + * \param invocation The invocation to notify + * \param bl_id ID of the PC for whom this happened + * \param sc_id ID of the status change entry that finished + * \param supplanted Whether the status_change finished normally (0) or was supplanted by a new status_change (1) + */ +void spell_effect_report_termination(BlockId invocation, BlockId bl_id, + StatusChange sc_id, int supplanted); + +/** + * Execute a spell invocation and sets up timers to finish + */ +void spell_execute(dumb_ptr invocation); + +/** + * Continue an NPC script embedded in a spell + */ +void spell_execute_script(dumb_ptr invocation); + +/** + * Stops all magic bound to the specified character + * + */ +void magic_stop_completely(dumb_ptr c); + +/** + * Attacks with a magical spell charged to the character + * + * Returns 0 if there is no charged spell or the spell is depleted. + */ +int spell_attack(BlockId caster, BlockId target); + +void spell_free_invocation(dumb_ptr invocation); + #endif // TMWA_MAP_MAGIC_STMT_HPP diff --git a/src/map/magic-v2.cpp b/src/map/magic-v2.cpp index 0239438..510c619 100644 --- a/src/map/magic-v2.cpp +++ b/src/map/magic-v2.cpp @@ -37,6 +37,8 @@ #include "itemdb.hpp" #include "magic-expr.hpp" #include "magic-interpreter.hpp" +#include "magic-interpreter-base.hpp" +#include "magic-stmt.hpp" #include "../poison.hpp" diff --git a/src/map/magic.cpp b/src/map/magic.cpp index fec8372..88ee1f1 100644 --- a/src/map/magic.cpp +++ b/src/map/magic.cpp @@ -1,3 +1,4 @@ +#include "magic.hpp" // magic.cpp - Entry to the magic system. // // Copyright © 2004-2011 The Mana World Development Team @@ -27,15 +28,12 @@ #include "../mmo/dumb_ptr.hpp" -#include "magic-interpreter.hpp" - -#include "map.hpp" -#include "pc.hpp" - #include "magic-expr.hpp" +#include "magic-interpreter.hpp" #include "magic-interpreter-base.hpp" #include "magic-stmt.hpp" -#include "magic.hpp" +#include "map.hpp" +#include "pc.hpp" #include "../poison.hpp" diff --git a/src/map/magic.hpp b/src/map/magic.hpp index 642ae21..cd0ff99 100644 --- a/src/map/magic.hpp +++ b/src/map/magic.hpp @@ -42,61 +42,4 @@ */ int magic_message(dumb_ptr caster, XString source_invocation); -/** - * Removes the shroud from a character - * - * \param character The character to remove the shroud from - */ -void magic_unshroud(dumb_ptr character); - -/** - * Notifies a running spell that a status_change timer triggered by the spell has expired - * - * \param invocation The invocation to notify - * \param bl_id ID of the PC for whom this happened - * \param sc_id ID of the status change entry that finished - * \param supplanted Whether the status_change finished normally (0) or was supplanted by a new status_change (1) - */ -void spell_effect_report_termination(BlockId invocation, BlockId bl_id, - StatusChange sc_id, int supplanted); - -/** - * Identifies the invocation used to trigger a spell - * - * Returns empty string if not found - */ -AString magic_find_invocation(XString spellname); - -/** - * Identifies the invocation used to denote a teleport location - * - * Returns empty string if not found - */ -AString magic_find_anchor_invocation(XString teleport_location); - -/** - * Execute a spell invocation and sets up timers to finish - */ -void spell_execute(dumb_ptr invocation); - -/** - * Continue an NPC script embedded in a spell - */ -void spell_execute_script(dumb_ptr invocation); - -/** - * Stops all magic bound to the specified character - * - */ -void magic_stop_completely(dumb_ptr c); - -/** - * Attacks with a magical spell charged to the character - * - * Returns 0 if there is no charged spell or the spell is depleted. - */ -int spell_attack(BlockId caster, BlockId target); - -void spell_free_invocation(dumb_ptr invocation); - #endif // TMWA_MAP_MAGIC_HPP diff --git a/src/map/map.cpp b/src/map/map.cpp index c98c315..b845abc 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -63,8 +63,8 @@ #include "clif.hpp" #include "grfio.hpp" #include "itemdb.hpp" -#include "magic.hpp" #include "magic-interpreter.hpp" // for is_spell inline body +#include "magic-stmt.hpp" #include "magic-v2.hpp" #include "mob.hpp" #include "npc.hpp" diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 47e45a5..c9e67ea 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -49,7 +49,7 @@ #include "clif.hpp" #include "intif.hpp" #include "itemdb.hpp" -#include "magic.hpp" +#include "magic-stmt.hpp" #include "map.hpp" #include "npc.hpp" #include "party.hpp" diff --git a/src/map/script.cpp b/src/map/script.cpp index 7abea69..158a832 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -61,7 +61,7 @@ #include "clif.hpp" #include "intif.hpp" #include "itemdb.hpp" -#include "magic.hpp" +#include "magic-interpreter-base.hpp" #include "map.hpp" #include "mob.hpp" #include "npc.hpp" diff --git a/src/map/skill.cpp b/src/map/skill.cpp index ab14427..8e67065 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -46,7 +46,7 @@ #include "battle.hpp" #include "clif.hpp" -#include "magic.hpp" +#include "magic-stmt.hpp" #include "mob.hpp" #include "pc.hpp" -- cgit v1.2.3-60-g2f50