DEADSOFTWARE

map: move map loading to separate file
[flatwaifu.git] / src / switch.c
index 980955dee5f54ad7ebb42b5be4c9b00f806fe2b0..719f0dd3635ef9988c621211f3c289096a6d8a0c 100644 (file)
 #include "player.h"
 #include "misc.h"
 #include "map.h"
-
-#define MAXSW 100
-
-extern map_block_t blk;
-
-#pragma pack(1)
-typedef struct{
-  byte x,y;
-  byte t,tm;
-  byte a,b,c,d;
-  byte f;
-}sw_t;
-#pragma pack()
-
-static sw_t sw[MAXSW];
-
-static void *sndswn,*sndswx,*sndnoway,*sndbdo,*sndbdc,*sndnotele;
-static int swsnd;
+#include "files.h"
+#include "game.h"
+#include "my.h"
+#include "monster.h"
+#include "render.h"
 
 int sw_secrets;
+sw_t sw[MAXSW];
 
-void SW_savegame(FILE* h) {
-  int n;
-
-  for(n=MAXSW;--n;) if(sw[n].t) break;
-  ++n;myfwrite(&n,1,4,h);myfwrite(sw,1,n*sizeof(sw[0]),h);
-  myfwrite(&sw_secrets,1,4,h);
-}
-
-void SW_loadgame(FILE* h) {
-  int n;
-
-  myfread(&n,1,4,h);myfread(sw,1,n*sizeof(sw[0]),h);
-  myfread(&sw_secrets,1,4,h);
-}
-
-int SW_load(FILE* h) {
-  int i;
-
-  switch(blk.t) {
-       case MB_SWITCH2:
-         sw_secrets=0;
-         for(i=0;i<MAXSW && blk.sz>0;++i,blk.sz-=sizeof(sw_t)) {
-               myfread(sw+i,1,sizeof(sw_t),h);
-    sw[i].c = short2host(sw[i].c);
-               sw[i].tm=0;sw[i].d=0;
-               sw[i].f|=0x80;
-               if(sw[i].t==SW_SECRET) ++sw_secrets;
-         }
-         return 1;
-  }return 0;
-}
+static void *sndswn, *sndswx, *sndnoway, *sndbdo, *sndbdc, *sndnotele;
+static int swsnd;
+static byte cht, chto, chf, f_ch;
 
-void SW_alloc(void) {
+void SW_alloc (void) {
   sndswn=Z_getsnd("SWTCHN");
   sndswx=Z_getsnd("SWTCHX");
   sndnoway=Z_getsnd("NOWAY");
@@ -90,15 +50,14 @@ void SW_alloc(void) {
   sndnotele=Z_getsnd("NOTELE");
 }
 
-void SW_init(void) {
+void SW_init (void) {
   int i;
-
-  for(i=0;i<MAXSW;++i) sw[i].t=0;
-  swsnd=0;
+  for (i = 0; i < MAXSW; i++) {
+    sw[i].t = 0;
+  }
+  swsnd = 0;
 }
 
-static byte cht,chto,chf,f_ch;
-
 static void door(byte x,byte y) {
   byte ex;
 
@@ -115,7 +74,7 @@ static void door(byte x,byte y) {
   }
 }
 
-void Z_water_trap(obj_t *o) {
+void Z_water_trap (obj_t *o) {
   int i,j,sx,sy,x,y;
 
   if((y=o->y)>=FLDH*CELH+o->h) return;
@@ -132,7 +91,7 @@ void Z_water_trap(obj_t *o) {
          }
 }
 
-void Z_untrap(byte t) {
+void Z_untrap (byte t) {
   byte *p;
   word n;
 
@@ -171,7 +130,7 @@ static int shutdoor(int i) {
   return 1;
 }
 
-void SW_act(void) {
+void SW_act (void) {
   int i;
 
   if(swsnd) --swsnd;
@@ -199,7 +158,7 @@ static int doortime(int t) {
   return 0;
 }
 
-void SW_cheat_open(void) {
+void SW_cheat_open (void) {
   int i;
 
   for(i=0;i<MAXSW;++i) if(sw[i].t && !sw[i].tm) switch(sw[i].t) {
@@ -211,7 +170,7 @@ void SW_cheat_open(void) {
   }
 }
 
-int SW_press(int x,int y,int r,int h,byte t,int o) {
+int SW_press (int x, int y, int r, int h, byte t, int o) {
   int sx,sy,i,p;
 
   sx=(x-r)/CELW;sy=(y-h+1)/CELH;
@@ -303,8 +262,10 @@ int SW_press(int x,int y,int r,int h,byte t,int o) {
                  else ++pl2.secrets;
                  sw[i].tm=1;sw[i].t=0;break;
       }
-      if(sw[i].tm)
-        {fldb[sw[i].y][sw[i].x]=walswp[fldb[sw[i].y][sw[i].x]];p=1;}
+      if (sw[i].tm != 0) {
+        R_switch_texture(sw[i].x, sw[i].y);
+        p = 1;
+      }
       if(sw[i].tm==1) sw[i].tm=0;
     }
   }