mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 14:02:59 +00:00 
			
		
		
		
	rogueviz::shmup:: all references to rogueviz in shmup replaced with handlers
This commit is contained in:
		
							
								
								
									
										14
									
								
								hyper.h
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								hyper.h
									
									
									
									
									
								
							| @@ -632,6 +632,9 @@ namespace multi { | |||||||
|   void showShmupConfig(); |   void showShmupConfig(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | template<class T> class hookset : public map<int, function<T>> {}; | ||||||
|  | typedef hookset<void()> *purehookset; | ||||||
|  |  | ||||||
| namespace shmup { | namespace shmup { | ||||||
|   using namespace multi; |   using namespace multi; | ||||||
|   void recall(); |   void recall(); | ||||||
| @@ -655,6 +658,7 @@ namespace shmup { | |||||||
|     bool dead; |     bool dead; | ||||||
|     bool notpushed; |     bool notpushed; | ||||||
|     bool inBoat; |     bool inBoat; | ||||||
|  |     bool no_targetting; | ||||||
|     monster *parent; // who shot this missile |     monster *parent; // who shot this missile | ||||||
|     eMonster parenttype; // type of the parent |     eMonster parenttype; // type of the parent | ||||||
|     int nextshot;    // when will it be able to shot (players/flailers) |     int nextshot;    // when will it be able to shot (players/flailers) | ||||||
| @@ -669,7 +673,7 @@ namespace shmup { | |||||||
|      |      | ||||||
|     monster() {  |     monster() {  | ||||||
|       dead = false; inBoat = false; parent = NULL; nextshot = 0;  |       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(); |     void store(); | ||||||
| @@ -711,6 +715,11 @@ namespace shmup { | |||||||
|    |    | ||||||
|   void pushmonsters(); |   void pushmonsters(); | ||||||
|   void popmonsters(); |   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; | static const int NOHINT = -1; | ||||||
| @@ -2001,9 +2010,6 @@ extern int ringcolor; | |||||||
|  |  | ||||||
| #include <functional> | #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) { | template<class T, class U> int addHook(hookset<T>*& m, int prio, const U& hook) { | ||||||
|   if(!m) m = new hookset<T> (); |   if(!m) m = new hookset<T> (); | ||||||
|   while(m->count(prio)) { |   while(m->count(prio)) { | ||||||
|   | |||||||
							
								
								
									
										37
									
								
								rogueviz.cpp
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								rogueviz.cpp
									
									
									
									
									
								
							| @@ -180,6 +180,7 @@ void addedge(int i, int j, edgeinfo *ei) { | |||||||
|     vd.virt = ei; |     vd.virt = ei; | ||||||
|      |      | ||||||
|     createViz(id, base, rgpushxto0(h)); |     createViz(id, base, rgpushxto0(h)); | ||||||
|  |     vd.m->no_targetting = true; | ||||||
|      |      | ||||||
|     addedge(i, id, ei); |     addedge(i, id, ei); | ||||||
|     addedge(id, j, ei); |     addedge(id, j, ei); | ||||||
| @@ -957,7 +958,10 @@ void describe(cell *c) { | |||||||
|   if(kind == kKohonen) return kohonen::describe(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; |   int i = m->pid; | ||||||
|   vertexdata& vd = vdata[i]; |   vertexdata& vd = vdata[i]; | ||||||
|  |  | ||||||
| @@ -987,10 +991,12 @@ string describe(shmup::monster *m) { | |||||||
|       help += "/" + fts(ei->weight)+":" + fts(ei->weight2) + " "; |       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; |   int i = m->pid; | ||||||
|   vertexdata& vd = vdata[i]; |   vertexdata& vd = vdata[i]; | ||||||
|  |  | ||||||
| @@ -999,6 +1005,8 @@ void activate(shmup::monster *m) { | |||||||
|   for(int i=0; i<isize(vd.edges); i++)  |   for(int i=0; i<isize(vd.edges); i++)  | ||||||
|       vd.edges[i].second->orig = NULL; |       vd.edges[i].second->orig = NULL; | ||||||
|    |    | ||||||
|  |   return true; | ||||||
|  |    | ||||||
|   /* if(ealpha == 1) ealpha = 8; |   /* if(ealpha == 1) ealpha = 8; | ||||||
|   else if(ealpha == 8) ealpha = 32; |   else if(ealpha == 8) ealpha = 32; | ||||||
|   else if(ealpha == 32) ealpha = 255; |   else if(ealpha == 32) ealpha = 255; | ||||||
| @@ -1065,8 +1073,8 @@ transmatrix& memo_relative_matrix(cell *c1, cell *c2) { | |||||||
|   return p; |   return p; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| void drawVertex(const transmatrix &V, cell *c, shmup::monster *m) { | bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) { | ||||||
|   if(m->dead) return; |   if(m->dead) return true; | ||||||
|   int i = m->pid; |   int i = m->pid; | ||||||
|   vertexdata& vd = vdata[i]; |   vertexdata& vd = vdata[i]; | ||||||
|    |    | ||||||
| @@ -1283,12 +1291,7 @@ void drawVertex(const transmatrix &V, cell *c, shmup::monster *m) { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   } |   return true; | ||||||
|  |  | ||||||
| bool virt(shmup::monster *m) { |  | ||||||
|   if(m->type != moRogueviz) return false; |  | ||||||
|   vertexdata& vd = vdata[m->pid]; |  | ||||||
|   return vd.virt; |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
| vector<int> legend; | vector<int> legend; | ||||||
| @@ -1489,10 +1492,11 @@ void close() { | |||||||
|   relmatrices.clear(); |   relmatrices.clear(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| void turn(int delta) { | bool turn(int delta) { | ||||||
|   if(!on) return; |   if(!on) return false; | ||||||
|   if(kind == kSAG) sag::iterate(); |   if(kind == kSAG) sag::iterate(); | ||||||
|   if(kind == kKohonen) kohonen::steps(); |   if(kind == kKohonen) kohonen::steps(); | ||||||
|  |   return false; | ||||||
|   // shmup::pc[0]->rebase(); |   // shmup::pc[0]->rebase(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -2044,7 +2048,12 @@ auto hooks  = | |||||||
| #endif | #endif | ||||||
|   addHook(clearmemory, 0, close) + |   addHook(clearmemory, 0, close) + | ||||||
|   addHook(hooks_prestats, 100, rogueviz_hud) + |   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; | ||||||
|  |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,12 +4,7 @@ namespace rogueviz { | |||||||
|   using namespace hr; |   using namespace hr; | ||||||
|  |  | ||||||
|   extern bool on; |   extern bool on; | ||||||
|   string describe(shmup::monster *m); |  | ||||||
|   void describe(cell *c); |   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 drawExtra(); | ||||||
|   void close(); |   void close(); | ||||||
|   void showMenu(); |   void showMenu(); | ||||||
|   | |||||||
							
								
								
									
										52
									
								
								shmup.cpp
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								shmup.cpp
									
									
									
									
									
								
							| @@ -1063,14 +1063,11 @@ bool isBullet(monster *m) { | |||||||
| bool isPlayer(monster *m) { return m->type == moPlayer; } | bool isPlayer(monster *m) { return m->type == moPlayer; } | ||||||
| bool isMonster(monster *m) { return m->type != moPlayer && m->type != moBullet; } | 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) { | void killMonster(monster* m, eMonster who_kills, int flags = 0) { | ||||||
|   int tk = tkills(); |   int tk = tkills(); | ||||||
| #if CAP_ROGUEVIZ |   if(callhandlers(false, hooks_kill, m)) return; | ||||||
|   if(m->type == moRogueviz) { |  | ||||||
|     rogueviz::activate(m); |  | ||||||
|     return; |  | ||||||
|     } |  | ||||||
| #endif |  | ||||||
|   if(m->dead) return; |   if(m->dead) return; | ||||||
|   m->dead = true; |   m->dead = true; | ||||||
|   if(isBullet(m) || isPlayer(m)) return; |   if(isBullet(m) || isPlayer(m)) return; | ||||||
| @@ -2006,9 +2003,7 @@ eItem targetRangedOrbKey(orbAction a) { | |||||||
|  |  | ||||||
|   for(monster *m2: nonvirtual) { |   for(monster *m2: nonvirtual) { | ||||||
|     if(m2->dead) continue; |     if(m2->dead) continue; | ||||||
| #if CAP_ROGUEVIZ |     if(m2->no_targetting) continue; | ||||||
|     if(rogueviz::virt(m2)) continue; |  | ||||||
| #endif |  | ||||||
|     if(!mousetarget || intval(mouseh, mousetarget->pat*C0) > intval(mouseh, m2->pat*C0))  |     if(!mousetarget || intval(mouseh, mousetarget->pat*C0) > intval(mouseh, m2->pat*C0))  | ||||||
|       mousetarget = m2; |       mousetarget = m2; | ||||||
|     } |     } | ||||||
| @@ -2874,8 +2869,12 @@ void fixStorage() { | |||||||
|   for(monster *m: restore) m->store(); |   for(monster *m: restore) m->store(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | hookset<bool(int)> *hooks_turn; | ||||||
|  |  | ||||||
| void turn(int delta) { | void turn(int delta) { | ||||||
|  |  | ||||||
|  |   if(callhandlers(false, hooks_turn, delta)) return; | ||||||
|  |  | ||||||
|   passive_switch = (gold() & 1) ? moSwitch1 : moSwitch2; |   passive_switch = (gold() & 1) ? moSwitch1 : moSwitch2; | ||||||
|   lmousetarget = NULL; |   lmousetarget = NULL; | ||||||
|   if(mousetarget && !mousetarget->isVirtual && intval(mouseh, mousetarget->pat*C0) < 0.1) |   if(mousetarget && !mousetarget->isVirtual && intval(mouseh, mousetarget->pat*C0) < 0.1) | ||||||
| @@ -3094,10 +3093,6 @@ void turn(int delta) { | |||||||
|     activateSafety(pc[0]->base->land); |     activateSafety(pc[0]->base->land); | ||||||
|     safety = false; |     safety = false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| #if CAP_ROGUEVIZ |  | ||||||
|   rogueviz::turn(delta); |  | ||||||
| #endif |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
| void recall() { | void recall() { | ||||||
| @@ -3150,6 +3145,8 @@ bool boatAt(cell *c) { | |||||||
|   return false; |   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) { | bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, transmatrix& Vboat0, ld zlev) { | ||||||
|  |  | ||||||
|    pair<mit, mit> p =  |    pair<mit, mit> p =  | ||||||
| @@ -3164,9 +3161,7 @@ bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, trans | |||||||
|     transmatrix view = V * m->at; |     transmatrix view = V * m->at; | ||||||
|      |      | ||||||
|     if(!mouseout()) { |     if(!mouseout()) { | ||||||
| #if CAP_ROGUEVIZ |       if(m->no_targetting) ; else | ||||||
|       if(rogueviz::virt(m)) ; else |  | ||||||
| #endif |  | ||||||
|       if(mapeditor::drawplayer || m->type != moPlayer) |       if(mapeditor::drawplayer || m->type != moPlayer) | ||||||
|       if(!mousetarget || intval(mouseh, mousetarget->pat*C0) > intval(mouseh, m->pat*C0))  |       if(!mousetarget || intval(mouseh, mousetarget->pat*C0) > intval(mouseh, m->pat*C0))  | ||||||
|         mousetarget = m; |         mousetarget = m; | ||||||
| @@ -3193,6 +3188,8 @@ bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, trans | |||||||
|     int q = ptds.size(); |     int q = ptds.size(); | ||||||
|     if(q != isize(ptds) && !m->inBoat) pushdown(c, q, view, zlev, true, false); |     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) { |     switch(m->type) { | ||||||
|       case moPlayer:  |       case moPlayer:  | ||||||
|         cpid = m->pid;  |         cpid = m->pid;  | ||||||
| @@ -3252,12 +3249,6 @@ bool drawMonster(const transmatrix& V, cell *c, const transmatrix*& Vboat, trans | |||||||
|         break; |         break; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| #if CAP_ROGUEVIZ       |  | ||||||
|       case moRogueviz: |  | ||||||
|         rogueviz::drawVertex(V, c, m); |  | ||||||
|         break; |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
|       default: |       default: | ||||||
|         if(m->inBoat) m->footphase = 0; |         if(m->inBoat) m->footphase = 0; | ||||||
|         int col = minf[m->type].color; |         int col = minf[m->type].color; | ||||||
| @@ -3587,20 +3578,13 @@ void virtualRebase(shmup::monster *m, bool tohex) { | |||||||
|   virtualRebase(m->base, m->at, tohex); |   virtualRebase(m->base, m->at, tohex); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | hookset<bool(shmup::monster*, string&)> *hooks_describe; | ||||||
|  |  | ||||||
| void addShmupHelp(string& out) { | void addShmupHelp(string& out) { | ||||||
|   if(shmup::mousetarget && intval(mouseh, tC0(shmup::mousetarget->pat)) < .1) { |   if(shmup::mousetarget && intval(mouseh, tC0(shmup::mousetarget->pat)) < .1) { | ||||||
|     out += ", ";  |     if(callhandlers(false, hooks_describe, shmup::mousetarget, out)) return; | ||||||
| #if CAP_ROGUEVIZ |     out += XLAT1(minf[shmup::mousetarget->type].name); | ||||||
|     if(shmup::mousetarget->type == moRogueviz) { |     help = generateHelpForMonster(shmup::mousetarget->type); | ||||||
|       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); |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue