P_ACS.C 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. //**************************************************************************
  2. //**
  3. //** p_acs.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_acs.c,v $
  6. //** $Revision: 1.31 $
  7. //** $Date: 95/10/09 16:25:17 $
  8. //** $Author: cjr $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #include "h2def.h"
  13. #include "p_local.h"
  14. // MACROS ------------------------------------------------------------------
  15. #define SCRIPT_CONTINUE 0
  16. #define SCRIPT_STOP 1
  17. #define SCRIPT_TERMINATE 2
  18. #define OPEN_SCRIPTS_BASE 1000
  19. #define PRINT_BUFFER_SIZE 256
  20. #define GAME_SINGLE_PLAYER 0
  21. #define GAME_NET_COOPERATIVE 1
  22. #define GAME_NET_DEATHMATCH 2
  23. #define TEXTURE_TOP 0
  24. #define TEXTURE_MIDDLE 1
  25. #define TEXTURE_BOTTOM 2
  26. #define S_DROP ACScript->stackPtr--
  27. #define S_POP ACScript->stack[--ACScript->stackPtr]
  28. #define S_PUSH(x) ACScript->stack[ACScript->stackPtr++] = x
  29. // TYPES -------------------------------------------------------------------
  30. typedef struct
  31. {
  32. int marker;
  33. int infoOffset;
  34. int code;
  35. } acsHeader_t;
  36. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  37. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  38. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  39. static void StartOpenACS(int number, int infoIndex, int *address);
  40. static void ScriptFinished(int number);
  41. static boolean TagBusy(int tag);
  42. static boolean AddToACSStore(int map, int number, byte *args);
  43. static int GetACSIndex(int number);
  44. static void Push(int value);
  45. static int Pop(void);
  46. static int Top(void);
  47. static void Drop(void);
  48. static int CmdNOP(void);
  49. static int CmdTerminate(void);
  50. static int CmdSuspend(void);
  51. static int CmdPushNumber(void);
  52. static int CmdLSpec1(void);
  53. static int CmdLSpec2(void);
  54. static int CmdLSpec3(void);
  55. static int CmdLSpec4(void);
  56. static int CmdLSpec5(void);
  57. static int CmdLSpec1Direct(void);
  58. static int CmdLSpec2Direct(void);
  59. static int CmdLSpec3Direct(void);
  60. static int CmdLSpec4Direct(void);
  61. static int CmdLSpec5Direct(void);
  62. static int CmdAdd(void);
  63. static int CmdSubtract(void);
  64. static int CmdMultiply(void);
  65. static int CmdDivide(void);
  66. static int CmdModulus(void);
  67. static int CmdEQ(void);
  68. static int CmdNE(void);
  69. static int CmdLT(void);
  70. static int CmdGT(void);
  71. static int CmdLE(void);
  72. static int CmdGE(void);
  73. static int CmdAssignScriptVar(void);
  74. static int CmdAssignMapVar(void);
  75. static int CmdAssignWorldVar(void);
  76. static int CmdPushScriptVar(void);
  77. static int CmdPushMapVar(void);
  78. static int CmdPushWorldVar(void);
  79. static int CmdAddScriptVar(void);
  80. static int CmdAddMapVar(void);
  81. static int CmdAddWorldVar(void);
  82. static int CmdSubScriptVar(void);
  83. static int CmdSubMapVar(void);
  84. static int CmdSubWorldVar(void);
  85. static int CmdMulScriptVar(void);
  86. static int CmdMulMapVar(void);
  87. static int CmdMulWorldVar(void);
  88. static int CmdDivScriptVar(void);
  89. static int CmdDivMapVar(void);
  90. static int CmdDivWorldVar(void);
  91. static int CmdModScriptVar(void);
  92. static int CmdModMapVar(void);
  93. static int CmdModWorldVar(void);
  94. static int CmdIncScriptVar(void);
  95. static int CmdIncMapVar(void);
  96. static int CmdIncWorldVar(void);
  97. static int CmdDecScriptVar(void);
  98. static int CmdDecMapVar(void);
  99. static int CmdDecWorldVar(void);
  100. static int CmdGoto(void);
  101. static int CmdIfGoto(void);
  102. static int CmdDrop(void);
  103. static int CmdDelay(void);
  104. static int CmdDelayDirect(void);
  105. static int CmdRandom(void);
  106. static int CmdRandomDirect(void);
  107. static int CmdThingCount(void);
  108. static int CmdThingCountDirect(void);
  109. static int CmdTagWait(void);
  110. static int CmdTagWaitDirect(void);
  111. static int CmdPolyWait(void);
  112. static int CmdPolyWaitDirect(void);
  113. static int CmdChangeFloor(void);
  114. static int CmdChangeFloorDirect(void);
  115. static int CmdChangeCeiling(void);
  116. static int CmdChangeCeilingDirect(void);
  117. static int CmdRestart(void);
  118. static int CmdAndLogical(void);
  119. static int CmdOrLogical(void);
  120. static int CmdAndBitwise(void);
  121. static int CmdOrBitwise(void);
  122. static int CmdEorBitwise(void);
  123. static int CmdNegateLogical(void);
  124. static int CmdLShift(void);
  125. static int CmdRShift(void);
  126. static int CmdUnaryMinus(void);
  127. static int CmdIfNotGoto(void);
  128. static int CmdLineSide(void);
  129. static int CmdScriptWait(void);
  130. static int CmdScriptWaitDirect(void);
  131. static int CmdClearLineSpecial(void);
  132. static int CmdCaseGoto(void);
  133. static int CmdBeginPrint(void);
  134. static int CmdEndPrint(void);
  135. static int CmdPrintString(void);
  136. static int CmdPrintNumber(void);
  137. static int CmdPrintCharacter(void);
  138. static int CmdPlayerCount(void);
  139. static int CmdGameType(void);
  140. static int CmdGameSkill(void);
  141. static int CmdTimer(void);
  142. static int CmdSectorSound(void);
  143. static int CmdAmbientSound(void);
  144. static int CmdSoundSequence(void);
  145. static int CmdSetLineTexture(void);
  146. static int CmdSetLineBlocking(void);
  147. static int CmdSetLineSpecial(void);
  148. static int CmdThingSound(void);
  149. static int CmdEndPrintBold(void);
  150. static void ThingCount(int type, int tid);
  151. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  152. // PUBLIC DATA DEFINITIONS -------------------------------------------------
  153. int ACScriptCount;
  154. byte *ActionCodeBase;
  155. acsInfo_t *ACSInfo;
  156. int MapVars[MAX_ACS_MAP_VARS];
  157. int WorldVars[MAX_ACS_WORLD_VARS];
  158. acsstore_t ACSStore[MAX_ACS_STORE+1]; // +1 for termination marker
  159. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  160. static acs_t *ACScript;
  161. static int *PCodePtr;
  162. static byte SpecArgs[8];
  163. static int ACStringCount;
  164. static char **ACStrings;
  165. static char PrintBuffer[PRINT_BUFFER_SIZE];
  166. static acs_t *NewScript;
  167. static int (*PCodeCmds[])(void) =
  168. {
  169. CmdNOP,
  170. CmdTerminate,
  171. CmdSuspend,
  172. CmdPushNumber,
  173. CmdLSpec1,
  174. CmdLSpec2,
  175. CmdLSpec3,
  176. CmdLSpec4,
  177. CmdLSpec5,
  178. CmdLSpec1Direct,
  179. CmdLSpec2Direct,
  180. CmdLSpec3Direct,
  181. CmdLSpec4Direct,
  182. CmdLSpec5Direct,
  183. CmdAdd,
  184. CmdSubtract,
  185. CmdMultiply,
  186. CmdDivide,
  187. CmdModulus,
  188. CmdEQ,
  189. CmdNE,
  190. CmdLT,
  191. CmdGT,
  192. CmdLE,
  193. CmdGE,
  194. CmdAssignScriptVar,
  195. CmdAssignMapVar,
  196. CmdAssignWorldVar,
  197. CmdPushScriptVar,
  198. CmdPushMapVar,
  199. CmdPushWorldVar,
  200. CmdAddScriptVar,
  201. CmdAddMapVar,
  202. CmdAddWorldVar,
  203. CmdSubScriptVar,
  204. CmdSubMapVar,
  205. CmdSubWorldVar,
  206. CmdMulScriptVar,
  207. CmdMulMapVar,
  208. CmdMulWorldVar,
  209. CmdDivScriptVar,
  210. CmdDivMapVar,
  211. CmdDivWorldVar,
  212. CmdModScriptVar,
  213. CmdModMapVar,
  214. CmdModWorldVar,
  215. CmdIncScriptVar,
  216. CmdIncMapVar,
  217. CmdIncWorldVar,
  218. CmdDecScriptVar,
  219. CmdDecMapVar,
  220. CmdDecWorldVar,
  221. CmdGoto,
  222. CmdIfGoto,
  223. CmdDrop,
  224. CmdDelay,
  225. CmdDelayDirect,
  226. CmdRandom,
  227. CmdRandomDirect,
  228. CmdThingCount,
  229. CmdThingCountDirect,
  230. CmdTagWait,
  231. CmdTagWaitDirect,
  232. CmdPolyWait,
  233. CmdPolyWaitDirect,
  234. CmdChangeFloor,
  235. CmdChangeFloorDirect,
  236. CmdChangeCeiling,
  237. CmdChangeCeilingDirect,
  238. CmdRestart,
  239. CmdAndLogical,
  240. CmdOrLogical,
  241. CmdAndBitwise,
  242. CmdOrBitwise,
  243. CmdEorBitwise,
  244. CmdNegateLogical,
  245. CmdLShift,
  246. CmdRShift,
  247. CmdUnaryMinus,
  248. CmdIfNotGoto,
  249. CmdLineSide,
  250. CmdScriptWait,
  251. CmdScriptWaitDirect,
  252. CmdClearLineSpecial,
  253. CmdCaseGoto,
  254. CmdBeginPrint,
  255. CmdEndPrint,
  256. CmdPrintString,
  257. CmdPrintNumber,
  258. CmdPrintCharacter,
  259. CmdPlayerCount,
  260. CmdGameType,
  261. CmdGameSkill,
  262. CmdTimer,
  263. CmdSectorSound,
  264. CmdAmbientSound,
  265. CmdSoundSequence,
  266. CmdSetLineTexture,
  267. CmdSetLineBlocking,
  268. CmdSetLineSpecial,
  269. CmdThingSound,
  270. CmdEndPrintBold
  271. };
  272. // CODE --------------------------------------------------------------------
  273. //==========================================================================
  274. //
  275. // P_LoadACScripts
  276. //
  277. //==========================================================================
  278. void P_LoadACScripts(int lump)
  279. {
  280. int i;
  281. int *buffer;
  282. acsHeader_t *header;
  283. acsInfo_t *info;
  284. header = W_CacheLumpNum(lump, PU_LEVEL);
  285. ActionCodeBase = (byte *)header;
  286. buffer = (int *)((byte *)header+header->infoOffset);
  287. ACScriptCount = *buffer++;
  288. if(ACScriptCount == 0)
  289. { // Empty behavior lump
  290. return;
  291. }
  292. ACSInfo = Z_Malloc(ACScriptCount*sizeof(acsInfo_t), PU_LEVEL, 0);
  293. memset(ACSInfo, 0, ACScriptCount*sizeof(acsInfo_t));
  294. for(i = 0, info = ACSInfo; i < ACScriptCount; i++, info++)
  295. {
  296. info->number = *buffer++;
  297. info->address = (int *)((byte *)ActionCodeBase+*buffer++);
  298. info->argCount = *buffer++;
  299. if(info->number >= OPEN_SCRIPTS_BASE)
  300. { // Auto-activate
  301. info->number -= OPEN_SCRIPTS_BASE;
  302. StartOpenACS(info->number, i, info->address);
  303. info->state = ASTE_RUNNING;
  304. }
  305. else
  306. {
  307. info->state = ASTE_INACTIVE;
  308. }
  309. }
  310. ACStringCount = *buffer++;
  311. ACStrings = (char **)buffer;
  312. for(i = 0; i < ACStringCount; i++)
  313. {
  314. ACStrings[i] += (int)ActionCodeBase;
  315. }
  316. memset(MapVars, 0, sizeof(MapVars));
  317. }
  318. //==========================================================================
  319. //
  320. // StartOpenACS
  321. //
  322. //==========================================================================
  323. static void StartOpenACS(int number, int infoIndex, int *address)
  324. {
  325. acs_t *script;
  326. script = Z_Malloc(sizeof(acs_t), PU_LEVSPEC, 0);
  327. memset(script, 0, sizeof(acs_t));
  328. script->number = number;
  329. // World objects are allotted 1 second for initialization
  330. script->delayCount = 35;
  331. script->infoIndex = infoIndex;
  332. script->ip = address;
  333. script->thinker.function = T_InterpretACS;
  334. P_AddThinker(&script->thinker);
  335. }
  336. //==========================================================================
  337. //
  338. // P_CheckACSStore
  339. //
  340. // Scans the ACS store and executes all scripts belonging to the current
  341. // map.
  342. //
  343. //==========================================================================
  344. void P_CheckACSStore(void)
  345. {
  346. acsstore_t *store;
  347. for(store = ACSStore; store->map != 0; store++)
  348. {
  349. if(store->map == gamemap)
  350. {
  351. P_StartACS(store->script, 0, store->args, NULL, NULL, 0);
  352. if(NewScript)
  353. {
  354. NewScript->delayCount = 35;
  355. }
  356. store->map = -1;
  357. }
  358. }
  359. }
  360. //==========================================================================
  361. //
  362. // P_StartACS
  363. //
  364. //==========================================================================
  365. static char ErrorMsg[128];
  366. boolean P_StartACS(int number, int map, byte *args, mobj_t *activator,
  367. line_t *line, int side)
  368. {
  369. int i;
  370. acs_t *script;
  371. int infoIndex;
  372. aste_t *statePtr;
  373. NewScript = NULL;
  374. if(map && map != gamemap)
  375. { // Add to the script store
  376. return AddToACSStore(map, number, args);
  377. }
  378. infoIndex = GetACSIndex(number);
  379. if(infoIndex == -1)
  380. { // Script not found
  381. //I_Error("P_StartACS: Unknown script number %d", number);
  382. sprintf(ErrorMsg, "P_STARTACS ERROR: UNKNOWN SCRIPT %d", number);
  383. P_SetMessage(&players[consoleplayer], ErrorMsg, true);
  384. }
  385. statePtr = &ACSInfo[infoIndex].state;
  386. if(*statePtr == ASTE_SUSPENDED)
  387. { // Resume a suspended script
  388. *statePtr = ASTE_RUNNING;
  389. return true;
  390. }
  391. if(*statePtr != ASTE_INACTIVE)
  392. { // Script is already executing
  393. return false;
  394. }
  395. script = Z_Malloc(sizeof(acs_t), PU_LEVSPEC, 0);
  396. memset(script, 0, sizeof(acs_t));
  397. script->number = number;
  398. script->infoIndex = infoIndex;
  399. script->activator = activator;
  400. script->line = line;
  401. script->side = side;
  402. script->ip = ACSInfo[infoIndex].address;
  403. script->thinker.function = T_InterpretACS;
  404. for(i = 0; i < ACSInfo[infoIndex].argCount; i++)
  405. {
  406. script->vars[i] = args[i];
  407. }
  408. *statePtr = ASTE_RUNNING;
  409. P_AddThinker(&script->thinker);
  410. NewScript = script;
  411. return true;
  412. }
  413. //==========================================================================
  414. //
  415. // AddToACSStore
  416. //
  417. //==========================================================================
  418. static boolean AddToACSStore(int map, int number, byte *args)
  419. {
  420. int i;
  421. int index;
  422. index = -1;
  423. for(i = 0; ACSStore[i].map != 0; i++)
  424. {
  425. if(ACSStore[i].script == number
  426. && ACSStore[i].map == map)
  427. { // Don't allow duplicates
  428. return false;
  429. }
  430. if(index == -1 && ACSStore[i].map == -1)
  431. { // Remember first empty slot
  432. index = i;
  433. }
  434. }
  435. if(index == -1)
  436. { // Append required
  437. if(i == MAX_ACS_STORE)
  438. {
  439. I_Error("AddToACSStore: MAX_ACS_STORE (%d) exceeded.",
  440. MAX_ACS_STORE);
  441. }
  442. index = i;
  443. ACSStore[index+1].map = 0;
  444. }
  445. ACSStore[index].map = map;
  446. ACSStore[index].script = number;
  447. *((int *)ACSStore[index].args) = *((int *)args);
  448. return true;
  449. }
  450. //==========================================================================
  451. //
  452. // P_StartLockedACS
  453. //
  454. //==========================================================================
  455. boolean P_StartLockedACS(line_t *line, byte *args, mobj_t *mo, int side)
  456. {
  457. int i;
  458. int lock;
  459. byte newArgs[5];
  460. char LockedBuffer[80];
  461. extern char *TextKeyMessages[11];
  462. lock = args[4];
  463. if(!mo->player)
  464. {
  465. return false;
  466. }
  467. if(lock)
  468. {
  469. if(!(mo->player->keys&(1<<(lock-1))))
  470. {
  471. sprintf(LockedBuffer, "YOU NEED THE %s\n",
  472. TextKeyMessages[lock-1]);
  473. P_SetMessage(mo->player, LockedBuffer, true);
  474. S_StartSound(mo, SFX_DOOR_LOCKED);
  475. return false;
  476. }
  477. }
  478. for(i = 0; i < 4; i++)
  479. {
  480. newArgs[i] = args[i];
  481. }
  482. newArgs[4] = 0;
  483. return P_StartACS(newArgs[0], newArgs[1], &newArgs[2], mo,
  484. line, side);
  485. }
  486. //==========================================================================
  487. //
  488. // P_TerminateACS
  489. //
  490. //==========================================================================
  491. boolean P_TerminateACS(int number, int map)
  492. {
  493. int infoIndex;
  494. infoIndex = GetACSIndex(number);
  495. if(infoIndex == -1)
  496. { // Script not found
  497. return false;
  498. }
  499. if(ACSInfo[infoIndex].state == ASTE_INACTIVE
  500. || ACSInfo[infoIndex].state == ASTE_TERMINATING)
  501. { // States that disallow termination
  502. return false;
  503. }
  504. ACSInfo[infoIndex].state = ASTE_TERMINATING;
  505. return true;
  506. }
  507. //==========================================================================
  508. //
  509. // P_SuspendACS
  510. //
  511. //==========================================================================
  512. boolean P_SuspendACS(int number, int map)
  513. {
  514. int infoIndex;
  515. infoIndex = GetACSIndex(number);
  516. if(infoIndex == -1)
  517. { // Script not found
  518. return false;
  519. }
  520. if(ACSInfo[infoIndex].state == ASTE_INACTIVE
  521. || ACSInfo[infoIndex].state == ASTE_SUSPENDED
  522. || ACSInfo[infoIndex].state == ASTE_TERMINATING)
  523. { // States that disallow suspension
  524. return false;
  525. }
  526. ACSInfo[infoIndex].state = ASTE_SUSPENDED;
  527. return true;
  528. }
  529. //==========================================================================
  530. //
  531. // P_Init
  532. //
  533. //==========================================================================
  534. void P_ACSInitNewGame(void)
  535. {
  536. memset(WorldVars, 0, sizeof(WorldVars));
  537. memset(ACSStore, 0, sizeof(ACSStore));
  538. }
  539. //==========================================================================
  540. //
  541. // T_InterpretACS
  542. //
  543. //==========================================================================
  544. void T_InterpretACS(acs_t *script)
  545. {
  546. int cmd;
  547. int action;
  548. if(ACSInfo[script->infoIndex].state == ASTE_TERMINATING)
  549. {
  550. ACSInfo[script->infoIndex].state = ASTE_INACTIVE;
  551. ScriptFinished(ACScript->number);
  552. P_RemoveThinker(&ACScript->thinker);
  553. return;
  554. }
  555. if(ACSInfo[script->infoIndex].state != ASTE_RUNNING)
  556. {
  557. return;
  558. }
  559. if(script->delayCount)
  560. {
  561. script->delayCount--;
  562. return;
  563. }
  564. ACScript = script;
  565. PCodePtr = ACScript->ip;
  566. do
  567. {
  568. cmd = *PCodePtr++;
  569. action = PCodeCmds[cmd]();
  570. } while(action == SCRIPT_CONTINUE);
  571. ACScript->ip = PCodePtr;
  572. if(action == SCRIPT_TERMINATE)
  573. {
  574. ACSInfo[script->infoIndex].state = ASTE_INACTIVE;
  575. ScriptFinished(ACScript->number);
  576. P_RemoveThinker(&ACScript->thinker);
  577. }
  578. }
  579. //==========================================================================
  580. //
  581. // P_TagFinished
  582. //
  583. //==========================================================================
  584. void P_TagFinished(int tag)
  585. {
  586. int i;
  587. if(TagBusy(tag) == true)
  588. {
  589. return;
  590. }
  591. for(i = 0; i < ACScriptCount; i++)
  592. {
  593. if(ACSInfo[i].state == ASTE_WAITINGFORTAG
  594. && ACSInfo[i].waitValue == tag)
  595. {
  596. ACSInfo[i].state = ASTE_RUNNING;
  597. }
  598. }
  599. }
  600. //==========================================================================
  601. //
  602. // P_PolyobjFinished
  603. //
  604. //==========================================================================
  605. void P_PolyobjFinished(int po)
  606. {
  607. int i;
  608. if(PO_Busy(po) == true)
  609. {
  610. return;
  611. }
  612. for(i = 0; i < ACScriptCount; i++)
  613. {
  614. if(ACSInfo[i].state == ASTE_WAITINGFORPOLY
  615. && ACSInfo[i].waitValue == po)
  616. {
  617. ACSInfo[i].state = ASTE_RUNNING;
  618. }
  619. }
  620. }
  621. //==========================================================================
  622. //
  623. // ScriptFinished
  624. //
  625. //==========================================================================
  626. static void ScriptFinished(int number)
  627. {
  628. int i;
  629. for(i = 0; i < ACScriptCount; i++)
  630. {
  631. if(ACSInfo[i].state == ASTE_WAITINGFORSCRIPT
  632. && ACSInfo[i].waitValue == number)
  633. {
  634. ACSInfo[i].state = ASTE_RUNNING;
  635. }
  636. }
  637. }
  638. //==========================================================================
  639. //
  640. // TagBusy
  641. //
  642. //==========================================================================
  643. static boolean TagBusy(int tag)
  644. {
  645. int sectorIndex;
  646. sectorIndex = -1;
  647. while((sectorIndex = P_FindSectorFromTag(tag, sectorIndex)) >= 0)
  648. {
  649. if(sectors[sectorIndex].specialdata)
  650. {
  651. return true;
  652. }
  653. }
  654. return false;
  655. }
  656. //==========================================================================
  657. //
  658. // GetACSIndex
  659. //
  660. // Returns the index of a script number. Returns -1 if the script number
  661. // is not found.
  662. //
  663. //==========================================================================
  664. static int GetACSIndex(int number)
  665. {
  666. int i;
  667. for(i = 0; i < ACScriptCount; i++)
  668. {
  669. if(ACSInfo[i].number == number)
  670. {
  671. return i;
  672. }
  673. }
  674. return -1;
  675. }
  676. //==========================================================================
  677. //
  678. // Push
  679. //
  680. //==========================================================================
  681. static void Push(int value)
  682. {
  683. ACScript->stack[ACScript->stackPtr++] = value;
  684. }
  685. //==========================================================================
  686. //
  687. // Pop
  688. //
  689. //==========================================================================
  690. static int Pop(void)
  691. {
  692. return ACScript->stack[--ACScript->stackPtr];
  693. }
  694. //==========================================================================
  695. //
  696. // Top
  697. //
  698. //==========================================================================
  699. static int Top(void)
  700. {
  701. return ACScript->stack[ACScript->stackPtr-1];
  702. }
  703. //==========================================================================
  704. //
  705. // Drop
  706. //
  707. //==========================================================================
  708. static void Drop(void)
  709. {
  710. ACScript->stackPtr--;
  711. }
  712. //==========================================================================
  713. //
  714. // P-Code Commands
  715. //
  716. //==========================================================================
  717. static int CmdNOP(void)
  718. {
  719. return SCRIPT_CONTINUE;
  720. }
  721. static int CmdTerminate(void)
  722. {
  723. return SCRIPT_TERMINATE;
  724. }
  725. static int CmdSuspend(void)
  726. {
  727. ACSInfo[ACScript->infoIndex].state = ASTE_SUSPENDED;
  728. return SCRIPT_STOP;
  729. }
  730. static int CmdPushNumber(void)
  731. {
  732. Push(*PCodePtr++);
  733. return SCRIPT_CONTINUE;
  734. }
  735. static int CmdLSpec1(void)
  736. {
  737. int special;
  738. special = *PCodePtr++;
  739. SpecArgs[0] = Pop();
  740. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  741. ACScript->side, ACScript->activator);
  742. return SCRIPT_CONTINUE;
  743. }
  744. static int CmdLSpec2(void)
  745. {
  746. int special;
  747. special = *PCodePtr++;
  748. SpecArgs[1] = Pop();
  749. SpecArgs[0] = Pop();
  750. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  751. ACScript->side, ACScript->activator);
  752. return SCRIPT_CONTINUE;
  753. }
  754. static int CmdLSpec3(void)
  755. {
  756. int special;
  757. special = *PCodePtr++;
  758. SpecArgs[2] = Pop();
  759. SpecArgs[1] = Pop();
  760. SpecArgs[0] = Pop();
  761. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  762. ACScript->side, ACScript->activator);
  763. return SCRIPT_CONTINUE;
  764. }
  765. static int CmdLSpec4(void)
  766. {
  767. int special;
  768. special = *PCodePtr++;
  769. SpecArgs[3] = Pop();
  770. SpecArgs[2] = Pop();
  771. SpecArgs[1] = Pop();
  772. SpecArgs[0] = Pop();
  773. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  774. ACScript->side, ACScript->activator);
  775. return SCRIPT_CONTINUE;
  776. }
  777. static int CmdLSpec5(void)
  778. {
  779. int special;
  780. special = *PCodePtr++;
  781. SpecArgs[4] = Pop();
  782. SpecArgs[3] = Pop();
  783. SpecArgs[2] = Pop();
  784. SpecArgs[1] = Pop();
  785. SpecArgs[0] = Pop();
  786. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  787. ACScript->side, ACScript->activator);
  788. return SCRIPT_CONTINUE;
  789. }
  790. static int CmdLSpec1Direct(void)
  791. {
  792. int special;
  793. special = *PCodePtr++;
  794. SpecArgs[0] = *PCodePtr++;
  795. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  796. ACScript->side, ACScript->activator);
  797. return SCRIPT_CONTINUE;
  798. }
  799. static int CmdLSpec2Direct(void)
  800. {
  801. int special;
  802. special = *PCodePtr++;
  803. SpecArgs[0] = *PCodePtr++;
  804. SpecArgs[1] = *PCodePtr++;
  805. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  806. ACScript->side, ACScript->activator);
  807. return SCRIPT_CONTINUE;
  808. }
  809. static int CmdLSpec3Direct(void)
  810. {
  811. int special;
  812. special = *PCodePtr++;
  813. SpecArgs[0] = *PCodePtr++;
  814. SpecArgs[1] = *PCodePtr++;
  815. SpecArgs[2] = *PCodePtr++;
  816. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  817. ACScript->side, ACScript->activator);
  818. return SCRIPT_CONTINUE;
  819. }
  820. static int CmdLSpec4Direct(void)
  821. {
  822. int special;
  823. special = *PCodePtr++;
  824. SpecArgs[0] = *PCodePtr++;
  825. SpecArgs[1] = *PCodePtr++;
  826. SpecArgs[2] = *PCodePtr++;
  827. SpecArgs[3] = *PCodePtr++;
  828. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  829. ACScript->side, ACScript->activator);
  830. return SCRIPT_CONTINUE;
  831. }
  832. static int CmdLSpec5Direct(void)
  833. {
  834. int special;
  835. special = *PCodePtr++;
  836. SpecArgs[0] = *PCodePtr++;
  837. SpecArgs[1] = *PCodePtr++;
  838. SpecArgs[2] = *PCodePtr++;
  839. SpecArgs[3] = *PCodePtr++;
  840. SpecArgs[4] = *PCodePtr++;
  841. P_ExecuteLineSpecial(special, SpecArgs, ACScript->line,
  842. ACScript->side, ACScript->activator);
  843. return SCRIPT_CONTINUE;
  844. }
  845. static int CmdAdd(void)
  846. {
  847. Push(Pop()+Pop());
  848. return SCRIPT_CONTINUE;
  849. }
  850. static int CmdSubtract(void)
  851. {
  852. int operand2;
  853. operand2 = Pop();
  854. Push(Pop()-operand2);
  855. return SCRIPT_CONTINUE;
  856. }
  857. static int CmdMultiply(void)
  858. {
  859. Push(Pop()*Pop());
  860. return SCRIPT_CONTINUE;
  861. }
  862. static int CmdDivide(void)
  863. {
  864. int operand2;
  865. operand2 = Pop();
  866. Push(Pop()/operand2);
  867. return SCRIPT_CONTINUE;
  868. }
  869. static int CmdModulus(void)
  870. {
  871. int operand2;
  872. operand2 = Pop();
  873. Push(Pop()%operand2);
  874. return SCRIPT_CONTINUE;
  875. }
  876. static int CmdEQ(void)
  877. {
  878. Push(Pop() == Pop());
  879. return SCRIPT_CONTINUE;
  880. }
  881. static int CmdNE(void)
  882. {
  883. Push(Pop() != Pop());
  884. return SCRIPT_CONTINUE;
  885. }
  886. static int CmdLT(void)
  887. {
  888. int operand2;
  889. operand2 = Pop();
  890. Push(Pop() < operand2);
  891. return SCRIPT_CONTINUE;
  892. }
  893. static int CmdGT(void)
  894. {
  895. int operand2;
  896. operand2 = Pop();
  897. Push(Pop() > operand2);
  898. return SCRIPT_CONTINUE;
  899. }
  900. static int CmdLE(void)
  901. {
  902. int operand2;
  903. operand2 = Pop();
  904. Push(Pop() <= operand2);
  905. return SCRIPT_CONTINUE;
  906. }
  907. static int CmdGE(void)
  908. {
  909. int operand2;
  910. operand2 = Pop();
  911. Push(Pop() >= operand2);
  912. return SCRIPT_CONTINUE;
  913. }
  914. static int CmdAssignScriptVar(void)
  915. {
  916. ACScript->vars[*PCodePtr++] = Pop();
  917. return SCRIPT_CONTINUE;
  918. }
  919. static int CmdAssignMapVar(void)
  920. {
  921. MapVars[*PCodePtr++] = Pop();
  922. return SCRIPT_CONTINUE;
  923. }
  924. static int CmdAssignWorldVar(void)
  925. {
  926. WorldVars[*PCodePtr++] = Pop();
  927. return SCRIPT_CONTINUE;
  928. }
  929. static int CmdPushScriptVar(void)
  930. {
  931. Push(ACScript->vars[*PCodePtr++]);
  932. return SCRIPT_CONTINUE;
  933. }
  934. static int CmdPushMapVar(void)
  935. {
  936. Push(MapVars[*PCodePtr++]);
  937. return SCRIPT_CONTINUE;
  938. }
  939. static int CmdPushWorldVar(void)
  940. {
  941. Push(WorldVars[*PCodePtr++]);
  942. return SCRIPT_CONTINUE;
  943. }
  944. static int CmdAddScriptVar(void)
  945. {
  946. ACScript->vars[*PCodePtr++] += Pop();
  947. return SCRIPT_CONTINUE;
  948. }
  949. static int CmdAddMapVar(void)
  950. {
  951. MapVars[*PCodePtr++] += Pop();
  952. return SCRIPT_CONTINUE;
  953. }
  954. static int CmdAddWorldVar(void)
  955. {
  956. WorldVars[*PCodePtr++] += Pop();
  957. return SCRIPT_CONTINUE;
  958. }
  959. static int CmdSubScriptVar(void)
  960. {
  961. ACScript->vars[*PCodePtr++] -= Pop();
  962. return SCRIPT_CONTINUE;
  963. }
  964. static int CmdSubMapVar(void)
  965. {
  966. MapVars[*PCodePtr++] -= Pop();
  967. return SCRIPT_CONTINUE;
  968. }
  969. static int CmdSubWorldVar(void)
  970. {
  971. WorldVars[*PCodePtr++] -= Pop();
  972. return SCRIPT_CONTINUE;
  973. }
  974. static int CmdMulScriptVar(void)
  975. {
  976. ACScript->vars[*PCodePtr++] *= Pop();
  977. return SCRIPT_CONTINUE;
  978. }
  979. static int CmdMulMapVar(void)
  980. {
  981. MapVars[*PCodePtr++] *= Pop();
  982. return SCRIPT_CONTINUE;
  983. }
  984. static int CmdMulWorldVar(void)
  985. {
  986. WorldVars[*PCodePtr++] *= Pop();
  987. return SCRIPT_CONTINUE;
  988. }
  989. static int CmdDivScriptVar(void)
  990. {
  991. ACScript->vars[*PCodePtr++] /= Pop();
  992. return SCRIPT_CONTINUE;
  993. }
  994. static int CmdDivMapVar(void)
  995. {
  996. MapVars[*PCodePtr++] /= Pop();
  997. return SCRIPT_CONTINUE;
  998. }
  999. static int CmdDivWorldVar(void)
  1000. {
  1001. WorldVars[*PCodePtr++] /= Pop();
  1002. return SCRIPT_CONTINUE;
  1003. }
  1004. static int CmdModScriptVar(void)
  1005. {
  1006. ACScript->vars[*PCodePtr++] %= Pop();
  1007. return SCRIPT_CONTINUE;
  1008. }
  1009. static int CmdModMapVar(void)
  1010. {
  1011. MapVars[*PCodePtr++] %= Pop();
  1012. return SCRIPT_CONTINUE;
  1013. }
  1014. static int CmdModWorldVar(void)
  1015. {
  1016. WorldVars[*PCodePtr++] %= Pop();
  1017. return SCRIPT_CONTINUE;
  1018. }
  1019. static int CmdIncScriptVar(void)
  1020. {
  1021. ACScript->vars[*PCodePtr++]++;
  1022. return SCRIPT_CONTINUE;
  1023. }
  1024. static int CmdIncMapVar(void)
  1025. {
  1026. MapVars[*PCodePtr++]++;
  1027. return SCRIPT_CONTINUE;
  1028. }
  1029. static int CmdIncWorldVar(void)
  1030. {
  1031. WorldVars[*PCodePtr++]++;
  1032. return SCRIPT_CONTINUE;
  1033. }
  1034. static int CmdDecScriptVar(void)
  1035. {
  1036. ACScript->vars[*PCodePtr++]--;
  1037. return SCRIPT_CONTINUE;
  1038. }
  1039. static int CmdDecMapVar(void)
  1040. {
  1041. MapVars[*PCodePtr++]--;
  1042. return SCRIPT_CONTINUE;
  1043. }
  1044. static int CmdDecWorldVar(void)
  1045. {
  1046. WorldVars[*PCodePtr++]--;
  1047. return SCRIPT_CONTINUE;
  1048. }
  1049. static int CmdGoto(void)
  1050. {
  1051. PCodePtr = (int *)(ActionCodeBase+*PCodePtr);
  1052. return SCRIPT_CONTINUE;
  1053. }
  1054. static int CmdIfGoto(void)
  1055. {
  1056. if(Pop())
  1057. {
  1058. PCodePtr = (int *)(ActionCodeBase+*PCodePtr);
  1059. }
  1060. else
  1061. {
  1062. PCodePtr++;
  1063. }
  1064. return SCRIPT_CONTINUE;
  1065. }
  1066. static int CmdDrop(void)
  1067. {
  1068. Drop();
  1069. return SCRIPT_CONTINUE;
  1070. }
  1071. static int CmdDelay(void)
  1072. {
  1073. ACScript->delayCount = Pop();
  1074. return SCRIPT_STOP;
  1075. }
  1076. static int CmdDelayDirect(void)
  1077. {
  1078. ACScript->delayCount = *PCodePtr++;
  1079. return SCRIPT_STOP;
  1080. }
  1081. static int CmdRandom(void)
  1082. {
  1083. int low;
  1084. int high;
  1085. high = Pop();
  1086. low = Pop();
  1087. Push(low+(P_Random()%(high-low+1)));
  1088. return SCRIPT_CONTINUE;
  1089. }
  1090. static int CmdRandomDirect(void)
  1091. {
  1092. int low;
  1093. int high;
  1094. low = *PCodePtr++;
  1095. high = *PCodePtr++;
  1096. Push(low+(P_Random()%(high-low+1)));
  1097. return SCRIPT_CONTINUE;
  1098. }
  1099. static int CmdThingCount(void)
  1100. {
  1101. int tid;
  1102. tid = Pop();
  1103. ThingCount(Pop(), tid);
  1104. return SCRIPT_CONTINUE;
  1105. }
  1106. static int CmdThingCountDirect(void)
  1107. {
  1108. int type;
  1109. type = *PCodePtr++;
  1110. ThingCount(type, *PCodePtr++);
  1111. return SCRIPT_CONTINUE;
  1112. }
  1113. static void ThingCount(int type, int tid)
  1114. {
  1115. int count;
  1116. int searcher;
  1117. mobj_t *mobj;
  1118. mobjtype_t moType;
  1119. thinker_t *think;
  1120. if(!(type+tid))
  1121. { // Nothing to count
  1122. return;
  1123. }
  1124. moType = TranslateThingType[type];
  1125. count = 0;
  1126. searcher = -1;
  1127. if(tid)
  1128. { // Count TID things
  1129. while((mobj = P_FindMobjFromTID(tid, &searcher)) != NULL)
  1130. {
  1131. if(type == 0)
  1132. { // Just count TIDs
  1133. count++;
  1134. }
  1135. else if(moType == mobj->type)
  1136. {
  1137. if(mobj->flags&MF_COUNTKILL && mobj->health <= 0)
  1138. { // Don't count dead monsters
  1139. continue;
  1140. }
  1141. count++;
  1142. }
  1143. }
  1144. }
  1145. else
  1146. { // Count only types
  1147. for(think = thinkercap.next; think != &thinkercap;
  1148. think = think->next)
  1149. {
  1150. if(think->function != P_MobjThinker)
  1151. { // Not a mobj thinker
  1152. continue;
  1153. }
  1154. mobj = (mobj_t *)think;
  1155. if(mobj->type != moType)
  1156. { // Doesn't match
  1157. continue;
  1158. }
  1159. if(mobj->flags&MF_COUNTKILL && mobj->health <= 0)
  1160. { // Don't count dead monsters
  1161. continue;
  1162. }
  1163. count++;
  1164. }
  1165. }
  1166. Push(count);
  1167. }
  1168. static int CmdTagWait(void)
  1169. {
  1170. ACSInfo[ACScript->infoIndex].waitValue = Pop();
  1171. ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORTAG;
  1172. return SCRIPT_STOP;
  1173. }
  1174. static int CmdTagWaitDirect(void)
  1175. {
  1176. ACSInfo[ACScript->infoIndex].waitValue = *PCodePtr++;
  1177. ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORTAG;
  1178. return SCRIPT_STOP;
  1179. }
  1180. static int CmdPolyWait(void)
  1181. {
  1182. ACSInfo[ACScript->infoIndex].waitValue = Pop();
  1183. ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORPOLY;
  1184. return SCRIPT_STOP;
  1185. }
  1186. static int CmdPolyWaitDirect(void)
  1187. {
  1188. ACSInfo[ACScript->infoIndex].waitValue = *PCodePtr++;
  1189. ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORPOLY;
  1190. return SCRIPT_STOP;
  1191. }
  1192. static int CmdChangeFloor(void)
  1193. {
  1194. int tag;
  1195. int flat;
  1196. int sectorIndex;
  1197. flat = R_FlatNumForName(ACStrings[Pop()]);
  1198. tag = Pop();
  1199. sectorIndex = -1;
  1200. while((sectorIndex = P_FindSectorFromTag(tag, sectorIndex)) >= 0)
  1201. {
  1202. sectors[sectorIndex].floorpic = flat;
  1203. }
  1204. return SCRIPT_CONTINUE;
  1205. }
  1206. static int CmdChangeFloorDirect(void)
  1207. {
  1208. int tag;
  1209. int flat;
  1210. int sectorIndex;
  1211. tag = *PCodePtr++;
  1212. flat = R_FlatNumForName(ACStrings[*PCodePtr++]);
  1213. sectorIndex = -1;
  1214. while((sectorIndex = P_FindSectorFromTag(tag, sectorIndex)) >= 0)
  1215. {
  1216. sectors[sectorIndex].floorpic = flat;
  1217. }
  1218. return SCRIPT_CONTINUE;
  1219. }
  1220. static int CmdChangeCeiling(void)
  1221. {
  1222. int tag;
  1223. int flat;
  1224. int sectorIndex;
  1225. flat = R_FlatNumForName(ACStrings[Pop()]);
  1226. tag = Pop();
  1227. sectorIndex = -1;
  1228. while((sectorIndex = P_FindSectorFromTag(tag, sectorIndex)) >= 0)
  1229. {
  1230. sectors[sectorIndex].ceilingpic = flat;
  1231. }
  1232. return SCRIPT_CONTINUE;
  1233. }
  1234. static int CmdChangeCeilingDirect(void)
  1235. {
  1236. int tag;
  1237. int flat;
  1238. int sectorIndex;
  1239. tag = *PCodePtr++;
  1240. flat = R_FlatNumForName(ACStrings[*PCodePtr++]);
  1241. sectorIndex = -1;
  1242. while((sectorIndex = P_FindSectorFromTag(tag, sectorIndex)) >= 0)
  1243. {
  1244. sectors[sectorIndex].ceilingpic = flat;
  1245. }
  1246. return SCRIPT_CONTINUE;
  1247. }
  1248. static int CmdRestart(void)
  1249. {
  1250. PCodePtr = ACSInfo[ACScript->infoIndex].address;
  1251. return SCRIPT_CONTINUE;
  1252. }
  1253. static int CmdAndLogical(void)
  1254. {
  1255. Push(Pop() && Pop());
  1256. return SCRIPT_CONTINUE;
  1257. }
  1258. static int CmdOrLogical(void)
  1259. {
  1260. Push(Pop() || Pop());
  1261. return SCRIPT_CONTINUE;
  1262. }
  1263. static int CmdAndBitwise(void)
  1264. {
  1265. Push(Pop()&Pop());
  1266. return SCRIPT_CONTINUE;
  1267. }
  1268. static int CmdOrBitwise(void)
  1269. {
  1270. Push(Pop()|Pop());
  1271. return SCRIPT_CONTINUE;
  1272. }
  1273. static int CmdEorBitwise(void)
  1274. {
  1275. Push(Pop()^Pop());
  1276. return SCRIPT_CONTINUE;
  1277. }
  1278. static int CmdNegateLogical(void)
  1279. {
  1280. Push(!Pop());
  1281. return SCRIPT_CONTINUE;
  1282. }
  1283. static int CmdLShift(void)
  1284. {
  1285. int operand2;
  1286. operand2 = Pop();
  1287. Push(Pop()<<operand2);
  1288. return SCRIPT_CONTINUE;
  1289. }
  1290. static int CmdRShift(void)
  1291. {
  1292. int operand2;
  1293. operand2 = Pop();
  1294. Push(Pop()>>operand2);
  1295. return SCRIPT_CONTINUE;
  1296. }
  1297. static int CmdUnaryMinus(void)
  1298. {
  1299. Push(-Pop());
  1300. return SCRIPT_CONTINUE;
  1301. }
  1302. static int CmdIfNotGoto(void)
  1303. {
  1304. if(Pop())
  1305. {
  1306. PCodePtr++;
  1307. }
  1308. else
  1309. {
  1310. PCodePtr = (int *)(ActionCodeBase+*PCodePtr);
  1311. }
  1312. return SCRIPT_CONTINUE;
  1313. }
  1314. static int CmdLineSide(void)
  1315. {
  1316. Push(ACScript->side);
  1317. return SCRIPT_CONTINUE;
  1318. }
  1319. static int CmdScriptWait(void)
  1320. {
  1321. ACSInfo[ACScript->infoIndex].waitValue = Pop();
  1322. ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORSCRIPT;
  1323. return SCRIPT_STOP;
  1324. }
  1325. static int CmdScriptWaitDirect(void)
  1326. {
  1327. ACSInfo[ACScript->infoIndex].waitValue = *PCodePtr++;
  1328. ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORSCRIPT;
  1329. return SCRIPT_STOP;
  1330. }
  1331. static int CmdClearLineSpecial(void)
  1332. {
  1333. if(ACScript->line)
  1334. {
  1335. ACScript->line->special = 0;
  1336. }
  1337. return SCRIPT_CONTINUE;
  1338. }
  1339. static int CmdCaseGoto(void)
  1340. {
  1341. if(Top() == *PCodePtr++)
  1342. {
  1343. PCodePtr = (int *)(ActionCodeBase+*PCodePtr);
  1344. Drop();
  1345. }
  1346. else
  1347. {
  1348. PCodePtr++;
  1349. }
  1350. return SCRIPT_CONTINUE;
  1351. }
  1352. static int CmdBeginPrint(void)
  1353. {
  1354. *PrintBuffer = 0;
  1355. return SCRIPT_CONTINUE;
  1356. }
  1357. static int CmdEndPrint(void)
  1358. {
  1359. player_t *player;
  1360. if(ACScript->activator && ACScript->activator->player)
  1361. {
  1362. player = ACScript->activator->player;
  1363. }
  1364. else
  1365. {
  1366. player = &players[consoleplayer];
  1367. }
  1368. P_SetMessage(player, PrintBuffer, true);
  1369. return SCRIPT_CONTINUE;
  1370. }
  1371. static int CmdEndPrintBold(void)
  1372. {
  1373. int i;
  1374. for(i = 0; i < MAXPLAYERS; i++)
  1375. {
  1376. if(playeringame[i])
  1377. {
  1378. P_SetYellowMessage(&players[i], PrintBuffer, true);
  1379. }
  1380. }
  1381. return SCRIPT_CONTINUE;
  1382. }
  1383. static int CmdPrintString(void)
  1384. {
  1385. strcat(PrintBuffer, ACStrings[Pop()]);
  1386. return SCRIPT_CONTINUE;
  1387. }
  1388. static int CmdPrintNumber(void)
  1389. {
  1390. char tempStr[16];
  1391. sprintf(tempStr, "%d", Pop());
  1392. strcat(PrintBuffer, tempStr);
  1393. return SCRIPT_CONTINUE;
  1394. }
  1395. static int CmdPrintCharacter(void)
  1396. {
  1397. char *bufferEnd;
  1398. bufferEnd = PrintBuffer+strlen(PrintBuffer);
  1399. *bufferEnd++ = Pop();
  1400. *bufferEnd = 0;
  1401. return SCRIPT_CONTINUE;
  1402. }
  1403. static int CmdPlayerCount(void)
  1404. {
  1405. int i;
  1406. int count;
  1407. count = 0;
  1408. for(i = 0; i < MAXPLAYERS; i++)
  1409. {
  1410. count += playeringame[i];
  1411. }
  1412. Push(count);
  1413. return SCRIPT_CONTINUE;
  1414. }
  1415. static int CmdGameType(void)
  1416. {
  1417. int gametype;
  1418. if(netgame == false)
  1419. {
  1420. gametype = GAME_SINGLE_PLAYER;
  1421. }
  1422. else if(deathmatch)
  1423. {
  1424. gametype = GAME_NET_DEATHMATCH;
  1425. }
  1426. else
  1427. {
  1428. gametype = GAME_NET_COOPERATIVE;
  1429. }
  1430. Push(gametype);
  1431. return SCRIPT_CONTINUE;
  1432. }
  1433. static int CmdGameSkill(void)
  1434. {
  1435. Push(gameskill);
  1436. return SCRIPT_CONTINUE;
  1437. }
  1438. static int CmdTimer(void)
  1439. {
  1440. Push(leveltime);
  1441. return SCRIPT_CONTINUE;
  1442. }
  1443. static int CmdSectorSound(void)
  1444. {
  1445. int volume;
  1446. mobj_t *mobj;
  1447. mobj = NULL;
  1448. if(ACScript->line)
  1449. {
  1450. mobj = (mobj_t *)&ACScript->line->frontsector->soundorg;
  1451. }
  1452. volume = Pop();
  1453. S_StartSoundAtVolume(mobj, S_GetSoundID(ACStrings[Pop()]), volume);
  1454. return SCRIPT_CONTINUE;
  1455. }
  1456. static int CmdThingSound(void)
  1457. {
  1458. int tid;
  1459. int sound;
  1460. int volume;
  1461. mobj_t *mobj;
  1462. int searcher;
  1463. volume = Pop();
  1464. sound = S_GetSoundID(ACStrings[Pop()]);
  1465. tid = Pop();
  1466. searcher = -1;
  1467. while((mobj = P_FindMobjFromTID(tid, &searcher)) != NULL)
  1468. {
  1469. S_StartSoundAtVolume(mobj, sound, volume);
  1470. }
  1471. return SCRIPT_CONTINUE;
  1472. }
  1473. static int CmdAmbientSound(void)
  1474. {
  1475. int volume;
  1476. volume = Pop();
  1477. S_StartSoundAtVolume(NULL, S_GetSoundID(ACStrings[Pop()]), volume);
  1478. return SCRIPT_CONTINUE;
  1479. }
  1480. static int CmdSoundSequence(void)
  1481. {
  1482. mobj_t *mobj;
  1483. mobj = NULL;
  1484. if(ACScript->line)
  1485. {
  1486. mobj = (mobj_t *)&ACScript->line->frontsector->soundorg;
  1487. }
  1488. SN_StartSequenceName(mobj, ACStrings[Pop()]);
  1489. return SCRIPT_CONTINUE;
  1490. }
  1491. static int CmdSetLineTexture(void)
  1492. {
  1493. line_t *line;
  1494. int lineTag;
  1495. int side;
  1496. int position;
  1497. int texture;
  1498. int searcher;
  1499. texture = R_TextureNumForName(ACStrings[Pop()]);
  1500. position = Pop();
  1501. side = Pop();
  1502. lineTag = Pop();
  1503. searcher = -1;
  1504. while((line = P_FindLine(lineTag, &searcher)) != NULL)
  1505. {
  1506. if(position == TEXTURE_MIDDLE)
  1507. {
  1508. sides[line->sidenum[side]].midtexture = texture;
  1509. }
  1510. else if(position == TEXTURE_BOTTOM)
  1511. {
  1512. sides[line->sidenum[side]].bottomtexture = texture;
  1513. }
  1514. else
  1515. { // TEXTURE_TOP
  1516. sides[line->sidenum[side]].toptexture = texture;
  1517. }
  1518. }
  1519. return SCRIPT_CONTINUE;
  1520. }
  1521. static int CmdSetLineBlocking(void)
  1522. {
  1523. line_t *line;
  1524. int lineTag;
  1525. boolean blocking;
  1526. int searcher;
  1527. blocking = Pop() ? ML_BLOCKING : 0;
  1528. lineTag = Pop();
  1529. searcher = -1;
  1530. while((line = P_FindLine(lineTag, &searcher)) != NULL)
  1531. {
  1532. line->flags = (line->flags&~ML_BLOCKING)|blocking;
  1533. }
  1534. return SCRIPT_CONTINUE;
  1535. }
  1536. static int CmdSetLineSpecial(void)
  1537. {
  1538. line_t *line;
  1539. int lineTag;
  1540. int special, arg1, arg2, arg3, arg4, arg5;
  1541. int searcher;
  1542. arg5 = Pop();
  1543. arg4 = Pop();
  1544. arg3 = Pop();
  1545. arg2 = Pop();
  1546. arg1 = Pop();
  1547. special = Pop();
  1548. lineTag = Pop();
  1549. searcher = -1;
  1550. while((line = P_FindLine(lineTag, &searcher)) != NULL)
  1551. {
  1552. line->special = special;
  1553. line->arg1 = arg1;
  1554. line->arg2 = arg2;
  1555. line->arg3 = arg3;
  1556. line->arg4 = arg4;
  1557. line->arg5 = arg5;
  1558. }
  1559. return SCRIPT_CONTINUE;
  1560. }