DEADSOFTWARE

e952a6c319a042ab3bd5d5bc39ba38296da26e4c
[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 MUS_free();
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 //MUS_start(music_time);
111 MUS_start(0);
114 void G_start (void) {
115 char s[8];
116 MUS_free();
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 //MUS_start(music_time);
135 MUS_start(0);
138 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
140 void G_init (void) {
141 int i,j;
142 char s[9];
144 logo("G_init: настройка ресурсов игры ");
145 logo_gas(5,GGAS_TOTAL);
146 telepsnd=Z_getsnd("TELEPT");
147 ltnsnd[0]=Z_getsnd("THUND1");
148 ltnsnd[1]=Z_getsnd("THUND2");
149 DOT_alloc();
150 SMK_alloc();
151 FX_alloc();
152 WP_alloc();
153 IT_alloc();
154 SW_alloc();
155 PL_alloc();
156 MN_alloc();
157 Z_initst();
158 logo_gas(GGAS_TOTAL,GGAS_TOTAL);
159 logo("\n");
160 GM_init();
161 pl1.color=0x70;
162 pl2.color=0x60;
163 g_trans=0;
166 static int G_beg_video (void) {
167 /*
168 switch(g_map) {
169 case 3: return A8_start("FALL");
170 case 4: return A8_start("KORIDOR");
171 case 5: return A8_start("SKULL");
172 case 6: return A8_start("TORCHES");
173 case 7: return A8_start("CACO");
174 case 8: return A8_start("DARTS");
175 case 9: return A8_start("FISH");
176 case 10: return A8_start("TRAP");
177 case 11: return A8_start("JAIL");
178 case 12: return A8_start("MMON1");
179 case 13: return A8_start("TOWER");
180 case 14: return A8_start("SAPOG");
181 case 15: return A8_start("SWITCH");
182 case 16: return A8_start("ACCEL");
183 case 17: return A8_start("MEAT");
184 case 18: return A8_start("LEGION");
185 case 19: return A8_start("CLOUDS");
187 */
188 return 0;
192 static int G_end_video (void) {
193 /*
194 switch(g_map) {
195 case 1: return A8_start("TRUBA");
196 case 10: return A8_start("GOTCHA");
198 */
199 return 0;
202 void G_act (void) {
203 static byte pcnt=0;
204 /*
205 if(g_trans) {
206 if(g_transt==0) {
207 V_setscr(NULL);memcpy(fx_scr1,scra,64000);
208 V_setscr(fx_scr2);
209 transdraw=1;G_draw();transdraw=0;
210 V_setscr(scrbuf);
212 FX_trans1(g_transt*2);
213 V_copytoscr(0,320,0,200);
214 if(++g_transt>32) {
215 g_trans=0;
217 return;
218 g_trans=0;
220 */ g_trans=0;
223 if(g_st==GS_BVIDEO || g_st==GS_EVIDEO) {
224 if (!A8_nextframe() || lastkey == KEY_ESCAPE) {
225 if (lastkey == KEY_ESCAPE) lastkey = KEY_UNKNOWN;
226 A8_close();
227 if(g_st==GS_BVIDEO) G_start();
228 else goto inter;
230 // V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
231 return;
232 }else if(g_st==GS_ENDANIM || g_st==GS_END2ANIM || g_st==GS_END3ANIM) {
233 if(!A8_nextframe()) {
234 switch(g_st) {
235 case GS_ENDANIM: g_st=GS_DARKEN;break;
236 case GS_END2ANIM: g_st=GS_END3ANIM;A8_start("KONEC");break;
237 case GS_END3ANIM: g_st=GS_ENDSCR;lastkey=0;break;
239 return;
241 // V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
242 return;
243 }else if(g_st==GS_DARKEN) {
244 g_st=GS_END2ANIM;A8_start("CREDITS");
245 return;
248 if(GM_act()) return;
252 switch(g_st) {
253 case GS_TITLE: case GS_ENDSCR:
255 return;
256 case GS_INTER:
257 #ifdef DEMO
258 if(keys[0x39] || keys[0x1C] || keys[0x9C]) {
259 set_trans(GS_TITLE);
261 #else
262 if (I_pressed(KEY_SPACE) || I_pressed(KEY_RETURN) || I_pressed(KEY_KP_ENTER)) {
263 if (!G_beg_video()) {
264 G_start();
265 } else {
266 g_st = GS_BVIDEO;
267 MUS_free();
270 #endif
271 return;
275 if(sky_type==2) {
276 if(lt_time>LT_DELAY || lt_force) {
277 if(!(rand()&31) || lt_force) {
278 lt_force=0;
279 lt_time=-LT_HITTIME;
280 lt_type=rand()%2;
281 lt_side=rand()&1;
282 lt_ypos=rand()&31;
283 Z_sound(ltnsnd[rand()&1],128);
285 }else ++lt_time;
287 ++g_time;
288 pl1.hit=0;pl1.hito=-3;
289 if(_2pl) {pl2.hit=0;pl2.hito=-3;}
290 G_code();
292 IT_act();
293 SW_act();
294 if(_2pl) {
295 if(pcnt) {PL_act(&pl1);PL_act(&pl2);}
296 else {PL_act(&pl2);PL_act(&pl1);}
297 pcnt^=1;
298 }else PL_act(&pl1);
299 MN_act();
300 if(fld_need_remap) BM_remapfld();
301 BM_clear(BM_PLR1|BM_PLR2|BM_MONSTER);
302 BM_mark(&pl1.o,BM_PLR1);
303 if(_2pl) BM_mark(&pl2.o,BM_PLR2);
304 MN_mark();
305 WP_act();
306 DOT_act();
307 SMK_act();
308 FX_act();
309 if(_2pl) {
310 PL_damage(&pl1);PL_damage(&pl2);
311 if(!(pl1.f&PLF_PNSND) && pl1.pain) PL_cry(&pl1);
312 if(!(pl2.f&PLF_PNSND) && pl2.pain) PL_cry(&pl2);
313 if((pl1.pain-=5) < 0) {pl1.pain=0;pl1.f&=(0xFFFF-PLF_PNSND);}
314 if((pl2.pain-=5) < 0) {pl2.pain=0;pl2.f&=(0xFFFF-PLF_PNSND);}
315 }else{
316 PL_damage(&pl1);
317 if(!(pl1.f&PLF_PNSND) && pl1.pain) PL_cry(&pl1);
318 if((pl1.pain-=5) < 0) {pl1.pain=0;pl1.f&=(0xFFFF-PLF_PNSND);}
320 if(g_exit==1) {
322 if(G_end_video()) {
323 MUS_free();
324 g_st=GS_EVIDEO;
325 return;
328 inter:
329 switch(g_map) {
330 case 19: g_st=GS_ENDANIM;A8_start("FINAL");break;
331 case 31: case 32: g_map=16;set_trans(GS_INTER);break;
332 default: ++g_map;set_trans(GS_INTER);break;
334 MUS_free();
335 if (g_st == GS_INTER) {
336 MUS_load("INTERMUS");
337 } else {
338 MUS_load("\x8a\x8e\x8d\x85\x96\x0");
339 MUS_volume(128);
341 MUS_start(0);
342 }else if(g_exit==2) {
343 switch(g_map) {
344 case 31: g_map=32;set_trans(GS_INTER);break;
345 case 32: g_map=16;set_trans(GS_INTER);break;
346 default: g_map=31;set_trans(GS_INTER);break;
348 MUS_free();
349 MUS_load("INTERMUS");
350 MUS_start(0);
353 #ifdef DEMO
354 if(g_dm && g_time>10920) {set_trans(GS_INTER);}
355 #endif
358 void G_respawn_player (player_t *p) {
359 int i;
361 if(dm_pnum==2) {
362 if(p==&pl1) i=dm_pl1p^=1;
363 else i=dm_pl2p^=1;
364 p->o.x=dm_pos[i].x;p->o.y=dm_pos[i].y;p->d=dm_pos[i].d;
365 FX_tfog(dm_pos[i].x,dm_pos[i].y);Z_sound(telepsnd,128);
366 return;
368 do{i=myrand(dm_pnum);}while(i==dm_pl1p || i==dm_pl2p);
369 p->o.x=dm_pos[i].x;p->o.y=dm_pos[i].y;p->d=dm_pos[i].d;
370 if(p==&pl1) dm_pl1p=i; else dm_pl2p=i;
371 FX_tfog(dm_pos[i].x,dm_pos[i].y);Z_sound(telepsnd,128);