DEADSOFTWARE

map: move map loading to separate file
[flatwaifu.git] / src / game.c
1 /*
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
21 */
23 #include "glob.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "files.h"
28 #include "memory.h"
29 #include "sound.h"
30 #include "view.h"
31 #include "bmap.h"
32 #include "fx.h"
33 #include "switch.h"
34 #include "weapons.h"
35 #include "items.h"
36 #include "dots.h"
37 #include "smoke.h"
38 #include "player.h"
39 #include "monster.h"
40 #include "menu.h"
41 #include "misc.h"
42 #include "map.h"
43 #include "my.h"
44 #include "game.h"
45 #include "config.h"
46 #include "music.h"
47 #include "a8.h"
48 #include "error.h"
49 #include "input.h"
51 #include "save.h"
53 #define LT_DELAY 8
54 #define LT_HITTIME 6
56 #define GETIME 1092
58 byte transdraw;
59 byte _2pl;
60 byte g_dm;
61 byte g_st = GS_TITLE;
62 byte g_exit;
63 byte g_map = 1;
64 char g_music[8] = "MENU";
65 dword g_time;
66 int dm_pnum;
67 int dm_pl1p;
68 int dm_pl2p;
69 pos_t dm_pos[100];
70 byte cheat;
72 static void *telepsnd;
74 int lt_time;
75 int lt_type;
76 int lt_side;
77 int lt_ypos;
78 static int lt_force;
79 static void *ltnsnd[2];
81 int g_trans;
82 static int g_transt;
84 static void set_trans(int st) {
85 switch(g_st) {
86 case GS_ENDANIM: case GS_END2ANIM: case GS_DARKEN:
87 case GS_BVIDEO: case GS_EVIDEO: case GS_END3ANIM:
88 g_st=st;return;
89 }
90 switch(g_st=st) {
91 case GS_ENDANIM: case GS_END2ANIM: case GS_DARKEN:
92 case GS_BVIDEO: case GS_EVIDEO: case GS_END3ANIM:
93 return;
94 }
95 g_trans=1;g_transt=0;
96 }
98 void load_game (int n) {
99 F_freemus();
100 W_init();
101 F_loadgame(n);
102 set_trans(GS_GAME);
103 pl1.drawst=0xFF;
104 if(_2pl) pl2.drawst=0xFF;
105 BM_remapfld();
106 BM_clear(BM_PLR1|BM_PLR2|BM_MONSTER);
107 BM_mark(&pl1.o,BM_PLR1);
108 if(_2pl) BM_mark(&pl2.o,BM_PLR2);
109 MN_mark();
110 S_startmusic(music_time);
113 void G_start (void) {
114 char s[8];
116 F_freemus();
117 sprintf(s,"MAP%02u",(word)g_map);
118 F_loadmap(s);
119 set_trans(GS_GAME);
120 pl1.drawst=0xFF;
121 if(_2pl) pl2.drawst=0xFF;
122 g_exit=0;
123 itm_rtime=(g_dm)?1092:0;
124 p_immortal=0;PL_JUMP=10;
125 g_time=0;
126 lt_time=1000;
127 lt_force=1;
128 if(!_2pl) pl1.lives=3;
129 BM_remapfld();
130 BM_clear(BM_PLR1|BM_PLR2|BM_MONSTER);
131 BM_mark(&pl1.o,BM_PLR1);
132 if(_2pl) BM_mark(&pl2.o,BM_PLR2);
133 MN_mark();
134 S_startmusic(music_time);
137 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
139 void G_init (void) {
140 int i,j;
141 char s[9];
143 logo("G_init: настройка ресурсов игры ");
144 logo_gas(5,GGAS_TOTAL);
145 telepsnd=Z_getsnd("TELEPT");
146 ltnsnd[0]=Z_getsnd("THUND1");
147 ltnsnd[1]=Z_getsnd("THUND2");
148 DOT_alloc();
149 SMK_alloc();
150 FX_alloc();
151 WP_alloc();
152 IT_alloc();
153 SW_alloc();
154 PL_alloc();
155 MN_alloc();
156 Z_initst();
157 logo_gas(GGAS_TOTAL,GGAS_TOTAL);
158 logo("\n");
159 GM_init();
160 pl1.color=0x70;
161 pl2.color=0x60;
162 g_trans=0;
165 static int G_beg_video (void) {
166 /*
167 switch(g_map) {
168 case 3: return A8_start("FALL");
169 case 4: return A8_start("KORIDOR");
170 case 5: return A8_start("SKULL");
171 case 6: return A8_start("TORCHES");
172 case 7: return A8_start("CACO");
173 case 8: return A8_start("DARTS");
174 case 9: return A8_start("FISH");
175 case 10: return A8_start("TRAP");
176 case 11: return A8_start("JAIL");
177 case 12: return A8_start("MMON1");
178 case 13: return A8_start("TOWER");
179 case 14: return A8_start("SAPOG");
180 case 15: return A8_start("SWITCH");
181 case 16: return A8_start("ACCEL");
182 case 17: return A8_start("MEAT");
183 case 18: return A8_start("LEGION");
184 case 19: return A8_start("CLOUDS");
186 */
187 return 0;
191 static int G_end_video (void) {
192 /*
193 switch(g_map) {
194 case 1: return A8_start("TRUBA");
195 case 10: return A8_start("GOTCHA");
197 */
198 return 0;
201 void G_act (void) {
202 static byte pcnt=0;
203 /*
204 if(g_trans) {
205 if(g_transt==0) {
206 V_setscr(NULL);memcpy(fx_scr1,scra,64000);
207 V_setscr(fx_scr2);
208 transdraw=1;G_draw();transdraw=0;
209 V_setscr(scrbuf);
211 FX_trans1(g_transt*2);
212 V_copytoscr(0,320,0,200);
213 if(++g_transt>32) {
214 g_trans=0;
216 return;
217 g_trans=0;
219 */ g_trans=0;
222 if(g_st==GS_BVIDEO || g_st==GS_EVIDEO) {
223 if (!A8_nextframe() || lastkey == KEY_ESCAPE) {
224 if (lastkey == KEY_ESCAPE) lastkey = KEY_UNKNOWN;
225 A8_close();
226 if(g_st==GS_BVIDEO) G_start();
227 else goto inter;
229 // V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
230 return;
231 }else if(g_st==GS_ENDANIM || g_st==GS_END2ANIM || g_st==GS_END3ANIM) {
232 if(!A8_nextframe()) {
233 switch(g_st) {
234 case GS_ENDANIM: g_st=GS_DARKEN;break;
235 case GS_END2ANIM: g_st=GS_END3ANIM;A8_start("KONEC");break;
236 case GS_END3ANIM: g_st=GS_ENDSCR;lastkey=0;break;
238 return;
240 // V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
241 return;
242 }else if(g_st==GS_DARKEN) {
243 g_st=GS_END2ANIM;A8_start("CREDITS");
244 return;
247 if(GM_act()) return;
251 switch(g_st) {
252 case GS_TITLE: case GS_ENDSCR:
254 return;
255 case GS_INTER:
256 #ifdef DEMO
257 if(keys[0x39] || keys[0x1C] || keys[0x9C]) {
258 set_trans(GS_TITLE);
260 #else
261 if (I_pressed(KEY_SPACE) || I_pressed(KEY_RETURN) || I_pressed(KEY_KP_ENTER)) {
262 if (!G_beg_video()) {
263 G_start();
264 } else {
265 g_st = GS_BVIDEO;
266 F_freemus();
269 #endif
270 return;
274 if(sky_type==2) {
275 if(lt_time>LT_DELAY || lt_force) {
276 if(!(rand()&31) || lt_force) {
277 lt_force=0;
278 lt_time=-LT_HITTIME;
279 lt_type=rand()%2;
280 lt_side=rand()&1;
281 lt_ypos=rand()&31;
282 Z_sound(ltnsnd[rand()&1],128);
284 }else ++lt_time;
286 ++g_time;
287 pl1.hit=0;pl1.hito=-3;
288 if(_2pl) {pl2.hit=0;pl2.hito=-3;}
289 G_code();
291 IT_act();
292 SW_act();
293 if(_2pl) {
294 if(pcnt) {PL_act(&pl1);PL_act(&pl2);}
295 else {PL_act(&pl2);PL_act(&pl1);}
296 pcnt^=1;
297 }else PL_act(&pl1);
298 MN_act();
299 if(fld_need_remap) BM_remapfld();
300 BM_clear(BM_PLR1|BM_PLR2|BM_MONSTER);
301 BM_mark(&pl1.o,BM_PLR1);
302 if(_2pl) BM_mark(&pl2.o,BM_PLR2);
303 MN_mark();
304 WP_act();
305 DOT_act();
306 SMK_act();
307 FX_act();
308 if(_2pl) {
309 PL_damage(&pl1);PL_damage(&pl2);
310 if(!(pl1.f&PLF_PNSND) && pl1.pain) PL_cry(&pl1);
311 if(!(pl2.f&PLF_PNSND) && pl2.pain) PL_cry(&pl2);
312 if((pl1.pain-=5) < 0) {pl1.pain=0;pl1.f&=(0xFFFF-PLF_PNSND);}
313 if((pl2.pain-=5) < 0) {pl2.pain=0;pl2.f&=(0xFFFF-PLF_PNSND);}
314 }else{
315 PL_damage(&pl1);
316 if(!(pl1.f&PLF_PNSND) && pl1.pain) PL_cry(&pl1);
317 if((pl1.pain-=5) < 0) {pl1.pain=0;pl1.f&=(0xFFFF-PLF_PNSND);}
319 if(g_exit==1) {
321 if(G_end_video()) {
322 F_freemus();
323 g_st=GS_EVIDEO;
324 return;
327 inter:
328 switch(g_map) {
329 case 19: g_st=GS_ENDANIM;A8_start("FINAL");break;
330 case 31: case 32: g_map=16;set_trans(GS_INTER);break;
331 default: ++g_map;set_trans(GS_INTER);break;
333 F_freemus();
334 if(g_st==GS_INTER) {
335 F_loadmus("INTERMUS");
336 }else {F_loadmus("\x8a\x8e\x8d\x85\x96\x0");if(mus_vol>0) {S_volumemusic(128);} }
337 S_startmusic(0);
338 }else if(g_exit==2) {
339 switch(g_map) {
340 case 31: g_map=32;set_trans(GS_INTER);break;
341 case 32: g_map=16;set_trans(GS_INTER);break;
342 default: g_map=31;set_trans(GS_INTER);break;
344 F_freemus();
345 F_loadmus("INTERMUS");
346 S_startmusic(0);
349 #ifdef DEMO
350 if(g_dm && g_time>10920) {set_trans(GS_INTER);}
351 #endif
354 void G_respawn_player (player_t *p) {
355 int i;
357 if(dm_pnum==2) {
358 if(p==&pl1) i=dm_pl1p^=1;
359 else i=dm_pl2p^=1;
360 p->o.x=dm_pos[i].x;p->o.y=dm_pos[i].y;p->d=dm_pos[i].d;
361 FX_tfog(dm_pos[i].x,dm_pos[i].y);Z_sound(telepsnd,128);
362 return;
364 do{i=myrand(dm_pnum);}while(i==dm_pl1p || i==dm_pl2p);
365 p->o.x=dm_pos[i].x;p->o.y=dm_pos[i].y;p->d=dm_pos[i].d;
366 if(p==&pl1) dm_pl1p=i; else dm_pl2p=i;
367 FX_tfog(dm_pos[i].x,dm_pos[i].y);Z_sound(telepsnd,128);