DEADSOFTWARE

map: move map loading to separate file
[flatwaifu.git] / src / switch.c
index 5eebc2d7d5af164406fd0ef6af2784fe194783d8..719f0dd3635ef9988c621211f3c289096a6d8a0c 100644 (file)
 #include "game.h"
 #include "my.h"
 #include "monster.h"
-
-#define MAXSW 100
-
-typedef struct {
-  byte x, y;
-  byte t, tm;
-  byte a, b, c, d;
-  byte f;
-} sw_t;
+#include "render.h"
 
 int sw_secrets;
+sw_t sw[MAXSW];
 
-static sw_t sw[MAXSW];
 static void *sndswn, *sndswx, *sndnoway, *sndbdo, *sndbdc, *sndnotele;
 static int swsnd;
 static byte cht, chto, chf, f_ch;
 
-void SW_savegame (FILE *h) {
-  int i, n;
-  for (n = MAXSW - 1; n >= 0 && sw[n].t == 0; n--) {
-    // empty
-  }
-  n += 1;
-  myfwrite32(n, h);
-  for (i = 0; i < n; i++) {
-    myfwrite8(sw[i].x, h);
-    myfwrite8(sw[i].y, h);
-    myfwrite8(sw[i].t, h);
-    myfwrite8(sw[i].tm, h);
-    myfwrite8(sw[i].a, h);
-    myfwrite8(sw[i].b, h);
-    myfwrite8(sw[i].c, h);
-    myfwrite8(sw[i].d, h);
-    myfwrite8(sw[i].f, h);
-  }
-  myfwrite32(sw_secrets, h);
-}
-
-void SW_loadgame (FILE *h) {
-  int i, n;
-  n = myfread32(h);
-  for (i = 0; i < n; i++) {
-    sw[i].x = myfread8(h);
-    sw[i].y = myfread8(h);
-    sw[i].t = myfread8(h);
-    sw[i].tm = myfread8(h);
-    sw[i].a = myfread8(h);
-    sw[i].b = myfread8(h);
-    sw[i].c = myfread8(h);
-    sw[i].d = myfread8(h);
-    sw[i].f = myfread8(h);
-  }
-  sw_secrets = myfread32(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 -= 9) {
-        sw[i].x = myfread8(h);
-        sw[i].y = myfread8(h);
-        sw[i].t = myfread8(h);
-        sw[i].tm = myfread8(h); // unused
-        sw[i].a = myfread8(h);
-        sw[i].b = myfread8(h);
-        sw[i].c = myfread8(h);
-        sw[i].d = myfread8(h); // unused
-        sw[i].f = myfread8(h);
-        sw[i].tm = 0;
-        sw[i].d = 0;
-        sw[i].f |= 0x80;
-        if (sw[i].t == SW_SECRET) {
-          ++sw_secrets;
-        }
-      }
-      return 1;
-  }
-  return 0;
-}
-
 void SW_alloc (void) {
   sndswn=Z_getsnd("SWTCHN");
   sndswx=Z_getsnd("SWTCHX");
@@ -335,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;
     }
   }