Free Hero Mesh

Check-in [dd82c6e9b5]
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:Add level exporting. (Importing is not implemented yet.)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dd82c6e9b51fae1a73732021276eda9e11889637
User & Date: user on 2021-03-06 06:04:00
Other Links: manifest | tags
Context
2021-03-07
00:56
Prevent double triggering of ARRIVED and DEPARTED messages. This fixes some test cases, although some test cases still fail. check-in: c2b53e3cd8 user: user tags: trunk
2021-03-06
06:04
Add level exporting. (Importing is not implemented yet.) check-in: dd82c6e9b5 user: user tags: trunk
05:22
Add the global examine command check-in: c1b51c9521 user: user tags: trunk
Changes

Modified bindings.doc from [6cec4c2c09] to [d258a8579c].

116
117
118
119
120
121
122




123
124
125
126
127
128
129
  and the Misc values (1 to 3), not the class and image; to edit the class
  and image, use the class selection menu.)

'^u' <location>
  Add an object with the current MRU values to that location, even if
  there is already another object of the same class at that location.





'lc' <number>
  Set the level code number. This is a 16-bit number which can be used in
  the class codes of your puzzle set for whatever purpose you wish; the
  game engine does not use this value itself.

'lv' <number>
  Set the level version number. This number is used to detect the validity







>
>
>
>







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  and the Misc values (1 to 3), not the class and image; to edit the class
  and image, use the class selection menu.)

'^u' <location>
  Add an object with the current MRU values to that location, even if
  there is already another object of the same class at that location.

'ex' <command>
  Export a level (given the operating system command to receive the
  exported data). See export.doc for details.

'lc' <number>
  Set the level code number. This is a 16-bit number which can be used in
  the class codes of your puzzle set for whatever purpose you wish; the
  game engine does not use this value itself.

'lv' <number>
  Set the level version number. This number is used to detect the validity

Modified default.heromeshrc from [0a5a74d628] to [ed90c9d16e].

143
144
145
146
147
148
149

150
151
152
153
154
155
156
?.editKey.R: select 're',substr(:resize,1,instr(:resize,'x')-1),substr(:resize,instr(:resize,'x')+1) where length(:resize);
?.editKey.ctrl.X: select 're',pfwidth(),pfheight();
?.editKey.ctrl.P: ^P
?.editKey.ctrl.Q: ^Q
?.editKey.ctrl.S: ^S
?.editKey.space: ^c
?.editKey.return: ^e

?.editClick.left: ^a
?.editClick.alt.left: ^u
?.editClick.right: delete from objects where x=$X and y=$Y and up is null;

! Global key bindings
?.?.kp_minus: select 'go',-(level()-1);
?.?.kp_plus: select 'go',-(level()+1);







>







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
?.editKey.R: select 're',substr(:resize,1,instr(:resize,'x')-1),substr(:resize,instr(:resize,'x')+1) where length(:resize);
?.editKey.ctrl.X: select 're',pfwidth(),pfheight();
?.editKey.ctrl.P: ^P
?.editKey.ctrl.Q: ^Q
?.editKey.ctrl.S: ^S
?.editKey.space: ^c
?.editKey.return: ^e
?.editKey.f2: select 'ex',:Export_Level;
?.editClick.left: ^a
?.editClick.alt.left: ^u
?.editClick.right: delete from objects where x=$X and y=$Y and up is null;

! Global key bindings
?.?.kp_minus: select 'go',-(level()-1);
?.?.kp_plus: select 'go',-(level()+1);

Modified edit.c from [2014453d2e] to [d19625c559].

690
691
692
693
694
695
696




































































697
698
699
700
701
702
703
  objects[n]->image=m->img;
  objects[n]->dir=m->dir;
  objects[n]->misc1=m->misc1;
  objects[n]->misc2=m->misc2;
  objects[n]->misc3=m->misc3;
  pflink(n);
}





































































static int editor_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  int x,y;
  switch(cmd) {
    case '^a': // Add object (no duplicates)
      if(prev) return prev;
      add_object_at(number&63?:64,number/64?:64,mru+curmru,1);







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







690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
  objects[n]->image=m->img;
  objects[n]->dir=m->dir;
  objects[n]->misc1=m->misc1;
  objects[n]->misc2=m->misc2;
  objects[n]->misc3=m->misc3;
  pflink(n);
}

static void fprint_esc(FILE*fp,Uint8 c,const char*t) {
  char isimg=0;
  if(!c) return;
  fputc(c,fp);
  while(*t) switch(c=*t++) {
    case 1 ... 8: fprintf(fp,"\\%c",c+'0'-1); break;
    case 10: fprintf(fp,"\\n"); break;
    case 11: fprintf(fp,"\\l"); break;
    case 12: fprintf(fp,"\\c"); break;
    case 14: fprintf(fp,"\\i"); isimg=1; break;
    case 15: fprintf(fp,"\\b"); break;
    case 16: fprintf(fp,"\\q"); break;
    case 31:
      if(!*t) break;
      fprintf(fp,"\\x%02X",*t++);
      break;
    case 32 ... 127:
      if(c=='\\') {
        if(isimg) isimg=0; else fputc(c,fp);
      }
      fputc(c,fp);
      break;
    default:
      fprintf(fp,"\\x%02X",c);
  }
  fputc('\n',fp);
}

static void fprint_misc(FILE*fp,Value v) {
  switch(v.t) {
    case TY_NUMBER: fprintf(fp," %u",(int)v.u); break;
    case TY_CLASS: fprintf(fp," $%s",classes[v.u]->name); break;
    case TY_MESSAGE: fprintf(fp," %s%s",v.u<256?"":"#",v.u<256?standard_message_names[v.u]:messages[v.u-256]);
    case TY_LEVELSTRING: fprintf(fp," %%%u",(int)v.u); break;
    default: fprintf(fp," ???"); break;
  }
}

static void export_level(const char*cmd) {
  int i;
  Uint32 n;
  Object*o;
  FILE*fp;
  if(!cmd) return;
  fp=popen(cmd,"w");
  if(!fp) {
    screen_message("Cannot open pipe");
    return;
  }
  fprintf(fp,"; Free Hero Mesh exported level ID=%d ORD=%d\n",level_id,level_ord);
  fprint_esc(fp,'@',level_title);
  fprintf(fp,"C %d\nD %d %d\n",level_code,pfwidth,pfheight);
  for(i=0;i<64*64;i++) {
    n=playfield[i];
    while(n!=VOIDLINK) {
      o=objects[n];
      fprintf(fp,"%d %d $%s %d",o->x,o->y,classes[o->class]->name,o->image);
      fprint_misc(fp,o->misc1);
      fprint_misc(fp,o->misc2);
      fprint_misc(fp,o->misc3);
      fprintf(fp," %d\n",o->dir);
      n=o->up;
    }
  }
  for(i=0;i<nlevelstrings;i++) fprint_esc(fp,'%',levelstrings[i]);
  pclose(fp);
}

static int editor_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  int x,y;
  switch(cmd) {
    case '^a': // Add object (no duplicates)
      if(prev) return prev;
      add_object_at(number&63?:64,number/64?:64,mru+curmru,1);
715
716
717
718
719
720
721




722
723
724
725
726
727
728
    case '^P': // Play
      return -2;
    case '^Q': // Quit
      return -1;
    case '^S': // Save level
      save_level();
      return 1;




    case 'go': // Select level
      load_level(number);
      return 1;
    case 'lc': // Set level code
      level_code=number;
      level_changed=1;
      return 0;







>
>
>
>







783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
    case '^P': // Play
      return -2;
    case '^Q': // Quit
      return -1;
    case '^S': // Save level
      save_level();
      return 1;
    case 'ex': // Export level
      if(argc<2) return prev;
      export_level(sqlite3_column_text(args,1));
      return prev;
    case 'go': // Select level
      load_level(number);
      return 1;
    case 'lc': // Set level code
      level_code=number;
      level_changed=1;
      return 0;

Added export.doc version [30a247908a].

























































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
This document describes the level export format of Free Hero Mesh.

You can use this format for the following purposes:

* To copy a level in Free Hero Mesh, within the same puzzle set or from
one puzzle set to another one.

* To export a level, to be parsed by an external program.

* To produce by an external program and then import into Free Hero Mesh.

* To edit it in a text editor.

Each line is one record, and is terminated by a line feed. Everything in
this file is case-sensitive.


=== Types of records ===

;comment
  A comment. A blank line is also a comment.

@title
  Specify the title of the level. This may contain escapes. A line break
  must be escaped, and a backslash must be escaped, although a quotation
  mark does not need to be escaped.

C code
  The level code number, from 0 to 65535.

D width height
  The play field dimensions. The width and height must be 1 to 64. This
  line must come before any objects are listed, and is mandatory.

x y $class image misc1 misc2 misc3 dir
  Specify an object. Objects are listed starting from the top left corner,
  going right, and within each cell the objects are listed from bottom to
  top. Coordinates are one-based. The image is a number (0 for the first
  image), misc1 to misc3 are misc values (see below), and dir is also a
  number (0 for east, up to 7 for southeast).

%string
  A level string. The level strings are numbered in order, starting from
  string 0. The format is like that of the title.


=== Misc values ===

A number is written in decimal, and must be 0 to 65535.

A class name has $ at first.

A message name will start with # if it is a user-defined message, or will
have no prefix if it is a standard message.

A reference to a level string starts with % and is then the number.

Nine of the misc values are written with spaces inside the value, although
there are spaces around the value.