42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
+
|
static const char*my_error;
static MessageVars msgvars;
static char lastimage_processing,changed,all_flushed;
static Value vstack[VSTACKSIZE];
static int vstackptr;
static const char*traceprefix;
static Uint8 current_key;
static Value quiz_obj;
#define Throw(x) (my_error=(x),longjmp(my_env,1))
#define StackReq(x,y) do{ if(vstackptr<(x)) Throw("Stack underflow"); if(vstackptr-(x)+(y)>=VSTACKSIZE) Throw("Stack overflow"); }while(0)
#define Push(x) (vstack[vstackptr++]=(x))
#define Pop() (vstack[--vstackptr])
// For arrival/departure masks
|
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
|
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
|
-
+
-
|
Value v;
if(lastobj==VOIDLINK) return;
n=lastobj;
while(o=objects[n]) {
p=o->prev;
if(!c || o->class==c) {
v=send_message(from,n,msg,arg1,arg2,arg3);
if(s>0) {
if(s) {
switch(v.t) {
case TY_NUMBER: t+=v.u; break;
case TY_CLASS: t++; break;
default:
if(v.t<=TY_MAXTYPE) Throw("Invalid return type for BroadcastSum");
t++;
}
} else {
if(s<0) arg2=v;
t++;
}
}
if(p==VOIDLINK) break;
n=p;
}
return t;
|
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
|
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
|
nobjects=0;
free(objects);
objects=0;
gameover=0;
}
const char*execute_turn(int key) {
Uint32 n;
Uint32 m,n;
Value v;
int i;
if(!key) return 0;
if(setjmp(my_env)) return my_error;
changed=0;
key_ignored=0;
all_flushed=0;
lastimage_processing=0;
vstackptr=0;
current_key=key;
for(n=0;n<nobjects;n++) if(objects[n]) {
objects[n]->distance=0;
objects[n]->oflags&=~(OF_KEYCLEARED|OF_DONE);
if(objects[n]->anim) objects[n]->anim->count=0;
}
// Input phase
m=VOIDLINK;
v=NVALUE(0);
if(!quiz_obj.t) {
n=lastobj;
while(n!=VOIDLINK) {
i=classes[objects[n]->class]->cflags;
if(i&CF_INPUT) v=send_message(VOIDLINK,n,MSG_KEY,NVALUE(key),v,NVALUE(0));
if(i&CF_PLAYER) m=n;
n=objects[n]->prev;
}
} else {
n=quiz_obj.u;
if(objects[n]->generation!=quiz_obj.t) n=VOIDLINK;
quiz_obj=NVALUE(0);
//TODO
v=send_message(VOIDLINK,n,MSG_KEY,NVALUE(key),NVALUE(0),NVALUE(1));
}
current_key=0;
if(key_ignored) {
quiz_obj=NVALUE(0);
if(key_ignored) return changed?"Invalid use of IgnoreKey":0;
return changed?"Invalid use of IgnoreKey":0;
}
move_number++;
// Beginning phase
if(!all_flushed) broadcast(m,0,MSG_BEGIN_TURN,m==VOIDLINK?NVALUE(objects[m]->x):NVALUE(0),m==VOIDLINK?NVALUE(objects[m]->y):NVALUE(0),v,0);
if(generation_number<=TY_MAXTYPE) return "Too many generations of objects";
return 0;
}
const char*init_level(void) {
if(setjmp(my_env)) return my_error;
if(main_options['t']) printf("[Level %d restarted]\n",level_id);
memcpy(globals,initglobals,sizeof(globals));
quiz_obj=NVALUE(0);
gameover=0;
changed=0;
key_ignored=0;
all_flushed=0;
lastimage_processing=0;
vstackptr=0;
move_number=0;
current_key=0;
broadcast(VOIDLINK,0,MSG_INIT,NVALUE(0),NVALUE(0),NVALUE(0),0);
broadcast(VOIDLINK,0,MSG_POSTINIT,NVALUE(0),NVALUE(0),NVALUE(0),0);
if(generation_number<=TY_MAXTYPE) return "Too many generations of objects";
return 0;
}
|