⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 load_chp.cpp

📁 轩辕2源代码.rar
💻 CPP
字号:
#include "ls.h"

static int   jump_line[1024],jump_new=0;
static char  jump_str[1024][32];
static char  goto_label[1024][32];
static int   goto_source[1024],goto_new=0;
static int   ip_save[65536],ip_record;
static int   chap_check=0;
static char  chap_check_name[100]="";
static Tline cline;
///////////////////////////////////////////////////////////////////////////
int TWORLD::compile_regist_label(char *name)
{ if (jump_new>=1024) return -1;
  strcpy(jump_str[jump_new],name);
  jump_line[jump_new]=ip;
  jump_new++;
  return 0;
}
int TWORLD::compile_find_label(char *name)
{ int i,find=-1;
  for (i=0,find=-1;i<jump_new&&find<0;i++)
    if (strcmp(name,jump_str[i])==0) find=i;
  return find;
}
int TWORLD::compile_regist_goto(char *name,int source)
{ if (goto_new>=1024) return -1;
  strcpy(goto_label[goto_new],name);
  goto_source[goto_new]=source;
  goto_new++;
  return 0;
}
int TWORLD::compile_translate_data(int start,int *data)
{ int l=0;
  if (cline.Word[start][0]>='0'&&cline.Word[start][0]<='9')
   { data[0]=1; data[1]=atoi(cline.Word[start]);
     data[2]=0; l=1;
   } else if (cline.Word[start][0]=='D') {
     data[0]=0; data[1]=atoi(cline.Word[start+2]);
     data[2]=atoi(cline.Word[start+5]); l=7;
   }
  return l;
}
///////////////////////////////////////////////////////////////////////////
int TWORLD::NEW_CHAPTER(int c,int clear)
{ int i,j,k,l;
  int error,done;
  int Data[100];
  char fname[100];
  static char null[20]="";
  static char word[1024];
  static char temp[20];

  for (i=0;i<1024;i++) {
    jump_line[i]=-1;
    goto_source[i]=-1;
    jump_str[i][0]=0;
    goto_label[i][0]=0;
  }
  dialog_clear();
  jump_new=0; ip=0;
  goto_new=0;
  ip_record=1;
  CHAPTER_DELAY=0;
  LGAME.chapter=-1;
  for (i=0;i<0x10000;i++) chapter[i]=0,ip_save[i]=0;
  if (clear) for (i=0;i<1000;i++) {
    data[1][i]=0;
    data[2][i]=0;
  }
  game_getfname(NAME_CHAPTER,c,fname);
  if (!cline.OpenFile(fname)) {
     voc.regist_msg("Error open chapter file: %s",fname);
     return -1;
  }
  for (done=0,error=0,i=-1;done==0&&error==0;)
   {  if (cline.GetLine(1))
       { if (strcmp(cline.Word[0],"CHAPTER")==0) i=atoi(cline.Word[1]);
            else i=-1;
       } else error=1;
      if (i==c) done=1;
   }
  if (error)
   { sprintf(msg,"can not find chapter %d error code=%d",c,error);
     voc.regist_msg("%s",msg);
     cline.CloseFile();
     return -2;
   }
  for (error=0,done=0,ip=0;done==0&&error==0&&ip<0x10000;)
   {  for (i=0;i<20;i++) cline.Word[i]=null;
      if (!cline.GetLine(1)) error=-3;
       else {
         if (strcmp(cline.Word[1],":")==0&&cline.WordCount>=2) {
            if (cline.WordCount==2) compile_regist_label(cline.Word[0]);
               else error=5;
            if (error) {
               voc.regist_msg("ERROR \"%s %s\",word count=%d\n",cline.Word[0],cline.Word[1],cline.WordCount);
            }
         } else if (strcmp(cline.Word[0],"GOTO")==0) {
            if (cline.WordCount==2) {
                compile_regist_goto(cline.Word[1],ip+1);
                chapter[ip]='J'; chapter[ip+1]=0;
                ip+=2;
            } else error=2;
         } else if (strcmp(cline.Word[0],"CALLBACK")==0) {
            i=1; if (cline.WordCount>1) i=atoi(cline.Word[1]);
            if (i>1) chapter[ip++]='X',chapter[ip++]=i;
              else chapter[ip++]='R';
         } else if (strcmp(cline.Word[0],"REDRAW")==0) {
            chapter[ip++]='X'; chapter[ip++]=2;
         } else if (strcmp(cline.Word[0],"LOADMAP")==0) {
            if (cline.WordCount==2) {
                chapter[ip]='M'; chapter[ip+1]=atoi(cline.Word[1]);
                ip+=2;
            } else error=3;
         } else if (strcmp(cline.Word[0],"CREATEACTOR")==0) {
            if (cline.WordCount==8) {
                chapter[ip]='C';
                chapter[ip+1]=atoi(cline.Word[1]);
                chapter[ip+2]=atoi(cline.Word[4]);
                chapter[ip+3]=atoi(cline.Word[6]);
                ip+=4;
            } else error=4;
         } else if (strcmp(cline.Word[0],"ACTOREVENT")==0) {
            for (i=0,j=3;i<3;i++) {
              if (strcmp(cline.Word[j],"-")==0) {
                 Data[i]=(-1)*atoi(cline.Word[j+1]);
                 j+=3;
              } else {
                 Data[i]=atoi(cline.Word[j]);
                 j+=2;
              }
            }
            chapter[ip]='E';
            chapter[ip+1]=atoi(cline.Word[1]);
            chapter[ip+2]=Data[0];
            chapter[ip+3]=Data[1];
            chapter[ip+4]=Data[2];
            ip+=5;
         } else if (strcmp(cline.Word[0],"ACTORMOVE")==0) {
            for (l=0,j=4,i=0;l!=1;i++) {
              chapter[ip+3+i]=atoi(cline.Word[j]);
              if (cline.Word[j+1][0]==')') l=1;
                else j+=2;
            }
            chapter[ip]='A';
            chapter[ip+1]=atoi(cline.Word[1]);
            chapter[ip+2]=i;
            ip+=(3+i);
         } else if (strcmp(cline.Word[0],"MAPEVENT")==0) {
            chapter[ip]='V';
            chapter[ip+1]=atoi(cline.Word[2]);
            chapter[ip+2]=atoi(cline.Word[4]);
            chapter[ip+3]=atoi(cline.Word[8]);
            chapter[ip+4]=atoi(cline.Word[10]);
            chapter[ip+5]=atoi(cline.Word[13]);
            chapter[ip+6]=atoi(cline.Word[15]);
            ip+=7;
         } else if (strcmp(cline.Word[0],"IF")==0) { // IF PROCESS
///////////////////////////////////////////////////////////////////////
            i=1; i+=compile_translate_data(i,&Data[0]);
            switch (cline.Word[i][0])
             { case '=': k=0; break;
               case '>': k=1; break;
               case '<': k=2; break;
               default : k=5; break;
             } i++;
            if (cline.Word[i+1][0]=='='&&(k==1||k==2)) k+=2, i++;
            j=compile_translate_data(i,&Data[3]); i+=j;
            chapter[ip]='I';
            for (i=0;i<3;i++) {
                chapter[ip+1+i]=Data[i];
                chapter[ip+5+i]=Data[3+i];
            }
            chapter[ip+4]=k;
            compile_regist_goto(cline.Word[cline.WordCount-1],ip+8);
            ip+=9;
///////////////////////////////////////////////////////////////////////
         } else if (strcmp(cline.Word[0],"SET")==0) {
            i=1; i+=compile_translate_data(i,&Data[0]);
            k=cline.Word[i][0]; i++;
            j=compile_translate_data(i,&Data[3]);
            chapter[ip]='L';
            for (i=0;i<3;i++) {
              chapter[ip+1+i]=Data[i];
              chapter[ip+4+i]=Data[3+i];
            }
            chapter[ip+7]=k;
            ip+=8;
         } else if (strcmp(cline.Word[0],"SAY")==0) {
            chapter[ip]='S';
            chapter[ip+1]=atoi(cline.Word[1]);
            chapter[ip+2]=atoi(cline.Word[3]);
            cline.GetString(word,5);
            i=dialog_put(word);
            chapter[ip+3]=i;
            ip+=4;
         } else if (strcmp(cline.Word[0],"DELACTOR")==0) {
            chapter[ip]='D';
            chapter[ip+1]=atoi(cline.Word[1]);
            ip+=2;
         } else if (strcmp(cline.Word[0],"STARTCHAPTER")==0) {
            chapter[ip]='N';
            chapter[ip+1]=atoi(cline.Word[1]);
            ip+=2;
         } else if (strcmp(cline.Word[0],"GAMEOVER")==0) {
            chapter[ip]='G';
            ip++;
         } else if (strcmp(cline.Word[0],"ERROR")==0) {
            chapter[ip]='W';
            cline.GetString(word,1);
            i=dialog_put(word);
            chapter[ip+1]=i;
            ip+=2;
         } else if (strcmp(cline.Word[0],"MUSIC")==0) {
            chapter[ip]='U';
            chapter[ip+1]=atoi(cline.Word[1]);
            ip+=2;
         } else if (strcmp(cline.Word[0],"SOUND")==0) {
            chapter[ip]='U';
            chapter[ip+1]=-1-atoi(cline.Word[1]);
            ip+=2;
         } else if (strcmp(cline.Word[0],"SCREEN")==0) {
            chapter[ip]='P';
            if (cline.WordCount==4) {
              chapter[ip+1]=0;
              if (strcmp(cline.Word[1],"AUTO")==0) chapter[ip+2]=-1;
                 else chapter[ip+2]=atoi(cline.Word[1]);
              chapter[ip+3]=atoi(cline.Word[3]);
              ip+=4;
            } else if (cline.WordCount==2) {
              chapter[ip+1]=1;
              chapter[ip+2]=atoi(cline.Word[1]);
              ip+=3;
            } else error=9;
         } else if (strcmp(cline.Word[0],"ACTORSPEED")==0) {
            chapter[ip]='B';
            chapter[ip+1]=atoi(cline.Word[1]);
            chapter[ip+2]=atoi(cline.Word[3]);
            ip+=3;
         } else if (strcmp(cline.Word[0],"MOVE")==0) {
            chapter[ip]='T';
            chapter[ip+1]=atoi(cline.Word[1]);
            chapter[ip+2]=atoi(cline.Word[4]);
            chapter[ip+3]=atoi(cline.Word[6]);
            ip+=4;
         } else if (strcmp(cline.Word[0],"EVENT")==0) {
            if (cline.WordCount==5) {
              chapter[ip]='Z';
              compile_regist_goto(cline.Word[4],ip+2);
              chapter[ip+1]=atoi(cline.Word[1]);
              chapter[ip+2]=0;
              ip+=3;
            } else error=6;
         } else if (strcmp(cline.Word[0],"GET")==0) {
            if (cline.WordCount==4) {
              chapter[ip]='F';
              chapter[ip+1]=atoi(cline.Word[1]);
              chapter[ip+2]=atoi(cline.Word[3]);
              ip+=3;
            } else error=7;
         } else if (strcmp(cline.Word[0],"MONEY")==0) {
            chapter[ip]='H';
            if (cline.WordCount==3&&cline.Word[1][0]=='-')
             { chapter[ip+1]=-atoi(cline.Word[2]);
             } else if (cline.WordCount==2) chapter[ip+1]=atoi(cline.Word[1]);
            else error=8;
            ip+=2;
         } else if (strcmp(cline.Word[0],"BUY")==0) {
             for (l=0,j=4,i=0;l!=1;i++) {
              chapter[ip+3+i]=atoi(cline.Word[j]);
              if (cline.Word[j+1][0]==')') l=1;
                else j+=2;
            }
            chapter[ip]='K';
            chapter[ip+1]=atoi(cline.Word[1]);
            chapter[ip+2]=i+1;
            chapter[ip+3+i]=-1;
            ip+=38+chapter[ip+2];
         } else if (strcmp(cline.Word[0],"SYSTEM")==0) {
            for (l=0,j=2,i=0;l!=1;i++) {
              chapter[ip+2+i]=atoi(cline.Word[j]);
              if (cline.Word[j+1][0]==')') l=1;
                else j+=2;
            }
            chapter[ip]='Y';
            chapter[ip+1]=i;
            ip+=2+i;
         } else if (strcmp(cline.Word[0],"FIGHT")==0) {
            chapter[ip]='O';
            chapter[ip+1]=atoi(cline.Word[1]);
            chapter[ip+2]='R';
            ip+=3;
         } else if (strcmp(cline.Word[0],"END")==0) {
            done=1;
         } else {
            sprintf(msg,"unknow command '%s'",cline.Word[0]);
            voc.regist_msg("%s",msg);
            error=100;
         }
      }
      ip_save[ip_record++]=ip;
   }
  cline.CloseFile();
  ip=0;
  if (error) voc.regist_msg("load chapter error %d\n",error);
  if (error) return error;
  for (i=0;i<goto_new&&error==0;i++) {
      j=compile_find_label(goto_label[i]);
      if (j<0) {
         voc.regist_msg("can not find label \"%s\" at ip=%d",goto_label[i],goto_source[i]);
         error=2;
      }
      else chapter[goto_source[i]]=jump_line[j];
  }
  if (chap_check) voc.regist_msg("load chapter file %s",fname);
  if (error==0) LGAME.chapter=c;
  return 0;
}
int game_getfname(int type,int index,char *name)
{ int i,j;
  char temp[200];
  name[0]=0;
  if (type<0||type>20) return -1;
  switch (type)
   { case NAME_MIDI: temp[0]='0'+index/10; index-=(index/10)*10;
                     temp[1]='0'+index;
                     temp[2]=0;
                     sprintf(name,"voc\\ls-%s.mid",temp);
                     break;
     case NAME_WAVE: temp[0]='0'+index/10; index-=(index/10)*10;
                     temp[1]='0'+index;
                     temp[2]=0;
                     sprintf(name,"voc\\ls-%s.voc",temp);
                     break;
     case NAME_FLOOR:strcpy(name,"pic\\map.pcx");
                     break;
     case NAME_MAPPIC:strcpy(name,"pic\\map.lpc");
                     break;
     case NAME_BACKPIC: sprintf(name,"pic\\back%d.gif",index);
                     break;
     case NAME_MAP:  temp[0]='0'+index/100; index-=(index/100)*100;
                     temp[1]='0'+index/10;  index-=(index/10)*10;
                     temp[2]='0'+index;     temp[3]=0;
                     sprintf(name,"data\\map-%s.ibt",temp);
                     break;
     case NAME_CHAPTER: sprintf(name,"ixt\\chap000.ixt");
                     if (chap_check) strcpy(name,chap_check_name);
                     break;
     case NAME_ACTOR:sprintf(name,"ixt\\actor0.ixt");
                     break;
     case NAME_SAVE: sprintf(name,"save\\rpg.%d",index+1);
                     break;
     case NAME_FONT: sprintf(name,"data\\hzk16.");
                     break;
     case NAME_ACTORPIC:
                     sprintf(name,"pic\\actorm%d.gif",index);
                     break;
     case NAME_SYSTEM:sprintf(name,"pic\\system.lpc");
                     break;
     case NAME_GOODS: sprintf(name,"ixt\\goods.ixt");
                     break;
     case NAME_TITLE: sprintf(name,"pic\\title%d.gif",index);
                     break;
     default:        voc.regist_msg("UNKNOW FILE TYPE");
                     break;
   }
  return 0;
}
int game_key(int key)
{ int k=0;
  switch (key)
   { case 0: if (lKeyOn(KEY_ENTER)||lKeyOn(KEY_SPACE)||lKeyOn(KEY_CTRL)) k=1; break;
     case 1: if (lKeyOn(KEY_ESC)||lKeyOn(KEY_ALT)) k=1; break;
   }
  return k;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -