diff --git a/src/switch.c b/src/switch.c
index 980955dee5f54ad7ebb42b5be4c9b00f806fe2b0..b04c3033119b5c81ba7480b07829fe21f69a125c 100644 (file)
--- a/src/switch.c
+++ b/src/switch.c
#include "player.h"
#include "misc.h"
#include "map.h"
+#include "files.h"
+#include "game.h"
+#include "my.h"
+#include "monster.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;
+typedef struct {
+ byte x, y;
+ byte t, tm;
+ byte a, b, c, d;
byte f;
-}sw_t;
+} sw_t;
#pragma pack()
-static sw_t sw[MAXSW];
-
-static void *sndswn,*sndswx,*sndnoway,*sndbdo,*sndbdc,*sndnotele;
-static int swsnd;
-
int sw_secrets;
-void SW_savegame(FILE* h) {
- int n;
+static sw_t sw[MAXSW];
+static void *sndswn, *sndswx, *sndnoway, *sndbdo, *sndbdc, *sndnotele;
+static int swsnd;
+static byte cht, chto, chf, f_ch;
- 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_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 n;
-
- myfread(&n,1,4,h);myfread(sw,1,n*sizeof(sw[0]),h);
- myfread(&sw_secrets,1,4,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 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;
+ 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) {
+void SW_alloc (void) {
sndswn=Z_getsnd("SWTCHN");
sndswx=Z_getsnd("SWTCHX");
sndnoway=Z_getsnd("NOWAY");
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;
}
}
-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;
}
}
-void Z_untrap(byte t) {
+void Z_untrap (byte t) {
byte *p;
word n;
return 1;
}
-void SW_act(void) {
+void SW_act (void) {
int i;
if(swsnd) --swsnd;
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) {
}
}
-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;