DEADSOFTWARE

map: move map loading to separate file
[flatwaifu.git] / src / game.c
index 194365ecc3a739663131a9eedb7c5f5b87a8705c..85108333d617a5508dba067bebb48510e2ad34a5 100644 (file)
@@ -26,9 +26,6 @@
 #include <string.h>
 #include "files.h"
 #include "memory.h"
-#include "vga.h"
-#include "error.h"
-#include "keyb.h"
 #include "sound.h"
 #include "view.h"
 #include "bmap.h"
 #include "menu.h"
 #include "misc.h"
 #include "map.h"
+#include "my.h"
+#include "game.h"
+#include "config.h"
+#include "music.h"
+#include "a8.h"
+#include "error.h"
+#include "input.h"
 
-#include <SDL_keysym.h>
+#include "save.h"
 
 #define LT_DELAY 8
 #define LT_HITTIME 6
 
 #define GETIME 1092
 
-
-int A8_start(char*);
-int A8_nextframe(void);
-void A8_close(void);
-
-
-void FX_trans1(int t);
-extern unsigned char fx_scr1[64000],fx_scr2[64000];
-
-extern short lastkey;
-
-
-extern int hit_xv,hit_yv;
-
-extern vgapal std_pal;
-void setgamma(int);
-
-extern int sw_secrets;
-
-#define PL_FLASH 90
-
-extern int PL_JUMP;
-
-extern map_block_t blk;
-
-extern byte clrmap[256*12];
-
-extern byte cheat;
-
-byte _2pl=0,g_dm=0,g_st=GS_TITLE,g_exit=0,g_map=1,_warp=0,g_music[8]="MENU";
-byte _net=0;
-int g_sttm=1092;
+byte transdraw;
+byte _2pl;
+byte g_dm;
+byte g_st = GS_TITLE;
+byte g_exit;
+byte g_map = 1;
+char g_music[8] = "MENU";
 dword g_time;
-int dm_pnum,dm_pl1p,dm_pl2p;
+int dm_pnum;
+int dm_pl1p;
+int dm_pl2p;
 pos_t dm_pos[100];
+byte cheat;
 
 static void *telepsnd;
-static void *scrnh[3];
-void *cd_scr;
 
-extern int sky_type;
-void *ltn[2][2];
-int lt_time,lt_type,lt_side,lt_ypos,lt_force;
-void *ltnsnd[2];
+int lt_time;
+int lt_type;
+int lt_side;
+int lt_ypos;
+static int lt_force;
+static void *ltnsnd[2];
 
-int g_trans=0,g_transt;
+int g_trans;
+static int g_transt;
 
 static void set_trans(int st) {
   switch(g_st) {
@@ -112,42 +95,11 @@ static void set_trans(int st) {
   g_trans=1;g_transt=0;
 }
 
-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);
-}
-
-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);
-}
-
-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);
-         return 1;
-  }return 0;
-}
-
-void load_game(int n) {
+void load_game (int n) {
   F_freemus();
   W_init();
   F_loadgame(n);
   set_trans(GS_GAME);
-  V_setscr((g_trans)?fx_scr2:scrbuf);V_setrect(0,SCRW,0,SCRH);//V_setrect(0,320,0,200);
-  V_clr(0,SCRW,0,SCRH,0);//V_clr(0,320,0,200,0);
-  if(_2pl) {w_o=0;Z_clrst();w_o=SCRH/2;Z_clrst();}//if(_2pl) {w_o=0;Z_clrst();w_o=100;Z_clrst();}
-  else {w_o=0;Z_clrst();}//else {w_o=50;Z_clrst();}
-  V_setscr(scrbuf);
   pl1.drawst=0xFF;
   if(_2pl) pl2.drawst=0xFF;
   BM_remapfld();
@@ -158,18 +110,13 @@ void load_game(int n) {
   S_startmusic(music_time);
 }
 
-void G_start(void) {
+void G_start (void) {
   char s[8];
 
   F_freemus();
   sprintf(s,"MAP%02u",(word)g_map);
   F_loadmap(s);
   set_trans(GS_GAME);
-  V_setscr((g_trans)?fx_scr2:scrbuf);V_setrect(0,SCRW,0,SCRH);//V_setrect(0,320,0,200);
-  V_clr(0,SCRW,0,SCRH,0);//V_clr(0,320,0,200,0);
-  if(_2pl) {w_o=0;Z_clrst();w_o=SCRH/2;Z_clrst();}//if(_2pl) {w_o=0;Z_clrst();w_o=100;Z_clrst();}
-  else {w_o=0;Z_clrst();}//else {w_o=50;Z_clrst();}
-  V_setscr(scrbuf);
   pl1.drawst=0xFF;
   if(_2pl) pl2.drawst=0xFF;
   g_exit=0;
@@ -189,22 +136,13 @@ void G_start(void) {
 
 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
 
-void G_init(void) {
+void G_init (void) {
   int i,j;
   char s[9];
 
   logo("G_init: настройка ресурсов игры ");
   logo_gas(5,GGAS_TOTAL);
   telepsnd=Z_getsnd("TELEPT");
-  scrnh[0]=M_lock(F_getresid("TITLEPIC"));
-  scrnh[1]=M_lock(F_getresid("INTERPIC"));
-  scrnh[2]=M_lock(F_getresid("ENDPIC"));
-  cd_scr=M_lock(F_getresid("CD1PIC"));
-  for(i=0;i<2;++i) {
-    sprintf(s,"LTN%c",i+'1');
-    for(j=0;j<2;++j)
-      ltn[i][j]=Z_getspr(s,j,0,NULL);
-  }
   ltnsnd[0]=Z_getsnd("THUND1");
   ltnsnd[1]=Z_getsnd("THUND2");
   DOT_alloc();
@@ -224,7 +162,7 @@ void G_init(void) {
   g_trans=0;
 }
 
-int G_beg_video(void) {
+static int G_beg_video (void) {
 /*
   switch(g_map) {
     case 3: return A8_start("FALL");
@@ -250,7 +188,7 @@ int G_beg_video(void) {
 }
 
 
-int G_end_video(void) {
+static int G_end_video (void) {
 /*
   switch(g_map) {
     case 1: return A8_start("TRUBA");
@@ -260,10 +198,7 @@ int G_end_video(void) {
   return 0;
 }
 
-
-static byte transdraw=0;
-
-void G_act(void) {
+void G_act (void) {
   static byte pcnt=0;
 /*
   if(g_trans) {
@@ -285,13 +220,13 @@ void G_act(void) {
 
   
   if(g_st==GS_BVIDEO || g_st==GS_EVIDEO) {
-    if(!A8_nextframe() || lastkey==SDLK_ESCAPE) {
-      if(lastkey==SDLK_ESCAPE) lastkey=0;
+    if (!A8_nextframe() || lastkey == KEY_ESCAPE) {
+      if (lastkey == KEY_ESCAPE) lastkey = KEY_UNKNOWN;
       A8_close();
       if(g_st==GS_BVIDEO) G_start();
       else goto inter;
     }
-    V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
+//    V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
     return;
   }else if(g_st==GS_ENDANIM || g_st==GS_END2ANIM || g_st==GS_END3ANIM) {
     if(!A8_nextframe()) {
@@ -299,9 +234,10 @@ void G_act(void) {
         case GS_ENDANIM: g_st=GS_DARKEN;break;
         case GS_END2ANIM: g_st=GS_END3ANIM;A8_start("KONEC");break;
         case GS_END3ANIM: g_st=GS_ENDSCR;lastkey=0;break;
-      }g_sttm=0;return;
+      }
+      return;
     }
-    V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
+//    V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
     return;
   }else if(g_st==GS_DARKEN) {
       g_st=GS_END2ANIM;A8_start("CREDITS");
@@ -322,10 +258,14 @@ void G_act(void) {
            set_trans(GS_TITLE);
          }
 #else
-          if(keys[SDLK_SPACE] || keys[SDLK_RETURN] || keys[SDLK_KP_ENTER])//if(keys[0x39] || keys[0x1C] || keys[0x9C])
-           if(!G_beg_video()) G_start(); else {
-             g_st=GS_BVIDEO;F_freemus();
+    if (I_pressed(KEY_SPACE) || I_pressed(KEY_RETURN) || I_pressed(KEY_KP_ENTER)) {
+           if (!G_beg_video()) {
+        G_start();
+      } else {
+             g_st = GS_BVIDEO;
+        F_freemus();
            }
+    }
 #endif
          return;
   }
@@ -348,7 +288,6 @@ void G_act(void) {
   if(_2pl) {pl2.hit=0;pl2.hito=-3;}
   G_code();
 
-  W_act();
   IT_act();
   SW_act();
   if(_2pl) {
@@ -412,125 +351,7 @@ inter:
 #endif
 }
 
-/*
-static void drawview(player_t *p) {
-  if(p->looky<-50) p->looky=-50;
-  else if(p->looky>50) p->looky=50;
-  w_x=p->o.x;w_y=p->o.y-12+p->looky;W_draw();PL_drawst(p);
-}
-*/
-static void drawview(player_t *p) {
-  if(p->looky<-SCRH/4) p->looky=-SCRH/4;
-  else if(p->looky>SCRH/4) p->looky=SCRH/4;
-  w_x=p->o.x;w_y=p->o.y-12+p->looky;
-  W_draw();
-  PL_drawst(p);
-}
-
-static int get_pu_st(int t) {
-  if(t>=PL_FLASH) return 1;
-  if((t/9)&1) return 0;
-  return 1;
-}
-
-static void pl_info(player_t *p,int y) {
-  dword t;
-
-  t=p->kills*10920/g_time;
-  Z_gotoxy(25,y);Z_printbf("KILLS");//Z_gotoxy(25,y);Z_printbf("KILLS");
-  Z_gotoxy(25,y+15);Z_printbf("KPM");//Z_gotoxy(25,y+15);Z_printbf("KPM");
-  Z_gotoxy(25,y+30);Z_printbf("SECRETS %u / %u",p->secrets,sw_secrets);//Z_gotoxy(25,y+30);Z_printbf("SECRETS %u / %u",p->secrets,sw_secrets);
-  Z_gotoxy(255,y);Z_printbf("%u",p->kills);//Z_gotoxy(255,y);Z_printbf("%u",p->kills);
-  Z_gotoxy(255,y+15);Z_printbf("%u.%u",t/10,t%10);//Z_gotoxy(255,y+15);Z_printbf("%u.%u",t/10,t%10);
-}
-
-void G_draw(void) {
-  int h;
-  word hr,mn,sc;
-  if(g_trans && !transdraw) return;
-  switch(g_st) {
-    case GS_ENDANIM: case GS_END2ANIM: case GS_DARKEN:
-    case GS_BVIDEO: case GS_EVIDEO: case GS_END3ANIM:
-      return;
-    case GS_TITLE:
-      V_center(1);//
-      V_pic(0,0,scrnh[0]);
-      V_center(0);//
-      break;
-    case GS_ENDSCR:
-      V_center(1);//
-      V_clr(0,SCRW,0,SCRH,0);V_pic(0,0,scrnh[2]);//V_clr(0,320,0,200,0);V_pic(0,0,scrnh[2]);
-      V_center(0);//
-      break;
-    case GS_INTER:
-        V_center(1);//
-        V_clr(0,SCRW,0,SCRH,0);//
-         V_pic(0,0,scrnh[1]);
-         Z_gotoxy(60,20);Z_printbf("LEVEL COMPLETE");
-         Z_calc_time(g_time,&hr,&mn,&sc);
-         Z_gotoxy(115,40);Z_printbf("TIME %u:%02u:%02u",hr,mn,sc);
-         h=60;
-         if(_2pl) {
-               Z_gotoxy(80,h);Z_printbf("PLAYER ONE");
-               Z_gotoxy(80,h+70);Z_printbf("PLAYER TWO");
-               h+=SCRH/10;//h+=20;
-         }
-         pl_info(&pl1,h);
-         if(_2pl) pl_info(&pl2,h+70);
-          V_center(0);//
-         break;
-  }
-  V_center(1);//
-  if(g_st!=GS_GAME) {
-    if(g_trans) return;
-    GM_draw();
-    V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
-    return;
-  }
-  V_center(0);//
-  
-  if(_2pl) {
-       w_o=0;WD=SCRW-120;HT=SCRH/2-2;drawview(&pl1);//w_o=0;drawview(&pl1);
-       w_o=SCRH/2;WD=SCRW-120;HT=SCRH/2-2;drawview(&pl2);//w_o=100;drawview(&pl2);
-  }else{
-       w_o=0;WD=SCRW-120;HT=SCRH-2;drawview(&pl1);//w_o=50;drawview(&pl1);
-  }
-  if(g_trans) return;
-  V_center(1);//
-  if(GM_draw()) {
-    pl1.drawst=pl2.drawst=0xFF;//pl1.drawst=pl2.drawst=0;
-    V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
-    return;
-  }
-  V_center(0);//
-  if(pl1.invl) h=get_pu_st(pl1.invl)*6;
-  else if(pl1.pain<15) h=0;
-  else if(pl1.pain<35) h=1;
-  else if(pl1.pain<55) h=2;
-  else if(pl1.pain<75) h=3;
-  else if(pl1.pain<95) h=4;
-  else h=5;
-  if(h) V_maptoscr(0,SCRW-120,1,(_2pl)?(SCRH/2-2):(SCRH-2),clrmap+h*256);//if(h) V_maptoscr(0,200,(_2pl)?1:51,98,clrmap+h*256);
-  else V_copytoscr(0,SCRW-120,1,(_2pl)?(SCRH/2-2):(SCRH-2)); //else V_copytoscr(0,200,(_2pl)?1:51,98);
-  if(pl1.drawst) V_copytoscr(SCRW-120,120,0,_2pl?(SCRH/2):SCRH);//if(pl1.drawst) V_copytoscr(200,120,(_2pl)?0:50,100);
-  pl1.drawst=0xFF;//pl1.drawst=0;
-  if(_2pl) {
-    if(pl2.invl) h=get_pu_st(pl2.invl)*6;
-    else if(pl2.pain<15) h=0;
-    else if(pl2.pain<35) h=1;
-    else if(pl2.pain<55) h=2;
-    else if(pl2.pain<75) h=3;
-    else if(pl2.pain<95) h=4;
-    else h=5;
-    if(h) V_maptoscr(0,SCRW-120,SCRH/2+1,SCRH/2-2,clrmap+h*256);//if(h) V_maptoscr(0,200,101,98,clrmap+h*256);
-    else V_copytoscr(0,SCRW-120,SCRH/2+1,SCRH/2-2);//else V_copytoscr(0,200,101,98);
-    if(pl2.drawst) V_copytoscr(SCRW-120,120,SCRH/2,SCRH/2);//if(pl2.drawst) V_copytoscr(200,120,100,100);
-    pl2.drawst=0xFF;//pl2.drawst=0;
-  }
-}
-
-void G_respawn_player(player_t *p) {
+void G_respawn_player (player_t *p) {
   int i;
 
   if(dm_pnum==2) {