2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
49 #define MAXX (FLDW*CELW-WD/2)
50 #define MAXY (FLDH*CELH-HT/2)
56 extern map_block_t blk
;
58 extern byte clrmap
[256*12];
59 void V_remap_rect(int,int,int,int,byte
*);
62 void *horiz
=NULL
;//static void *horiz=NULL;
63 int w_o
,w_x
,w_y
,sky_type
=1;
71 byte fldb
[FLDH
][FLDW
];
72 byte fldf
[FLDH
][FLDW
];
75 extern int lt_time
,lt_type
,lt_side
,lt_ypos
;
76 extern void *ltn
[2][2];
78 static void getname(int n
,char *s
) {
79 if(walh
[n
]==-1) {memset(s
,0,8);return;}
81 memcpy(s
,"_WATER_",8);s
[7]=(byte
)walp
[n
]-1+'0';
84 F_getresname(s
,walh
[n
]&0x7FFF);
87 static short getani(char *n
) {
88 if(strncasecmp(n
,"WALL22_1",8)==0) return 1;
89 if(strncasecmp(n
,"WALL58_1",8)==0) return 2;
90 if(strncasecmp(n
,"W73A_1",8)==0) return 3;
91 if(strncasecmp(n
,"RP2_1",8)==0) return 4;
95 void W_savegame(FILE* h
) {
99 myfwrite(&sky_type
,1,4,h
);
101 getname(i
,s
);myfwrite(s
,1,8,h
);
103 myfwrite(walf
,1,sizeof(walf
),h
);
104 myfwrite(walswp
,1,sizeof(walswp
),h
);
105 myfwrite(fldb
,1,FLDW
*FLDH
,h
);
106 myfwrite(fld
,1,FLDW
*FLDH
,h
);
107 myfwrite(fldf
,1,FLDW
*FLDH
,h
);
110 void W_loadgame(FILE* h
) {
114 myfread(&sky_type
,1,4,h
);
117 myfread(s
,1,8,h
);if(!s
[0]) {walh
[i
]=-1;walp
[i
]=NULL
;continue;}
119 if(strncasecmp(s
,"_WATER_",7)==0) { //if(memicmp(s,"_WATER_",7)==0) {
120 walh
[i
]=-2;walp
[i
]=(void*)(s
[7]-'0'+1);
121 }else walp
[i
]=M_lock(walh
[i
]=F_getresid(s
));
123 myfread(walf
,1,sizeof(walf
),h
);
124 for(i
=1;i
<256;++i
) if(walf
[i
]&1) walh
[i
]|=0x8000;
125 myfread(walswp
,1,sizeof(walswp
),h
);
126 myfread(fldb
,1,FLDW
*FLDH
,h
);
127 myfread(fld
,1,FLDW
*FLDH
,h
);
128 myfread(fldf
,1,FLDW
*FLDH
,h
);
129 strcpy(s
,"RSKY1");s
[4]=sky_type
+'0';
131 horiz
=M_lock(F_getresid(s
));
134 void W_adjust(void) {
135 int MAXX
=(FLDW
*CELW
-WD
/2);//
136 int MAXY
=(FLDH
*CELH
-HT
/2);//
138 if(w_x
<WD
/2) w_x
=WD
/2;
139 if(w_y
<HT
/2) w_y
=HT
/2;
140 if(w_x
>MAXX
) w_x
=MAXX
;
141 if(w_y
>MAXY
) w_y
=MAXY
;
146 V_setrect(0,WD
,w_o
+1,HT
);
150 //V_pic(127-(word)(w_x-WD/2)*56U/(word)(MAXX-WD/2),w_o+123-(word)(w_y-HT/2)*28U/(word)(MAXY-HT/2),horiz);
151 vgaimg
*img
= (vgaimg
*)horiz
;
168 if(sky_type
==2) if(lt_time
<0) {
169 if(!lt_side
) V_spr(0,w_o
+lt_ypos
,ltn
[lt_type
][(lt_time
<-5)?0:1]);
170 else V_spr2(WD
-1,w_o
+lt_ypos
,ltn
[lt_type
][(lt_time
<-5)?0:1]);
172 }else V_clr(0,WD
,w_o
+1,HT
,0x97);
173 Z_drawfld((byte
*)fldb
, 1);
177 if(_2pl
) PL_draw(&pl2
);
182 Z_drawfld((byte
*)fldf
, 0);
184 if(lt_time
==-4 || lt_time
==-2)
185 V_remap_rect(0,WD
,w_o
+1,HT
,clrmap
+256*11);
191 static char *anm
[ANIT
-1][5]={
192 {"WALL22_1","WALL23_1","WALL23_2",NULL
,NULL
},
193 {"WALL58_1","WALL58_2","WALL58_3",NULL
,NULL
},
194 {"W73A_1","W73A_2",NULL
,NULL
,NULL
},
195 {"RP2_1","RP2_2","RP2_3","RP2_4",NULL
}
198 for(i
=1;i
<ANIT
;++i
) {
199 for(j
=0;anm
[i
-1][j
];++j
)
200 anih
[i
][j
]=F_getresid(anm
[i
-1][j
]);
201 for(;j
<5;++j
) anih
[i
][j
]=-1;
203 memset(anic
,0,sizeof(anic
));
213 horiz
=M_lock(F_getresid("RSKY1"));
221 if(g_time%3
!=0) return;
222 for(i
=1;i
<256;++i
) if((a
=walani
[i
])!=0) {
223 if(anih
[a
][++anic
[a
]]==-1) anic
[a
]=0;
224 walp
[i
]=M_lock(anih
[a
][anic
[a
]]);
228 static void unpack(void *buf
,int len
,void *obuf
) {
232 for(p
=(byte
*)buf
,o
=(byte
*)obuf
,l
=len
;l
;++p
,--l
) if(*p
==255) {
233 n
=*((word
*)(++p
));memset(o
,*(p
+=2),n
);o
+=n
;l
-=3;
237 int W_load(FILE* h
) {
244 for(i
=0;i
<256;++i
) {walh
[i
]=-1;walswp
[i
]=i
;walani
[i
]=0;}
245 for(i
=1;i
<256 && blk
.sz
>0;++i
,blk
.sz
-=sizeof(w
)) {
246 myfread(&w
,1,sizeof(w
),h
);
248 if(strncasecmp(w
.n
,"_WATER_",7)==0) //if(memicmp(w.n,"_WATER_",7)==0)
249 {walp
[i
]=(void*)(w
.n
[7]-'0'+1);walh
[i
]=-2;continue;}
250 walp
[i
]=M_lock(walh
[i
]=F_getresid(w
.n
));
251 if(w
.n
[0]=='S' && w
.n
[1]=='W' && w
.n
[4]=='_') walswp
[i
]=0;
252 walf
[i
]=(w
.t
)?1:0;if(w
.t
) walh
[i
]|=0x8000;
254 if(strncasecmp(w
.n
,"VTRAP01",8)==0) walf
[i
]|=2; //if(memicmp(w.n,"VTRAP01",8)==0) walf[i]|=2;
255 walani
[i
]=getani(w
.n
);
257 for(j
=i
,i
=1;i
<256;++i
) if(walswp
[i
]==0) {
259 F_getresname(w
.n
,walh
[i
]&0x7FFF);
261 g
=F_getresid(w
.n
)|(walh
[i
]&0x8000);
262 for(k
=1;k
<256;++k
) if(walh
[k
]==g
) break;
264 walh
[k
=j
++]=g
;walp
[k
]=M_lock(g
);
265 walf
[k
]=(g
&0x8000)?1:0;
267 walswp
[i
]=k
;walswp
[k
]=i
;
270 case MB_BACK
: p
=fldb
;goto unp
;
271 case MB_WTYPE
: p
=fld
;goto unp
;
272 case MB_FRONT
: p
=fldf
;
273 unp
: switch(blk
.st
) {
274 case 0: myfread(p
,1,FLDW
*FLDH
,h
);break;
276 if(!(buf
=malloc(blk
.sz
)))
277 ERR_fatal("Не хватает памяти");
278 myfread(buf
,1,blk
.sz
,h
);
279 unpack(buf
,blk
.sz
,p
);free(buf
);break;
283 sky_type
=0;myfread(&sky_type
,1,2,h
);
284 strcpy(w
.n
,"RSKY1");w
.n
[4]=sky_type
+'0';
286 horiz
=M_lock(F_getresid(w
.n
));