From 9cc8039347c5136adf4c1936db0d221a8217b26a Mon Sep 17 00:00:00 2001 From: mekolat Date: Wed, 24 Jun 2015 18:27:45 -0400 Subject: remove ugly workaround --- src/map/globals.cpp | 1 - src/map/globals.hpp | 1 - src/map/npc.cpp | 41 ++++++++++++++++++++++------------------- src/map/script-fun.cpp | 6 +----- 4 files changed, 23 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/map/globals.cpp b/src/map/globals.cpp index c96037e..49d6074 100644 --- a/src/map/globals.cpp +++ b/src/map/globals.cpp @@ -73,7 +73,6 @@ namespace tmwa BlockId npc_id = START_NPC_NUM; Map ev_db; DMap> npcs_by_name; - DMap spells_by_name; DMap spells_by_events; // used for clock-based event triggers // only tm_min, tm_hour, and tm_mday are used diff --git a/src/map/globals.hpp b/src/map/globals.hpp index 84e4765..1c8e70d 100644 --- a/src/map/globals.hpp +++ b/src/map/globals.hpp @@ -68,7 +68,6 @@ namespace tmwa extern BlockId npc_id; extern Map ev_db; extern DMap> npcs_by_name; - extern DMap spells_by_name; extern DMap spells_by_events; extern tm ev_tm_b; extern Map party_db; diff --git a/src/map/npc.cpp b/src/map/npc.cpp index ae126ea..137cd71 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -154,19 +154,11 @@ dumb_ptr npc_name2id(NpcName name) return npcs_by_name.get(name); } -/*========================================== - * NPC Spells - *------------------------------------------ - */ -NpcName spell_name2id(RString name) -{ - return spells_by_name.get(name); -} - /*========================================== * NPC Spells Events *------------------------------------------ */ +static NpcEvent spell_event2id(RString name) { return spells_by_events.get(name); @@ -209,31 +201,23 @@ int magic_message(dumb_ptr caster, XString source_invocation) { auto pair = magic_tokenise(source_invocation); // Spell Cast - NpcName spell_name = spell_name2id(pair.first); NpcEvent spell_event = spell_event2id(pair.first); PRINTF("Cast: %s\n"_fmt, RString(pair.first)); RString spell_params = pair.second; - dumb_ptr nd = npc_name2id(spell_event.label? spell_event.npc: spell_name); + dumb_ptr nd = npc_name2id(spell_event.npc); if (nd) { PRINTF("NPC: '%s' %d\n"_fmt, nd->name, nd->bl_id); PRINTF("Params: '%s'\n"_fmt, spell_params); - caster->npc_id = nd->bl_id; - dumb_ptr map_bl = map_id2bl(nd->bl_id); - if (!map_bl) - map_addnpc(caster->bl_m, nd); argrec_t arg[1] = { {"@args$"_s, spell_params}, }; - if (spell_event.label) - caster->npc_pos = npc_event_do_l(spell_event, caster->bl_id, arg); - else - caster->npc_pos = run_script_l(ScriptPointer(script_or_parent(nd->is_script()), 0), caster->bl_id, nd->bl_id, arg); + npc_event_do_l(spell_event, caster->bl_id, arg); return 1; } return 0; @@ -321,6 +305,7 @@ void npc_event_do_sub(NpcEvent key, struct event_data *ev, } } +// XXX maybe merge npc_event_do_l into npc_event ? int npc_event_do_l(NpcEvent name, BlockId rid, Slice args) { int c = 0; @@ -330,6 +315,17 @@ int npc_event_do_l(NpcEvent name, BlockId rid, Slice args) return npc_event_doall_l(name.label, rid, args); } + if (!name.label && rid) + { + dumb_ptr sd = map_id2bl(rid)->is_player(); + dumb_ptr nd = npc_name2id(name.npc)->is_script(); + if (!nd || !sd || sd->npc_id) + return 0; + sd->npc_id = nd->bl_id; + sd->npc_pos = run_script_l(ScriptPointer(script_or_parent(nd), 0), rid, nd->bl_id, args); + return sd->npc_pos; + } + for (auto& pair : ev_db) npc_event_do_sub(pair.first, &pair.second, &c, name, rid, args); return c; @@ -609,6 +605,12 @@ void npc_settimerevent_tick(dumb_ptr nd, interval_t newtimer) int npc_event(dumb_ptr sd, NpcEvent eventname, int mob_kill) { + if (!eventname.label && eventname.npc && sd) + { + npc_event_do_l(eventname, sd->bl_id, nullptr); + return 1; + } + Option> ev_ = ev_db.search(eventname); dumb_ptr nd; @@ -816,6 +818,7 @@ int npc_click(dumb_ptr sd, BlockId id) npc_event_dequeue(sd); break; case NpcSubtype::SCRIPT: + // XXX use npc_event_script_l instead? sd->npc_pos = run_script(ScriptPointer(script_or_parent(nd->is_script()), 0), sd->bl_id, id); break; case NpcSubtype::MESSAGE: diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 6fe77bf..8afe4ef 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -3667,14 +3667,10 @@ static void builtin_registercmd(ScriptState *st) { RString evoke = conv_str(st, &AARG(0)); - NpcName npcname = stringish(conv_str(st, &AARG(1))); ZString event_ = conv_str(st, &AARG(1)); NpcEvent event; extract(event_, &event); - if (event.label) - spells_by_events.put(evoke, event); - else - spells_by_name.put(evoke, npcname); + spells_by_events.put(evoke, event); } /*========================================== -- cgit v1.2.3-60-g2f50