/// Callback for npc OnTimer*: labels. /// This will be called later if you call npc_timerevent_start. /// This function may only expire, but not deactivate, the counter. static void npc_timerevent(TimerData *, tick_t tick, BlockId id, interval_t data) { dumb_ptr<npc_data_script> nd = map_id2bl(id)->is_npc()->is_script(); assert (nd != nullptr); assert (nd->npc_subtype == NpcSubtype::SCRIPT); assert (nd->scr.next_event != nd->scr.timer_eventv.end()); nd->scr.timertick = tick; const auto te = nd->scr.next_event; // nd->scr.timerid = nullptr; // er, isn't this the same as nd->scr.timer = te->timer? interval_t t = nd->scr.timer += data; assert (t == te->timer); ++nd->scr.next_event; if (nd->scr.next_event != nd->scr.timer_eventv.end()) { interval_t next = nd->scr.next_event->timer - t; nd->scr.timerid = Timer(tick + next, std::bind(npc_timerevent, ph::_1, ph::_2, id, next)); } run_script(ScriptPointer(borrow(*nd->scr.script), te->pos), BlockId(), nd->bl_id); }
static void npc_event_do_sub(NpcEvent key, struct event_data *ev, int *c, NpcEvent name, BlockId rid, Slice<argrec_t> argv) { nullpo_retv(ev); if (name == key) { run_script_l(ScriptPointer(borrow(*ev->nd->scr.script), ev->pos), rid, ev->nd->bl_id, argv); (*c)++; } }
/*========================================== * 全てのNPCのOn*イベント実行 *------------------------------------------ */ static void npc_event_doall_sub(NpcEvent key, struct event_data *ev, int *c, ScriptLabel name, BlockId rid, Slice<argrec_t> argv) { ScriptLabel p = key.label; nullpo_retv(ev); if (name == p) { if (ev->nd->scr.parent != BlockId()) return; // temporary npcs only respond to commands directly issued to them run_script_l(ScriptPointer(script_or_parent(ev->nd), ev->pos), rid, ev->nd->bl_id, argv); (*c)++; } }