Free Hero Mesh

Check-in [169561bd42]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement -O switch to output private solutions on stdout.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 169561bd42b31b5eecf7b595d4ba67f53f9ef1c2
User & Date: user on 2022-07-02 16:14:27
Other Links: manifest | tags
Context
2022-07-04
05:43
Implement crushing (similar to pieces being crushed in ZZT if they cannot be pushed). check-in: 08e7014805 user: user tags: trunk
2022-07-02
16:14
Implement -O switch to output private solutions on stdout. check-in: 169561bd42 user: user tags: trunk
2022-07-01
21:09
Change MoveItem to Uint16 and fix the encoders/decoders for future use (only numbers 8 to 255 are currently in use). check-in: 1aadd6299e user: user tags: trunk
Changes

Modified commandline.doc from [ba85a74445] to [0d7234c266].

17
18
19
20
21
22
23



24
25
26
27
28
29
30

-L
  Display all tokens being read from the class definition file.

-M
  Write details of macro expansion to stdout.




-T
  Mode for testing some internal functions of Free Hero Mesh and SDL. You
  probably do not need to use this mode yourself.

-U
  Enable unstable/experimental features. These features may change in
  future and may later be made not needing this switch; but for now you







>
>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

-L
  Display all tokens being read from the class definition file.

-M
  Write details of macro expansion to stdout.

-O
  Write a solution Hamster archive with private solutions to stdout.

-T
  Mode for testing some internal functions of Free Hero Mesh and SDL. You
  probably do not need to use this mode yourself.

-U
  Enable unstable/experimental features. These features may change in
  future and may later be made not needing this switch; but for now you

Modified game.c from [d17a145787] to [d822424b13].

1681
1682
1683
1684
1685
1686
1687








































1688
1689
1690
1691
1692
1693
1694
      rc=1; continue;
    }
    printf(": OK\n");
    cont: ;
  }
  exit(rc);
}









































void locate_me(int x,int y) {
  Uint8 c=7;
  SDL_Rect r,rh,rv;
  SDL_Event ev;
  if(!screen) return;
  redraw_game();







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
      rc=1; continue;
    }
    printf(": OK\n");
    cont: ;
  }
  exit(rc);
}

void export_private_solutions(void) {
  int rc=0;
  const char*t;
  int i0,i1,i2,i,j,n;
  unsigned char*data;
  long sz;
  for(n=1;n<=level_nindex;n++) {
    level_id=level_index[n-1];
    data=read_userstate(FIL_LEVEL,level_id,&sz);
    if(!data) continue;
    if(!sz || *data) {
      free(data);
      continue;
    }
    i0=i1=i2=0;
    for(i=1;i<sz;) {
      if(data[i]==0x02 && i+2<=sz) i0=i+1;
      else if(data[i]==0x41 && i+3<=sz) i1=i+1;
      else if(data[i]==0x81 && i+5<=sz) i2=i+1;
      if(data[i]<0x40) i+=strnlen(data+i,sz-i)+1;
      else if(data[i]<0x80) i+=3;
      else if(data[i]<0xC0) i+=5;
      else i+=9;
    }
    if(i0 && i1) {
      i=strnlen(data+i0,sz-i0);
      printf("%d.SOL",level_id);
      putchar(0); // null terminator of lump name
      j=i+(i2?7:3);
      putchar(j>>16); putchar(j>>24); putchar(j); putchar(j>>8); // lump data size
      putchar(data[i1]); putchar(data[i1+1]); // level version
      putchar(i2?0x80:0x00); // flag
      if(i2) fwrite(data+i2,1,4,stdout); // score
      fwrite(data+i0,1,i,stdout); // move list
    }
    free(data);
  }
  exit(rc);
}

void locate_me(int x,int y) {
  Uint8 c=7;
  SDL_Rect r,rh,rv;
  SDL_Event ev;
  if(!screen) return;
  redraw_game();

Modified heromesh.h from [bd543a863e] to [73a29c9f38].

332
333
334
335
336
337
338

339
340
341
342
343
344
345
int encode_move(FILE*fp,MoveItem v);
int encode_move_list(FILE*fp);
MoveItem decode_move(FILE*fp);
int decode_move_list(FILE*fp);

void run_game(void);
void run_auto_test(void);

void locate_me(int x,int y);

// == edit ==

typedef struct {
  Uint8 x0,y0,x1,y1;
} EditorRect;







>







332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
int encode_move(FILE*fp,MoveItem v);
int encode_move_list(FILE*fp);
MoveItem decode_move(FILE*fp);
int decode_move_list(FILE*fp);

void run_game(void);
void run_auto_test(void);
void export_private_solutions(void);
void locate_me(int x,int y);

// == edit ==

typedef struct {
  Uint8 x0,y0,x1,y1;
} EditorRect;

Modified main.c from [f8cd0b8bae] to [90be19d7e2].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#if 0
gcc ${CFLAGS:--s -O2} -o ${EXE:-~/bin/heromesh} -Wno-multichar main.c class.o picture.o bindings.o function.o exec.o game.o edit.o picedit.o sound.o smallxrm.o hash.o sqlite3.o `sdl-config --cflags --libs` -ldl -lpthread -lm
exit
#endif

/*
  This program is part of Free Hero Mesh and is public domain.
*/

//#define _GNU_SOURCE
#define HEROMESH_MAIN
#include "SDL.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>









<







1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
#if 0
gcc ${CFLAGS:--s -O2} -o ${EXE:-~/bin/heromesh} -Wno-multichar main.c class.o picture.o bindings.o function.o exec.o game.o edit.o picedit.o sound.o smallxrm.o hash.o sqlite3.o `sdl-config --cflags --libs` -ldl -lpthread -lm
exit
#endif

/*
  This program is part of Free Hero Mesh and is public domain.
*/


#define HEROMESH_MAIN
#include "SDL.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
    main_options['r']=1;
  }
  if(main_options['n'] && main_options['i']) fatal("Switches -n and -i are conflicting\n");
  if(main_options['n'] || main_options['i']) {
    if(main_options['r']) fatal("Switches -r and -%c are conflicting\n",main_options['i']?'i':'n');
    main_options['x']=1;
  }
  if(main_options['a']) main_options['r']=main_options['x']=1;
  if(main_options['p']) main_options['r']=1;
  if(main_options['f']) main_options['x']=1;
  if(!main_options['c']) {
    set_path(argv[0]);
    load_options();
  }
  if(argc>optind) read_options(argc-optind,argv+optind);







|







1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
    main_options['r']=1;
  }
  if(main_options['n'] && main_options['i']) fatal("Switches -n and -i are conflicting\n");
  if(main_options['n'] || main_options['i']) {
    if(main_options['r']) fatal("Switches -r and -%c are conflicting\n",main_options['i']?'i':'n');
    main_options['x']=1;
  }
  if(main_options['a'] || main_options['O']) main_options['r']=main_options['x']=1;
  if(main_options['p']) main_options['r']=1;
  if(main_options['f']) main_options['x']=1;
  if(!main_options['c']) {
    set_path(argv[0]);
    load_options();
  }
  if(argc>optind) read_options(argc-optind,argv+optind);
1157
1158
1159
1160
1161
1162
1163

1164
1165
1166
1167
1168
1169
1170
  } else if(level_ord=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,10)) {
    if(level_ord>level_nindex) level_ord=level_nindex;
    log_if_error(load_level(-level_ord));
  }
  optionquery[1]=Q_maxTrigger;
  max_trigger=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,10);
  if(main_options['a']) run_auto_test();

  if(main_options['x']) {
    if(main_options['i']) {
      batch_import();
      if(main_options['f']) flush_usercache();
      return 0;
    } else if(main_options['f']) {
      if(main_options['r']) fatal("Cannot flush user cache; puzzle set is read-only\n");







>







1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
  } else if(level_ord=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,10)) {
    if(level_ord>level_nindex) level_ord=level_nindex;
    log_if_error(load_level(-level_ord));
  }
  optionquery[1]=Q_maxTrigger;
  max_trigger=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,10);
  if(main_options['a']) run_auto_test();
  if(main_options['O']) export_private_solutions();
  if(main_options['x']) {
    if(main_options['i']) {
      batch_import();
      if(main_options['f']) flush_usercache();
      return 0;
    } else if(main_options['f']) {
      if(main_options['r']) fatal("Cannot flush user cache; puzzle set is read-only\n");

Modified man6/heromesh.6 from [a7335c1e28] to [fe215be8ba].

17
18
19
20
21
22
23


24
25
26
27
28
29
30
.SH OPTIONS
.IP -C
Dump all class data.
.IP -H
Dump the hash table.
.IP -L
Display all tokens being read from the class definition file.


.IP -U
Enable experimental/unstable features.
.IP -a
Autotest levels, ensuring that the provided solution is valid.
.IP -c
Only load classes and then terminate.
This can be used to verify that the class definition file does not contain syntax errors.







>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
.SH OPTIONS
.IP -C
Dump all class data.
.IP -H
Dump the hash table.
.IP -L
Display all tokens being read from the class definition file.
.IP -O
Output a solution Hamster archive with private solutions to stdout and then terminate.
.IP -U
Enable experimental/unstable features.
.IP -a
Autotest levels, ensuring that the provided solution is valid.
.IP -c
Only load classes and then terminate.
This can be used to verify that the class definition file does not contain syntax errors.