summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e5c2edd)
raw | patch | inline | side by side (parent: e5c2edd)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 10 Mar 2020 19:57:16 +0000 (22:57 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 10 Mar 2020 19:57:16 +0000 (22:57 +0300) |
15 files changed:
src/dots.c | patch | blob | history | |
src/files.c | patch | blob | history | |
src/fx.c | patch | blob | history | |
src/game.c | patch | blob | history | |
src/items.c | patch | blob | history | |
src/misc.h | patch | blob | history | |
src/miscc.c | patch | blob | history | |
src/monster.c | patch | blob | history | |
src/my.c | patch | blob | history | |
src/my.h | patch | blob | history | |
src/player.c | patch | blob | history | |
src/smoke.c | patch | blob | history | |
src/switch.c | patch | blob | history | |
src/view.c | patch | blob | history | |
src/weapons.c | patch | blob | history |
diff --git a/src/dots.c b/src/dots.c
index d89b9d6122fd359742141cf17d219cbeaa99e2df..4f52130d53b46eec45097304ad53a25c6b963373 100644 (file)
--- a/src/dots.c
+++ b/src/dots.c
static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
static int ldot;
-void DOT_savegame(FILE* h) {
- int i,n;
-
- for(i=n=0;i<MAXDOT;++i) if(dot[i].t) ++n;
- myfwrite(&n,1,4,h);
- for(i=0;i<MAXDOT;++i) if(dot[i].t) myfwrite(&dot[i],1,sizeof(dot_t),h);
+void DOT_savegame (FILE *h) {
+ int i, n;
+ for (i = n = 0; i < MAXDOT; ++i) {
+ if (dot[i].t) {
+ ++n;
+ }
+ }
+ myfwrite32(n, h);
+ for (i = 0; i < MAXDOT; ++i) {
+ if (dot[i].t) {
+ myfwrite32(dot[i].o.x, h);
+ myfwrite32(dot[i].o.y, h);
+ myfwrite32(dot[i].o.xv, h);
+ myfwrite32(dot[i].o.yv, h);
+ myfwrite32(dot[i].o.vx, h);
+ myfwrite32(dot[i].o.vy, h);
+ myfwrite32(dot[i].o.r, h);
+ myfwrite32(dot[i].o.h, h);
+ myfwrite8(dot[i].c, h);
+ myfwrite8(dot[i].t, h);
+ }
+ }
}
-void DOT_loadgame(FILE* h) {
- int n;
-
- myfread(&n,1,4,h);
- myfread(dot,1,n*sizeof(dot_t),h);
+void DOT_loadgame (FILE *h) {
+ int i, n;
+ myfread32(&n, h);
+ for (i = 0; i < n; i++) {
+ myfread32(&dot[i].o.x, h);
+ myfread32(&dot[i].o.y, h);
+ myfread32(&dot[i].o.xv, h);
+ myfread32(&dot[i].o.yv, h);
+ myfread32(&dot[i].o.vx, h);
+ myfread32(&dot[i].o.vy, h);
+ myfread32(&dot[i].o.r, h);
+ myfread32(&dot[i].o.h, h);
+ myfread8(&dot[i].c, h);
+ myfread8(&dot[i].t, h);
+ }
}
void DOT_init(void) {
diff --git a/src/files.c b/src/files.c
index eb6d36e943bbbda1b55d1082d79d7b04c473aade..ef33a03d24265c6228e6a8a39f6b1987cfc90e04 100644 (file)
--- a/src/files.c
+++ b/src/files.c
return p;
}
-void F_getsavnames(void) {
-
- int i; FILE *h;
+void F_getsavnames (void) {
+ int i;
+ FILE *h;
short ver;
char *p;
-
- for(i=0;i<7;++i) {
- p = getsavfpname(i,1);
- memset(savname[i],0,24);savok[i]=0;
- if((h=fopen(p,"rb"))==NULL) continue; //if((h=open(n,O_RDONLY|O_BINARY))==-1) continue;
- myfread(savname[i],1,24,h);ver=-1;myfread(&ver,1,2,h);
- fclose(h);savname[i][23]=0;savok[i]=(ver==3)?1:0;//savok[i]=(ver==2)?1:0;
+ for (i = 0; i < 7; ++i) {
+ p = getsavfpname(i, 1);
+ memset(savname[i], 0, 24);
+ savok[i] = 0;
+ h = fopen(p, "rb");
+ if (h != NULL) {
+ ver = -1;
+ myfread(savname[i], 24, 1, h);
+ myfread16(&ver, h);
+ savname[i][23] = 0;
+ savok[i] = (ver == 3) ? 1 : 0;
+ fclose(h);
+ }
}
}
-void F_savegame(int n,char *s) {
-
- FILE* h;
- char *p;
- p=getsavfpname(n,0);
- if((h=fopen(p,"wb"))==NULL) return;
- myfwrite(s,1,24,h);myfwrite("\3\0",1,2,h);//myfwrite("\2\0",1,2,h);
- G_savegame(h);
- W_savegame(h);
- DOT_savegame(h);
- SMK_savegame(h);
- FX_savegame(h);
- IT_savegame(h);
- MN_savegame(h);
- PL_savegame(h);
- SW_savegame(h);
- WP_savegame(h);
- fclose(h);
+void F_savegame (int n, char *s) {
+ char *p = getsavfpname(n, 0);
+ FILE *h = fopen(p, "wb");
+ if (h != NULL) {
+ myfwrite(s, 24, 1, h); // slot name
+ myfwrite16(3, h); // version
+ G_savegame(h);
+ W_savegame(h);
+ DOT_savegame(h);
+ SMK_savegame(h);
+ FX_savegame(h);
+ IT_savegame(h);
+ MN_savegame(h);
+ PL_savegame(h);
+ SW_savegame(h);
+ WP_savegame(h);
+ fclose(h);
+ }
}
-void F_loadgame(int n) {
- FILE* h;
+void F_loadgame (int n) {
short ver;
- char *p;
- p=getsavfpname(n,1);
-
- if((h=fopen(p,"rb"))==NULL) return;//if((h=open(fn,O_BINARY|O_RDONLY))==-1) return;
- fseek(h,24,SEEK_SET);myfread(&ver,1,2,h);if(ver!=3) return;//if(ver!=2) return;
- G_loadgame(h);
- W_loadgame(h);
- DOT_loadgame(h);
- SMK_loadgame(h);
- FX_loadgame(h);
- IT_loadgame(h);
- MN_loadgame(h);
- PL_loadgame(h);
- SW_loadgame(h);
- WP_loadgame(h);
- fclose(h);
+ char *p = getsavfpname(n, 1);
+ FILE *h = fopen(p, "rb");
+ if (h != NULL) {
+ fseek(h, 24, SEEK_SET); // skip name
+ myfread16(&ver, h); // version
+ if (ver == 3) {
+ G_loadgame(h);
+ W_loadgame(h);
+ DOT_loadgame(h);
+ SMK_loadgame(h);
+ FX_loadgame(h);
+ IT_loadgame(h);
+ MN_loadgame(h);
+ PL_loadgame(h);
+ SW_loadgame(h);
+ WP_loadgame(h);
+ }
+ fclose(h);
+ }
}
void F_addwad(char *fn) {
map_block_t blk;
void F_loadmap(char n[8]) {
-
- int r;
+ int r, o;
FILE *h;
map_header_t hdr;
- int o;
-
W_init();
- r=F_getresid(n);
- fseek(h=wadh[wad[r].f],wad[r].o,SEEK_SET);
- myfread(&hdr,1,sizeof(hdr),h);
- hdr.ver = short2host(hdr.ver);
- if(memcmp(hdr.id,"Doom2D\x1A",8)!=0)
- ERR_fatal("%.8s не является уровнем",n);
+ r = F_getresid(n);
+ h = wadh[wad[r].f];
+ fseek(h, wad[r].o, SEEK_SET);
+ myfread(hdr.id, 8, 1, h);
+ myfread16(&hdr.ver, h);
+ if (memcmp(hdr.id, "Doom2D\x1A", 8) != 0) {
+ ERR_fatal("%.8s не является уровнем", n);
+ }
for(;;) {
- myfread(&blk,1,sizeof(blk),h);
- blk.t = short2host(blk.t);
- blk.st = short2host(blk.st);
- blk.sz = int2host(blk.sz);
- if(blk.t==MB_END) break;
- if(blk.t==MB_COMMENT)
- {fseek(h,blk.sz,SEEK_CUR);continue;}
- o=ftell(h)+blk.sz;
- if(!G_load(h))
- if(!W_load(h))
- if(!IT_load(h))
- if(!SW_load(h))
- ERR_fatal("Неизвестный блок %d(%d) в уровне %.8s",blk.t,blk.st,n);
- fseek(h,o,SEEK_SET);
+ myfread16(&blk.t, h);
+ myfread16(&blk.st, h);
+ myfread32(&blk.sz, h);
+ if(blk.t == MB_END) {
+ break;
+ }
+ if(blk.t == MB_COMMENT) {
+ fseek(h, blk.sz, SEEK_CUR);
+ continue;
+ }
+ o = ftell(h) + blk.sz;
+ if(!G_load(h)) {
+ if(!W_load(h)) {
+ if(!IT_load(h)) {
+ if(!SW_load(h)) {
+ ERR_fatal("Неизвестный блок %d(%d) в уровне %.8s", blk.t, blk.st, n);
+ }
+ }
+ }
+ }
+ fseek(h, o, SEEK_SET);
}
-
}
/*void F_freemus(void) {
diff --git a/src/fx.c b/src/fx.c
index 8a38050cf9bfc7789bae981efaa0e6791fe09298..9947854ac121d6b86c3a0b0c1f67692b96acec2a 100644 (file)
--- a/src/fx.c
+++ b/src/fx.c
}
}
-void FX_savegame(FILE* h) {
- int i,n;
-
- for(i=n=0;i<MAXFX;++i) if(fx[i].t) ++n;
- myfwrite(&n,1,4,h);
- for(i=0;i<MAXFX;++i) if(fx[i].t) myfwrite(&fx[i],1,sizeof(fx_t),h);
+void FX_savegame (FILE *h) {
+ int i, n;
+ for (i = n = 0; i < MAXFX; ++i) {
+ if (fx[i].t) {
+ ++n;
+ }
+ }
+ myfwrite32(n, h);
+ for (i = 0; i < MAXFX; ++i) {
+ if (fx[i].t) {
+ myfwrite32(fx[i].x, h);
+ myfwrite32(fx[i].y, h);
+ myfwrite32(fx[i].xv, h);
+ myfwrite32(fx[i].yv, h);
+ myfwrite8(fx[i].t, h);
+ myfwrite8(fx[i].s, h);
+ }
+ }
}
-void FX_loadgame(FILE* h) {
- int n;
-
- myfread(&n,1,4,h);
- myfread(fx,1,n*sizeof(fx_t),h);
+void FX_loadgame (FILE *h) {
+ int i, n;
+ myfread32(&n, h);
+ for (i = 0; i < n; i++) {
+ myfread32(&fx[i].x, h);
+ myfread32(&fx[i].y, h);
+ myfread32(&fx[i].xv, h);
+ myfread32(&fx[i].yv, h);
+ myfread8(&fx[i].t, h);
+ myfread8(&fx[i].s, h);
+ }
}
void FX_alloc(void) {
diff --git a/src/game.c b/src/game.c
index 1b35f7eb5469c3ed164c92c607d13602fbe1e77e..1846b5760ee06854dd05e1b8d2f84fbe7828bf20 100644 (file)
--- a/src/game.c
+++ b/src/game.c
}
void G_savegame(FILE* h) {
- myfwrite(&_2pl,1,1,h);myfwrite(&g_dm,1,1,h);myfwrite(&g_exit,1,1,h);myfwrite(&g_map,1,1,h);
- myfwrite(&g_time,1,4,h);myfwrite(&dm_pl1p,1,4,h);myfwrite(&dm_pl2p,1,4,h);
- myfwrite(&dm_pnum,1,4,h);myfwrite(dm_pos,1,dm_pnum*sizeof(pos_t),h);
- myfwrite(&cheat,1,1,h);
- myfwrite(g_music,1,8,h);
+ myfwrite8(_2pl, h);
+ myfwrite8(g_dm, h);
+ myfwrite8(g_exit, h);
+ myfwrite8(g_map, h);
+ myfwrite32(g_time, h);
+ myfwrite32(dm_pl1p, h);
+ myfwrite32(dm_pl2p, h);
+ myfwrite32(dm_pnum, h);
+ int i = 0;
+ while (i < dm_pnum) {
+ myfwrite32(dm_pos[i].x, h);
+ myfwrite32(dm_pos[i].y, h);
+ myfwrite8(dm_pos[i].d, h);
+ i += 1;
+ }
+ myfwrite8(cheat, h);
+ myfwrite(g_music, 8, 1, h);
}
void G_loadgame(FILE* h) {
- myfread(&_2pl,1,1,h);myfread(&g_dm,1,1,h);myfread(&g_exit,1,1,h);myfread(&g_map,1,1,h);
- myfread(&g_time,1,4,h);myfread(&dm_pl1p,1,4,h);myfread(&dm_pl2p,1,4,h);
- myfread(&dm_pnum,1,4,h);myfread(dm_pos,1,dm_pnum*sizeof(pos_t),h);
- myfread(&cheat,1,1,h);
- myfread(g_music,1,8,h);F_loadmus(g_music);
+ myfread8(&_2pl, h);
+ myfread8(&g_dm, h);
+ myfread8(&g_exit, h);
+ myfread8(&g_map, h);
+ myfread32(&g_time, h);
+ myfread32(&dm_pl1p, h);
+ myfread32(&dm_pl2p, h);
+ myfread32(&dm_pnum, h);
+ int i = 0;
+ while (i < dm_pnum) {
+ myfread32(&dm_pos[i].x, h);
+ myfread32(&dm_pos[i].y, h);
+ myfread8(&dm_pos[i].d, h);
+ i += 1;
+ }
+ myfread8(&cheat, h);
+ myfread(g_music, 8, 1, h);
+ F_loadmus(g_music);
}
-int G_load(FILE* h) {
- switch(blk.t) {
+int G_load (FILE *h) {
+ switch (blk.t) {
case MB_MUSIC:
- myfread(g_music,1,8,h);
- if (music_random) F_randmus(g_music);
- F_loadmus(g_music);
+ myfread(g_music, 8, 1, h);
+ if (music_random) {
+ F_randmus(g_music);
+ }
+ F_loadmus(g_music);
return 1;
- }return 0;
+ }
+ return 0;
}
void load_game(int n) {
diff --git a/src/items.c b/src/items.c
index 126fd5ce4e24e5f80fbc1e39895917cb3dc8fb75..005c375a658c258e671919bac7b3c35923c113e8 100644 (file)
--- a/src/items.c
+++ b/src/items.c
int itm_rtime=1092;
-void IT_savegame(FILE* h) {
- int n;
-
- for(n=MAXITEM;--n;) if(it[n].t) break;
- ++n;myfwrite(&n,1,4,h);
- myfwrite(it,1,n*sizeof(it[0]),h);
- myfwrite(&itm_rtime,1,4,h);
+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 n;
-
- myfread(&n,1,4,h);
- myfread(it,1,n*sizeof(it[0]),h);
- myfread(&itm_rtime,1,4,h);
+void IT_loadgame (FILE *h) {
+ int i, n;
+ myfread32(&n, h);
+ for (i = 0; i < n; i++) {
+ myfread32(&it[i].o.x, h);
+ myfread32(&it[i].o.y, h);
+ myfread32(&it[i].o.xv, h);
+ myfread32(&it[i].o.yv, h);
+ myfread32(&it[i].o.vx, h);
+ myfread32(&it[i].o.vy, h);
+ myfread32(&it[i].o.r, h);
+ myfread32(&it[i].o.h, h);
+ myfread32(&it[i].t, h);
+ myfread32(&it[i].s, h);
+ }
+ myfread32(&itm_rtime, h);
}
void IT_alloc(void) {
tsndtm=rsndtm=0;
}
-int IT_load(FILE* h) {
- int m,i,j;
+int IT_load (FILE *h) {
+ int m, i, j;
old_thing_t t;
-
- switch(blk.t) {
+ switch (blk.t) {
case MB_THING:
- for(i=0;blk.sz>0;++i,blk.sz-=8) {
- myfread(&t,1,sizeof(t),h);
- t.x = short2host(t.x);
- t.y = short2host(t.y);
- t.t = short2host(t.t);
- t.f = short2host(t.f);
- it[i].o.x=t.x;it[i].o.y=t.y;
- it[i].t=t.t;it[i].s=t.f;
- if(!it[i].t) break;
- if((it[i].s&THF_DM) && !g_dm) it[i].t=0;
- }m=i;
- for(i=0,j=-1;i<m;++i) if(it[i].t==TH_PLR1) {j=i;it[i].t=0;}
- if(!g_dm) {
- if(j==-1) ERR_fatal("Предмет игрок_1 не найден");
- dm_pos[0].x=it[j].o.x;dm_pos[0].y=it[j].o.y;dm_pos[0].d=it[j].s&THF_DIR;
+ for (i = 0; blk.sz > 0; ++i, blk.sz -= 8) {
+ myfread16(&t.x, h);
+ myfread16(&t.y, h);
+ myfread16(&t.t, h);
+ myfread16(&t.f, h);
+ it[i].o.x = t.x;
+ it[i].o.y = t.y;
+ it[i].t = t.t;
+ it[i].s = t.f;
+ if (it[i].t && (it[i].s & THF_DM) && !g_dm) {
+ it[i].t=0;
+ }
}
- for(i=0,j=-1;i<m;++i) if(it[i].t==TH_PLR2) {j=i;it[i].t=0;}
- if(!g_dm && _2pl) {
- if(j==-1) ERR_fatal("Предмет игрок_2 не найден");
- dm_pos[1].x=it[j].o.x;dm_pos[1].y=it[j].o.y;dm_pos[1].d=it[j].s&THF_DIR;
+ m = i;
+ for (i = 0, j = -1; i < m; ++i) {
+ if (it[i].t == TH_PLR1) {
+ j = i;
+ it[i].t = 0;
+ }
+ }
+ if (!g_dm) {
+ if (j == -1) {
+ ERR_fatal("Предмет игрок_1 не найден");
+ }
+ dm_pos[0].x = it[j].o.x;
+ dm_pos[0].y = it[j].o.y;
+ dm_pos[0].d = it[j].s & THF_DIR;
}
- for(i=0,j=0;i<m;++i) if(it[i].t==TH_DMSTART) {
- if(g_dm)
- {dm_pos[j].x=it[i].o.x;dm_pos[j].y=it[i].o.y;dm_pos[j].d=it[i].s&THF_DIR;}
- it[i].t=0;++j;
+ for (i = 0, j = -1; i < m; ++i) {
+ if (it[i].t == TH_PLR2) {
+ j = i;
+ it[i].t = 0;
+ }
+ }
+ if (!g_dm && _2pl) {
+ if (j == -1) {
+ ERR_fatal("Предмет игрок_2 не найден");
+ }
+ dm_pos[1].x = it[j].o.x;
+ dm_pos[1].y = it[j].o.y;
+ dm_pos[1].d = it[j].s & THF_DIR;
}
- if(g_dm && j<2) ERR_fatal("Меньше 2-ух точек DM");
- if(g_dm) {
- dm_pnum=j;
- dm_pl1p=myrand(dm_pnum);
- do{ dm_pl2p=myrand(dm_pnum); }while(dm_pl2p==dm_pl1p);
- }else {dm_pl1p=0;dm_pl2p=1;dm_pnum=2;}
- PL_spawn(&pl1,dm_pos[dm_pl1p].x,dm_pos[dm_pl1p].y,dm_pos[dm_pl1p].d);
- if(_2pl) PL_spawn(&pl2,dm_pos[dm_pl2p].x,dm_pos[dm_pl2p].y,dm_pos[dm_pl2p].d);
- for(i=0;i<m;++i)
- if(it[i].t>=TH_CLIP && it[i].t<TH_DEMON) {
- it[i].s=0;it[i].t=it[i].t-TH_CLIP+I_CLIP;
- if(it[i].t>=I_KEYR && it[i].t<=I_KEYB) it[i].t|=0x8000;
- }else if(it[i].t>=TH_DEMON) {
- MN_spawn(it[i].o.x,it[i].o.y,it[i].s&THF_DIR,it[i].t-TH_DEMON+MN_DEMON);
- it[i].t=0;
- }
+ for (i = 0, j = 0; i < m; ++i) {
+ if (it[i].t == TH_DMSTART) {
+ if (g_dm) {
+ dm_pos[j].x = it[i].o.x;
+ dm_pos[j].y = it[i].o.y;
+ dm_pos[j].d = it[i].s & THF_DIR;
+ }
+ it[i].t = 0;
+ ++j;
+ }
+ }
+ if (g_dm && j < 2) {
+ ERR_fatal("Меньше 2-ух точек DM");
+ }
+ if (g_dm) {
+ dm_pnum = j;
+ dm_pl1p = myrand(dm_pnum);
+ do {
+ dm_pl2p = myrand(dm_pnum);
+ } while (dm_pl2p == dm_pl1p);
+ } else {
+ dm_pl1p = 0;
+ dm_pl2p = 1;
+ dm_pnum = 2;
+ }
+ PL_spawn(&pl1, dm_pos[dm_pl1p].x, dm_pos[dm_pl1p].y, dm_pos[dm_pl1p].d);
+ if (_2pl) {
+ PL_spawn(&pl2, dm_pos[dm_pl2p].x, dm_pos[dm_pl2p].y, dm_pos[dm_pl2p].d);
+ }
+ for (i = 0; i < m; ++i) {
+ if (it[i].t >= TH_CLIP && it[i].t < TH_DEMON) {
+ it[i].s = 0;
+ it[i].t = it[i].t - TH_CLIP + I_CLIP;
+ if (it[i].t >= I_KEYR && it[i].t <= I_KEYB) {
+ it[i].t |= 0x8000;
+ }
+ } else if (it[i].t >= TH_DEMON) {
+ MN_spawn(it[i].o.x, it[i].o.y, it[i].s & THF_DIR, it[i].t - TH_DEMON + MN_DEMON);
+ it[i].t = 0;
+ }
+ }
return 1;
- }return 0;
+ }
+ return 0;
}
static void takesnd(int t) {
diff --git a/src/misc.h b/src/misc.h
index 60eaee5bf5ec9ce7ea63f24d91ef3c1aea4047c1..3a96a5e0003996a1142e9a92080b8495b7a89315 100644 (file)
--- a/src/misc.h
+++ b/src/misc.h
// Miscellaneous functions
+#include <stdint.h>
+
#define MAXDIST 2000000L
enum{
void Z_clrst();
-unsigned short int short2host (unsigned short int x);
-unsigned int int2host (unsigned int x);
+uint16_t short2host (uint16_t x);
+uint32_t int2host (uint32_t x);
diff --git a/src/miscc.c b/src/miscc.c
index 7123938b16356714846b4fed3ba705b5ab6c4c19..4f5a302458bda126792daa857a8fb9fb14917e0e 100644 (file)
--- a/src/miscc.c
+++ b/src/miscc.c
*h = t;
}
-unsigned short int short2host (unsigned short int x) {
-#if __BIG_ENDIAN__
+#define SWAP_VAR(a, b) do { unsigned char t = a; a = b; b = t; } while(0)
+
+uint16_t short2swap (uint16_t x) {
union {
- unsigned char a[2];
- unsigned short int x;
+ uint8_t a[2];
+ uint16_t x;
} y;
y.x = x;
- unsigned char t = y.a[0]; y.a[0] = y.a[1]; y.a[1] = t;
+ SWAP_VAR(y.a[0], y.a[1]);
return y.x;
-#else
- return x;
-#endif
}
-unsigned int int2host (unsigned int x) {
-#if __BIG_ENDIAN__
+uint32_t int2swap (uint32_t x) {
union {
- unsigned char a[4];
- unsigned int x;
+ uint8_t a[4];
+ uint32_t x;
} y;
y.x = x;
- #define SWAP_VAR(a, b) do { unsigned char t = a; a = b; b = t; } while(0)
SWAP_VAR(y.a[0], y.a[3]);
SWAP_VAR(y.a[1], y.a[2]);
- #undef SWAP_VAR
return y.x;
+}
+
+#undef SWAP_VAR
+
+uint16_t short2host (uint16_t x) {
+#if __BIG_ENDIAN__
+ return short2swap(x);
#else
return x;
#endif
}
+
+uint32_t int2host (uint32_t x) {
+#if __BIG_ENDIAN__
+ return int2swap(x);
+#else
+ return x;
+#endif
+}
\ No newline at end of file
diff --git a/src/monster.c b/src/monster.c
index 98b909ebf803eea40342235b1c98770727e85c84..b0d677f7f5fb0e76136378ba271e7fcb937e22e1 100644 (file)
--- a/src/monster.c
+++ b/src/monster.c
8, 26, 400, 70, 8,10, 30, 50 // man
};
-void MN_savegame(FILE* h) {
- int n;
-
- for(n=MAXMN;--n;) if(mn[n].t) break;
- ++n;myfwrite(&n,1,4,h);
- myfwrite(mn,1,n*sizeof(mn[0]),h);
- myfwrite(&mnum,1,4,h);myfwrite(&gsndt,1,4,h);
+void MN_savegame (FILE *h) {
+ int i, n;
+ for (n = MAXMN - 1; n >= 0 && mn[n].t == 0; n--) {
+ // empty
+ }
+ n += 1;
+ myfwrite32(n, h);
+ for (i = 0; i < n; i++) {
+ myfwrite32(mn[i].o.x, h);
+ myfwrite32(mn[i].o.y, h);
+ myfwrite32(mn[i].o.xv, h);
+ myfwrite32(mn[i].o.yv, h);
+ myfwrite32(mn[i].o.vx, h);
+ myfwrite32(mn[i].o.vy, h);
+ myfwrite32(mn[i].o.r, h);
+ myfwrite32(mn[i].o.h, h);
+ myfwrite8(mn[i].t, h);
+ myfwrite8(mn[i].d, h);
+ myfwrite8(mn[i].st, h);
+ myfwrite8(mn[i].ftime, h);
+ myfwrite32(mn[i].fobj, h);
+ myfwrite32(mn[i].s, h);
+ myfwrite32(mn[i].ap, h); // useless, changed after load
+ myfwrite32(mn[i].aim, h);
+ myfwrite32(mn[i].life, h);
+ myfwrite32(mn[i].pain, h);
+ myfwrite32(mn[i].ac, h);
+ myfwrite32(mn[i].tx, h);
+ myfwrite32(mn[i].ty, h);
+ myfwrite32(mn[i].ammo, h);
+ myfwrite16(mn[i].atm, h);
+ }
+ myfwrite32(mnum, h);
+ myfwrite32(gsndt, h);
}
static void setst(int,int);
static int MN_hit(int n,int d,int o,int t);
-void MN_loadgame(FILE* h) {
- int n,c;
-
- myfread(&n,1,4,h);
- myfread(mn,1,n*sizeof(mn[0]),h);
- myfread(&mnum,1,4,h);myfread(&gsndt,1,4,h);
- for(n=0;n<MAXMN;++n) if(mn[n].t) {
- c=mn[n].ac;setst(n,mn[n].st);mn[n].ac=c;
+void MN_loadgame (FILE *h) {
+ int i, n, c;
+ myfread32(&n, h);
+ for (i = 0; i < n; i++) {
+ myfread32(&mn[i].o.x, h);
+ myfread32(&mn[i].o.y, h);
+ myfread32(&mn[i].o.xv, h);
+ myfread32(&mn[i].o.yv, h);
+ myfread32(&mn[i].o.vx, h);
+ myfread32(&mn[i].o.vy, h);
+ myfread32(&mn[i].o.r, h);
+ myfread32(&mn[i].o.h, h);
+ myfread8(&mn[i].t, h);
+ myfread8(&mn[i].d, h);
+ myfread8(&mn[i].st, h);
+ myfread8(&mn[i].ftime, h);
+ myfread32(&mn[i].fobj, h);
+ myfread32(&mn[i].s, h);
+ myfread32(&mn[i].ap, h); // useless, changed after loading
+ myfread32(&mn[i].aim, h);
+ myfread32(&mn[i].life, h);
+ myfread32(&mn[i].pain, h);
+ myfread32(&mn[i].ac, h);
+ myfread32(&mn[i].tx, h);
+ myfread32(&mn[i].ty, h);
+ myfread32(&mn[i].ammo, h);
+ myfread16(&mn[i].atm, h);
+ }
+ myfread32(&mnum, h);
+ myfread32(&gsndt, h);
+ for (n = 0; n < MAXMN; ++n) {
+ if (mn[n].t) {
+ c = mn[n].ac;
+ setst(n, mn[n].st);
+ mn[n].ac = c;
+ }
}
}
diff --git a/src/my.c b/src/my.c
index 0a7fcbcd6ce4a20958b2d915e730c2ee9fb89a81..e4c2d459dd0b728dc02ea691e91942e1cb631990 100644 (file)
--- a/src/my.c
+++ b/src/my.c
#include "glob.h"
#include "error.h"
#include <stdio.h>
+#include <stdint.h>
+#include <assert.h>
void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext)
{
}
}
-size_t myfreadc(void *ptr, size_t size, size_t n, FILE *f) {
+size_t myfreadc (void *ptr, size_t size, size_t n, FILE *f) {
return fread(ptr, size, n, f);
}
-void myfread(void *ptr, size_t size, size_t n, FILE *f) {
+void myfread (void *ptr, size_t size, size_t n, FILE *f) {
if (myfreadc(ptr, size, n, f) != n) {
ERR_fatal("File reading error\n");
}
}
-void myfwrite(void *ptr, size_t n, size_t size, FILE *f) {
- size_t s = fwrite(ptr,n,size,f);
+void myfread8 (uint8_t *x, FILE *f) {
+ myfread(x, 1, 1, f);
+}
+
+void myfread16 (uint16_t *x, FILE *f) {
+ myfread(x, 2, 1, f);
+ *x = short2host(*x);
+}
+
+void myfread32 (uint32_t *x, FILE *f) {
+ myfread(x, 4, 1, f);
+ *x = int2host(*x);
+}
+
+void myfwrite (void *ptr, size_t size, size_t n, FILE *f) {
+ assert(fwrite(ptr, size, n, f) == n);
+}
+
+void myfwrite8 (uint8_t x, FILE *f) {
+ myfwrite(&x, 1, 1, f);
+}
+
+void myfwrite16 (uint16_t x, FILE *f) {
+ x = short2host(x);
+ myfwrite(&x, 2, 1, f);
+}
+
+void myfwrite32 (uint32_t x, FILE *f) {
+ x = int2host(x);
+ myfwrite(&x, 4, 1, f);
}
void myrandomize(void)
diff --git a/src/my.h b/src/my.h
index 607cccda66cea520a58052a634131a07bad82927..37ba02b380528a2d9ddc31da89d4d3e193a1384c 100644 (file)
--- a/src/my.h
+++ b/src/my.h
extern "C" {
#endif
-int fexists(char * filename);
+#include <stdio.h>
+#include <stdint.h>
+
+void mysplitpath (const char *path, char *drv, char *dir, char *name, char *ext);
+
+size_t myfreadc(void *ptr, size_t size, size_t n, FILE *f);
+
+void myfread (void *ptr, size_t size, size_t n, FILE *f);
+void myfread8 (uint8_t *x, FILE *f);
+void myfread16 (uint16_t *x, FILE *f);
+void myfread32 (uint32_t *x, FILE *f);
+
+void myfwrite(void *ptr, size_t size, size_t n, FILE *f);
+void myfwrite8 (uint8_t x, FILE *f);
+void myfwrite16 (uint16_t x, FILE *f);
+void myfwrite32 (uint32_t x, FILE *f);
+
+void myrandomize (void);
+int fexists (char *filename);
#ifdef __cplusplus
}
diff --git a/src/player.c b/src/player.c
index fd1080a4a49a52e34b738f06af873b8ded08d86e..5a8a80ebb361689b65c3dcd5a8d79e971177e49f 100644 (file)
--- a/src/player.c
+++ b/src/player.c
} _keys;
#pragma pack()
-void PL_savegame(FILE* h) {
- myfwrite(&pl1,1,sizeof(pl1)-sizeof(_keys),h);//myfwrite(&pl1,1,sizeof(pl1),h);
- if(_2pl) myfwrite(&pl2,1,sizeof(pl2)-sizeof(_keys),h);//myfwrite(&pl2,1,sizeof(pl2),h);
- myfwrite(&PL_JUMP,1,4,h);myfwrite(&PL_RUN,1,4,h);myfwrite(&p_immortal,1,1,h);
+void PL_save_player (player_t *p, FILE *h) {
+ myfwrite32(p->o.x, h);
+ myfwrite32(p->o.y, h);
+ myfwrite32(p->o.xv, h);
+ myfwrite32(p->o.yv, h);
+ myfwrite32(p->o.vx, h);
+ myfwrite32(p->o.vy, h);
+ myfwrite32(p->o.r, h);
+ myfwrite32(p->o.h, h);
+ myfwrite32(p->looky, h);
+ myfwrite32(p->st, h);
+ myfwrite32(p->s, h);
+ myfwrite32(p->life, h);
+ myfwrite32(p->armor, h);
+ myfwrite32(p->hit, h);
+ myfwrite32(p->hito, h);
+ myfwrite32(p->pain, h);
+ myfwrite32(p->air, h);
+ myfwrite32(p->invl, h);
+ myfwrite32(p->suit, h);
+ myfwrite8(p->d, h);
+ myfwrite32(p->frag, h);
+ myfwrite32(p->ammo, h);
+ myfwrite32(p->shel, h);
+ myfwrite32(p->rock, h);
+ myfwrite32(p->cell, h);
+ myfwrite32(p->fuel, h);
+ myfwrite32(p->kills, h);
+ myfwrite32(p->secrets, h);
+ myfwrite8(p->fire, h);
+ myfwrite8(p->cwpn, h);
+ myfwrite8(p->csnd, h);
+ myfwrite8(p->amul, h);
+ myfwrite16(p->wpns, h);
+ myfwrite8(p->wpn, h);
+ myfwrite8(p->f, h);
+ myfwrite8(p->drawst, h);
+ myfwrite8(p->color, h);
+ myfwrite32(p->id, h);
+ myfwrite8(p->keys, h);
+ myfwrite8(p->lives, h);
+ // k* not saved
}
-void PL_loadgame(FILE* h) {
- myfread(&pl1,1,sizeof(pl1)-sizeof(_keys),h);//myfread(&pl1,1,sizeof(pl1),h);
- if(_2pl) myfread(&pl2,1,sizeof(pl2)-sizeof(_keys),h);//myfread(&pl2,1,sizeof(pl2),h);
- myfread(&PL_JUMP,1,4,h);myfread(&PL_RUN,1,4,h);myfread(&p_immortal,1,1,h);
+void PL_savegame (FILE *h) {
+ PL_save_player(&pl1, h);
+ if (_2pl) {
+ PL_save_player(&pl2, h);
+ }
+ myfwrite32(PL_JUMP, h);
+ myfwrite32(PL_RUN, h);
+ myfwrite8(p_immortal, h);
+}
+
+void PL_load_player (player_t *p, FILE *h) {
+ myfread32(&p->o.x, h);
+ myfread32(&p->o.y, h);
+ myfread32(&p->o.xv, h);
+ myfread32(&p->o.yv, h);
+ myfread32(&p->o.vx, h);
+ myfread32(&p->o.vy, h);
+ myfread32(&p->o.r, h);
+ myfread32(&p->o.h, h);
+ myfread32(&p->looky, h);
+ myfread32(&p->st, h);
+ myfread32(&p->s, h);
+ myfread32(&p->life, h);
+ myfread32(&p->armor, h);
+ myfread32(&p->hit, h);
+ myfread32(&p->hito, h);
+ myfread32(&p->pain, h);
+ myfread32(&p->air, h);
+ myfread32(&p->invl, h);
+ myfread32(&p->suit, h);
+ myfread8(&p->d, h);
+ myfread32(&p->frag, h);
+ myfread32(&p->ammo, h);
+ myfread32(&p->shel, h);
+ myfread32(&p->rock, h);
+ myfread32(&p->cell, h);
+ myfread32(&p->fuel, h);
+ myfread32(&p->kills, h);
+ myfread32(&p->secrets, h);
+ myfread8(&p->fire, h);
+ myfread8(&p->cwpn, h);
+ myfread8(&p->csnd, h);
+ myfread8(&p->amul, h);
+ myfread16(&p->wpns, h);
+ myfread8(&p->wpn, h);
+ myfread8(&p->f, h);
+ myfread8(&p->drawst, h);
+ myfread8(&p->color, h);
+ myfread32(&p->id, h);
+ myfread8(&p->keys, h);
+ myfread8(&p->lives, h);
+ // k* not saved
+}
+
+void PL_loadgame (FILE *h) {
+ PL_load_player(&pl1, h);
+ if (_2pl) {
+ PL_load_player(&pl2, h);
+ }
+ myfread32(&PL_JUMP, h);
+ myfread32(&PL_RUN, h);
+ myfread8(&p_immortal, h);
}
static int nonz(int a) {return (a)?a:1;}
diff --git a/src/smoke.c b/src/smoke.c
index 4ec8117a26a12bff82048fc138da3f7eed9b5d43..6b012610b2eb64487d85602e9dc595bf65a50e19 100644 (file)
--- a/src/smoke.c
+++ b/src/smoke.c
0xBC,0xBA,0xB8,0xB6,0xB4,0xB2,0xB0,0xD5,0xD6,0xD7,0xA1,0xA0,0xE3,0xE2,0xE1,0xE0
};
-void SMK_savegame(FILE* h) {
- int i,n;
-
- for(i=n=0;i<MAXSMOK;++i) if(sm[i].t) ++n;
- myfwrite(&n,1,4,h);
- for(i=0;i<MAXSMOK;++i) if(sm[i].t) myfwrite(&sm[i],1,sizeof(sm[0]),h);
+void SMK_savegame (FILE *h) {
+ int i, n;
+ for (i = n = 0; i < MAXSMOK; ++i) {
+ if (sm[i].t) {
+ ++n;
+ }
+ }
+ myfwrite32(n, h);
+ for (i = 0; i < MAXSMOK; ++i) {
+ if (sm[i].t) {
+ myfwrite32(sm[i].x, h);
+ myfwrite32(sm[i].y, h);
+ myfwrite32(sm[i].xv, h);
+ myfwrite32(sm[i].xv, h);
+ myfwrite8(sm[i].t, h);
+ myfwrite8(sm[i].s, h);
+ myfwrite16(sm[i].o, h);
+ }
+ }
}
-void SMK_loadgame(FILE* h) {
- int n;
-
- myfread(&n,1,4,h);
- myfread(sm,1,n*sizeof(sm[0]),h);
+void SMK_loadgame (FILE *h) {
+ int i, n;
+ myfread32(&n, h);
+ for (i = 0; i < n; ++i) {
+ myfread32(&sm[i].x, h);
+ myfread32(&sm[i].y, h);
+ myfread32(&sm[i].xv, h);
+ myfread32(&sm[i].xv, h);
+ myfread8(&sm[i].t, h);
+ myfread8(&sm[i].s, h);
+ myfread16(&sm[i].o, h);
+ }
}
void SMK_init(void) {
diff --git a/src/switch.c b/src/switch.c
index 980955dee5f54ad7ebb42b5be4c9b00f806fe2b0..275aed721c9c13437bd38955260f5c70093e3863 100644 (file)
--- a/src/switch.c
+++ b/src/switch.c
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;
+ myfread32(&n, h);
+ for (i = 0; i < n; i++) {
+ myfread8(&sw[i].x, h);
+ myfread8(&sw[i].y, h);
+ myfread8(&sw[i].t, h);
+ myfread8(&sw[i].tm, h);
+ myfread8(&sw[i].a, h);
+ myfread8(&sw[i].b, h);
+ myfread8(&sw[i].c, h);
+ myfread8(&sw[i].d, h);
+ myfread8(&sw[i].f, h);
+ }
+ myfread32(&sw_secrets, 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;
+ sw_secrets = 0;
+ for (i = 0; i < MAXSW && blk.sz > 0; ++i, blk.sz -= 9) {
+ myfread8(&sw[i].x, h);
+ myfread8(&sw[i].y, h);
+ myfread8(&sw[i].t, h);
+ myfread8(&sw[i].tm, h); // unused
+ myfread8(&sw[i].a, h);
+ myfread8(&sw[i].b, h);
+ myfread8(&sw[i].c, h);
+ myfread8(&sw[i].d, h); // unused
+ myfread8(&sw[i].f, 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) {
diff --git a/src/view.c b/src/view.c
index 3bf36772cd60cec019f9d89528746c84613d03c6..034b0aa80a6a7bf5956d901f5c3c9e84cce4bee2 100644 (file)
--- a/src/view.c
+++ b/src/view.c
void W_savegame(FILE* h) {
char s[8];
int i;
-
- myfwrite(&sky_type,1,4,h);
- for(i=1;i<256;++i) {
- getname(i,s);myfwrite(s,1,8,h);
+ myfwrite32(sky_type, h);
+ for(i = 1; i < 256; ++i) {
+ getname(i, s);
+ myfwrite(s, 8, 1, h);
+ }
+ for (i = 0; i < 256; i++) {
+ myfwrite32(walf[i], h);
+ }
+ for (i = 0; i < 256; i++) {
+ myfwrite8(walswp[i], h);
}
- myfwrite(walf,1,sizeof(walf),h);
- myfwrite(walswp,1,sizeof(walswp),h);
- myfwrite(fldb,1,FLDW*FLDH,h);
- myfwrite(fld,1,FLDW*FLDH,h);
- myfwrite(fldf,1,FLDW*FLDH,h);
+ myfwrite(fldb, FLDW*FLDH, 1, h);
+ myfwrite(fld, FLDW*FLDH, 1, h);
+ myfwrite(fldf, FLDW*FLDH, 1, h);
}
void W_loadgame(FILE* h) {
char s[8];
int i;
-
- myfread(&sky_type,1,4,h);
- for(i=1;i<256;++i) {
+ myfread32(&sky_type, h);
+ for (i = 1; i < 256; ++i) {
walani[i]=0;
- myfread(s,1,8,h);if(!s[0]) {walh[i]=-1;walp[i]=NULL;continue;}
- walani[i]=getani(s);
- if(strncasecmp(s,"_WATER_",7)==0) { //if(memicmp(s,"_WATER_",7)==0) {
- walh[i]=-2;walp[i]=(void*)(s[7]-'0'+1);
+ myfread(s, 8, 1, h);
+ if (!s[0]) {
+ walh[i] = -1;
+ walp[i] = NULL;
} else {
- walh[i]=F_getresid(s);
- walp[i]=V_getvgaimg(walh[i]);
+ walani[i] = getani(s);
+ if (strncasecmp(s, "_WATER_", 7) == 0) {
+ walh[i] = -2;
+ walp[i] = (void*)(s[7] - '0' + 1);
+ } else {
+ walh[i] = F_getresid(s);
+ walp[i] = V_getvgaimg(walh[i]);
+ }
}
}
- myfread(walf,1,sizeof(walf),h);
- for(i=1;i<256;++i) if(walf[i]&1) walh[i]|=0x8000;
- myfread(walswp,1,sizeof(walswp),h);
- myfread(fldb,1,FLDW*FLDH,h);
- myfread(fld,1,FLDW*FLDH,h);
- myfread(fldf,1,FLDW*FLDH,h);
- strcpy(s,"RSKY1");s[4]=sky_type+'0';
+ for (i = 0; i < 256; i++) {
+ myfread32(&walf[i], h);
+ if (i > 0 && walf[i] & 1) {
+ walh[i] |= 0x8000;
+ }
+ }
+ for (i = 0; i < 256; i++) {
+ myfread8(&walswp[i], h);
+ }
+ myfread(fldb, FLDW*FLDH, 1, h);
+ myfread(fld, FLDW*FLDH, 1, h);
+ myfread(fldf, FLDW*FLDH, 1, h);
+ strcpy(s, "RSKY1");
+ s[4] = '0' + sky_type;
M_unlock(horiz);
- horiz=V_loadvgaimg(s);
+ horiz = V_loadvgaimg(s);
}
void W_adjust(void) {
}
}
-int W_load(FILE* h) {
- int i,j,k,g;
- static wall_t w;
- void *p,*buf;
-
- switch(blk.t) {
- case MB_WALLNAMES:
- for(i=0;i<256;++i) {walh[i]=-1;walswp[i]=i;walani[i]=0;}
- for(i=1;i<256 && blk.sz>0;++i,blk.sz-=sizeof(w)) {
- myfread(&w,1,sizeof(w),h);
-
- if(strncasecmp(w.n,"_WATER_",7)==0) //if(memicmp(w.n,"_WATER_",7)==0)
- {walp[i]=(void*)(w.n[7]-'0'+1);walh[i]=-2;continue;}
-
- walh[i]=F_getresid(w.n);
- walp[i]=V_getvgaimg(walh[i]);
- if(w.n[0]=='S' && w.n[1]=='W' && w.n[4]=='_') walswp[i]=0;
- walf[i]=(w.t)?1:0;if(w.t) walh[i]|=0x8000;
-
- if(strncasecmp(w.n,"VTRAP01",8)==0) walf[i]|=2; //if(memicmp(w.n,"VTRAP01",8)==0) walf[i]|=2;
- walani[i]=getani(w.n);
- }
- for(j=i,i=1;i<256;++i) if(walswp[i]==0) {
- if(j>=256) break;
- F_getresname(w.n,walh[i]&0x7FFF);
- w.n[5]^=1;
- g=F_getresid(w.n)|(walh[i]&0x8000);
- for(k=1;k<256;++k) if(walh[k]==g) break;
- if(k>=256) {
- walh[k=j++]=g;walp[k]=V_getvgaimg(g);
- walf[k]=(g&0x8000)?1:0;
- }
- walswp[i]=k;walswp[k]=i;
+int W_load (FILE *h) {
+ int i, j, k, g;
+ void *p, *buf;
+ wall_t w;
+ switch (blk.t) {
+ case MB_WALLNAMES:
+ for (i = 0; i < 256; ++i) {
+ walh[i] = -1;
+ walswp[i] = i;
+ walani[i] = 0;
+ }
+ for (i = 1; i < 256 && blk.sz > 0; ++i, blk.sz -= 9) {
+ myfread(w.n, 8, 1, h);
+ myfread8(&w.t, h);
+ if (strncasecmp(w.n, "_WATER_", 7) == 0) {
+ walp[i] = (void*)(w.n[7] - '0' + 1);
+ walh[i] = -2;
+ } else {
+ walh[i] = F_getresid(w.n);
+ walp[i] = V_getvgaimg(walh[i]);
+ if (w.n[0] == 'S' && w.n[1] == 'W' && w.n[4] == '_') {
+ walswp[i] = 0;
+ }
+ walf[i] = w.t ? 1 : 0;
+ if (w.t) {
+ walh[i] |= 0x8000;
+ }
+ if (strncasecmp(w.n, "VTRAP01", 8) == 0) {
+ walf[i] |= 2;
+ }
+ walani[i] = getani(w.n);
+ }
}
+ for (j = i, i = 1; i < 256 && j < 256; ++i) {
+ if (walswp[i] == 0) {
+ F_getresname(w.n, walh[i] & 0x7FFF);
+ w.n[5] ^= 1;
+ g = F_getresid(w.n) | (walh[i] & 0x8000);
+ k = 1;
+ while (k < 256 && walh[k] != g) {
+ k += 1;
+ }
+ if(k >= 256) {
+ k = j;
+ j += 1;
+ walh[k] = g;
+ walp[k] = V_getvgaimg(g);
+ walf[k] = g & 0x8000 ? 1 : 0;
+ }
+ walswp[i] = k;
+ walswp[k] = i;
+ }
+ }
return 1;
- case MB_BACK: p=fldb;goto unp;
- case MB_WTYPE: p=fld;goto unp;
- case MB_FRONT: p=fldf;
- unp: switch(blk.st) {
- case 0: myfread(p,1,FLDW*FLDH,h);break;
+ case MB_BACK:
+ p = fldb;
+ goto unp;
+ case MB_WTYPE:
+ p = fld;
+ goto unp;
+ case MB_FRONT:
+ p = fldf;
+ unp:
+ switch (blk.st) {
+ case 0:
+ myfread(p, FLDW * FLDH, 1, h);
+ break;
case 1:
- if(!(buf=malloc(blk.sz)))
+ buf = malloc(blk.sz);
+ if(buf == NULL) {
ERR_fatal("Не хватает памяти");
- myfread(buf,1,blk.sz,h);
- unpack(buf,blk.sz,p);free(buf);break;
- default: return 0;
- }return 1;
+ }
+ myfread(buf, blk.sz, 1, h);
+ unpack(buf, blk.sz, p);
+ free(buf);
+ break;
+ default:
+ return 0;
+ }
+ return 1;
case MB_SKY:
- sky_type=0;myfread(&sky_type,2,1,h);
- sky_type = short2host(sky_type);
- strcpy(w.n,"RSKY1");w.n[4]=sky_type+'0';
+ myfread16(&sky_type, h);
+ strcpy(w.n, "RSKY1");
+ w.n[4] = '0' + sky_type;
M_unlock(horiz);
- horiz=V_loadvgaimg(w.n);
+ horiz = V_loadvgaimg(w.n);
return 1;
- }return 0;
+ }
+ return 0;
}
diff --git a/src/weapons.c b/src/weapons.c
index b778a0ec96c484a448264ae979454c9a9e0b70a7..4a5a063d426b2e92e6695717ff50d0933f7032e9 100644 (file)
--- a/src/weapons.c
+++ b/src/weapons.c
static void throw(int,int,int,int,int,int,int,int);
-void WP_savegame(FILE* h) {
- int n;
-
- for(n=MAXWPN;--n;) if(wp[n].t) break;
- ++n;myfwrite(&n,1,4,h);myfwrite(wp,1,n*sizeof(wp[0]),h);
+void WP_savegame (FILE *h) {
+ int i, n;
+ for (n = MAXWPN - 1; n >= 0 && wp[n].t == 0; n--) {
+ // empty
+ }
+ n += 1;
+ myfwrite32(n, h);
+ for (i = 0; i < n; i++) {
+ myfwrite32(wp[i].o.x, h);
+ myfwrite32(wp[i].o.y, h);
+ myfwrite32(wp[i].o.xv, h);
+ myfwrite32(wp[i].o.yv, h);
+ myfwrite32(wp[i].o.vx, h);
+ myfwrite32(wp[i].o.vy, h);
+ myfwrite32(wp[i].o.r, h);
+ myfwrite32(wp[i].o.h, h);
+ myfwrite8(wp[i].t, h);
+ myfwrite8(wp[i].s, h);
+ myfwrite32(wp[i].own, h);
+ myfwrite16(wp[i].target, h);
+ }
}
-void WP_loadgame(FILE* h) {
- int n;
-
- myfread(&n,1,4,h);myfread(wp,1,n*sizeof(wp[0]),h);
+void WP_loadgame (FILE *h) {
+ int i, n;
+ myfread32(&n, h);
+ for (i = 0; i < n; i++) {
+ myfread32(&wp[i].o.x, h);
+ myfread32(&wp[i].o.y, h);
+ myfread32(&wp[i].o.xv, h);
+ myfread32(&wp[i].o.yv, h);
+ myfread32(&wp[i].o.vx, h);
+ myfread32(&wp[i].o.vy, h);
+ myfread32(&wp[i].o.r, h);
+ myfread32(&wp[i].o.h, h);
+ myfread8(&wp[i].t, h);
+ myfread8(&wp[i].s, h);
+ myfread32(&wp[i].own, h);
+ myfread16(&wp[i].target, h);
+ }
}
void WP_alloc(void) {