Free Hero Mesh

Check-in [5d19455a9e]
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 level strings and quiz buttons
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5d19455a9e87ee6bb572597010bb97c1194b3905
User & Date: user on 2020-12-20 18:49:06
Other Links: manifest | tags
Context
2020-12-20
21:17
Implement NewX and NewY check-in: 8f8397ce1b user: user tags: trunk
18:49
Implement level strings and quiz buttons check-in: 5d19455a9e user: user tags: trunk
08:28
Implement inventory; also correct a mistake in create() check-in: e22341996b user: user tags: trunk
Changes

Modified exec.c from [2b1ee96014] to [160b4b6c27].

30
31
32
33
34
35
36


37
38
39
40
41
42
43
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45







+
+







Uint8 pfwidth,pfheight;
Sint8 gameover,key_ignored;
Uint8 generation_number_inc;
Uint32 move_number;
unsigned char*quiz_text;
Inventory*inventory;
Uint32 ninventory;
char**levelstrings;
Uint16 nlevelstrings;

typedef struct {
  Uint16 msg;
  Uint32 from;
  Value arg1,arg2,arg3;
} MessageVars;

67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83







-
+








static const Sint8 x_delta[8]={1,1,0,-1,-1,-1,0,1};
static const Sint8 y_delta[8]={0,-1,-1,-1,0,1,1,1};

const char*value_string_ptr(Value v) {
  switch(v.t) {
    case TY_STRING: return stringpool[v.u];
    //TODO: Level strings
    case TY_LEVELSTRING: return v.u<nlevelstrings?levelstrings[v.u]:"<Invalid level string>";
    default: fatal("Internal confusion: Trying to get string pointer for a non-string\n");
  }
}

void pfunlink(Uint32 n) {
  Object*o=objects[n];
  if(o->down==VOIDLINK) playfield[o->x+o->y*64-65]=o->up;
1556
1557
1558
1559
1560
1561
1562


1563
1564
1565
1566
1567
1568
1569
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573







+
+







    free(objects[i]);
  }
  nobjects=0;
  free(objects);
  objects=0;
  gameover=0;
  clear_inventory();
  for(i=0;i<nlevelstrings;i++) free(levelstrings[i]);
  nlevelstrings=0;
}

static void execute_animation(Uint32 obj) {
  Object*o=objects[obj];
  Animation*a=o->anim;
  if(!(a->step[a->lstep].flag&ANI_ONCE)) return;
  if(a->ltime>=a->step[a->lstep].speed) {

Modified heromesh.h from [dafcdb1ee6] to [70c31aabbe].

233
234
235
236
237
238
239


240
241
242
243
244
245
246
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248







+
+







extern Uint8 pfwidth,pfheight;
extern Sint8 gameover,key_ignored;
extern Uint8 generation_number_inc;
extern Uint32 move_number;
extern unsigned char*quiz_text;
extern Inventory*inventory;
extern Uint32 ninventory;
extern char**levelstrings;
extern Uint16 nlevelstrings;

const char*value_string_ptr(Value v);
void pfunlink(Uint32 n);
void pflink(Uint32 n);
Uint32 objalloc(Uint16 c);
void objtrash(Uint32 n);
void annihilate(void);

Modified main.c from [55a050f2d9] to [f7a8e77b3c].

196
197
198
199
200
201
202

203
204
205
206
207
208
209
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210







+








const char*load_level(int lvl) {
  // Load level by ID. Returns null pointer if successful, or an error message if it failed.
  long sz=0;
  unsigned char*buf=lvl>=0?read_lump(FIL_LEVEL,lvl,&sz,0):0;
  unsigned char*p=buf;
  unsigned char*end=buf+sz;
  unsigned char*q;
  int i,n,x,y,z;
  Uint16 lo=0;
  Uint32 o;
  Uint32 mru[2];
  if(lvl<0 && level_index && -lvl<=level_nindex) {
    lo=-lvl;
    lvl=level_index[~lvl];
308
309
310
311
312
313
314
315














316
317
318
319
320
321
322
309
310
311
312
313
314
315

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        objects[o]->x=x;
        objects[o]->y=y;
        pflink(o);
        n=0;
      }
    }
  }
  // skip level strings for now
  // Level strings
  i=0;
  while(p<end) {
    if(i>=max_objects) goto bad3;
    q=memchr(p,0,end-p);
    if(!q) goto bad1;
    levelstrings=realloc(levelstrings,(i+1)*sizeof(char*));
    if(!levelstrings) fatal("Allocation failed\n");
    levelstrings[i]=strdup(p);
    if(!levelstrings[i]) fatal("Allocation failed\n");
    p=q+1;
    i++;
  }
  nlevelstrings=i;
  if(p>end) goto bad1;
  free(buf);
  level_id=lvl;
  level_ord=lo;
  if(level_index && !lo) {
    for(i=0;i<level_nindex;i++) if(level_index[i]==lvl) {
      level_ord=i+1;

Modified picture.c from [608c347ef7] to [b40b537e21].

604
605
606
607
608
609
610
















611

612
613
614
615
616
617
618
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+







      }
    }
  }
  SDL_LockSurface(screen);
}

static void pop_quiz(int x,int y,PopLine*li,Uint8 c,Uint8 v) {
  SDL_Rect r;
  Uint8*p=screen->pixels;
  Uint16 pitch=screen->pitch;
  int xx,yy;
  const unsigned char*f=fontdata+(v<<3);
  if(li->h>16) y+=(li->h-16)/2;
  r.x=x;
  r.y=y;
  r.w=r.h=16;
  SDL_FillRect(screen,&r,0x07);
  if(y+16>=screen->h || x+24>=screen->w) return;
  p+=(y+4)*pitch+x+4;
  for(yy=0;yy<8;yy++) {
    for(xx=0;xx<8;xx++) p[xx]=(*f<<xx)&128?c:0x07;
    p+=pitch;
    ++f;
  
  }
}

void draw_popup(const unsigned char*txt) {
  static colo[8]={1,144,188,173,83,98,218,15};
  static PopLine li[64];
  SDL_Rect r;
  int bx,by,x,y,c;