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 [dbcc43fd0c]:

To Artifact [f9d077868e]:


2481
2482
2483
2484
2485
2486
2487

2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
  Uint8 x=objects[obj]->x;
  Uint8 y=objects[obj]->y;
  Uint8 d=objects[obj]->dir;
  Uint32 un=VOIDLINK;
  Uint32 n=VOIDLINK;
  Uint32 m;
  Uint16 g;

  Value v;
  ChoicePoint cp[MAXCHOICE];
  Uint8 cpi=0;
  Uint16 ccl=objects[obj]->class;
  Uint8 cim=objects[obj]->image;
  if(!x) return VOIDLINK;
  cp->depth=vstackptr;
  again: switch(code[ptr++]) {
    case 0 ... 7:
      n=VOIDLINK;
      x+=x_delta[code[ptr-1]];
      y+=y_delta[code[ptr-1]];
      if(x<1 || x>pfwidth || y<1 || y>pfheight) goto fail;







>





|







2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
  Uint8 x=objects[obj]->x;
  Uint8 y=objects[obj]->y;
  Uint8 d=objects[obj]->dir;
  Uint32 un=VOIDLINK;
  Uint32 n=VOIDLINK;
  Uint32 m;
  Uint16 g;
  Uint32 total=0;
  Value v;
  ChoicePoint cp[MAXCHOICE];
  Uint8 cpi=0;
  Uint16 ccl=objects[obj]->class;
  Uint8 cim=objects[obj]->image;
  if(!x) goto stop;
  cp->depth=vstackptr;
  again: switch(code[ptr++]) {
    case 0 ... 7:
      n=VOIDLINK;
      x+=x_delta[code[ptr-1]];
      y+=y_delta[code[ptr-1]];
      if(x<1 || x>pfwidth || y<1 || y>pfheight) goto fail;
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
          if(v.u==1) goto fail;
          else if(v.u==2) break;
          else if(v.u) Throw("Invalid return value from message in pattern matching");
        } else if(v.t>TY_MAXTYPE) {
          n=v_object(v);
          x=objects[n]->x;
          y=objects[n]->y;
          if(!x) return VOIDLINK;
        } else {
          Throw("Type mismatch");
        }
        m=objects[m]->up;
      }
      break;
    case OP_ADD:
      if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
      m=(n==VOIDLINK?obj_bottom_at(x,y):n);
      Push(OVALUE(m));
      break;
    case OP_AGAIN:
      if(cp[cpi].ptr!=ptr+1) {
        if(cpi>=MAXCHOICE-1) Throw("Choice overflow");
        cpi++;
        cp[cpi].ptr=ptr+1;
      }







|









|







2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
          if(v.u==1) goto fail;
          else if(v.u==2) break;
          else if(v.u) Throw("Invalid return value from message in pattern matching");
        } else if(v.t>TY_MAXTYPE) {
          n=v_object(v);
          x=objects[n]->x;
          y=objects[n]->y;
          if(!x) goto stop;
        } else {
          Throw("Type mismatch");
        }
        m=objects[m]->up;
      }
      break;
    case OP_ADD:
      if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
      m=(n==VOIDLINK?obj_bottom_at(x,y):n);
      if(all==2) total++; else Push(OVALUE(m));
      break;
    case OP_AGAIN:
      if(cp[cpi].ptr!=ptr+1) {
        if(cpi>=MAXCHOICE-1) Throw("Choice overflow");
        cpi++;
        cp[cpi].ptr=ptr+1;
      }
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
        d=v.u&7;
      } else if(v.t==TY_MARK) {
        goto fail;
      } else if(v.t>TY_MAXTYPE) {
        n=v_object(v);
        x=objects[n]->x;
        y=objects[n]->y;
        if(!x) return VOIDLINK;
      } else {
        Throw("Type mismatch");
      }
      break;
    case OP_HEIGHT:
      if(playfield[x+y*64-65]==VOIDLINK || height_at(x,y)<=objects[obj]->climb) goto fail;
      break;







|







2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
        d=v.u&7;
      } else if(v.t==TY_MARK) {
        goto fail;
      } else if(v.t>TY_MAXTYPE) {
        n=v_object(v);
        x=objects[n]->x;
        y=objects[n]->y;
        if(!x) goto stop;
      } else {
        Throw("Type mismatch");
      }
      break;
    case OP_HEIGHT:
      if(playfield[x+y*64-65]==VOIDLINK || height_at(x,y)<=objects[obj]->climb) goto fail;
      break;
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
    case OP_LOC:
      if(vstackptr>=VSTACKSIZE-2) Throw("Stack overflow");
      Push(NVALUE(x));
      Push(NVALUE(y));
      break;
    case OP_MARK:
      if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
      Push(UVALUE(0,TY_MARK));
      break;
    case OP_MUL:
      cp[cpi].x=x;
      cp[cpi].y=y;
      cp[cpi].dir=d;
      break;
    case OP_NEXT:







|







2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
    case OP_LOC:
      if(vstackptr>=VSTACKSIZE-2) Throw("Stack overflow");
      Push(NVALUE(x));
      Push(NVALUE(y));
      break;
    case OP_MARK:
      if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
      if(all!=2) Push(UVALUE(0,TY_MARK));
      break;
    case OP_MUL:
      cp[cpi].x=x;
      cp[cpi].y=y;
      cp[cpi].dir=d;
      break;
    case OP_NEXT:
2718
2719
2720
2721
2722
2723
2724

2725




2726
2727
2728
2729
2730
2731
2732
      cp[cpi-5].dir=6;
      cp[cpi-6].dir=7;
      break;
    case OP_RET:
      if(all) {
        if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
        if(n==VOIDLINK) n=obj_bottom_at(x,y);

        Push(OVALUE(n));




        goto fail;
      } else if(un==VOIDLINK) {
        return n==VOIDLINK?obj_bottom_at(x,y):n;
      } else {
        return VOIDLINK;
      }
      break;







>
|
>
>
>
>







2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
      cp[cpi-5].dir=6;
      cp[cpi-6].dir=7;
      break;
    case OP_RET:
      if(all) {
        if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
        if(n==VOIDLINK) n=obj_bottom_at(x,y);
        if(all!=2) {
          Push(OVALUE(n));
        } else {
          if(un==VOIDLINK && n!=VOIDLINK) total++;
          else if(un!=VOIDLINK) return total+(n==VOIDLINK?1:0);
        }
        goto fail;
      } else if(un==VOIDLINK) {
        return n==VOIDLINK?obj_bottom_at(x,y):n;
      } else {
        return VOIDLINK;
      }
      break;
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776


2777
2778
2779
2780
2781

2782
2783
2784
2785
2786

2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
      cp[cpi-1]=cp[cpi-2]=cp[cpi];
      cp[cpi].dir=2;
      cp[cpi-1].dir=4;
      cp[cpi-2].dir=6;
      break;
    case OP_SUB:
      if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
      Push(NVALUE(0));
      break;
    case OP_THEN:
      // This opcode does nothing
      break;
    case OP_TRACE:
      if(main_options['t']) {
        printf("ptr=%d cpi=%d x=%d y=%d dir=%d obj=%lu ",ptr,cpi,x,y,d,(long)n);
        printf("[ptr=%d x=%d y=%d dir=%d]\n",cp[cpi].ptr,cp[cpi].x,cp[cpi].y,cp[cpi].dir);
      }
      break;
    default:
      fprintf(stderr,"Unrecognized opcode 0x%04X at 0x%04X in pattern\n",code[ptr-1],ptr-1);
      Throw("Internal error: Unimplemented opcode in pattern");
  }
  goto again;
  fail:
  if(!all) {
    if(vstackptr<cp->depth) Throw("Stack underflow in pattern matching");
    vstackptr=cp[cpi].depth;
  }
  if(!cpi) return un;
  x=cp[cpi].x;
  y=cp[cpi].y;
  d=cp[cpi].dir;
  ptr=cp[cpi].ptr;
  n=VOIDLINK;
  cpi--;
  goto again;


}

static Uint32 v_pattern_anywhere(Uint16*code,int ptr,char all) {
  int i;
  Uint32 n;

  for(i=0;i<pfheight*64;i++) {
    n=playfield[i];
    if(n!=VOIDLINK) {
      n=v_pattern(code,ptr,n,all);
      if(n!=VOIDLINK && !all) return n;

    }
  }
  return VOIDLINK;
}

static int v_case(Uint16*code,int ptr,Value v) {
  int n=(code[ptr]&255)+1;
  int t0=(code[ptr]>>12)&15;
  int t1=(code[ptr]>>8)&15;
  int i,j,v0,v1;







|




















|







>
>





>





>


|







2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
      cp[cpi-1]=cp[cpi-2]=cp[cpi];
      cp[cpi].dir=2;
      cp[cpi-1].dir=4;
      cp[cpi-2].dir=6;
      break;
    case OP_SUB:
      if(vstackptr>=VSTACKSIZE-1) Throw("Stack overflow");
      if(all==2) total--; else Push(NVALUE(0));
      break;
    case OP_THEN:
      // This opcode does nothing
      break;
    case OP_TRACE:
      if(main_options['t']) {
        printf("ptr=%d cpi=%d x=%d y=%d dir=%d obj=%lu ",ptr,cpi,x,y,d,(long)n);
        printf("[ptr=%d x=%d y=%d dir=%d]\n",cp[cpi].ptr,cp[cpi].x,cp[cpi].y,cp[cpi].dir);
      }
      break;
    default:
      fprintf(stderr,"Unrecognized opcode 0x%04X at 0x%04X in pattern\n",code[ptr-1],ptr-1);
      Throw("Internal error: Unimplemented opcode in pattern");
  }
  goto again;
  fail:
  if(!all) {
    if(vstackptr<cp->depth) Throw("Stack underflow in pattern matching");
    vstackptr=cp[cpi].depth;
  }
  if(!cpi) return (all==2?total+(un==VOIDLINK?0:1):un);
  x=cp[cpi].x;
  y=cp[cpi].y;
  d=cp[cpi].dir;
  ptr=cp[cpi].ptr;
  n=VOIDLINK;
  cpi--;
  goto again;
  stop:
  return (all==2?total:VOIDLINK);
}

static Uint32 v_pattern_anywhere(Uint16*code,int ptr,char all) {
  int i;
  Uint32 n;
  Uint32 t=0;
  for(i=0;i<pfheight*64;i++) {
    n=playfield[i];
    if(n!=VOIDLINK) {
      n=v_pattern(code,ptr,n,all);
      if(n!=VOIDLINK && !all) return n;
      if(all==2) t+=n;
    }
  }
  return (all==2?t:VOIDLINK);
}

static int v_case(Uint16*code,int ptr,Value v) {
  int n=(code[ptr]&255)+1;
  int t0=(code[ptr]>>12)&15;
  int t1=(code[ptr]>>8)&15;
  int i,j,v0,v1;
3498
3499
3500
3501
3502
3503
3504



3505
3506
3507
3508
3509
3510
3511
    case OP_OVER: StackReq(2,3); t2=Pop(); t1=Pop(); Push(t1); Push(t2); Push(t1); break;
    case OP_PATTERN: StackReq(0,1); i=code[ptr++]; j=v_pattern(code,ptr,obj,0); ptr=i; Push(OVALUE(j)); break;
    case OP_PATTERN_C: StackReq(1,1); i=code[ptr++]; j=v_object(Pop()); if(j!=VOIDLINK) j=v_pattern(code,ptr,j,0); ptr=i; Push(OVALUE(j)); break;
    case OP_PATTERN_E: StackReq(0,1); i=code[ptr++]; j=v_pattern_anywhere(code,ptr,0); ptr=i; Push(OVALUE(j)); break;
    case OP_PATTERNS: StackReq(0,1); i=code[ptr++]; v_pattern(code,ptr,obj,1); ptr=i; break;
    case OP_PATTERNS_C: StackReq(1,1); i=code[ptr++]; j=v_object(Pop()); if(j!=VOIDLINK) v_pattern(code,ptr,j,1); ptr=i; break;
    case OP_PATTERNS_E: StackReq(0,1); i=code[ptr++]; v_pattern_anywhere(code,ptr,1); ptr=i; break;



    case OP_PICK: StackReq(0,1); t1=Pop(); Numeric(t1); if(t1.u>=vstackptr) Throw("Stack index out of range"); t1=vstack[vstackptr-t1.u-1]; Push(t1); break;
    case OP_PLAYER: StackReq(0,1); if(classes[o->class]->cflags&CF_PLAYER) Push(NVALUE(1)); else Push(NVALUE(0)); break;
    case OP_PLAYER_C: StackReq(1,1); GetClassFlagOf(CF_PLAYER); break;
    case OP_PLUSMOVE: StackReq(1,1); t1=Pop(); Numeric(t1); i=defer_move(obj,t1.u,1); Push(NVALUE(i)); break;
    case OP_PLUSMOVE_C: StackReq(2,1); t1=Pop(); Numeric(t1); i=v_object(Pop()); i=defer_move(i,t1.u,1); Push(NVALUE(i)); break;
    case OP_PLUSMOVE_D: StackReq(1,0); t1=Pop(); Numeric(t1); defer_move(obj,t1.u,1); break;
    case OP_PLUSMOVE_CD: StackReq(2,1); t1=Pop(); Numeric(t1); i=v_object(Pop()); defer_move(i,t1.u,1); break;







>
>
>







3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
    case OP_OVER: StackReq(2,3); t2=Pop(); t1=Pop(); Push(t1); Push(t2); Push(t1); break;
    case OP_PATTERN: StackReq(0,1); i=code[ptr++]; j=v_pattern(code,ptr,obj,0); ptr=i; Push(OVALUE(j)); break;
    case OP_PATTERN_C: StackReq(1,1); i=code[ptr++]; j=v_object(Pop()); if(j!=VOIDLINK) j=v_pattern(code,ptr,j,0); ptr=i; Push(OVALUE(j)); break;
    case OP_PATTERN_E: StackReq(0,1); i=code[ptr++]; j=v_pattern_anywhere(code,ptr,0); ptr=i; Push(OVALUE(j)); break;
    case OP_PATTERNS: StackReq(0,1); i=code[ptr++]; v_pattern(code,ptr,obj,1); ptr=i; break;
    case OP_PATTERNS_C: StackReq(1,1); i=code[ptr++]; j=v_object(Pop()); if(j!=VOIDLINK) v_pattern(code,ptr,j,1); ptr=i; break;
    case OP_PATTERNS_E: StackReq(0,1); i=code[ptr++]; v_pattern_anywhere(code,ptr,1); ptr=i; break;
    case OP_PATTERNC: StackReq(0,1); i=code[ptr++]; j=v_pattern(code,ptr,obj,2); ptr=i; Push(NVALUE(j)); break;
    case OP_PATTERNC_C: StackReq(1,1); i=code[ptr++]; j=v_object(Pop()); if(j!=VOIDLINK) j=v_pattern(code,ptr,j,2); else j=0; Push(NVALUE(j)); ptr=i; break;
    case OP_PATTERNC_E: StackReq(0,1); i=code[ptr++]; j=v_pattern_anywhere(code,ptr,2); ptr=i; Push(NVALUE(j)); break;
    case OP_PICK: StackReq(0,1); t1=Pop(); Numeric(t1); if(t1.u>=vstackptr) Throw("Stack index out of range"); t1=vstack[vstackptr-t1.u-1]; Push(t1); break;
    case OP_PLAYER: StackReq(0,1); if(classes[o->class]->cflags&CF_PLAYER) Push(NVALUE(1)); else Push(NVALUE(0)); break;
    case OP_PLAYER_C: StackReq(1,1); GetClassFlagOf(CF_PLAYER); break;
    case OP_PLUSMOVE: StackReq(1,1); t1=Pop(); Numeric(t1); i=defer_move(obj,t1.u,1); Push(NVALUE(i)); break;
    case OP_PLUSMOVE_C: StackReq(2,1); t1=Pop(); Numeric(t1); i=v_object(Pop()); i=defer_move(i,t1.u,1); Push(NVALUE(i)); break;
    case OP_PLUSMOVE_D: StackReq(1,0); t1=Pop(); Numeric(t1); defer_move(obj,t1.u,1); break;
    case OP_PLUSMOVE_CD: StackReq(2,1); t1=Pop(); Numeric(t1); i=v_object(Pop()); defer_move(i,t1.u,1); break;