1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "glk/alan3/location.h"
#include "glk/alan3/instance.h"
#include "glk/alan3/options.h"
#include "glk/alan3/word.h"
#include "glk/alan3/inter.h"
#include "glk/alan3/glkio.h"
#include "glk/alan3/lists.h"
#include "glk/alan3/checkentry.h"
#include "glk/alan3/debug.h"
#include "glk/alan3/memory.h"
#include "glk/alan3/dictionary.h"
#include "glk/alan3/output.h"
#include "glk/alan3/msg.h"
#include "glk/alan3/current.h"
namespace Glk {
namespace Alan3 {
/*----------------------------------------------------------------------*/
static void traceExit(CONTEXT, int location, int dir, const char *what) {
printf("\n<EXIT %s[%d] from ",
(char *)pointerTo(dictionary[playerWords[currentWordIndex - 1].code].string), dir);
CALL1(traceSay, location)
printf("[%d], %s:>\n", location, what);
}
/*======================================================================*/
void go(CONTEXT, int location, int dir) {
ExitEntry *theExit;
bool ok;
Aword oldloc;
theExit = (ExitEntry *) pointerTo(instances[location].exits);
if (instances[location].exits != 0) {
while (!isEndOfArray(theExit)) {
if (theExit->code == (uint)dir) {
ok = TRUE;
if (theExit->checks != 0) {
if (traceSectionOption)
CALL3(traceExit, location, dir, "Checking")
FUNC2(checksFailed, ok, theExit->checks, EXECUTE_CHECK_BODY_ON_FAIL)
ok = !ok;
}
if (ok) {
oldloc = location;
if (theExit->action != 0) {
if (traceSectionOption)
CALL3(traceExit, location, dir, "Executing")
CALL1(interpret, theExit->action)
}
/* Still at the same place? */
if (where(HERO, TRANSITIVE) == (int)oldloc) {
if (traceSectionOption)
CALL3(traceExit, location, dir, "Moving")
CALL2(locate, HERO, theExit->target)
}
return;
} else {
CALL1(error, NO_MSG)
}
}
theExit++;
}
}
CALL1(error, M_NO_WAY)
}
/*======================================================================*/
bool exitto(int to, int from) {
ExitEntry *theExit;
if (instances[from].exits == 0)
return FALSE; /* No exits */
for (theExit = (ExitEntry *) pointerTo(instances[from].exits); !isEndOfArray(theExit); theExit++)
if (theExit->target == (uint)to)
return TRUE;
return FALSE;
}
/*======================================================================*/
void look(CONTEXT) {
uint i;
/* Set describe flag for all objects and actors */
for (i = 1; i <= header->instanceMax; i++)
admin[i].alreadyDescribed = FALSE;
if (anyOutput)
para();
setSubHeaderStyle();
CALL1(sayInstance, current.location)
setNormalStyle();
newline();
capitalize = TRUE;
if (describe(context, current.location) && !context._break)
describeInstances(context);
}
} // End of namespace Alan3
} // End of namespace Glk
|