1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 17:10:36 +00:00

rogueviz::shmup:: all references to rogueviz in shmup replaced with handlers

This commit is contained in:
Zeno Rogue 2018-07-09 19:32:34 +02:00
parent 9a1ec47034
commit d523ceabfd
4 changed files with 52 additions and 58 deletions

14
hyper.h
View File

@ -632,6 +632,9 @@ namespace multi {
void showShmupConfig();
}
template<class T> class hookset : public map<int, function<T>> {};
typedef hookset<void()> *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<bool(int)> *hooks_turn;
extern hookset<bool(const transmatrix&, cell*, shmup::monster*)> *hooks_draw;
extern hookset<bool(shmup::monster*)> *hooks_kill;
extern hookset<bool(shmup::monster*, string&)> *hooks_describe;
}
static const int NOHINT = -1;
@ -2001,9 +2010,6 @@ extern int ringcolor;
#include <functional>
template<class T> class hookset : public map<int, function<T>> {};
typedef hookset<void()> *purehookset;
template<class T, class U> int addHook(hookset<T>*& m, int prio, const U& hook) {
if(!m) m = new hookset<T> ();
while(m->count(prio)) {

View File

@ -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; i<isize(vd.edges); i++)
vd.edges[i].second->orig = 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<int> 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;
};

View File

@ -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();

View File

@ -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<bool(shmup::monster*)> *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<bool(int)> *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<bool(const transmatrix&, cell*, shmup::monster*)> *hooks_draw;
bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, transmatrix& Vboat0, ld zlev) {
pair<mit, mit> 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<bool(shmup::monster*, string&)> *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
{
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, [] () {