X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fswitch.c;h=b04c3033119b5c81ba7480b07829fe21f69a125c;hb=2bb81ea2565c3627c954b5c37326db89b0048472;hp=cc418b8bc5287bf7291fe8612e680fe2ff9e6e83;hpb=8fb3d3f767b8e5d094e8bcbee350f4d16ab17c5a;p=flatwaifu.git diff --git a/src/switch.c b/src/switch.c index cc418b8..b04c303 100644 --- a/src/switch.c +++ b/src/switch.c @@ -28,59 +28,95 @@ #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;i0;++i,blk.sz-=sizeof(sw_t)) { - myfread(sw+i,1,sizeof(sw_t),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; + 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"); @@ -89,15 +125,14 @@ void SW_alloc(void) { sndnotele=Z_getsnd("NOTELE"); } -void SW_init(void) { +void SW_init (void) { int i; - - for(i=0;iy)>=FLDH*CELH+o->h) return; @@ -131,7 +166,7 @@ void Z_water_trap(obj_t *o) { } } -void Z_untrap(byte t) { +void Z_untrap (byte t) { byte *p; word n; @@ -170,7 +205,7 @@ static int shutdoor(int i) { return 1; } -void SW_act(void) { +void SW_act (void) { int i; if(swsnd) --swsnd; @@ -198,7 +233,7 @@ static int doortime(int t) { return 0; } -void SW_cheat_open(void) { +void SW_cheat_open (void) { int i; for(i=0;i