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 [197962d870]:

To Artifact [5acd447fb3]:


46
47
48
49
50
51
52


53
54
55
56
57
58
59
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61







+
+







Sint32 max_volume=10000;
Uint8 back_color=1;
Uint8 inv_back_color=9;
char**stringpool;
AnimationSlot anim_slot[8];
Uint8 keymask[256/8];
Uint16 array_size;
Uint16*orders;
Uint8 norders;

#define HASH_SIZE 8888
#define LOCAL_HASH_SIZE 5555
typedef struct {
  Uint16 id;
  char*txt;
} Hash;
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268







-
+







  if(!cl->name) fatal("Allocation failed\n");
  cl->edithelp=cl->gamehelp=0;
  cl->codes=cl->messages=cl->images=0;
  cl->height=cl->weight=cl->climb=cl->density=cl->volume=cl->strength=cl->arrivals=cl->departures=0;
  cl->temperature=cl->misc4=cl->misc5=cl->misc6=cl->misc7=0;
  cl->uservars=cl->hard[0]=cl->hard[1]=cl->hard[2]=cl->hard[3]=cl->nmsg=0;
  cl->oflags=cl->sharp[0]=cl->sharp[1]=cl->sharp[2]=cl->sharp[3]=0;
  cl->shape=cl->shovable=cl->collisionLayers=cl->nimages=0;
  cl->shape=cl->shovable=cl->collisionLayers=cl->nimages=cl->order=0;
  cl->cflags=f;
  if(undef_class<=n) undef_class=n+1;
}

Uint16 get_message_ptr(int c,int m) {
  if(!classes[c]) return 0xFFFF;
  if(classes[c]->nmsg<=m) return 0xFFFF;
2100
2101
2102
2103
2104
2105
2106

































































2107
2108
2109
2110
2111
2112
2113
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    if(i==size && data[i-1]) fatal("Malformed CLASS.DEF lump\n");
    if(messages[n]) fatal("Duplicate message number %d\n",n+256);
    messages[n]=strdup(p);
    if(!messages[n]) fatal("Allocation failed\n");
  }
  free(data);
}

static void parse_order_block(void) {
  // OP_MISC1, OP_MISC1_C, etc = properties (_C=reverse)
  // 0x1000...0x10FF = Have flag
  // OP_RET = end of block
  Uint16 beg,ptr;
  orders=malloc(0x4000*sizeof(Uint16));
  if(!orders) fatal("Allocation failed\n");
  nxttok();
  if(tokent==TF_INT) {
    if(tokenv<1 || tokenv>254) ParseError("Order number out of range\n");
    beg=ptr=tokenv;
    nxttok();
  } else {
    beg=ptr=128;
  }
  while(tokent!=TF_CLOSE) {
    if(tokent!=TF_OPEN) ParseError("Open or close parenthesis expected\n");
    if(ptr>=0x3FFD) ParseError("Out of order memory\n");
    nxttok();
    if(Tokenf(TF_MACRO|TF_COMMA|TF_EQUAL) || !Tokenf(TF_NAME)) ParseError("Unexpected token in (Order) block\n");
    if(norders==beg) ParseError("Too many orders\n");
    orders[norders++]=ptr;
    switch(tokenv) {
      case OP_INPUT: case OP_PLAYER:
        orders[ptr++]=tokenv;
        break;
      case OP_USERFLAG:
        tokenv=look_hash(glohash,HASH_SIZE,0x1000,0x10FF,0,"user flags");
        if(!tokenv) ParseError("User flag ^%s not defined\n",tokenstr);
        orders[ptr++]=tokenv;
        break;
      default: ParseError("Unexpected token in (Order) block\n");
    }
    nxttok();
    while(tokent!=TF_CLOSE) {
      if(Tokenf(TF_MACRO|TF_EQUAL) || !Tokenf(TF_NAME)) ParseError("Unexpected token in (Order) block\n");
      if(ptr>=0x3FFE) ParseError("Out of order memory\n");
      switch(tokenv) {
        case OP_MISC1: case OP_MISC1_C:
        case OP_MISC2: case OP_MISC2_C:
        case OP_MISC3: case OP_MISC3_C:
        case OP_MISC4: case OP_MISC4_C:
        case OP_MISC5: case OP_MISC5_C:
        case OP_MISC6: case OP_MISC6_C:
        case OP_MISC7: case OP_MISC7_C:
        case OP_TEMPERATURE: case OP_TEMPERATURE_C:
        case OP_DENSITY: case OP_DENSITY_C:
        case OP_XLOC: case OP_XLOC_C:
        case OP_YLOC: case OP_YLOC_C:
        case OP_IMAGE: case OP_IMAGE_C:
          orders[ptr++]=tokenv;
          break;
      }
      nxttok();
    }
    orders[ptr++]=OP_RET;
  }
  if(!norders) ParseError("Empty (Order) block\n");
  orders=realloc(orders,ptr*sizeof(Uint16))?:orders;
}

static void set_class_orders(void) {
  //TODO
}

void load_classes(void) {
  int i;
  int gloptr=0;
  Hash*glolocalhash;
  char*nam=sqlite3_mprintf("%s.class",basefilename);
  sqlite3_stmt*vst=0;
2244
2245
2246
2247
2248
2249
2250




2251
2252
2253
2254
2255
2256
2257
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328







+
+
+
+







        case OP_CODEPAGE:
          nxttok();
          if(tokent!=TF_INT || tokenv<1 || tokenv>65535) ParseError("Number from 1 to 65535 expected\n");
          set_code_page(tokenv);
          nxttok();
          if(tokent!=TF_CLOSE) ParseError("Expected close parenthesis\n");
          break;
        case OP_ORDER:
          if(norders) ParseError("Extra (Order) block\n");
          parse_order_block();
          break;
        default:
          ParseError("Invalid top level definition: %s\n",tokenstr);
      }
    } else {
      ParseError("Invalid top level definition\n");
    }
  }
2284
2285
2286
2287
2288
2289
2290

2291
2292
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364







+


  for(i=1;i<undef_class;i++) if(classes[i] && (classes[i]->cflags&CF_NOCLASS1)) fatal("Class $%s mentioned but not defined\n",classes[i]->name);
  if(macros) for(i=0;i<MAX_MACRO;i++) if(macros[i]) free_macro(macros[i]);
  free(macros);
  if(array_size) {
    array_data=malloc(array_size*sizeof(Value));
    if(!array_data) fatal("Array allocation failed\n");
  }
  if(norders) set_class_orders();
  fprintf(stderr,"Done\n");
}