X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fswitch.c;h=a04650889c04feace9571f39701ae9ac0a8a1a51;hb=c46b82f5794be555af272740e67ead316b9b1f90;hp=980955dee5f54ad7ebb42b5be4c9b00f806fe2b0;hpb=e5c2eddc151a59db4e611a77901732d7c15fde90;p=flatwaifu.git diff --git a/src/switch.c b/src/switch.c index 980955d..a046508 100644 --- a/src/switch.c +++ b/src/switch.c @@ -28,6 +28,7 @@ #include "player.h" #include "misc.h" #include "map.h" +#include "my.h" #define MAXSW 100 @@ -49,36 +50,69 @@ static int swsnd; int sw_secrets; -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_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].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; + 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; + } + return 0; } void SW_alloc(void) {