1 //=============================================================================
2 //
3 // Adventure Game Studio (AGS)
4 //
5 // Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
6 // The full list of copyright holders can be found in the Copyright.txt
7 // file, which is part of this source code distribution.
8 //
9 // The AGS source code is provided under the Artistic License 2.0.
10 // A copy of this license can be found in the file License.txt and at
11 // http://www.opensource.org/licenses/artistic-license-2.0.php
12 //
13 //=============================================================================
14 
15 #include "executingscript.h"
16 #include <string.h>
17 #include "debug/debug_log.h"
18 #include "debug/debugger.h"
19 
queue_action(PostScriptAction act,int data,const char * aname)20 int ExecutingScript::queue_action(PostScriptAction act, int data, const char *aname) {
21     if (numPostScriptActions >= MAX_QUEUED_ACTIONS)
22         quitprintf("!%s: Cannot queue action, post-script queue full", aname);
23 
24     if (numPostScriptActions > 0) {
25         // if something that will terminate the room has already
26         // been queued, don't allow a second thing to be queued
27         switch (postScriptActions[numPostScriptActions - 1]) {
28     case ePSANewRoom:
29     case ePSARestoreGame:
30     case ePSARestoreGameDialog:
31     case ePSARunAGSGame:
32     case ePSARestartGame:
33         quitprintf("!%s: Cannot run this command, since there was a %s command already queued to run in \"%s\", line %d",
34             aname, postScriptActionNames[numPostScriptActions - 1],
35             postScriptActionPositions[numPostScriptActions - 1].Section.GetCStr(), postScriptActionPositions[numPostScriptActions - 1].Line);
36         break;
37         // MACPORT FIX 9/6/5: added default clause to remove warning
38     default:
39         break;
40         }
41     }
42 
43     postScriptActions[numPostScriptActions] = act;
44     postScriptActionData[numPostScriptActions] = data;
45     postScriptActionNames[numPostScriptActions] = aname;
46     get_script_position(postScriptActionPositions[numPostScriptActions]);
47     numPostScriptActions++;
48     return numPostScriptActions - 1;
49 }
50 
run_another(const char * namm,ScriptInstType scinst,size_t param_count,const RuntimeScriptValue & p1,const RuntimeScriptValue & p2)51 void ExecutingScript::run_another(const char *namm, ScriptInstType scinst, size_t param_count, const RuntimeScriptValue &p1, const RuntimeScriptValue &p2) {
52     if (numanother < MAX_QUEUED_SCRIPTS)
53         numanother++;
54     else {
55         /*debug_script_warn("Warning: too many scripts to run, ignored %s(%d,%d)",
56         script_run_another[numanother - 1], run_another_p1[numanother - 1],
57         run_another_p2[numanother - 1]);*/
58     }
59     int thisslot = numanother - 1;
60     QueuedScript &script = ScFnQueue[thisslot];
61     script.FnName.SetString(namm, MAX_FUNCTION_NAME_LEN);
62     script.Instance = scinst;
63     script.ParamCount = param_count;
64     script.Param1 = p1;
65     script.Param2 = p2;
66 }
67 
init()68 void ExecutingScript::init() {
69     inst = NULL;
70     forked = 0;
71     numanother = 0;
72     numPostScriptActions = 0;
73 }
74 
ExecutingScript()75 ExecutingScript::ExecutingScript() {
76     init();
77 }
78