1437 } else { |
1437 } else { |
1438 grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price); |
1438 grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price); |
1439 } |
1439 } |
1440 } break; |
1440 } break; |
1441 |
1441 |
1442 case 0x09: // Cargo translation table |
1442 case 0x09: { // Cargo translation table |
1443 /* This is loaded during the initialisation stage, so just skip it here. */ |
1443 if (gvid != 0) { |
1444 /* Each entry is 4 bytes. */ |
1444 if (i == 0) grfmsg(1, "InitChangeInfo: Cargo translation table must start at zero"); |
1445 buf += 4; |
1445 /* Skip data */ |
1446 break; |
1446 buf += 4; |
|
1447 break; |
|
1448 } |
|
1449 if (i == 0) { |
|
1450 free(_cur_grffile->cargo_list); |
|
1451 _cur_grffile->cargo_max = numinfo; |
|
1452 _cur_grffile->cargo_list = MallocT<CargoLabel>(numinfo); |
|
1453 } |
|
1454 CargoLabel cl = grf_load_dword(&buf); |
|
1455 _cur_grffile->cargo_list[i] = BSWAP32(cl); |
|
1456 } break; |
1447 |
1457 |
1448 case 0x0A: { // Currency display names |
1458 case 0x0A: { // Currency display names |
1449 uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); |
1459 uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); |
1450 StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf)); |
1460 StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf)); |
1451 |
1461 |
2204 |
2214 |
2205 SETBIT(_cur_grfconfig->flags, GCF_UNSAFE); |
2215 SETBIT(_cur_grfconfig->flags, GCF_UNSAFE); |
2206 |
2216 |
2207 /* Skip remainder of GRF */ |
2217 /* Skip remainder of GRF */ |
2208 _skip_sprites = -1; |
2218 _skip_sprites = -1; |
2209 } |
|
2210 |
|
2211 /* Action 0x00 (GLS_INIT) */ |
|
2212 static void InitChangeInfo(byte *buf, int len) |
|
2213 { |
|
2214 byte *bufend = buf + len; |
|
2215 |
|
2216 if (!check_length(len, 6, "InitChangeInfo")) return; |
|
2217 buf++; |
|
2218 uint8 feature = grf_load_byte(&buf); |
|
2219 uint8 numprops = grf_load_byte(&buf); |
|
2220 uint8 numinfo = grf_load_byte(&buf); |
|
2221 uint8 index = grf_load_extended(&buf); |
|
2222 |
|
2223 while (numprops-- && buf < bufend) { |
|
2224 uint8 prop = grf_load_byte(&buf); |
|
2225 |
|
2226 switch (feature) { |
|
2227 case GSF_GLOBALVAR: |
|
2228 switch (prop) { |
|
2229 case 0x09: // Cargo Translation Table |
|
2230 if (index != 0) { |
|
2231 grfmsg(1, "InitChangeInfo: Cargo translation table must start at zero"); |
|
2232 return; |
|
2233 } |
|
2234 |
|
2235 free(_cur_grffile->cargo_list); |
|
2236 _cur_grffile->cargo_max = numinfo; |
|
2237 _cur_grffile->cargo_list = MallocT<CargoLabel>(numinfo); |
|
2238 |
|
2239 for (uint i = 0; i < numinfo; i++) { |
|
2240 CargoLabel cl = grf_load_dword(&buf); |
|
2241 _cur_grffile->cargo_list[i] = BSWAP32(cl); |
|
2242 } |
|
2243 break; |
|
2244 } |
|
2245 break; |
|
2246 } |
|
2247 } |
|
2248 } |
2219 } |
2249 |
2220 |
2250 /* Action 0x00 (GLS_RESERVE) */ |
2221 /* Action 0x00 (GLS_RESERVE) */ |
2251 static void ReserveChangeInfo(byte *buf, int len) |
2222 static void ReserveChangeInfo(byte *buf, int len) |
2252 { |
2223 { |
5407 * --pasky */ |
5378 * --pasky */ |
5408 /* We need a pre-stage to set up GOTO labels of Action 0x10 because the grf |
5379 /* We need a pre-stage to set up GOTO labels of Action 0x10 because the grf |
5409 * is not in memory and scanning the file every time would be too expensive. |
5380 * is not in memory and scanning the file every time would be too expensive. |
5410 * In other stages we skip action 0x10 since it's already dealt with. */ |
5381 * In other stages we skip action 0x10 since it's already dealt with. */ |
5411 static const SpecialSpriteHandler handlers[][GLS_END] = { |
5382 static const SpecialSpriteHandler handlers[][GLS_END] = { |
5412 /* 0x00 */ { NULL, SafeChangeInfo, NULL, InitChangeInfo, ReserveChangeInfo, FeatureChangeInfo, }, |
5383 /* 0x00 */ { NULL, SafeChangeInfo, NULL, NULL, ReserveChangeInfo, FeatureChangeInfo, }, |
5413 /* 0x01 */ { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, }, |
5384 /* 0x01 */ { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, }, |
5414 /* 0x02 */ { NULL, NULL, NULL, NULL, NULL, NewSpriteGroup, }, |
5385 /* 0x02 */ { NULL, NULL, NULL, NULL, NULL, NewSpriteGroup, }, |
5415 /* 0x03 */ { NULL, GRFUnsafe, NULL, NULL, NULL, FeatureMapSpriteGroup, }, |
5386 /* 0x03 */ { NULL, GRFUnsafe, NULL, NULL, NULL, FeatureMapSpriteGroup, }, |
5416 /* 0x04 */ { NULL, NULL, NULL, NULL, NULL, FeatureNewName, }, |
5387 /* 0x04 */ { NULL, NULL, NULL, NULL, NULL, FeatureNewName, }, |
5417 /* 0x05 */ { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, }, |
5388 /* 0x05 */ { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, }, |
5453 |
5424 |
5454 if (action == 0xFF) { |
5425 if (action == 0xFF) { |
5455 grfmsg(7, "DecodeSpecialSprite: Handling data block in stage %d", stage); |
5426 grfmsg(7, "DecodeSpecialSprite: Handling data block in stage %d", stage); |
5456 GRFDataBlock(buf, num); |
5427 GRFDataBlock(buf, num); |
5457 } else if (action == 0xFE) { |
5428 } else if (action == 0xFE) { |
5458 grfmsg(7, "DecodeSpecialSprite: andling import block in stage %d", stage); |
5429 grfmsg(7, "DecodeSpecialSprite: Handling import block in stage %d", stage); |
5459 GRFImportBlock(buf, num); |
5430 GRFImportBlock(buf, num); |
5460 } else if (action >= lengthof(handlers)) { |
5431 } else if (action >= lengthof(handlers)) { |
5461 grfmsg(7, "DecodeSpecialSprite: Skipping unknown action 0x%02X", action); |
5432 grfmsg(7, "DecodeSpecialSprite: Skipping unknown action 0x%02X", action); |
5462 } else if (handlers[action][stage] == NULL) { |
5433 } else if (handlers[action][stage] == NULL) { |
5463 grfmsg(7, "DecodeSpecialSprite: Skipping action 0x%02X in stage %d", action, stage); |
5434 grfmsg(7, "DecodeSpecialSprite: Skipping action 0x%02X in stage %d", action, stage); |