Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [d2afebc6be]:

To Artifact [05d4b7dc52]:


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
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







+
+
+
+
+




















+
+
+








int encode_move(FILE*fp,MoveItem v) {
  // Encodes a single move and writes the encoded move to the file.
  // Returns the number of bytes of the encoded move.
  if(v>=8 && v<256) {
    fputc(v,fp);
    return 1;
  } else if(v>=0x8000 && v<=0x8FFF) {
    fputc(KEY_XY,fp);
    fputc(((v>>6)&63)+1,fp);
    fputc((v&63)+1,fp);
    return 3;
  } else {
    fatal("Unencodable move (%u)\n",(int)v);
  }
}

int encode_move_list(FILE*fp) {
  // Encodes the current replay list into the file; returns the number of bytes.
  // Does not write a null terminator.
  int i;
  int c=0;
  for(i=0;i<replay_count;i++) c+=encode_move(fp,replay_list[i]);
  return c;
}

MoveItem decode_move(FILE*fp) {
  // Decodes a single move from the file, and returns the move.
  // Returns zero if there is no more moves.
  int v=fgetc(fp);
  if(v>=8 && v<256) {
    return v;
  } else if(v==KEY_XY) {
    v=0x8000|((fgetc(fp)-1)<<6);
    return v|(fgetc(fp)-1);
  } else if(v==EOF || !v) {
    return 0;
  } else {
    fatal("Undecodable move (%u)\n",v);
  }
}

204
205
206
207
208
209
210
211










212
213
214
215
216
217
218
212
213
214
215
216
217
218

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235







-
+
+
+
+
+
+
+
+
+
+







    snprintf(buf,8,"%5d",replay_pos);
    draw_text(8,52,buf,0xF0,0xF9);
    snprintf(buf,8,"%5d",replay_count);
    draw_text(8,screen->h-8,buf,0xF0,solution_replay?0xFA:0xFC);
    for(y=44,x=replay_pos-(screen->h-68)/32;;x++) {
      y+=16;
      if(y+24>screen->h) break;
      if(x>=0 && x<replay_count) draw_key(16,y,replay_list[x],0xF8,0xFB);
      if(x>=0 && x<replay_count) {
        if(replay_list[x]<256) {
          draw_key(16,y,replay_list[x],0xF8,0xFB);
        } else if((replay_list[x]&0xF000)==0x8000) {
          sprintf(buf,"%02u",((replay_list[x]>>6)&63)+1);
          draw_text(16,y,buf,0xF8,0x47);
          sprintf(buf,"%02u",(replay_list[x]&63)+1);
          draw_text(16,y+8,buf,0xF8,0x45);
        }
      }
      if(x==replay_count) draw_key(16,y,1,0xF0,0xF8);
      if(x==replay_pos) draw_text(0,y,inserting?"I~":"~~",0xF0,0xFE);
      if(x==replay_mark) draw_text(32,y,"~~",0xF0,0xFD);
    }
    SDL_UnlockSurface(screen);
  }
  if(quiz_text) draw_popup(quiz_text);
1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1229
1230
1231
1232
1233
1234
1235

1236
1237
1238
1239
1240
1241
1242
1243







-
+







  sqlite3_finalize(st);
  if(i==1) begin_level(mo&8?-sel-divmin:~sel);
  return i;
}

static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  switch(cmd) {
    case '\' ': // Play a move
    case '\' ': play: // Play a move
      if(replay_time) {
        replay_time=0;
        return -3;
      }
      if(solution_replay) {
        screen_message("You cannot play your own moves during the solution replay");
        return -3;
1348
1349
1350
1351
1352
1353
1354







1355
1356
1357
1358
1359
1360
1361
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385







+
+
+
+
+
+
+







      do_export_moves(sqlite3_column_text(args,1));
      return 0;
    case 'rs': // Replay speed
      number+=replay_speed;
      if(number<1) number=1; else if(number>255) number=255;
      replay_speed=number;
      return prev;
    case 'xy': // Coordinate input
      if(argc<3 || !has_xy_input) break;
      argc=sqlite3_column_int(args,1);
      number=sqlite3_column_int(args,2);
      if(argc<1 || argc>pfwidth || number<1 || number>pfheight) return 0;
      number=(number-1)|((argc-1)<<6)|0x8000;
      goto play;
    default:
      return prev;
  }
}

static void do_autowin(void) {
  const char*name;
1422
1423
1424
1425
1426
1427
1428
1429

1430
1431
1432
1433
1434
1435
1436
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1460







-
+







    static SDL_Event ev={SDL_USEREVENT};
    SDL_PushEvent(&ev);
  }
  timerflag=1;
  return n;
}

static inline void input_move(Uint8 k) {
static inline void input_move(MoveItem k) {
  const char*t=execute_turn(k);
  if(replay_pos>0xFFFE && !gameover) t="Too many moves played";
  if(t) {
    screen_message(t);
    gameover=-1;
    return;
  }