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

📄 t_func.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 4 页
字号:
// Emacs style mode select -*- C++ -*-//---------------------------------------------------------------------------//// $Id: t_func.c,v 1.6 2001/04/30 17:19:24 stroggonmeth Exp $//// Copyright(C) 2000 Simon Howard//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA//// $Log: t_func.c,v $// Revision 1.6  2001/04/30 17:19:24  stroggonmeth// HW fix and misc. changes//// Revision 1.5  2001/03/21 18:24:56  stroggonmeth// Misc changes and fixes. Code cleanup//// Revision 1.4  2001/03/13 22:14:20  stroggonmeth// Long time no commit. 3D floors, FraggleScript, portals, ect.//// Revision 1.3  2000/11/09 17:56:20  stroggonmeth// Hopefully fixed a few bugs and did a few optimizations.//// Revision 1.2  2000/11/04 16:23:44  bpereira// no message//// Revision 1.1  2000/11/02 17:57:28  stroggonmeth// FraggleScript files...//////--------------------------------------------------------------------------//// Functions//// functions are stored as variables(see variable.c), the// value being a pointer to a 'handler' function for the// function. Arguments are stored in an argc/argv-style list//// this module contains all the handler functions for the// basic FraggleScript Functions.//// By Simon Howard////---------------------------------------------------------------------------/* includes ************************/#include <stdio.h>#include "command.h"#include "doomstat.h"#include "doomtype.h"#include "d_main.h"#include "g_game.h"#include "hu_stuff.h"#include "info.h"#include "m_random.h"#include "p_mobj.h"#include "p_tick.h"#include "p_spec.h"//#include "p_hubs.h"#include "p_inter.h"#include "r_data.h"#include "r_main.h"#include "r_segs.h"#include "s_sound.h"#include "w_wad.h"#include "z_zone.h"#include "p_local.h"#include "p_setup.h"#include "d_think.h"#include "t_parse.h"#include "t_spec.h"#include "t_script.h"#include "t_oper.h"#include "t_vari.h"#include "t_func.h"//extern int firstcolormaplump, lastcolormaplump;      // r_data.csvalue_t evaluate_expression(int start, int stop);int find_operator(int start, int stop, char *value);// functions. SF_ means Script Function not, well.. heh, me        /////////// actually running a function //////////////*******************  FUNCTIONS *******************/// the actual handler functions for the// functions themselves// arguments are evaluated and passed to the// handler functions using 't_argc' and 't_argv'// in a similar way to the way C does with command// line options.// values can be returned from the functions using// the variable 't_return'void SF_Print(){  int i;  if(!t_argc) return;  for(i=0; i<t_argc; i++)    {      CONS_Printf("%s", stringvalue(t_argv[i]));    }}        // return a random number from 0 to 255void SF_Rnd(){  t_return.type = svt_int;  t_return.value.i = P_Random();}// looping section. using the rover, find the highest level// loop we are currently in and return the section_t for it.section_t *looping_section(){  section_t *best = NULL;         // highest level loop we're in                                  // that has been found so far  int n;  // check thru all the hashchains  for(n=0; n<SECTIONSLOTS; n++)    {      section_t *current = current_script->sections[n];      // check all the sections in this hashchain      while(current)        {          // a loop?          if(current->type == st_loop)            // check to see if it's a loop that we're inside            if(rover >= current->start && rover <= current->end)              {                // a higher nesting level than the best one so far?                if(!best || (current->start > best->start))                  best = current;     // save it              }          current = current->next;        }    }  return best;    // return the best one found}        // "continue;" in FraggleScript is a functionvoid SF_Continue(){  section_t *section;  if(!(section = looping_section()) )       // no loop found    {      script_error("continue() not in loop\n");      return;    }  rover = section->end;      // jump to the closing brace}void SF_Break(){  section_t *section;  if(!(section = looping_section()) )    {      script_error("break() not in loop\n");      return;    }  rover = section->end+1;   // jump out of the loop}void SF_Goto(){  if(t_argc < 1)    {      script_error("incorrect arguments to goto\n");      return;    }  // check argument is a labelptr  if(t_argv[0].type != svt_label)    {      script_error("goto argument not a label\n");      return;    }  // go there then if everythings fine  rover = t_argv[0].value.labelptr;}void SF_Return(){  killscript = true;      // kill the script}void SF_Include(){  char tempstr[9];  if(t_argc < 1)    {      script_error("incorrect arguments to include()");      return;    }  memset(tempstr, 0, 9);  if(t_argv[0].type == svt_string)    strncpy(tempstr, t_argv[0].value.s, 8);  else    sprintf(tempstr, "%s", stringvalue(t_argv[0]));  parse_include(tempstr);}void SF_Input(){/*        static char inputstr[128];                gets(inputstr);        t_return.type = svt_string;        t_return.value.s = inputstr;*/  CONS_Printf("input() function not available in doom\a\n");}void SF_Beep(){  CONS_Printf("\a");}void SF_Clock(){  t_return.type = svt_int;  t_return.value.i = (gametic*100)/35;}    /**************** doom stuff ****************/void SF_ExitLevel(){  G_ExitLevel();}        // centremsgvoid SF_Tip(){  int     i;  char    *tempstr;  int     strsize = 0;  if(current_script->trigger->player != &players[displayplayer])    return;  for(i = 0; i < t_argc; i++)    strsize += strlen(stringvalue(t_argv[i]));  tempstr = Z_Malloc(strsize + 1, PU_STATIC, 0);  tempstr[0] = '\0';  for(i=0; i<t_argc; i++)    sprintf(tempstr, "%s%s", tempstr, stringvalue(t_argv[i]));  HU_SetTip(tempstr, 53);  Z_Free(tempstr);}// SoM: Timed tip!void SF_TimedTip(){  int     i;  char    *tempstr;  int     strsize = 0;  int     tiptime;  if(t_argc < 2)  {    script_error("Missing parameters.\n");    return;  }  tiptime = (intvalue(t_argv[0]) * 35) / 100;  if(current_script->trigger->player != &players[displayplayer])    return;  for(i = 0; i < t_argc; i++)    strsize += strlen(stringvalue(t_argv[i]));  tempstr = Z_Malloc(strsize + 1, PU_STATIC, 0);  tempstr[0] = '\0';  for(i=1; i<t_argc; i++)    sprintf(tempstr, "%s%s", tempstr, stringvalue(t_argv[i]));  //CONS_Printf("%s\n", tempstr);  HU_SetTip(tempstr, tiptime);  Z_Free(tempstr);}// tip to a particular playervoid SF_PlayerTip(){  int     i, plnum;  char    *tempstr;  int     strsize = 0;  if(!t_argc)    { script_error("player not specified\n"); return;}  plnum = intvalue(t_argv[0]);  if(consoleplayer != plnum) return;  for(i = 0; i < t_argc; i++)    strsize += strlen(stringvalue(t_argv[i]));  tempstr = Z_Malloc(strsize + 1, PU_STATIC, 0);  tempstr[0] = '\0';  for(i=1; i<t_argc; i++)    sprintf(tempstr, "%s%s", tempstr, stringvalue(t_argv[i]));  //CONS_Printf("%s\n", tempstr);  HU_SetTip(tempstr, 53);  Z_Free(tempstr);}        // message playervoid SF_Message(){  int     i;  char    *tempstr;  int     strsize = 0;  if(current_script->trigger->player != &players[displayplayer])    return;  for(i = 0; i < t_argc; i++)    strsize += strlen(stringvalue(t_argv[i]));  tempstr = Z_Malloc(strsize + 1, PU_STATIC, 0);  tempstr[0] = '\0';  for(i=0; i<t_argc; i++)    sprintf(tempstr, "%s%s", tempstr, stringvalue(t_argv[i]));  CONS_Printf("%s\n", tempstr);  Z_Free(tempstr);}        // message to a particular playervoid SF_PlayerMsg(){  int     i, plnum;  char    *tempstr;  int     strsize = 0;  if(!t_argc)    { script_error("player not specified\n"); return;}  plnum = intvalue(t_argv[0]);  if(displayplayer != plnum) return;  for(i = 0; i < t_argc; i++)    strsize += strlen(stringvalue(t_argv[i]));  tempstr = Z_Malloc(strsize + 1, PU_STATIC, 0);  tempstr[0] = '\0';  for(i=1; i<t_argc; i++)    sprintf(tempstr, "%s%s", tempstr, stringvalue(t_argv[i]));  CONS_Printf("%s\n", tempstr);  Z_Free(tempstr);}void SF_PlayerInGame(){  if(!t_argc)    { script_error("player not specified\n"); return;}  t_return.type = svt_int;  t_return.value.i = playeringame[intvalue(t_argv[0])];}void SF_PlayerName(){  int plnum;  if(!t_argc)    {      player_t *pl;      pl = current_script->trigger->player;      if(pl) plnum = pl - players;      else        {          script_error("script not started by player\n");          return;        }    }  else    plnum = intvalue(t_argv[0]);  t_return.type = svt_string;  t_return.value.s = player_names[plnum];}        // object being controlled by playervoid SF_PlayerObj(){  int plnum;  if(!t_argc)    {      player_t *pl;      pl = current_script->trigger->player;      if(pl) plnum = pl - players;      else        {          script_error("script not started by player\n");          return;        }    }  else    plnum = intvalue(t_argv[0]);  t_return.type = svt_mobj;  t_return.value.mobj = players[plnum].mo;}void SF_MobjIsPlayer(){  mobj_t*  mobj;  if(t_argc == 0)  {    t_return.type = svt_int;    t_return.value.i = current_script->trigger->player ? 1 : 0;    return;  }  mobj = MobjForSvalue(t_argv[0]);  t_return.type = svt_int;  if(!mobj)    t_return.value.i = 0;  else    t_return.value.i = mobj->player ? 1 : 0;  return;}void SF_PlayerKeys(){  int  playernum;  int  keynum;  int  givetake;  if(t_argc < 2)  {    script_error("missing parameters for playerkeys\n");    return;  }  if(t_argc == 2)  {    if(t_argv[0].type == svt_mobj)    {      if(!t_argv[0].value.mobj->player)      {        script_error("mobj not a player!\n");        return;      }      playernum = t_argv[0].value.mobj->player - players;    }    else      playernum = intvalue(t_argv[0]);    keynum = intvalue(t_argv[1]);    if(!playeringame[playernum])    {      script_error("player %i not in game\n", playernum);      return;    }    if(keynum > 5)    {      script_error("keynum out of range! %s\n", keynum);      return;    }    t_return.type = svt_int;    t_return.value.i = players[playernum].cards & (1 << keynum);    return;  }  else  {    if(t_argv[0].type == svt_mobj)    {      if(!t_argv[0].value.mobj->player)      {        script_error("mobj not a player!\n");        return;      }      playernum = t_argv[0].value.mobj->player - players;    }    else      playernum = intvalue(t_argv[0]);    keynum = intvalue(t_argv[1]);    if(!playeringame[playernum])    {      script_error("player %i not in game\n", playernum);      return;    }    if(keynum > 6)    {      script_error("keynum out of range! %s\n", keynum);      return;    }    givetake = intvalue(t_argv[2]);    t_return.type = svt_int;    if(givetake)      players[playernum].cards |= (1 << keynum);    else      players[playernum].cards &= ~(1 << keynum);    t_return.value.i = 0;    return;  }}void SF_PlayerAmmo(){  int  playernum;  int  ammonum;  int  newammo;  if(t_argc < 2)  {    script_error("missing parameters for playerammo\n");    return;  }  if(t_argc == 2)  {    if(t_argv[0].type == svt_mobj)    {      if(!t_argv[0].value.mobj->player)

⌨️ 快捷键说明

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