437 } |
437 } |
438 } |
438 } |
439 |
439 |
440 typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len); |
440 typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len); |
441 |
441 |
|
442 static bool CommonVehicleChangeInfo(EngineInfo *ei, int prop, byte **buf) |
|
443 { |
|
444 switch (prop) { |
|
445 case 0x00: // Introduction date |
|
446 ei->base_intro = grf_load_word(buf) + DAYS_TILL_ORIGINAL_BASE_YEAR; |
|
447 break; |
|
448 |
|
449 case 0x02: // Decay speed |
|
450 ei->decay_speed = grf_load_byte(buf); |
|
451 break; |
|
452 |
|
453 case 0x03: // Vehicle life |
|
454 ei->lifelength = grf_load_byte(buf); |
|
455 break; |
|
456 |
|
457 case 0x04: // Model life |
|
458 ei->base_life = grf_load_byte(buf); |
|
459 break; |
|
460 |
|
461 case 0x06: // Climates available |
|
462 ei->climates = grf_load_byte(buf); |
|
463 /* Sometimes a GRF wants hidden vehicles. Setting climates to |
|
464 * zero may cause the ID to be reallocated. */ |
|
465 if (ei->climates == 0) ei->climates = 0x80; |
|
466 break; |
|
467 |
|
468 case 0x07: // Loading speed |
|
469 /* Amount of cargo loaded during a vehicle's "loading tick" */ |
|
470 ei->load_amount = grf_load_byte(buf); |
|
471 break; |
|
472 |
|
473 default: |
|
474 return false; |
|
475 } |
|
476 |
|
477 return true; |
|
478 } |
|
479 |
442 static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) |
480 static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) |
443 { |
481 { |
444 byte *buf = *bufp; |
482 byte *buf = *bufp; |
445 bool ret = false; |
483 bool ret = false; |
446 |
484 |
696 case 0x09: // Running cost factor |
734 case 0x09: // Running cost factor |
697 rvi->running_cost = grf_load_byte(&buf); |
735 rvi->running_cost = grf_load_byte(&buf); |
698 break; |
736 break; |
699 |
737 |
700 case 0x0A: { // Running cost base |
738 case 0x0A: { // Running cost base |
701 uint32 base= grf_load_dword(&buf); |
739 uint32 base = grf_load_dword(&buf); |
702 |
740 |
703 /* These magic numbers are used in GRFs to specify the base cost: |
741 /* These magic numbers are used in GRFs to specify the base cost: |
704 * http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts |
742 * http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts |
705 */ |
743 */ |
706 if (base == 0) { |
744 if (base == 0) { |
2327 return; |
2365 return; |
2328 } |
2366 } |
2329 |
2367 |
2330 while (numprops-- && buf < bufend) { |
2368 while (numprops-- && buf < bufend) { |
2331 uint8 prop = grf_load_byte(&buf); |
2369 uint8 prop = grf_load_byte(&buf); |
2332 bool ignoring = false; |
2370 |
2333 |
2371 if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) { |
2334 switch (feature) { |
2372 grfmsg(1, "FeatureChangeInfo: Ignoring property 0x%02X of feature 0x%02X (not implemented)", prop, feature); |
2335 case GSF_TRAIN: |
2373 } |
2336 case GSF_ROAD: |
|
2337 case GSF_SHIP: |
|
2338 case GSF_AIRCRAFT: { |
|
2339 bool handled = true; |
|
2340 |
|
2341 for (uint i = 0; i < numinfo; i++) { |
|
2342 Engine *e = GetNewEngine(_cur_grffile, (VehicleType)feature, engine + i); |
|
2343 EngineInfo *ei = &e->info; |
|
2344 |
|
2345 /* Common properties for vehicles */ |
|
2346 switch (prop) { |
|
2347 case 0x00: // Introduction date |
|
2348 ei->base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR; |
|
2349 break; |
|
2350 |
|
2351 case 0x02: // Decay speed |
|
2352 ei->decay_speed = grf_load_byte(&buf); |
|
2353 break; |
|
2354 |
|
2355 case 0x03: // Vehicle life |
|
2356 ei->lifelength = grf_load_byte(&buf); |
|
2357 break; |
|
2358 |
|
2359 case 0x04: // Model life |
|
2360 ei->base_life = grf_load_byte(&buf); |
|
2361 break; |
|
2362 |
|
2363 case 0x06: // Climates available |
|
2364 ei->climates = grf_load_byte(&buf); |
|
2365 // XXX sometimes a grf wants hidden vehicles :o |
|
2366 if (ei->climates == 0) ei->climates = 0x80; |
|
2367 break; |
|
2368 |
|
2369 case 0x07: // Loading speed |
|
2370 /* Hyronymus explained me what does |
|
2371 * this mean and insists on having a |
|
2372 * credit ;-). --pasky */ |
|
2373 ei->load_amount = grf_load_byte(&buf); |
|
2374 break; |
|
2375 |
|
2376 default: |
|
2377 handled = false; |
|
2378 break; |
|
2379 } |
|
2380 } |
|
2381 |
|
2382 if (handled) break; |
|
2383 } /* FALL THROUGH */ |
|
2384 |
|
2385 default: |
|
2386 if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) { |
|
2387 ignoring = true; |
|
2388 } |
|
2389 break; |
|
2390 } |
|
2391 |
|
2392 if (ignoring) grfmsg(1, "FeatureChangeInfo: Ignoring property 0x%02X of feature 0x%02X (not implemented)", prop, feature); |
|
2393 } |
2374 } |
2394 } |
2375 } |
2395 |
2376 |
2396 /* Action 0x00 (GLS_SAFETYSCAN) */ |
2377 /* Action 0x00 (GLS_SAFETYSCAN) */ |
2397 static void SafeChangeInfo(byte *buf, size_t len) |
2378 static void SafeChangeInfo(byte *buf, size_t len) |