DEADSOFTWARE

save: move save code to separated file
[flatwaifu.git] / src / items.c
index 8918203274c4155ec9123ccd700ead1c0176ad05..65f39e2bb5f5437a02ff017ead6f102bc9003776 100644 (file)
 #include "misc.h"
 #include "map.h"
 #include "my.h"
-
-extern map_block_t blk;
-
+#include "files.h"
+#include "game.h"
 item_t it[MAXITEM];
 
 static void *snd[4];
-static int tsndtm,rsndtm;
-
-int itm_rtime=1092;
+static int tsndtm, rsndtm;
 
-void IT_savegame (FILE *h) {
-  int i, n;
-  for (n = MAXITEM - 1; n >= 0 && it[n].t == 0; n--) {
-    // empty
-  }
-  n += 1;
-  myfwrite32(n, h);
-  for (i = 0; i < n; i++) {
-    myfwrite32(it[i].o.x, h);
-    myfwrite32(it[i].o.y, h);
-    myfwrite32(it[i].o.xv, h);
-    myfwrite32(it[i].o.yv, h);
-    myfwrite32(it[i].o.vx, h);
-    myfwrite32(it[i].o.vy, h);
-    myfwrite32(it[i].o.r, h);
-    myfwrite32(it[i].o.h, h);
-    myfwrite32(it[i].t, h);
-    myfwrite32(it[i].s, h);
-  }
-  myfwrite32(itm_rtime, h);
-}
-
-void IT_loadgame (FILE *h) {
-  int i, n;
-  n = myfread32(h);
-  for (i = 0; i < n; i++) {
-    it[i].o.x = myfread32(h);
-    it[i].o.y = myfread32(h);
-    it[i].o.xv = myfread32(h);
-    it[i].o.yv = myfread32(h);
-    it[i].o.vx = myfread32(h);
-    it[i].o.vy = myfread32(h);
-    it[i].o.r = myfread32(h);
-    it[i].o.h = myfread32(h);
-    it[i].t = myfread32(h);
-    it[i].s = myfread32(h);
-  }
-  itm_rtime = myfread32(h);
-}
+int itm_rtime = 1092;
 
 void IT_alloc (void) {
   int i, j, n;
@@ -96,14 +55,17 @@ void IT_alloc (void) {
   }
 }
 
-void IT_init(void) {
+void IT_init (void) {
   int i;
-
-  for(i=0;i<MAXITEM;++i) {
-       it[i].t=I_NONE;
-       it[i].o.xv=it[i].o.yv=it[i].o.vx=it[i].o.vy=0;
+  for (i = 0; i < MAXITEM; ++i) {
+    it[i].t = I_NONE;
+    it[i].o.xv = 0;
+    it[i].o.yv = 0;
+    it[i].o.vx = 0;
+    it[i].o.vy = 0;
   }
-  tsndtm=rsndtm=0;
+  tsndtm = 0;
+  rsndtm = 0;
 }
 
 int IT_load (FILE *h) {
@@ -199,17 +161,17 @@ int IT_load (FILE *h) {
   return 0;
 }
 
-static void takesnd(int t) {
+static void takesnd (int t) {
   if(tsndtm) return;
   t&=0x7FFF;
   if(t<=I_CELP || (t>=I_BPACK && t<=I_BFG) || t==I_GUN2)
     {tsndtm=Z_sound(snd[1],128);return;}
   if(t==I_MEGA || t==I_INVL || t==I_SUPER)
     {tsndtm=Z_sound(snd[2],192);return;}
-  tsndtm=Z_sound(snd[0],256);
+  tsndtm=Z_sound(snd[0], 255);
 }
 
-void IT_act(void) {
+void IT_act (void) {
   int i,j;
 
   if(tsndtm) --tsndtm;
@@ -251,7 +213,7 @@ void IT_act(void) {
        }
 }
 
-void IT_spawn(int x,int y,int t) {
+void IT_spawn (int x,int y,int t) {
   int i;
 
   for(i=0;i<MAXITEM;++i) if(!it[i].t) {
@@ -263,7 +225,7 @@ void IT_spawn(int x,int y,int t) {
   }
 }
 
-void IT_drop_ammo(int t,int n,int x,int y) {
+void IT_drop_ammo (int t, int n, int x, int y) {
   static int an[8]={10,4,1,40,50,25,5,100};
   int a;