1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * Additional copyright for this file:
8 * Copyright (C) 1994-1998 Revolution Software Ltd.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24
25
26 #include "common/textconsole.h"
27
28 #include "sword2/sword2.h"
29 #include "sword2/defs.h"
30 #include "sword2/header.h"
31 #include "sword2/logic.h"
32
33 namespace Sword2 {
34
sendEvent(uint32 id,uint32 interact_id)35 void Logic::sendEvent(uint32 id, uint32 interact_id) {
36 for (int i = 0; i < ARRAYSIZE(_eventList); i++) {
37 if (_eventList[i].id == id || !_eventList[i].id) {
38 _eventList[i].id = id;
39 _eventList[i].interact_id = interact_id;
40 return;
41 }
42 }
43
44 error("sendEvent() ran out of event slots");
45 }
46
setPlayerActionEvent(uint32 id,uint32 interact_id)47 void Logic::setPlayerActionEvent(uint32 id, uint32 interact_id) {
48 // Full script id of action script number 2
49 sendEvent(id, (interact_id << 16) | 2);
50 }
51
checkEventWaiting()52 int Logic::checkEventWaiting() {
53 for (int i = 0; i < ARRAYSIZE(_eventList); i++) {
54 if (_eventList[i].id == readVar(ID))
55 return 1;
56 }
57
58 return 0;
59 }
60
startEvent()61 void Logic::startEvent() {
62 // call this from stuff like fnWalk
63 // you must follow with a return IR_TERMINATE
64
65 for (int i = 0; i < ARRAYSIZE(_eventList); i++) {
66 if (_eventList[i].id == readVar(ID)) {
67 logicOne(_eventList[i].interact_id);
68 _eventList[i].id = 0;
69 return;
70 }
71 }
72
73 error("startEvent() can't find event for id %d", readVar(ID));
74 }
75
clearEvent(uint32 id)76 void Logic::clearEvent(uint32 id) {
77 for (int i = 0; i < ARRAYSIZE(_eventList); i++) {
78 if (_eventList[i].id == id) {
79 _eventList[i].id = 0;
80 return;
81 }
82 }
83 }
84
killAllIdsEvents(uint32 id)85 void Logic::killAllIdsEvents(uint32 id) {
86 for (int i = 0; i < ARRAYSIZE(_eventList); i++) {
87 if (_eventList[i].id == id)
88 _eventList[i].id = 0;
89 }
90 }
91
92 // For the debugger
93
countEvents()94 uint32 Logic::countEvents() {
95 uint32 count = 0;
96
97 for (int i = 0; i < ARRAYSIZE(_eventList); i++) {
98 if (_eventList[i].id)
99 count++;
100 }
101
102 return count;
103 }
104
105 } // End of namespace Sword2
106