14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"
#include "quarks.h"
#include "cursorshapes.h"
#include "names.h"
static volatile Uint8 timerflag;
static int exam_scroll;
static Uint8*inputs;
static int inputs_size,inputs_count;
static void redraw_game(void) {
char buf[32];
|
>
>
>
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"
#include "quarks.h"
#include "cursorshapes.h"
#include "names.h"
Uint8*replay_list;
Uint16 replay_size,replay_count,replay_pos,replay_mark;
static volatile Uint8 timerflag;
static int exam_scroll;
static Uint8*inputs;
static int inputs_size,inputs_count;
static void redraw_game(void) {
char buf[32];
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
draw_text(0,40,buf,0xF0,0xF1);
SDL_UnlockSurface(screen);
SDL_Flip(screen);
}
static void begin_level(int id) {
const char*t;
free(inputs);
inputs=0;
inputs_size=inputs_count=0;
t=load_level(id)?:init_level();
if(t) {
gameover=-1;
screen_message(t);
} else {
gameover=0;
}
|
<
|
|
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
draw_text(0,40,buf,0xF0,0xF1);
SDL_UnlockSurface(screen);
SDL_Flip(screen);
}
static void begin_level(int id) {
const char*t;
inputs_count=0;
replay_pos=0;
t=load_level(id)?:init_level();
if(t) {
gameover=-1;
screen_message(t);
} else {
gameover=0;
}
|
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
if(xy<0 || xy>=64*64) return;
n=playfield[xy];
if(n==VOIDLINK) return;
while(n!=VOIDLINK && objects[n]->up!=VOIDLINK) n=objects[n]->up;
if(!classes[objects[n]->class]->gamehelp) return;
s=sqlite3_mprintf("\x0C\x0E%s:%d\\ %s\x0B\x0F%s",classes[objects[n]->class]->name,objects[n]->image,classes[objects[n]->class]->name,classes[objects[n]->class]->gamehelp);
if(!s) fatal("Allocation failed\n");
modal_draw_popup(s);
sqlite3_free(s);
}
static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
switch(cmd) {
case '\' ': // Play a move
if(inputs_count>=inputs_size) {
inputs=realloc(inputs,inputs_size+=32);
if(!inputs) fatal("Allocation failed\n");
}
inputs[inputs_count++]=number;
return 0;
case '^E': // Edit
return -2;
case '^Q': // Quit
return -1;
case '^T': // Show title
modal_draw_popup(level_title);
return prev;
|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
if(xy<0 || xy>=64*64) return;
n=playfield[xy];
if(n==VOIDLINK) return;
while(n!=VOIDLINK && objects[n]->up!=VOIDLINK) n=objects[n]->up;
if(!classes[objects[n]->class]->gamehelp) return;
s=sqlite3_mprintf("\x0C\x0E%s:%d\\ %s\x0B\x0F%s",classes[objects[n]->class]->name,objects[n]->image,classes[objects[n]->class]->name,classes[objects[n]->class]->gamehelp);
if(!s) fatal("Allocation failed\n");
modal_draw_popup(s);
sqlite3_free(s);
}
static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
switch(cmd) {
case '\' ': // Play a move
if(inputs_count>=inputs_size) {
inputs=realloc(inputs,inputs_size+=32);
if(!inputs) fatal("Allocation failed\n");
}
inputs[inputs_count++]=number;
return 0;
case '+ ': // Replay
if(number>replay_count-replay_pos) number=replay_count-replay_pos;
if(inputs_count+number>=inputs_size) {
inputs=realloc(inputs,inputs_size+=number+1);
if(!inputs) fatal("Allocation failed\n");
}
memcpy(inputs+inputs_count,replay_list+replay_pos,number);
inputs_count+=number;
return 0;
case '- ': // Rewind
number=replay_pos-number;
if(number<0) number=0;
//fallthru
case '= ': // Restart
begin_level(level_id);
if(!number) return 1;
if(number>replay_count) number=replay_count;
if(number>=inputs_size) {
inputs=realloc(inputs,inputs_size=number+1);
if(!inputs) fatal("Allocation failed\n");
}
memcpy(inputs,replay_list,inputs_count=number);
return 1;
case '^E': // Edit
return -2;
case '^Q': // Quit
return -1;
case '^T': // Show title
modal_draw_popup(level_title);
return prev;
|
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
|
}
timerflag=1;
return n;
}
static inline void input_move(Uint8 k) {
const char*t=execute_turn(k);
if(t) {
screen_message(t);
gameover=-1;
return;
}
//TODO: Record this move, if applicable
}
void run_game(void) {
int i;
SDL_Event ev;
set_caption();
begin_level(level_id);
|
>
|
>
>
>
>
>
>
>
|
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
}
timerflag=1;
return n;
}
static inline void input_move(Uint8 k) {
const char*t=execute_turn(k);
if(replay_pos==65534 && !gameover) t="Too many moves played";
if(t) {
screen_message(t);
gameover=-1;
return;
}
if(!key_ignored) {
if(replay_pos>=replay_size) {
replay_list=realloc(replay_list,replay_size+=0x200);
if(!replay_list) fatal("Allocation failed\n");
}
replay_list[replay_pos++]=k;
if(replay_pos>replay_count) replay_count=replay_pos;
}
}
void run_game(void) {
int i;
SDL_Event ev;
set_caption();
begin_level(level_id);
|