diff --git a/hyper.h b/hyper.h index 6456030d..44e8d396 100644 --- a/hyper.h +++ b/hyper.h @@ -632,6 +632,9 @@ namespace multi { void showShmupConfig(); } +template class hookset : public map> {}; +typedef hookset *purehookset; + namespace shmup { using namespace multi; void recall(); @@ -655,6 +658,7 @@ namespace shmup { bool dead; bool notpushed; bool inBoat; + bool no_targetting; monster *parent; // who shot this missile eMonster parenttype; // type of the parent int nextshot; // when will it be able to shot (players/flailers) @@ -669,7 +673,7 @@ namespace shmup { monster() { dead = false; inBoat = false; parent = NULL; nextshot = 0; - stunoff = 0; blowoff = 0; footphase = 0; + stunoff = 0; blowoff = 0; footphase = 0; no_targetting = false; } void store(); @@ -711,6 +715,11 @@ namespace shmup { void pushmonsters(); void popmonsters(); + + extern hookset *hooks_turn; + extern hookset *hooks_draw; + extern hookset *hooks_kill; + extern hookset *hooks_describe; } static const int NOHINT = -1; @@ -2001,9 +2010,6 @@ extern int ringcolor; #include -template class hookset : public map> {}; -typedef hookset *purehookset; - template int addHook(hookset*& m, int prio, const U& hook) { if(!m) m = new hookset (); while(m->count(prio)) { diff --git a/rogueviz.cpp b/rogueviz.cpp index aadf8491..9d1a5799 100644 --- a/rogueviz.cpp +++ b/rogueviz.cpp @@ -180,6 +180,7 @@ void addedge(int i, int j, edgeinfo *ei) { vd.virt = ei; createViz(id, base, rgpushxto0(h)); + vd.m->no_targetting = true; addedge(i, id, ei); addedge(id, j, ei); @@ -957,7 +958,10 @@ void describe(cell *c) { if(kind == kKohonen) return kohonen::describe(c); } -string describe(shmup::monster *m) { +bool describe_monster(shmup::monster *m, string& out) { + + if(m->type != moRogueviz) return false; + int i = m->pid; vertexdata& vd = vdata[i]; @@ -987,10 +991,12 @@ string describe(shmup::monster *m) { help += "/" + fts(ei->weight)+":" + fts(ei->weight2) + " "; } - return o; + out += o; + return true; } -void activate(shmup::monster *m) { +bool activate(shmup::monster *m) { + if(m->type != moRogueviz) return false; int i = m->pid; vertexdata& vd = vdata[i]; @@ -999,6 +1005,8 @@ void activate(shmup::monster *m) { for(int i=0; iorig = NULL; + return true; + /* if(ealpha == 1) ealpha = 8; else if(ealpha == 8) ealpha = 32; else if(ealpha == 32) ealpha = 255; @@ -1065,8 +1073,8 @@ transmatrix& memo_relative_matrix(cell *c1, cell *c2) { return p; } -void drawVertex(const transmatrix &V, cell *c, shmup::monster *m) { - if(m->dead) return; +bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) { + if(m->dead) return true; int i = m->pid; vertexdata& vd = vdata[i]; @@ -1283,12 +1291,7 @@ void drawVertex(const transmatrix &V, cell *c, shmup::monster *m) { } } - } - -bool virt(shmup::monster *m) { - if(m->type != moRogueviz) return false; - vertexdata& vd = vdata[m->pid]; - return vd.virt; + return true; } vector legend; @@ -1489,10 +1492,11 @@ void close() { relmatrices.clear(); } -void turn(int delta) { - if(!on) return; +bool turn(int delta) { + if(!on) return false; if(kind == kSAG) sag::iterate(); if(kind == kKohonen) kohonen::steps(); + return false; // shmup::pc[0]->rebase(); } @@ -2044,7 +2048,12 @@ auto hooks = #endif addHook(clearmemory, 0, close) + addHook(hooks_prestats, 100, rogueviz_hud) + - addHook(hooks_calcparam, 100, fixparam); + addHook(hooks_calcparam, 100, fixparam) + + addHook(shmup::hooks_draw, 100, drawVertex) + + addHook(shmup::hooks_describe, 100, describe_monster) + + addHook(shmup::hooks_turn, 100, turn) + + addHook(shmup::hooks_kill, 100, activate) + + 0; }; diff --git a/rogueviz.h b/rogueviz.h index 2a18696d..f639498e 100644 --- a/rogueviz.h +++ b/rogueviz.h @@ -4,12 +4,7 @@ namespace rogueviz { using namespace hr; extern bool on; - string describe(shmup::monster *m); void describe(cell *c); - void activate(shmup::monster *m); - void drawVertex(const transmatrix &V, cell *c, shmup::monster *m); - bool virt(shmup::monster *m); - void turn(int delta); void drawExtra(); void close(); void showMenu(); diff --git a/shmup.cpp b/shmup.cpp index f5049c2e..b3512713 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -1063,14 +1063,11 @@ bool isBullet(monster *m) { bool isPlayer(monster *m) { return m->type == moPlayer; } bool isMonster(monster *m) { return m->type != moPlayer && m->type != moBullet; } +hookset *hooks_kill; + void killMonster(monster* m, eMonster who_kills, int flags = 0) { int tk = tkills(); -#if CAP_ROGUEVIZ - if(m->type == moRogueviz) { - rogueviz::activate(m); - return; - } -#endif + if(callhandlers(false, hooks_kill, m)) return; if(m->dead) return; m->dead = true; if(isBullet(m) || isPlayer(m)) return; @@ -2006,9 +2003,7 @@ eItem targetRangedOrbKey(orbAction a) { for(monster *m2: nonvirtual) { if(m2->dead) continue; -#if CAP_ROGUEVIZ - if(rogueviz::virt(m2)) continue; -#endif + if(m2->no_targetting) continue; if(!mousetarget || intval(mouseh, mousetarget->pat*C0) > intval(mouseh, m2->pat*C0)) mousetarget = m2; } @@ -2874,8 +2869,12 @@ void fixStorage() { for(monster *m: restore) m->store(); } +hookset *hooks_turn; + void turn(int delta) { + if(callhandlers(false, hooks_turn, delta)) return; + passive_switch = (gold() & 1) ? moSwitch1 : moSwitch2; lmousetarget = NULL; if(mousetarget && !mousetarget->isVirtual && intval(mouseh, mousetarget->pat*C0) < 0.1) @@ -3094,10 +3093,6 @@ void turn(int delta) { activateSafety(pc[0]->base->land); safety = false; } - -#if CAP_ROGUEVIZ - rogueviz::turn(delta); -#endif } void recall() { @@ -3150,6 +3145,8 @@ bool boatAt(cell *c) { return false; } +hookset *hooks_draw; + bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, transmatrix& Vboat0, ld zlev) { pair p = @@ -3164,9 +3161,7 @@ bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, trans transmatrix view = V * m->at; if(!mouseout()) { -#if CAP_ROGUEVIZ - if(rogueviz::virt(m)) ; else -#endif + if(m->no_targetting) ; else if(mapeditor::drawplayer || m->type != moPlayer) if(!mousetarget || intval(mouseh, mousetarget->pat*C0) > intval(mouseh, m->pat*C0)) mousetarget = m; @@ -3193,6 +3188,8 @@ bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, trans int q = ptds.size(); if(q != isize(ptds) && !m->inBoat) pushdown(c, q, view, zlev, true, false); + if(callhandlers(false, hooks_draw, V, c, m)) return false; + switch(m->type) { case moPlayer: cpid = m->pid; @@ -3252,12 +3249,6 @@ bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, trans break; } -#if CAP_ROGUEVIZ - case moRogueviz: - rogueviz::drawVertex(V, c, m); - break; -#endif - default: if(m->inBoat) m->footphase = 0; int col = minf[m->type].color; @@ -3587,22 +3578,15 @@ void virtualRebase(shmup::monster *m, bool tohex) { virtualRebase(m->base, m->at, tohex); } +hookset *hooks_describe; + void addShmupHelp(string& out) { if(shmup::mousetarget && intval(mouseh, tC0(shmup::mousetarget->pat)) < .1) { - out += ", "; -#if CAP_ROGUEVIZ - if(shmup::mousetarget->type == moRogueviz) { - help = XLAT(minf[shmup::mousetarget->type].help); - out += rogueviz::describe(shmup::mousetarget); - } - else -#endif - { - out += XLAT1(minf[shmup::mousetarget->type].name); - help = generateHelpForMonster(shmup::mousetarget->type); - } + if(callhandlers(false, hooks_describe, shmup::mousetarget, out)) return; + out += XLAT1(minf[shmup::mousetarget->type].name); + help = generateHelpForMonster(shmup::mousetarget->type); } - } + } auto hooks = addHook(clearmemory, 0, shmup::clearMemory) + addHook(hooks_removecells, 0, [] () {