src/newgrf.cpp
changeset 10038 bff6d78e3b37
parent 10032 1f6c6f3bea28
child 10039 1f236afd6cd1
equal deleted inserted replaced
10037:a06670f961a8 10038:bff6d78e3b37
   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 
   667 			case 0x2A: // Long format introduction date (days since year 0)
   705 			case 0x2A: // Long format introduction date (days since year 0)
   668 				ei->base_intro = grf_load_dword(&buf);
   706 				ei->base_intro = grf_load_dword(&buf);
   669 				break;
   707 				break;
   670 
   708 
   671 			default:
   709 			default:
   672 				ret = true;
   710 				ret = !CommonVehicleChangeInfo(ei, prop, &buf);
   673 				break;
   711 				break;
   674 		}
   712 		}
   675 	}
   713 	}
   676 
   714 
   677 	*bufp = buf;
   715 	*bufp = buf;
   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) {
   804 			case 0x20: // Alter purchase list sort order
   842 			case 0x20: // Alter purchase list sort order
   805 				AlterVehicleListOrder(e->index, grf_load_extended(&buf));
   843 				AlterVehicleListOrder(e->index, grf_load_extended(&buf));
   806 				break;
   844 				break;
   807 
   845 
   808 			default:
   846 			default:
   809 				ret = true;
   847 				ret = !CommonVehicleChangeInfo(ei, prop, &buf);
   810 				break;
   848 				break;
   811 		}
   849 		}
   812 	}
   850 	}
   813 
   851 
   814 	*bufp = buf;
   852 	*bufp = buf;
   917 			case 0x1B: // Alter purchase list sort order
   955 			case 0x1B: // Alter purchase list sort order
   918 				AlterVehicleListOrder(e->index, grf_load_extended(&buf));
   956 				AlterVehicleListOrder(e->index, grf_load_extended(&buf));
   919 				break;
   957 				break;
   920 
   958 
   921 			default:
   959 			default:
   922 				ret = true;
   960 				ret = !CommonVehicleChangeInfo(ei, prop, &buf);
   923 				break;
   961 				break;
   924 		}
   962 		}
   925 	}
   963 	}
   926 
   964 
   927 	*bufp = buf;
   965 	*bufp = buf;
  1026 			case 0x1B: // Alter purchase list sort order
  1064 			case 0x1B: // Alter purchase list sort order
  1027 				AlterVehicleListOrder(e->index, grf_load_extended(&buf));
  1065 				AlterVehicleListOrder(e->index, grf_load_extended(&buf));
  1028 				break;
  1066 				break;
  1029 
  1067 
  1030 			default:
  1068 			default:
  1031 				ret = true;
  1069 				ret = !CommonVehicleChangeInfo(ei, prop, &buf);
  1032 				break;
  1070 				break;
  1033 		}
  1071 		}
  1034 	}
  1072 	}
  1035 
  1073 
  1036 	*bufp = buf;
  1074 	*bufp = buf;
  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)