📄 t_script.c
字号:
// Emacs style mode select -*- C++ -*-//----------------------------------------------------------------------------//// $Id: t_script.c,v 1.2 2001/03/13 22:14:20 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_script.c,v $// Revision 1.2 2001/03/13 22:14:20 stroggonmeth// Long time no commit. 3D floors, FraggleScript, portals, ect.//// Revision 1.1 2000/11/02 17:57:28 stroggonmeth// FraggleScript files...//////--------------------------------------------------------------------------//// scripting.//// delayed scripts, running scripts, console cmds etc in here// the interface between FraggleScript and the rest of the game//// By Simon Howard////----------------------------------------------------------------------------#include "doomstat.h"#include "command.h"//#include "c_net.h"//#include "c_runcmd.h"#include "g_game.h"#include "r_state.h"#include "p_info.h"#include "p_mobj.h"#include "p_spec.h"#include "p_setup.h"#include "w_wad.h"#include "z_zone.h"#include "t_script.h"#include "t_parse.h"#include "t_vari.h"#include "t_func.h"void clear_runningscripts();// script tree://// global_script// / \.// hubscript thingscript// / \ / \.// levelscript [levelscript] ... scripts ...// / \ / \.// ... scripts... ... scripts ...//// the level script is just the stuff put in the wad,// which the other scripts are derivatives ofscript_t levelscript;// the thing script//script_t thingscript;// the individual scripts//script_t *scripts[MAXSCRIPTS]; // the scriptsmobj_t *t_trigger;runningscript_t runningscripts; // first in chain// T_Init()//// called at program startvoid T_Init(){ init_variables(); init_functions();}//// T_ClearScripts()//// called at level start, clears all scripts//void T_ClearScripts(){ int i; // stop runningscripts clear_runningscripts(); // clear the levelscript levelscript.data = Z_Malloc(5, PU_LEVEL, 0); // empty data levelscript.data[0] = '\0'; levelscript.scriptnum = -1; levelscript.parent = &hub_script; // clear levelscript variables for(i=0; i<VARIABLESLOTS; i++) { levelscript.variables[i] = NULL; }}void T_LoadThingScript(){/* char *scriptlump; int lumpnum, lumplen; if(thingscript.data) Z_Free(thingscript.data); // load lump into thingscript.data // get lumpnum, lumplen lumpnum = W_CheckNumForName("THINGSCR"); if(lumpnum == -1) return; lumplen = W_LumpLength(lumpnum); // alloc space for lump and copy lump data into it thingscript.data = Z_Malloc(lumplen+10, PU_STATIC, 0); scriptlump = W_CacheLumpNum(lumpnum, PU_CACHE); memcpy(thingscript.data, scriptlump, lumplen); // add '\0' to end of string thingscript.data[lumplen] = '\0'; // preprocess script preprocess(&thingscript); // run script thingscript.trigger = players[0].mo; run_script(&thingscript); */}void T_PreprocessScripts(){ // run the levelscript first // get the other scripts // levelscript started by player 0 'superplayer' levelscript.trigger = players[0].mo; preprocess(&levelscript); run_script(&levelscript); // load and run the thing script T_LoadThingScript();}void T_RunScript(int n){ script_t *script; if(n<0 || n>=MAXSCRIPTS) return; // use the level's child script script n script = levelscript.children[n]; if(!script) return; script->trigger = t_trigger; // save trigger in script run_script(script);}// T_RunThingScript:// identical to T_RunScript but runs a script// from the thingscript list rather than the// levelscript listvoid T_RunThingScript(int n){/* script_t *script; if(n<0 || n>=MAXSCRIPTS) return; // use the level's child script script n script = thingscript.children[n]; if(!script) return; script->trigger = t_trigger; // save trigger in script run_script(script);*/}// console scripting debugging commandsvoid COM_T_DumpScript_f (void){ script_t *script; if(COM_Argc() < 2) { CONS_Printf("usage: T_DumpScript <scriptnum>\n"); return; } if(!strcmp(COM_Argv(1), "global")) script = &levelscript; else script = levelscript.children[atoi(COM_Argv(1))]; if(!script) { CONS_Printf("script '%s' not defined.\n", COM_Argv(1)); return; } CONS_Printf("%s\n", script->data);}void COM_T_RunScript_f (void){ int sn; if(COM_Argc() < 2) { CONS_Printf("Usage: T_RunScript <script>\n"); return; } sn = atoi(COM_Argv(1)); if(!levelscript.children[sn]) { CONS_Printf("script not defined\n"); return; } t_trigger = players[consoleplayer].mo; T_RunScript(sn);}/************************ PAUSING SCRIPTS ************************/runningscript_t *freelist=NULL; // maintain a freelist for speedrunningscript_t *new_runningscript(){ // check the freelist if(freelist) { runningscript_t *returnv=freelist; freelist = freelist->next; return returnv; } // alloc static: can be used in other levels too return Z_Malloc(sizeof(runningscript_t), PU_STATIC, 0);}static void free_runningscript(runningscript_t *runscr){ // add to freelist runscr->next = freelist; freelist = runscr;}static boolean wait_finished(runningscript_t *script){ switch(script->wait_type) { case wt_none: return true; // uh? hehe case wt_scriptwait: // waiting for script to finish { runningscript_t *current; for(current = runningscripts.next; current; current = current->next) { if(current == script) continue; // ignore this script if(current->script->scriptnum == script->wait_data) return false; // script still running } return true; // can continue now } case wt_delay: // just count down { return --script->wait_data <= 0; } case wt_tagwait: { int secnum = -1; while ((secnum = P_FindSectorFromTag(script->wait_data, secnum)) >= 0) { sector_t *sec = §ors[secnum]; if(sec->floordata || sec->ceilingdata || sec->lightingdata) return false; // not finished } return true; } default: return true; } return false;}void T_DelayedScripts(){ runningscript_t *current, *next; int i; if(!info_scripts) return; // no level scripts current = runningscripts.next; while(current) { if(wait_finished(current)) { // copy out the script variables from the // runningscript_t for(i=0; i<VARIABLESLOTS; i++) current->script->variables[i] = current->variables[i]; current->script->trigger = current->trigger; // copy trigger // continue the script continue_script(current->script, current->savepoint); // unhook from chain and free current->prev->next = current->next; if(current->next) current->next->prev = current->prev; next = current->next; // save before freeing free_runningscript(current); } else next = current->next; current = next; // continue to next in chain
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -