Debian Codegraph @

prboom2/src/hexen/p_acs.c

raw
1 //
2 // Copyright(C) 1993-1996 Id Software, Inc.
3 // Copyright(C) 1993-2008 Raven Software
4 // Copyright(C) 2005-2014 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16
17 #include "doomdef.h"
18 #include "doomstat.h"
19 #include "m_misc.h"
20 #include "m_random.h"
21 #include "s_sound.h"
22 #include "sounds.h"
23 #include "w_wad.h"
24 #include "lprintf.h"
25 #include "r_main.h"
26 #include "p_tick.h"
27 #include "p_spec.h"
28 #include "p_inter.h"
29
30 #include "hexen/p_things.h"
31 #include "hexen/po_man.h"
32 #include "hexen/sn_sonix.h"
33
34 #include "dsda/id_list.h"
35 #include "dsda/map_format.h"
36
37 #include "p_acs.h"
38
39 #define MAX_SCRIPT_ARGS 3
40 #define SCRIPT_CONTINUE 0
41 #define SCRIPT_STOP 1
42 #define SCRIPT_TERMINATE 2
43 #define OPEN_SCRIPTS_BASE 1000
44 #define PRINT_BUFFER_SIZE 256
45 #define GAME_SINGLE_PLAYER 0
46 #define GAME_NET_COOPERATIVE 1
47 #define GAME_NET_DEATHMATCH 2
48 #define TEXTURE_TOP 0
49 #define TEXTURE_MIDDLE 1
50 #define TEXTURE_BOTTOM 2
51
52 #ifdef _MSC_VER // proff: This is the same as __attribute__ ((packed)) in GNUC
53 #pragma pack(push)
54 #pragma pack(1)
55 #endif //_MSC_VER
56
57 typedef struct {
58 int marker;
59 int infoOffset;
60 int code;
61 } PACKEDATTR acsHeader_t;
62
63 #ifdef _MSC_VER
64 #pragma pack(pop)
65 #endif //_MSC_VER
66
67 static void StartOpenACS(int number, int infoIndex, int offset);
68 static void ScriptFinished(int number);
69 static dboolean TagBusy(int tag);
70 static dboolean AddToACSStore(int map, int number, byte * args);
71 static int GetACSIndex(int number);
72 static void Push(int value);
73 static int Pop(void);
74 static int Top(void);
75 static void Drop(void);
76
77 static int CmdNOP(void);
78 static int CmdTerminate(void);
79 static int CmdSuspend(void);
80 static int CmdPushNumber(void);
81 static int CmdLSpec1(void);
82 static int CmdLSpec2(void);
83 static int CmdLSpec3(void);
84 static int CmdLSpec4(void);
85 static int CmdLSpec5(void);
86 static int CmdLSpec1Direct(void);
87 static int CmdLSpec2Direct(void);
88 static int CmdLSpec3Direct(void);
89 static int CmdLSpec4Direct(void);
90 static int CmdLSpec5Direct(void);
91 static int CmdAdd(void);
92 static int CmdSubtract(void);
93 static int CmdMultiply(void);
94 static int CmdDivide(void);
95 static int CmdModulus(void);
96 static int CmdEQ(void);
97 static int CmdNE(void);
98 static int CmdLT(void);
99 static int CmdGT(void);
100 static int CmdLE(void);
101 static int CmdGE(void);
102 static int CmdAssignScriptVar(void);
103 static int CmdAssignMapVar(void);
104 static int CmdAssignWorldVar(void);
105 static int CmdPushScriptVar(void);
106 static int CmdPushMapVar(void);
107 static int CmdPushWorldVar(void);
108 static int CmdAddScriptVar(void);
109 static int CmdAddMapVar(void);
110 static int CmdAddWorldVar(void);
111 static int CmdSubScriptVar(void);
112 static int CmdSubMapVar(void);
113 static int CmdSubWorldVar(void);
114 static int CmdMulScriptVar(void);
115 static int CmdMulMapVar(void);
116 static int CmdMulWorldVar(void);
117 static int CmdDivScriptVar(void);
118 static int CmdDivMapVar(void);
119 static int CmdDivWorldVar(void);
120 static int CmdModScriptVar(void);
121 static int CmdModMapVar(void);
122 static int CmdModWorldVar(void);
123 static int CmdIncScriptVar(void);
124 static int CmdIncMapVar(void);
125 static int CmdIncWorldVar(void);
126 static int CmdDecScriptVar(void);
127 static int CmdDecMapVar(void);
128 static int CmdDecWorldVar(void);
129 static int CmdGoto(void);
130 static int CmdIfGoto(void);
131 static int CmdDrop(void);
132 static int CmdDelay(void);
133 static int CmdDelayDirect(void);
134 static int CmdRandom(void);
135 static int CmdRandomDirect(void);
136 static int CmdThingCount(void);
137 static int CmdThingCountDirect(void);
138 static int CmdTagWait(void);
139 static int CmdTagWaitDirect(void);
140 static int CmdPolyWait(void);
141 static int CmdPolyWaitDirect(void);
142 static int CmdChangeFloor(void);
143 static int CmdChangeFloorDirect(void);
144 static int CmdChangeCeiling(void);
145 static int CmdChangeCeilingDirect(void);
146 static int CmdRestart(void);
147 static int CmdAndLogical(void);
148 static int CmdOrLogical(void);
149 static int CmdAndBitwise(void);
150 static int CmdOrBitwise(void);
151 static int CmdEorBitwise(void);
152 static int CmdNegateLogical(void);
153 static int CmdLShift(void);
154 static int CmdRShift(void);
155 static int CmdUnaryMinus(void);
156 static int CmdIfNotGoto(void);
157 static int CmdLineSide(void);
158 static int CmdScriptWait(void);
159 static int CmdScriptWaitDirect(void);
160 static int CmdClearLineSpecial(void);
161 static int CmdCaseGoto(void);
162 static int CmdBeginPrint(void);
163 static int CmdEndPrint(void);
164 static int CmdPrintString(void);
165 static int CmdPrintNumber(void);
166 static int CmdPrintCharacter(void);
167 static int CmdPlayerCount(void);
168 static int CmdGameType(void);
169 static int CmdGameSkill(void);
170 static int CmdTimer(void);
171 static int CmdSectorSound(void);
172 static int CmdAmbientSound(void);
173 static int CmdSoundSequence(void);
174 static int CmdSetLineTexture(void);
175 static int CmdSetLineBlocking(void);
176 static int CmdSetLineSpecial(void);
177 static int CmdThingSound(void);
178 static int CmdEndPrintBold(void);
179
180 static void ThingCount(int type, int tid);
181
182 int ACScriptCount;
183 const byte *ActionCodeBase;
184 static int ActionCodeSize;
185 acsInfo_t *ACSInfo;
186 int MapVars[MAX_ACS_MAP_VARS];
187 int WorldVars[MAX_ACS_WORLD_VARS];
188 acsstore_t ACSStore[MAX_ACS_STORE + 1]; // +1 for termination marker
189
190 static char EvalContext[64];
191 static acs_t *ACScript;
192 static unsigned int PCodeOffset;
193 static int SpecArgs[8];
194 static int ACStringCount;
195 static const char **ACStrings;
196 static char PrintBuffer[PRINT_BUFFER_SIZE];
197 static acs_t *NewScript;
198
199 static int (*PCodeCmds[]) (void) =
200 {
201 CmdNOP,
202 CmdTerminate,
203 CmdSuspend,
204 CmdPushNumber,
205 CmdLSpec1,
206 CmdLSpec2,
207 CmdLSpec3,
208 CmdLSpec4,
209 CmdLSpec5,
210 CmdLSpec1Direct,
211 CmdLSpec2Direct,
212 CmdLSpec3Direct,
213 CmdLSpec4Direct,
214 CmdLSpec5Direct,
215 CmdAdd,
216 CmdSubtract,
217 CmdMultiply,
218 CmdDivide,
219 CmdModulus,
220 CmdEQ,
221 CmdNE,
222 CmdLT,
223 CmdGT,
224 CmdLE,
225 CmdGE,
226 CmdAssignScriptVar,
227 CmdAssignMapVar,
228 CmdAssignWorldVar,
229 CmdPushScriptVar,
230 CmdPushMapVar,
231 CmdPushWorldVar,
232 CmdAddScriptVar,
233 CmdAddMapVar,
234 CmdAddWorldVar,
235 CmdSubScriptVar,
236 CmdSubMapVar,
237 CmdSubWorldVar,
238 CmdMulScriptVar,
239 CmdMulMapVar,
240 CmdMulWorldVar,
241 CmdDivScriptVar,
242 CmdDivMapVar,
243 CmdDivWorldVar,
244 CmdModScriptVar,
245 CmdModMapVar,
246 CmdModWorldVar,
247 CmdIncScriptVar,
248 CmdIncMapVar,
249 CmdIncWorldVar,
250 CmdDecScriptVar,
251 CmdDecMapVar,
252 CmdDecWorldVar,
253 CmdGoto,
254 CmdIfGoto,
255 CmdDrop,
256 CmdDelay,
257 CmdDelayDirect,
258 CmdRandom,
259 CmdRandomDirect,
260 CmdThingCount,
261 CmdThingCountDirect,
262 CmdTagWait,
263 CmdTagWaitDirect,
264 CmdPolyWait,
265 CmdPolyWaitDirect,
266 CmdChangeFloor,
267 CmdChangeFloorDirect,
268 CmdChangeCeiling,
269 CmdChangeCeilingDirect,
270 CmdRestart,
271 CmdAndLogical,
272 CmdOrLogical,
273 CmdAndBitwise,
274 CmdOrBitwise,
275 CmdEorBitwise,
276 CmdNegateLogical,
277 CmdLShift,
278 CmdRShift,
279 CmdUnaryMinus,
280 CmdIfNotGoto,
281 CmdLineSide,
282 CmdScriptWait,
283 CmdScriptWaitDirect,
284 CmdClearLineSpecial,
285 CmdCaseGoto,
286 CmdBeginPrint,
287 CmdEndPrint,
288 CmdPrintString,
289 CmdPrintNumber,
290 CmdPrintCharacter,
291 CmdPlayerCount,
292 CmdGameType,
293 CmdGameSkill,
294 CmdTimer,
295 CmdSectorSound,
296 CmdAmbientSound,
297 CmdSoundSequence,
298 CmdSetLineTexture,
299 CmdSetLineBlocking,
300 CmdSetLineSpecial,
301 CmdThingSound,
302 CmdEndPrintBold,
303 };
304
305 static void ACSAssert(int condition, const char *fmt, ...)
306 {
307 char buf[128];
308 va_list args;
309
310 if (condition)
311 {
312 return;
313 }
314
315 va_start(args, fmt);
316 vsnprintf(buf, sizeof(buf), fmt, args);
317 va_end(args);
318 I_Error("ACS assertion failure: in %s: %s", EvalContext, buf);
319 }
320
321 static int ReadCodeInt(void)
322 {
323 int result;
324 const int *ptr;
325
326 ACSAssert(PCodeOffset + 3 < ActionCodeSize,
327 "unexpectedly reached end of ACS lump");
328
329 ptr = (const int *) (ActionCodeBase + PCodeOffset);
330 result = LittleLong(*ptr);
331 PCodeOffset += 4;
332
333 return result;
334 }
335
336 static int ReadScriptVar(void)
337 {
338 int var = ReadCodeInt();
339 ACSAssert(var >= 0, "negative script variable: %d < 0", var);
340 ACSAssert(var < MAX_ACS_SCRIPT_VARS,
341 "invalid script variable: %d >= %d", var, MAX_ACS_SCRIPT_VARS);
342 return var;
343 }
344
345 static int ReadMapVar(void)
346 {
347 int var = ReadCodeInt();
348 ACSAssert(var >= 0, "negative map variable: %d < 0", var);
349 ACSAssert(var < MAX_ACS_MAP_VARS,
350 "invalid map variable: %d >= %d", var, MAX_ACS_MAP_VARS);
351 return var;
352 }
353
354 static int ReadWorldVar(void)
355 {
356 int var = ReadCodeInt();
357 ACSAssert(var >= 0, "negative world variable: %d < 0", var);
358 ACSAssert(var < MAX_ACS_WORLD_VARS,
359 "invalid world variable: %d >= %d", var, MAX_ACS_WORLD_VARS);
360 return var;
361 }
362
363 static const char *StringLookup(int string_index)
364 {
365 ACSAssert(string_index >= 0,
366 "negative string index: %d < 0", string_index);
367 ACSAssert(string_index < ACStringCount,
368 "invalid string index: %d >= %d", string_index, ACStringCount);
369 return ACStrings[string_index];
370 }
371
372 static int ReadOffset(void)
373 {
374 int offset = ReadCodeInt();
375 ACSAssert(offset >= 0, "negative lump offset %d", offset);
376 ACSAssert(offset < ActionCodeSize, "invalid lump offset: %d >= %d",
377 offset, ActionCodeSize);
378 return offset;
379 }
380
381 void P_LoadACScripts(int lump)
382 {
383 int i, offset;
384 const acsHeader_t *header;
385 acsInfo_t *info;
386
387 ActionCodeBase = W_LumpByNum(lump);
388 ActionCodeSize = W_LumpLength(lump);
389
390 snprintf(EvalContext, sizeof(EvalContext), "header parsing of lump #%d", lump);
391
392 header = (const acsHeader_t *) ActionCodeBase;
393 PCodeOffset = LittleLong(header->infoOffset);
394
395 ACScriptCount = ReadCodeInt();
396
397 if (ACScriptCount == 0)
398 { // Empty behavior lump
399 return;
400 }
401
402 ACSInfo = Z_MallocLevel(ACScriptCount * sizeof(acsInfo_t));
403 memset(ACSInfo, 0, ACScriptCount * sizeof(acsInfo_t));
404 for (i = 0, info = ACSInfo; i < ACScriptCount; i++, info++)
405 {
406 info->number = ReadCodeInt();
407 info->offset = ReadOffset();
408 info->argCount = ReadCodeInt();
409
410 if (info->argCount > MAX_SCRIPT_ARGS)
411 {
412 fprintf(stderr, "Warning: ACS script #%i has %i arguments, more "
413 "than the maximum of %i. Enforcing limit.\n"
414 "If you are seeing this message, please report "
415 "the name of the WAD where you saw it.\n",
416 i, info->argCount, MAX_SCRIPT_ARGS);
417 info->argCount = MAX_SCRIPT_ARGS;
418 }
419
420 if (info->number >= OPEN_SCRIPTS_BASE)
421 { // Auto-activate
422 info->number -= OPEN_SCRIPTS_BASE;
423 StartOpenACS(info->number, i, info->offset);
424 info->state = ASTE_RUNNING;
425 }
426 else
427 {
428 info->state = ASTE_INACTIVE;
429 }
430 }
431
432 ACStringCount = ReadCodeInt();
433 ACSAssert(ACStringCount >= 0, "negative string count %d", ACStringCount);
434 ACStrings = Z_MallocLevel(ACStringCount * sizeof(char *));
435
436 for (i=0; i<ACStringCount; ++i)
437 {
438 offset = ReadOffset();
439 ACStrings[i] = (const char *) ActionCodeBase + offset;
440 ACSAssert(memchr(ACStrings[i], '\0', ActionCodeSize - offset) != NULL,
441 "string %d missing terminating NUL", i);
442 }
443
444 memset(MapVars, 0, sizeof(MapVars));
445 }
446
447 static void StartOpenACS(int number, int infoIndex, int offset)
448 {
449 acs_t *script;
450
451 script = Z_MallocLevel(sizeof(acs_t));
452 memset(script, 0, sizeof(acs_t));
453 script->number = number;
454
455 // World objects are allotted 1 second for initialization
456 script->delayCount = 35;
457
458 script->infoIndex = infoIndex;
459 script->ip = offset;
460 script->thinker.function = T_InterpretACS;
461 P_AddThinker(&script->thinker);
462 }
463
464 void P_CheckACSStore(void)
465 {
466 acsstore_t *store;
467
468 for (store = ACSStore; store->map != 0; store++)
469 {
470 if (store->map == gamemap)
471 {
472 P_StartACS(store->script, 0, store->args, NULL, NULL, 0);
473 if (NewScript)
474 {
475 NewScript->delayCount = 35;
476 }
477 store->map = -1;
478 }
479 }
480 }
481
482 static char ErrorMsg[128];
483
484 dboolean P_StartACS(int number, int map, byte * args, mobj_t * activator,
485 line_t * line, int side)
486 {
487 int i;
488 acs_t *script;
489 int infoIndex;
490 aste_t *statePtr;
491
492 NewScript = NULL;
493 if (map && map != gamemap)
494 { // Add to the script store
495 return AddToACSStore(map, number, args);
496 }
497 infoIndex = GetACSIndex(number);
498 if (infoIndex == -1)
499 { // Script not found
500 //I_Error("P_StartACS: Unknown script number %d", number);
501 snprintf(ErrorMsg, sizeof(ErrorMsg), "P_STARTACS ERROR: UNKNOWN SCRIPT %d", number);
502 P_SetMessage(&players[consoleplayer], ErrorMsg, true);
503 }
504 statePtr = &ACSInfo[infoIndex].state;
505 if (*statePtr == ASTE_SUSPENDED)
506 { // Resume a suspended script
507 *statePtr = ASTE_RUNNING;
508 return true;
509 }
510 if (*statePtr != ASTE_INACTIVE)
511 { // Script is already executing
512 return false;
513 }
514 script = Z_MallocLevel(sizeof(acs_t));
515 memset(script, 0, sizeof(acs_t));
516 script->number = number;
517 script->infoIndex = infoIndex;
518 P_SetTarget(&script->activator, activator);
519 script->line = line;
520 script->side = side;
521 script->ip = ACSInfo[infoIndex].offset;
522 script->thinker.function = T_InterpretACS;
523 for (i = 0; i < MAX_SCRIPT_ARGS && i < ACSInfo[infoIndex].argCount; i++)
524 {
525 script->vars[i] = args[i];
526 }
527 *statePtr = ASTE_RUNNING;
528 P_AddThinker(&script->thinker);
529 NewScript = script;
530 return true;
531 }
532
533 static dboolean AddToACSStore(int map, int number, byte * args)
534 {
535 int i;
536 int index;
537
538 index = -1;
539 for (i = 0; ACSStore[i].map != 0; i++)
540 {
541 if (ACSStore[i].script == number && ACSStore[i].map == map)
542 { // Don't allow duplicates
543 return false;
544 }
545 if (index == -1 && ACSStore[i].map == -1)
546 { // Remember first empty slot
547 index = i;
548 }
549 }
550 if (index == -1)
551 { // Append required
552 if (i == MAX_ACS_STORE)
553 {
554 I_Error("AddToACSStore: MAX_ACS_STORE (%d) exceeded.",
555 MAX_ACS_STORE);
556 }
557 index = i;
558 ACSStore[index + 1].map = 0;
559 }
560 ACSStore[index].map = map;
561 ACSStore[index].script = number;
562 memcpy(ACSStore[index].args, args, MAX_SCRIPT_ARGS);
563 return true;
564 }
565
566 dboolean P_StartLockedACS(line_t * line, byte * args, mobj_t * mo, int side)
567 {
568 int i;
569 int lock;
570 byte newArgs[5];
571
572 extern char *TextKeyMessages[11];
573 extern char LockedBuffer[80];
574
575 lock = args[4];
576 if (!mo->player)
577 {
578 return false;
579 }
580 if (lock)
581 {
582 if (!mo->player->cards[lock - 1])
583 {
584 snprintf(LockedBuffer, sizeof(LockedBuffer),
585 "YOU NEED THE %s\n", TextKeyMessages[lock - 1]);
586 P_SetMessage(mo->player, LockedBuffer, true);
587 S_StartMobjSound(mo, hexen_sfx_door_locked);
588 return false;
589 }
590 }
591 for (i = 0; i < 4; i++)
592 {
593 newArgs[i] = args[i];
594 }
595 newArgs[4] = 0;
596 return P_StartACS(newArgs[0], newArgs[1], &newArgs[2], mo, line, side);
597 }
598
599 dboolean P_TerminateACS(int number, int map)
600 {
601 int infoIndex;
602
603 infoIndex = GetACSIndex(number);
604 if (infoIndex == -1)
605 { // Script not found
606 return false;
607 }
608 if (ACSInfo[infoIndex].state == ASTE_INACTIVE
609 || ACSInfo[infoIndex].state == ASTE_TERMINATING)
610 { // States that disallow termination
611 return false;
612 }
613 ACSInfo[infoIndex].state = ASTE_TERMINATING;
614 return true;
615 }
616
617 dboolean P_SuspendACS(int number, int map)
618 {
619 int infoIndex;
620
621 infoIndex = GetACSIndex(number);
622 if (infoIndex == -1)
623 { // Script not found
624 return false;
625 }
626 if (ACSInfo[infoIndex].state == ASTE_INACTIVE
627 || ACSInfo[infoIndex].state == ASTE_SUSPENDED
628 || ACSInfo[infoIndex].state == ASTE_TERMINATING)
629 { // States that disallow suspension
630 return false;
631 }
632 ACSInfo[infoIndex].state = ASTE_SUSPENDED;
633 return true;
634 }
635
636 void P_ACSInitNewGame(void)
637 {
638 memset(WorldVars, 0, sizeof(WorldVars));
639 memset(ACSStore, 0, sizeof(ACSStore));
640 }
641
642 void T_InterpretACS(acs_t * script)
643 {
644 int cmd;
645 int action;
646
647 if (ACSInfo[script->infoIndex].state == ASTE_TERMINATING)
648 {
649 ACSInfo[script->infoIndex].state = ASTE_INACTIVE;
650 ScriptFinished(ACScript->number);
651 P_RemoveThinker(&ACScript->thinker);
652 return;
653 }
654 if (ACSInfo[script->infoIndex].state != ASTE_RUNNING)
655 {
656 return;
657 }
658 if (script->delayCount)
659 {
660 script->delayCount--;
661 return;
662 }
663 ACScript = script;
664 PCodeOffset = ACScript->ip;
665
666 do
667 {
668 snprintf(EvalContext, sizeof(EvalContext), "script %d @0x%x",
669 ACSInfo[script->infoIndex].number, PCodeOffset);
670 cmd = ReadCodeInt();
671 snprintf(EvalContext, sizeof(EvalContext), "script %d @0x%x, cmd=%d",
672 ACSInfo[script->infoIndex].number, PCodeOffset, cmd);
673 ACSAssert(cmd >= 0, "negative ACS instruction %d", cmd);
674 ACSAssert(cmd < arrlen(PCodeCmds),
675 "invalid ACS instruction %d (maybe this WAD is designed "
676 "for an advanced source port and is not vanilla "
677 "compatible)", cmd);
678 action = PCodeCmds[cmd]();
679 } while (action == SCRIPT_CONTINUE);
680
681 ACScript->ip = PCodeOffset;
682
683 if (action == SCRIPT_TERMINATE)
684 {
685 ACSInfo[script->infoIndex].state = ASTE_INACTIVE;
686 ScriptFinished(ACScript->number);
687 P_RemoveThinker(&ACScript->thinker);
688 }
689 }
690
691 void P_TagFinished(int tag)
692 {
693 int i;
694
695 if (!map_format.acs) return;
696
697 if (TagBusy(tag) == true)
698 {
699 return;
700 }
701 for (i = 0; i < ACScriptCount; i++)
702 {
703 if (ACSInfo[i].state == ASTE_WAITINGFORTAG
704 && ACSInfo[i].waitValue == tag)
705 {
706 ACSInfo[i].state = ASTE_RUNNING;
707 }
708 }
709 }
710
711 void P_PolyobjFinished(int po)
712 {
713 int i;
714
715 if (PO_Busy(po) == true)
716 {
717 return;
718 }
719 for (i = 0; i < ACScriptCount; i++)
720 {
721 if (ACSInfo[i].state == ASTE_WAITINGFORPOLY
722 && ACSInfo[i].waitValue == po)
723 {
724 ACSInfo[i].state = ASTE_RUNNING;
725 }
726 }
727 }
728
729 static void ScriptFinished(int number)
730 {
731 int i;
732
733 for (i = 0; i < ACScriptCount; i++)
734 {
735 if (ACSInfo[i].state == ASTE_WAITINGFORSCRIPT
736 && ACSInfo[i].waitValue == number)
737 {
738 ACSInfo[i].state = ASTE_RUNNING;
739 }
740 }
741 }
742
743 static dboolean TagBusy(int tag)
744 {
745 const int *id_p;
746
747 FIND_SECTORS(id_p, tag)
748 {
749 if (sectors[*id_p].floordata || sectors[*id_p].ceilingdata)
750 {
751 return true;
752 }
753 }
754 return false;
755 }
756
757 static int GetACSIndex(int number)
758 {
759 int i;
760
761 for (i = 0; i < ACScriptCount; i++)
762 {
763 if (ACSInfo[i].number == number)
764 {
765 return i;
766 }
767 }
768 return -1;
769 }
770
771 void CheckACSPresent(int number)
772 {
773 if (GetACSIndex(number) == -1)
774 {
775 I_Error("Required ACS script %d not initialized", number);
776 }
777 }
778
779 static void Push(int value)
780 {
781 ACSAssert(ACScript->stackPtr < ACS_STACK_DEPTH,
782 "maximum stack depth exceeded: %d >= %d",
783 ACScript->stackPtr, ACS_STACK_DEPTH);
784 ACScript->stack[ACScript->stackPtr++] = value;
785 }
786
787 static int Pop(void)
788 {
789 ACSAssert(ACScript->stackPtr > 0, "pop of empty stack");
790 return ACScript->stack[--ACScript->stackPtr];
791 }
792
793 static int Top(void)
794 {
795 ACSAssert(ACScript->stackPtr > 0, "read from top of empty stack");
796 return ACScript->stack[ACScript->stackPtr - 1];
797 }
798
799 static void Drop(void)
800 {
801 ACSAssert(ACScript->stackPtr > 0, "drop on empty stack");
802 ACScript->stackPtr--;
803 }
804
805 static int CmdNOP(void)
806 {
807 return SCRIPT_CONTINUE;
808 }
809
810 static int CmdTerminate(void)
811 {
812 return SCRIPT_TERMINATE;
813 }
814
815 static int CmdSuspend(void)
816 {
817 ACSInfo[ACScript->infoIndex].state = ASTE_SUSPENDED;
818 return SCRIPT_STOP;
819 }
820
821 static int CmdPushNumber(void)
822 {
823 Push(ReadCodeInt());
824 return SCRIPT_CONTINUE;
825 }
826
827 static int CmdLSpec1(void)
828 {
829 int special;
830
831 special = ReadCodeInt();
832 SpecArgs[0] = Pop();
833 map_format.execute_line_special(special, SpecArgs, ACScript->line,
834 ACScript->side, ACScript->activator);
835 return SCRIPT_CONTINUE;
836 }
837
838 static int CmdLSpec2(void)
839 {
840 int special;
841
842 special = ReadCodeInt();
843 SpecArgs[1] = Pop();
844 SpecArgs[0] = Pop();
845 map_format.execute_line_special(special, SpecArgs, ACScript->line,
846 ACScript->side, ACScript->activator);
847 return SCRIPT_CONTINUE;
848 }
849
850 static int CmdLSpec3(void)
851 {
852 int special;
853
854 special = ReadCodeInt();
855 SpecArgs[2] = Pop();
856 SpecArgs[1] = Pop();
857 SpecArgs[0] = Pop();
858 map_format.execute_line_special(special, SpecArgs, ACScript->line,
859 ACScript->side, ACScript->activator);
860 return SCRIPT_CONTINUE;
861 }
862
863 static int CmdLSpec4(void)
864 {
865 int special;
866
867 special = ReadCodeInt();
868 SpecArgs[3] = Pop();
869 SpecArgs[2] = Pop();
870 SpecArgs[1] = Pop();
871 SpecArgs[0] = Pop();
872 map_format.execute_line_special(special, SpecArgs, ACScript->line,
873 ACScript->side, ACScript->activator);
874 return SCRIPT_CONTINUE;
875 }
876
877 static int CmdLSpec5(void)
878 {
879 int special;
880
881 special = ReadCodeInt();
882 SpecArgs[4] = Pop();
883 SpecArgs[3] = Pop();
884 SpecArgs[2] = Pop();
885 SpecArgs[1] = Pop();
886 SpecArgs[0] = Pop();
887 map_format.execute_line_special(special, SpecArgs, ACScript->line,
888 ACScript->side, ACScript->activator);
889 return SCRIPT_CONTINUE;
890 }
891
892 static int CmdLSpec1Direct(void)
893 {
894 int special;
895
896 special = ReadCodeInt();
897 SpecArgs[0] = ReadCodeInt();
898 map_format.execute_line_special(special, SpecArgs, ACScript->line,
899 ACScript->side, ACScript->activator);
900 return SCRIPT_CONTINUE;
901 }
902
903 static int CmdLSpec2Direct(void)
904 {
905 int special;
906
907 special = ReadCodeInt();
908 SpecArgs[0] = ReadCodeInt();
909 SpecArgs[1] = ReadCodeInt();
910 map_format.execute_line_special(special, SpecArgs, ACScript->line,
911 ACScript->side, ACScript->activator);
912 return SCRIPT_CONTINUE;
913 }
914
915 static int CmdLSpec3Direct(void)
916 {
917 int special;
918
919 special = ReadCodeInt();
920 SpecArgs[0] = ReadCodeInt();
921 SpecArgs[1] = ReadCodeInt();
922 SpecArgs[2] = ReadCodeInt();
923 map_format.execute_line_special(special, SpecArgs, ACScript->line,
924 ACScript->side, ACScript->activator);
925 return SCRIPT_CONTINUE;
926 }
927
928 static int CmdLSpec4Direct(void)
929 {
930 int special;
931
932 special = ReadCodeInt();
933 SpecArgs[0] = ReadCodeInt();
934 SpecArgs[1] = ReadCodeInt();
935 SpecArgs[2] = ReadCodeInt();
936 SpecArgs[3] = ReadCodeInt();
937 map_format.execute_line_special(special, SpecArgs, ACScript->line,
938 ACScript->side, ACScript->activator);
939 return SCRIPT_CONTINUE;
940 }
941
942 static int CmdLSpec5Direct(void)
943 {
944 int special;
945
946 special = ReadCodeInt();
947 SpecArgs[0] = ReadCodeInt();
948 SpecArgs[1] = ReadCodeInt();
949 SpecArgs[2] = ReadCodeInt();
950 SpecArgs[3] = ReadCodeInt();
951 SpecArgs[4] = ReadCodeInt();
952 map_format.execute_line_special(special, SpecArgs, ACScript->line,
953 ACScript->side, ACScript->activator);
954 return SCRIPT_CONTINUE;
955 }
956
957 static int CmdAdd(void)
958 {
959 Push(Pop() + Pop());
960 return SCRIPT_CONTINUE;
961 }
962
963 static int CmdSubtract(void)
964 {
965 int operand2;
966
967 operand2 = Pop();
968 Push(Pop() - operand2);
969 return SCRIPT_CONTINUE;
970 }
971
972 static int CmdMultiply(void)
973 {
974 Push(Pop() * Pop());
975 return SCRIPT_CONTINUE;
976 }
977
978 static int CmdDivide(void)
979 {
980 int operand2;
981
982 operand2 = Pop();
983 Push(Pop() / operand2);
984 return SCRIPT_CONTINUE;
985 }
986
987 static int CmdModulus(void)
988 {
989 int operand2;
990
991 operand2 = Pop();
992 Push(Pop() % operand2);
993 return SCRIPT_CONTINUE;
994 }
995
996 static int CmdEQ(void)
997 {
998 Push(Pop() == Pop());
999 return SCRIPT_CONTINUE;
1000 }
1001
1002 static int CmdNE(void)
1003 {
1004 Push(Pop() != Pop());
1005 return SCRIPT_CONTINUE;
1006 }
1007
1008 static int CmdLT(void)
1009 {
1010 int operand2;
1011
1012 operand2 = Pop();
1013 Push(Pop() < operand2);
1014 return SCRIPT_CONTINUE;
1015 }
1016
1017 static int CmdGT(void)
1018 {
1019 int operand2;
1020
1021 operand2 = Pop();
1022 Push(Pop() > operand2);
1023 return SCRIPT_CONTINUE;
1024 }
1025
1026 static int CmdLE(void)
1027 {
1028 int operand2;
1029
1030 operand2 = Pop();
1031 Push(Pop() <= operand2);
1032 return SCRIPT_CONTINUE;
1033 }
1034
1035 static int CmdGE(void)
1036 {
1037 int operand2;
1038
1039 operand2 = Pop();
1040 Push(Pop() >= operand2);
1041 return SCRIPT_CONTINUE;
1042 }
1043
1044 static int CmdAssignScriptVar(void)
1045 {
1046 ACScript->vars[ReadScriptVar()] = Pop();
1047 return SCRIPT_CONTINUE;
1048 }
1049
1050 static int CmdAssignMapVar(void)
1051 {
1052 MapVars[ReadMapVar()] = Pop();
1053 return SCRIPT_CONTINUE;
1054 }
1055
1056 static int CmdAssignWorldVar(void)
1057 {
1058 WorldVars[ReadWorldVar()] = Pop();
1059 return SCRIPT_CONTINUE;
1060 }
1061
1062 static int CmdPushScriptVar(void)
1063 {
1064 Push(ACScript->vars[ReadScriptVar()]);
1065 return SCRIPT_CONTINUE;
1066 }
1067
1068 static int CmdPushMapVar(void)
1069 {
1070 Push(MapVars[ReadMapVar()]);
1071 return SCRIPT_CONTINUE;
1072 }
1073
1074 static int CmdPushWorldVar(void)
1075 {
1076 Push(WorldVars[ReadWorldVar()]);
1077 return SCRIPT_CONTINUE;
1078 }
1079
1080 static int CmdAddScriptVar(void)
1081 {
1082 ACScript->vars[ReadScriptVar()] += Pop();
1083 return SCRIPT_CONTINUE;
1084 }
1085
1086 static int CmdAddMapVar(void)
1087 {
1088 MapVars[ReadMapVar()] += Pop();
1089 return SCRIPT_CONTINUE;
1090 }
1091
1092 static int CmdAddWorldVar(void)
1093 {
1094 WorldVars[ReadWorldVar()] += Pop();
1095 return SCRIPT_CONTINUE;
1096 }
1097
1098 static int CmdSubScriptVar(void)
1099 {
1100 ACScript->vars[ReadScriptVar()] -= Pop();
1101 return SCRIPT_CONTINUE;
1102 }
1103
1104 static int CmdSubMapVar(void)
1105 {
1106 MapVars[ReadMapVar()] -= Pop();
1107 return SCRIPT_CONTINUE;
1108 }
1109
1110 static int CmdSubWorldVar(void)
1111 {
1112 WorldVars[ReadWorldVar()] -= Pop();
1113 return SCRIPT_CONTINUE;
1114 }
1115
1116 static int CmdMulScriptVar(void)
1117 {
1118 ACScript->vars[ReadScriptVar()] *= Pop();
1119 return SCRIPT_CONTINUE;
1120 }
1121
1122 static int CmdMulMapVar(void)
1123 {
1124 MapVars[ReadMapVar()] *= Pop();
1125 return SCRIPT_CONTINUE;
1126 }
1127
1128 static int CmdMulWorldVar(void)
1129 {
1130 WorldVars[ReadWorldVar()] *= Pop();
1131 return SCRIPT_CONTINUE;
1132 }
1133
1134 static int CmdDivScriptVar(void)
1135 {
1136 ACScript->vars[ReadScriptVar()] /= Pop();
1137 return SCRIPT_CONTINUE;
1138 }
1139
1140 static int CmdDivMapVar(void)
1141 {
1142 MapVars[ReadMapVar()] /= Pop();
1143 return SCRIPT_CONTINUE;
1144 }
1145
1146 static int CmdDivWorldVar(void)
1147 {
1148 WorldVars[ReadWorldVar()] /= Pop();
1149 return SCRIPT_CONTINUE;
1150 }
1151
1152 static int CmdModScriptVar(void)
1153 {
1154 ACScript->vars[ReadScriptVar()] %= Pop();
1155 return SCRIPT_CONTINUE;
1156 }
1157
1158 static int CmdModMapVar(void)
1159 {
1160 MapVars[ReadMapVar()] %= Pop();
1161 return SCRIPT_CONTINUE;
1162 }
1163
1164 static int CmdModWorldVar(void)
1165 {
1166 WorldVars[ReadWorldVar()] %= Pop();
1167 return SCRIPT_CONTINUE;
1168 }
1169
1170 static int CmdIncScriptVar(void)
1171 {
1172 ++ACScript->vars[ReadScriptVar()];
1173 return SCRIPT_CONTINUE;
1174 }
1175
1176 static int CmdIncMapVar(void)
1177 {
1178 ++MapVars[ReadMapVar()];
1179 return SCRIPT_CONTINUE;
1180 }
1181
1182 static int CmdIncWorldVar(void)
1183 {
1184 ++WorldVars[ReadWorldVar()];
1185 return SCRIPT_CONTINUE;
1186 }
1187
1188 static int CmdDecScriptVar(void)
1189 {
1190 --ACScript->vars[ReadScriptVar()];
1191 return SCRIPT_CONTINUE;
1192 }
1193
1194 static int CmdDecMapVar(void)
1195 {
1196 --MapVars[ReadMapVar()];
1197 return SCRIPT_CONTINUE;
1198 }
1199
1200 static int CmdDecWorldVar(void)
1201 {
1202 --WorldVars[ReadWorldVar()];
1203 return SCRIPT_CONTINUE;
1204 }
1205
1206 static int CmdGoto(void)
1207 {
1208 PCodeOffset = ReadOffset();
1209 return SCRIPT_CONTINUE;
1210 }
1211
1212 static int CmdIfGoto(void)
1213 {
1214 int offset;
1215
1216 offset = ReadOffset();
1217
1218 if (Pop() != 0)
1219 {
1220 PCodeOffset = offset;
1221 }
1222 return SCRIPT_CONTINUE;
1223 }
1224
1225 static int CmdDrop(void)
1226 {
1227 Drop();
1228 return SCRIPT_CONTINUE;
1229 }
1230
1231 static int CmdDelay(void)
1232 {
1233 ACScript->delayCount = Pop();
1234 return SCRIPT_STOP;
1235 }
1236
1237 static int CmdDelayDirect(void)
1238 {
1239 ACScript->delayCount = ReadCodeInt();
1240 return SCRIPT_STOP;
1241 }
1242
1243 static int CmdRandom(void)
1244 {
1245 int low;
1246 int high;
1247
1248 high = Pop();
1249 low = Pop();
1250 Push(low + (P_Random(pr_hexen) % (high - low + 1)));
1251 return SCRIPT_CONTINUE;
1252 }
1253
1254 static int CmdRandomDirect(void)
1255 {
1256 int low;
1257 int high;
1258
1259 low = ReadCodeInt();
1260 high = ReadCodeInt();
1261 Push(low + (P_Random(pr_hexen) % (high - low + 1)));
1262 return SCRIPT_CONTINUE;
1263 }
1264
1265 static int CmdThingCount(void)
1266 {
1267 int tid;
1268
1269 tid = Pop();
1270 ThingCount(Pop(), tid);
1271 return SCRIPT_CONTINUE;
1272 }
1273
1274 static int CmdThingCountDirect(void)
1275 {
1276 int type;
1277
1278 type = ReadCodeInt();
1279 ThingCount(type, ReadCodeInt());
1280 return SCRIPT_CONTINUE;
1281 }
1282
1283 static void ThingCount(int type, int tid)
1284 {
1285 int count;
1286 int searcher;
1287 mobj_t *mobj;
1288 mobjtype_t moType;
1289 thinker_t *think;
1290
1291 if (!(type + tid))
1292 { // Nothing to count
1293 return;
1294 }
1295 moType = TranslateThingType[type];
1296 count = 0;
1297 searcher = -1;
1298 if (tid)
1299 { // Count TID things
1300 while ((mobj = P_FindMobjFromTID(tid, &searcher)) != NULL)
1301 {
1302 if (type == 0)
1303 { // Just count TIDs
1304 count++;
1305 }
1306 else if (moType == mobj->type)
1307 {
1308 if (mobj->flags & MF_COUNTKILL && mobj->health <= 0)
1309 { // Don't count dead monsters
1310 continue;
1311 }
1312 count++;
1313 }
1314 }
1315 }
1316 else
1317 { // Count only types
1318 for (think = thinkercap.next; think != &thinkercap;
1319 think = think->next)
1320 {
1321 if (think->function != P_MobjThinker)
1322 { // Not a mobj thinker
1323 continue;
1324 }
1325 mobj = (mobj_t *) think;
1326 if (mobj->type != moType)
1327 { // Doesn't match
1328 continue;
1329 }
1330 if (mobj->flags & MF_COUNTKILL && mobj->health <= 0)
1331 { // Don't count dead monsters
1332 continue;
1333 }
1334 count++;
1335 }
1336 }
1337 Push(count);
1338 }
1339
1340 static int CmdTagWait(void)
1341 {
1342 ACSInfo[ACScript->infoIndex].waitValue = Pop();
1343 ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORTAG;
1344 return SCRIPT_STOP;
1345 }
1346
1347 static int CmdTagWaitDirect(void)
1348 {
1349 ACSInfo[ACScript->infoIndex].waitValue = ReadCodeInt();
1350 ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORTAG;
1351 return SCRIPT_STOP;
1352 }
1353
1354 static int CmdPolyWait(void)
1355 {
1356 ACSInfo[ACScript->infoIndex].waitValue = Pop();
1357 ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORPOLY;
1358 return SCRIPT_STOP;
1359 }
1360
1361 static int CmdPolyWaitDirect(void)
1362 {
1363 ACSInfo[ACScript->infoIndex].waitValue = ReadCodeInt();
1364 ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORPOLY;
1365 return SCRIPT_STOP;
1366 }
1367
1368 static int CmdChangeFloor(void)
1369 {
1370 int tag;
1371 int flat;
1372 const int *id_p;
1373
1374 flat = R_FlatNumForName(StringLookup(Pop()));
1375 tag = Pop();
1376 FIND_SECTORS(id_p, tag)
1377 {
1378 sectors[*id_p].floorpic = flat;
1379 }
1380 return SCRIPT_CONTINUE;
1381 }
1382
1383 static int CmdChangeFloorDirect(void)
1384 {
1385 int tag;
1386 int flat;
1387 const int *id_p;
1388
1389 tag = ReadCodeInt();
1390 flat = R_FlatNumForName(StringLookup(ReadCodeInt()));
1391 FIND_SECTORS(id_p, tag)
1392 {
1393 sectors[*id_p].floorpic = flat;
1394 }
1395 return SCRIPT_CONTINUE;
1396 }
1397
1398 static int CmdChangeCeiling(void)
1399 {
1400 int tag;
1401 int flat;
1402 const int *id_p;
1403
1404 flat = R_FlatNumForName(StringLookup(Pop()));
1405 tag = Pop();
1406 FIND_SECTORS(id_p, tag)
1407 {
1408 sectors[*id_p].ceilingpic = flat;
1409 }
1410 return SCRIPT_CONTINUE;
1411 }
1412
1413 static int CmdChangeCeilingDirect(void)
1414 {
1415 int tag;
1416 int flat;
1417 const int *id_p;
1418
1419 tag = ReadCodeInt();
1420 flat = R_FlatNumForName(StringLookup(ReadCodeInt()));
1421 FIND_SECTORS(id_p, tag)
1422 {
1423 sectors[*id_p].ceilingpic = flat;
1424 }
1425 return SCRIPT_CONTINUE;
1426 }
1427
1428 static int CmdRestart(void)
1429 {
1430 PCodeOffset = ACSInfo[ACScript->infoIndex].offset;
1431 return SCRIPT_CONTINUE;
1432 }
1433
1434 static int CmdAndLogical(void)
1435 {
1436 Push(Pop() && Pop());
1437 return SCRIPT_CONTINUE;
1438 }
1439
1440 static int CmdOrLogical(void)
1441 {
1442 Push(Pop() || Pop());
1443 return SCRIPT_CONTINUE;
1444 }
1445
1446 static int CmdAndBitwise(void)
1447 {
1448 Push(Pop() & Pop());
1449 return SCRIPT_CONTINUE;
1450 }
1451
1452 static int CmdOrBitwise(void)
1453 {
1454 Push(Pop() | Pop());
1455 return SCRIPT_CONTINUE;
1456 }
1457
1458 static int CmdEorBitwise(void)
1459 {
1460 Push(Pop() ^ Pop());
1461 return SCRIPT_CONTINUE;
1462 }
1463
1464 static int CmdNegateLogical(void)
1465 {
1466 Push(!Pop());
1467 return SCRIPT_CONTINUE;
1468 }
1469
1470 static int CmdLShift(void)
1471 {
1472 int operand2;
1473
1474 operand2 = Pop();
1475 Push(Pop() << operand2);
1476 return SCRIPT_CONTINUE;
1477 }
1478
1479 static int CmdRShift(void)
1480 {
1481 int operand2;
1482
1483 operand2 = Pop();
1484 Push(Pop() >> operand2);
1485 return SCRIPT_CONTINUE;
1486 }
1487
1488 static int CmdUnaryMinus(void)
1489 {
1490 Push(-Pop());
1491 return SCRIPT_CONTINUE;
1492 }
1493
1494 static int CmdIfNotGoto(void)
1495 {
1496 int offset;
1497
1498 offset = ReadOffset();
1499
1500 if (Pop() == 0)
1501 {
1502 PCodeOffset = offset;
1503 }
1504 return SCRIPT_CONTINUE;
1505 }
1506
1507 static int CmdLineSide(void)
1508 {
1509 Push(ACScript->side);
1510 return SCRIPT_CONTINUE;
1511 }
1512
1513 static int CmdScriptWait(void)
1514 {
1515 ACSInfo[ACScript->infoIndex].waitValue = Pop();
1516 ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORSCRIPT;
1517 return SCRIPT_STOP;
1518 }
1519
1520 static int CmdScriptWaitDirect(void)
1521 {
1522 ACSInfo[ACScript->infoIndex].waitValue = ReadCodeInt();
1523 ACSInfo[ACScript->infoIndex].state = ASTE_WAITINGFORSCRIPT;
1524 return SCRIPT_STOP;
1525 }
1526
1527 static int CmdClearLineSpecial(void)
1528 {
1529 if (ACScript->line)
1530 {
1531 ACScript->line->special = 0;
1532 }
1533 return SCRIPT_CONTINUE;
1534 }
1535
1536 static int CmdCaseGoto(void)
1537 {
1538 int value;
1539 int offset;
1540
1541 value = ReadCodeInt();
1542 offset = ReadOffset();
1543
1544 if (Top() == value)
1545 {
1546 PCodeOffset = offset;
1547 Drop();
1548 }
1549
1550 return SCRIPT_CONTINUE;
1551 }
1552
1553 static int CmdBeginPrint(void)
1554 {
1555 *PrintBuffer = 0;
1556 return SCRIPT_CONTINUE;
1557 }
1558
1559 static int CmdEndPrint(void)
1560 {
1561 player_t *player;
1562
1563 if (ACScript->activator && ACScript->activator->player)
1564 {
1565 player = ACScript->activator->player;
1566 }
1567 else
1568 {
1569 player = &players[consoleplayer];
1570 }
1571 P_SetMessage(player, PrintBuffer, true);
1572 return SCRIPT_CONTINUE;
1573 }
1574
1575 static int CmdEndPrintBold(void)
1576 {
1577 int i;
1578
1579 for (i = 0; i < g_maxplayers; i++)
1580 {
1581 if (playeringame[i])
1582 {
1583 P_SetYellowMessage(&players[i], PrintBuffer, true);
1584 }
1585 }
1586 return SCRIPT_CONTINUE;
1587 }
1588
1589 static int CmdPrintString(void)
1590 {
1591 M_StringConcat(PrintBuffer, StringLookup(Pop()), sizeof(PrintBuffer));
1592 return SCRIPT_CONTINUE;
1593 }
1594
1595 static int CmdPrintNumber(void)
1596 {
1597 char tempStr[16];
1598
1599 snprintf(tempStr, sizeof(tempStr), "%d", Pop());
1600 M_StringConcat(PrintBuffer, tempStr, sizeof(PrintBuffer));
1601 return SCRIPT_CONTINUE;
1602 }
1603
1604 static int CmdPrintCharacter(void)
1605 {
1606 char tempStr[2];
1607
1608 tempStr[0] = Pop();
1609 tempStr[1] = '\0';
1610 M_StringConcat(PrintBuffer, tempStr, sizeof(PrintBuffer));
1611
1612 return SCRIPT_CONTINUE;
1613 }
1614
1615 static int CmdPlayerCount(void)
1616 {
1617 int i;
1618 int count;
1619
1620 count = 0;
1621 for (i = 0; i < g_maxplayers; i++)
1622 {
1623 count += playeringame[i];
1624 }
1625 Push(count);
1626 return SCRIPT_CONTINUE;
1627 }
1628
1629 static int CmdGameType(void)
1630 {
1631 int gametype;
1632
1633 if (netgame == false)
1634 {
1635 gametype = GAME_SINGLE_PLAYER;
1636 }
1637 else if (deathmatch)
1638 {
1639 gametype = GAME_NET_DEATHMATCH;
1640 }
1641 else
1642 {
1643 gametype = GAME_NET_COOPERATIVE;
1644 }
1645 Push(gametype);
1646 return SCRIPT_CONTINUE;
1647 }
1648
1649 static int CmdGameSkill(void)
1650 {
1651 Push(gameskill);
1652 return SCRIPT_CONTINUE;
1653 }
1654
1655 static int CmdTimer(void)
1656 {
1657 Push(leveltime);
1658 return SCRIPT_CONTINUE;
1659 }
1660
1661 static int CmdSectorSound(void)
1662 {
1663 int volume;
1664 mobj_t *mobj;
1665
1666 mobj = NULL;
1667 if (ACScript->line)
1668 {
1669 mobj = (mobj_t *) & ACScript->line->frontsector->soundorg;
1670 }
1671 volume = Pop();
1672 S_StartSoundAtVolume(mobj, S_GetSoundID(StringLookup(Pop())), volume, 0);
1673 return SCRIPT_CONTINUE;
1674 }
1675
1676 static int CmdThingSound(void)
1677 {
1678 int tid;
1679 int sound;
1680 int volume;
1681 mobj_t *mobj;
1682 int searcher;
1683
1684 volume = Pop();
1685 sound = S_GetSoundID(StringLookup(Pop()));
1686 tid = Pop();
1687 searcher = -1;
1688 while ((mobj = P_FindMobjFromTID(tid, &searcher)) != NULL)
1689 {
1690 S_StartSoundAtVolume(mobj, sound, volume, 0);
1691 }
1692 return SCRIPT_CONTINUE;
1693 }
1694
1695 static int CmdAmbientSound(void)
1696 {
1697 int volume;
1698
1699 volume = Pop();
1700 S_StartSoundAtVolume(NULL, S_GetSoundID(StringLookup(Pop())), volume, 0);
1701 return SCRIPT_CONTINUE;
1702 }
1703
1704 static int CmdSoundSequence(void)
1705 {
1706 mobj_t *mobj;
1707
1708 mobj = NULL;
1709 if (ACScript->line)
1710 {
1711 mobj = (mobj_t *) & ACScript->line->frontsector->soundorg;
1712 }
1713 SN_StartSequenceName(mobj, StringLookup(Pop()));
1714 return SCRIPT_CONTINUE;
1715 }
1716
1717 static int CmdSetLineTexture(void)
1718 {
1719 line_t *line;
1720 int lineTag;
1721 int side;
1722 int position;
1723 int texture;
1724 int searcher;
1725
1726 texture = R_TextureNumForName(StringLookup(Pop()));
1727 position = Pop();
1728 side = Pop();
1729 lineTag = Pop();
1730 searcher = -1;
1731 while ((line = P_FindLine(lineTag, &searcher)) != NULL)
1732 {
1733 if (position == TEXTURE_MIDDLE)
1734 {
1735 sides[line->sidenum[side]].midtexture = texture;
1736 }
1737 else if (position == TEXTURE_BOTTOM)
1738 {
1739 sides[line->sidenum[side]].bottomtexture = texture;
1740 }
1741 else
1742 { // TEXTURE_TOP
1743 sides[line->sidenum[side]].toptexture = texture;
1744 }
1745 }
1746 return SCRIPT_CONTINUE;
1747 }
1748
1749 static int CmdSetLineBlocking(void)
1750 {
1751 line_t *line;
1752 int lineTag;
1753 dboolean blocking;
1754 int searcher;
1755
1756 blocking = Pop()? ML_BLOCKING : 0;
1757 lineTag = Pop();
1758 searcher = -1;
1759 while ((line = P_FindLine(lineTag, &searcher)) != NULL)
1760 {
1761 line->flags = (line->flags & ~ML_BLOCKING) | blocking;
1762 }
1763 return SCRIPT_CONTINUE;
1764 }
1765
1766 static int CmdSetLineSpecial(void)
1767 {
1768 line_t *line;
1769 int lineTag;
1770 int special, arg1, arg2, arg3, arg4, arg5;
1771 int searcher;
1772
1773 arg5 = Pop();
1774 arg4 = Pop();
1775 arg3 = Pop();
1776 arg2 = Pop();
1777 arg1 = Pop();
1778 special = Pop();
1779 lineTag = Pop();
1780 searcher = -1;
1781 while ((line = P_FindLine(lineTag, &searcher)) != NULL)
1782 {
1783 line->special = special;
1784 line->special_args[0] = arg1;
1785 line->special_args[1] = arg2;
1786 line->special_args[2] = arg3;
1787 line->special_args[3] = arg4;
1788 line->special_args[4] = arg5;
1789 }
1790 return SCRIPT_CONTINUE;
1791 }