📄 script.c
字号:
/******************************************/
/* script.c */
/* */
/* 水晶之约中的脚本解释机 */
/* */
/* 编译环境DJGPP */
/* */
/* 编译需allegro V4.1.13支持 */
/* */
/* Cat Tom 12.5.2003 */
/******************************************/
/******************************************************************/
/*加载脚本*/
void Load_Script(char *fname)
{
FILE *fp;
char temp;
int script_ctr=0,i=0; /*字符循环的计数器*/
int label_ctr=0; /*跳转数组赋值的计数器*/
if(RPG_Script.script_flag!=SCRIPT_SHUT)return; /*假如脚本还在运行中则返回*/
fp=fopen(fname,"r");
strcpy(RPG_Script.filename,fname);
while(1)
{
temp = getc(fp);
if(feof(fp))break;
if(temp=='@') /*假如遇到@为标号行*/
{
i=0;
do{
RPG_Script.label_sign[label_ctr][i]=getc(fp);
if(RPG_Script.label_sign[label_ctr][i]=='\n'||feof(fp))
{
RPG_Script.label_sign[label_ctr][i]='\0';
break;
}
i++;
}while(1);
RPG_Script.label_offset[label_ctr]=script_ctr+1;
label_ctr++;
}
else if(temp=='#') /*假如遇到#为注释行*/
while(!feof(fp)&&getc(fp)!='\n');
else if(temp=='\n')continue;/*假如遇到回车则忽略*/
else if(temp==' ')continue; /*假如遇到空格忽略*/
else if(temp==';')continue; /*忽略分号*/
else /*否则做命令读入*/
{
RPG_Script.command[script_ctr]=temp;
script_ctr++;
}
}
RPG_Script.command[script_ctr] = '\0';
RPG_Script.size=script_ctr;
fclose (fp);
RPG_Script.cmd_offset=0; /*脚本读取复位*/
RPG_Script.script_flag=SCRIPT_WAIT; /*脚本标志设为等待*/
}
/******************************************************************/
/*整数乘方*/
int Pow_Int(int a,int b)
{
int temp=1,i;
for(i=0;i<b;i++)
{
temp*=a;
}
return temp;
}
/*读入字符串*/
void Read_Str(char *str)
{
int i;
char temp;
RPG_Script.cmd_offset++; /*跳过第一个引号*/
i=0;
while(1)
{
temp=RPG_Script.command[RPG_Script.cmd_offset];
if(temp=='\"')break;
else str[i]=temp,i++,RPG_Script.cmd_offset++;
}
str[i]='\0';
RPG_Script.cmd_offset++; /*跳过第二个引号*/
RPG_Script.cmd_offset++; /*跳过括号或逗号*/
}
/*读入整数,如果发现$则返回该地址变量的值*/
int Read_Num()
{
int i=0,j;
int num[6],answer=0;
char temp;
if(RPG_Script.command[RPG_Script.cmd_offset]=='-')
{
RPG_Script.cmd_offset++;
return -Read_Num();
}
else if(RPG_Script.command[RPG_Script.cmd_offset]=='$')
{
RPG_Script.cmd_offset++;
return RPG_Script.temp[Read_Num()];
}
else
{
while(1)
{
temp=RPG_Script.command[RPG_Script.cmd_offset];
if(temp==','||temp==')')break;
else
{
num[i]=temp-48;
i++;
RPG_Script.cmd_offset++;
}
}
RPG_Script.cmd_offset++; /*跳过括号或逗号*/
for(j=0;j<i;j++)
answer+=(num[j]*Pow_Int(10,i-j-1));
return answer;
}
}
/******************************************************************/
void scr_talk()
{
char str[200],temp;
if(RPG_Script.script_flag==SCRIPT_HANG)
{
printf("talk:This command cannot run in hanged mode.");
return;
}
temp=Read_Num();
Read_Str(str);
/*printf("%d,",temp);
puts(str); */
/*启动对话模块*/
TalkBox.photo_num=temp;
strcpy(TalkBox.string,str);
TalkBox.talk_flag=TALK_YES;
RPG_Script.script_flag=SCRIPT_BUSY; /*启动一条语句后,将标志设为语句执行中。由语句的执行函数来恢复等待*/
}
void scr_delay()
{
int temp;
if(RPG_Script.script_flag==SCRIPT_HANG)
{
printf("delay:This command cannot run in hanged mode.");
return;
}
temp=Read_Num();
DelayData.delay_time=temp;
DelayData.delay_flag=DELAY_YES;
RPG_Script.script_flag=SCRIPT_BUSY; /*启动一条语句后,将标志设为语句执行中。由语句的执行函数来恢复等待*/
}
void scr_add()
{
int temp1,temp2,temp3;
temp1=Read_Num();
temp2=Read_Num();
temp3=Read_Num();
if(temp3==0)RPG_Script.temp[temp1]-=temp2;
else RPG_Script.temp[temp1]+=temp2;
}
void scr_if()
{
int temp1,temp2,i;
char str[32];
temp1=Read_Num();
temp2=Read_Num();
Read_Str(str);
if(RPG_Script.temp[temp1]==temp2)
{
for(i=0;i<32;i++)
if(!strcmp(str,RPG_Script.label_sign[i]))
{
RPG_Script.cmd_offset=RPG_Script.label_offset[i]-1;
break;
}
}
}
void scr_goto()
{
char str[32];
int i;
Read_Str(str);
for(i=0;i<32;i++)
if(!strcmp(str,RPG_Script.label_sign[i]))
{
RPG_Script.cmd_offset=RPG_Script.label_offset[i]-1;
break;
}
}
void scr_npc_walk()
{
int temp1,temp2,temp3;
if(RPG_Script.script_flag==SCRIPT_HANG)
{
printf("NPC_walk:This command cannot run in hanged mode.");
return;
}
temp1=Read_Num();
temp2=Read_Num();
temp3=Read_Num();
NPC_Lib.scr_npc_num=temp1;
NPC_Lib.npc[temp1].dir=temp2;
NPC_Lib.scr_step=temp3;
RPG_Script.script_flag=SCRIPT_BUSY; /*启动一条语句后,将标志设为语句执行中。由语句的执行函数来恢复等待*/
}
void scr_npc_status()
{
int temp1,temp2;
temp1=Read_Num();
temp2=Read_Num();
NPC_Lib.npc[temp1].status=temp2;
}
void scr_scn_status()
{
int temp;
temp=Read_Num();
Screen.status=temp;
}
void scr_scn_set()
{
int tempx,tempy;
tempx=Read_Num();
tempy=Read_Num();
Screen.xx=tempx;
Screen.yy=tempy;
}
void scr_scn_mov()
{
float tempx,tempy,temps,k;
if(RPG_Script.script_flag==SCRIPT_HANG)
{
printf("screen_mov:This command cannot run in hanged mode.");
return;
}
tempx=Read_Num();
tempy=Read_Num();
temps=Read_Num();
Screen.target_x=tempx;
Screen.target_y=tempy;
if(Screen.xx==tempx)
{
Screen.inc_x=0;
Screen.inc_y=(tempy>=Screen.yy?1:-1)*temps;
Screen.mov_counter=abs(Screen.yy-tempy)/temps;
}
else if(Screen.yy==tempy)
{
Screen.inc_y=0;
Screen.inc_x=(tempx>=Screen.xx?1:-1)*temps;
Screen.mov_counter=abs(Screen.xx-tempx)/temps;
}
else
{
k=fabs((tempy-Screen.yy)/(tempx-Screen.xx));
if(k<=1)
{
Screen.inc_x=(tempx>=Screen.xx?1:-1)*temps;
Screen.inc_y=(tempy>=Screen.yy?k:-k)*temps;
Screen.mov_counter=abs(Screen.xx-tempx)/temps;
}
else
{
Screen.inc_x=(tempx>=Screen.xx?1/k:-1/k)*temps;
Screen.inc_y=(tempy>=Screen.yy?1:-1)*temps;
Screen.mov_counter=abs(Screen.yy-tempy)/temps;
}
}
Screen.script_drv=SCN_DRV_YES;
RPG_Script.script_flag=SCRIPT_BUSY; /*启动一条语句后,将标志设为语句执行中。由语句的执行函数来恢复等待*/
}
void scr_npc_set()
{
int temp1,temp2,temp3;
temp1=Read_Num();
temp2=Read_Num();
temp3=Read_Num();
RPG_Map.data[NPC_Lib.npc[temp1].xx][NPC_Lib.npc[temp1].yy]=WALK_YES;
NPC_Lib.npc[temp1].xx=temp2;
NPC_Lib.npc[temp1].yy=temp3;
NPC_Lib.npc[temp1].map_x=temp2*32;
NPC_Lib.npc[temp1].map_y=temp3*32;
NPC_Lib.npc[temp1].counter1=0;
NPC_Lib.npc[temp1].counter2=0;
RPG_Map.data[NPC_Lib.npc[temp1].xx][NPC_Lib.npc[temp1].yy]=WALK_NO;
}
void scr_npc_turn()
{
int temp1,temp2;
temp1=Read_Num();
temp2=Read_Num();
NPC_Lib.npc[temp1].dir=temp2;
}
void scr_set()
{
int temp1,temp2;
temp1=Read_Num();
temp2=Read_Num();
RPG_Script.temp[temp1]=temp2;
}
void scr_game_status()
{
int temp;
temp=Read_Num();
if(temp==1)RPG_Script.script_flag=SCRIPT_HANG;
else RPG_Script.script_flag=SCRIPT_WAIT;
}
void scr_load_map()
{
char str1[30],str2[30],str3[30];
Read_Str(str1);
Read_Str(str2);
Read_Str(str3);
ReadMap(&RPG_Map,str1,str2,str3);
}
void scr_go_inout()
{
int temp1,temp2,r,g,b,k=0;
if(RPG_Script.script_flag==SCRIPT_HANG)
{
printf("screen_mov:This command cannot run in hanged mode.");
return;
}
temp1=Read_Num();
temp2=Read_Num();
Fade.target_color=temp1;
Fade.inout_flag=temp2;
if(temp2==FADE_IN)Fade.counter1=255;
else Fade.counter1=0;
Fade.active_flag=FADE_ACTIVE;
RPG_Script.script_flag=SCRIPT_BUSY;
}
void scr_end()
{
RPG_Script.cmd_offset++;
/*清空堆栈*/
RPG_Script.fname_stack_off=0;
RPG_Script.cmd_stack_off=0;
RPG_Script.flag_stack_off=0;
RPG_Script.script_flag=SCRIPT_SHUT;
}
void scr_call()
{
char str[30];
Read_Str(str);
/*把当前文件名压入堆栈*/
strcpy(RPG_Script.fname_stack[RPG_Script.fname_stack_off],RPG_Script.filename);
RPG_Script.fname_stack_off++;
/*当前状态压入堆栈*/
RPG_Script.flag_stack[RPG_Script.flag_stack_off]=RPG_Script.script_flag;
RPG_Script.flag_stack_off++;
/*把当前指针偏移压入堆栈*/
RPG_Script.cmd_stack[RPG_Script.cmd_stack_off]=RPG_Script.cmd_offset;
RPG_Script.cmd_stack_off++;
RPG_Script.script_flag=SCRIPT_SHUT;
Load_Script(str);
/*puts(RPG_Script.command);
while(1); */
}
void scr_return()
{
char str[30];
RPG_Script.cmd_offset++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -