Changeset - r1872:f2d5f6d1aa5c
[Not reviewed]
master
0 1 0
orudge - 19 years ago 2005-05-29 20:36:11
orudge@openttd.org
(svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
1 file changed with 27 insertions and 3 deletions:
newgrf.c
27
3
0 comments (0 inline, 0 general)
newgrf.c
Show inline comments
 
@@ -306,97 +306,101 @@ static bool RailVehicleChangeInfo(uint e
 
		case 0x18: {	/* AI rank */
 
			/* TODO: _railveh_score should be merged to _rail_vehicle_info. */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
			ret = true;
 
		}	break;
 
		case 0x19: { /* Engine traction type */
 
			/* TODO: What do the individual numbers mean?
 
			 * XXX: And in what base are they, in fact? --pasky */
 
			FOR_EACH_OBJECT {
 
				uint8 traction = grf_load_byte(&buf);
 
				int engclass;
 

	
 
				if (traction <= 0x07)
 
					engclass = 0;
 
				else if (traction <= 0x27)
 
					engclass = 1;
 
				else if (traction <= 0x31)
 
					engclass = 2;
 
				else
 
					break;
 

	
 
				rvi[i].engclass = engclass;
 
			}
 
		}	break;
 
		case 0x1D: {	/* Refit cargo */
 
			FOR_EACH_OBJECT {
 
				uint32 refit_mask = grf_load_dword(&buf);
 

	
 
				_engine_refit_masks[engine + i] = refit_mask;
 
			}
 
		}	break;
 

	
 
		/* TODO */
 
		/* Fall-through for unimplemented two bytes long properties. */
 
		case 0x1B:	/* Powered wagons power bonus */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
		/* Fall-through for unimplemented one byte long properties. */
 
		case 0x1A:	/* Sort order */
 
		case 0x1C:	/* Refit cost */
 
		case 0x1E:	/* Callback */
 
		case 0x1F:	/* Tractive effort */
 
		case 0x20:	/* Air drag */
 
		case 0x21:	/* Shorter tenders */
 
		case 0x22:	/* Visual */
 
		case 0x23: {/* Powered wagons weight bonus */
 
		case 0x23:	/* Powered wagons weight bonus */
 
		case 0x24:	/* High byte of vehicle weight */
 
		case 0x25:	/* User-defined bit mask to set when checking veh. var. 42 */
 
		case 0x26:	/* Retire vehicle early */
 
			{
 
			/* TODO */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
			ret = true;
 
		}	break;
 
		default:
 
			ret = true;
 
	}
 
	*bufp = buf;
 
	return ret;
 
}
 

	
 
static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
 
{
 
	RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
 
	byte *buf = *bufp;
 
	int i;
 
	bool ret = false;
 

	
 
	switch (prop) {
 
		case 0x08: {	/* Speed */
 
			FOR_EACH_OBJECT {
 
				uint8 speed = grf_load_byte(&buf);
 

	
 
				rvi[i].max_speed = speed; // ?? units
 
			}
 
		}	break;
 
		case 0x09: {	/* Running cost factor */
 
			FOR_EACH_OBJECT {
 
				uint8 runcost = grf_load_byte(&buf);
 

	
 
				rvi[i].running_cost = runcost;
 
			}
 
		}	break;
 
		case 0x0A:	/* Running cost base */
 
			/* TODO: I have no idea. --pasky */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
			ret = true;
 
			break;
 
		case 0x0E: {	/* Sprite ID */
 
			FOR_EACH_OBJECT {
 
				uint8 spriteid = grf_load_byte(&buf);
 

	
 
				if (spriteid == 0xFF)
 
					spriteid = 0xFD; // cars have different custom id in the GRF file
 
@@ -412,96 +416,100 @@ static bool RoadVehicleChangeInfo(uint e
 
		case 0x0F: {	/* Cargo capacity */
 
			FOR_EACH_OBJECT {
 
				uint16 capacity = grf_load_word(&buf);
 

	
 
				rvi[i].capacity = capacity;
 
			}
 
		}	break;
 
		case 0x10: { /* Cargo type */
 
			FOR_EACH_OBJECT {
 
				uint8 cargo = grf_load_byte(&buf);
 

	
 
				rvi[i].cargo_type = cargo;
 
			}
 
		}	break;
 
		case 0x11: {	/* Cost factor */
 
			FOR_EACH_OBJECT {
 
				uint8 cost_factor = grf_load_byte(&buf);
 

	
 
				rvi[i].base_cost = cost_factor; // ?? is it base_cost?
 
			}
 
		}	break;
 
		case 0x12: {	/* SFX */
 
			FOR_EACH_OBJECT {
 
				uint8 sfx = grf_load_byte(&buf);
 

	
 
				rvi[i].sfx = sfx;
 
			}
 
		}	break;
 
		case 0x13:      /* Power in 10hp */
 
		case 0x14:      /* Weight in 1/4 tons */
 
		case 0x15:      /* Speed in mph*0.8 */
 
			/* TODO: Support for road vehicles realistic power
 
			 * computations (called rvpower in TTDPatch) is just
 
			 * missing in OTTD yet. --pasky */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
			ret = true;
 
			break;
 
		case 0x16: {	/* Cargos available for refitting */
 
			FOR_EACH_OBJECT {
 
				uint32 refit_mask = grf_load_dword(&buf);
 

	
 
				_engine_refit_masks[ROAD_ENGINES_INDEX + engine + i] = refit_mask;
 
			}
 
		}	break;
 
		case 0x17:      /* Callback */
 
		case 0x18:      /* Tractive effort */
 
		case 0x19:      /* Air drag */
 
		case 0x1A:      /* Refit cost */
 
		case 0x1B:      /* Retire vehicle early */
 
			{
 
			/* TODO */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
			ret = true;
 
			break;
 
		default:
 
			ret = true;
 
	}
 

	
 
	*bufp = buf;
 
	return ret;
 
}
 

	
 
static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
 
{
 
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
 
	byte *buf = *bufp;
 
	int i;
 
	bool ret = false;
 

	
 
	//printf("e %x prop %x?\n", engine, prop);
 
	switch (prop) {
 
		case 0x08: {	/* Sprite ID */
 
			FOR_EACH_OBJECT {
 
				uint8 spriteid = grf_load_byte(&buf);
 

	
 
				if (spriteid == 0xFF)
 
					spriteid = 0xFD; // ships have different custom id in the GRF file
 

	
 
				// This is currently not used but there's no reason
 
				// in not having it here for the future.
 
				if (spriteid == 0xFD && svi[i].image_index != 0xFD)
 
					_engine_original_sprites[SHIP_ENGINES_INDEX + engine + i] = svi[i].image_index;
 

	
 
				svi[i].image_index = spriteid;
 
			}
 
		}	break;
 
		case 0x09: {	/* Refittable */
 
			FOR_EACH_OBJECT {
 
				uint8 refittable = grf_load_byte(&buf);
 

	
 
				svi[i].refittable = refittable;
 
			}
 
		}	break;
 
		case 0x0A: {	/* Cost factor */
 
			FOR_EACH_OBJECT {
 
				uint8 cost_factor = grf_load_byte(&buf);
 
@@ -513,97 +521,106 @@ static bool ShipVehicleChangeInfo(uint e
 
			FOR_EACH_OBJECT {
 
				uint8 speed = grf_load_byte(&buf);
 

	
 
				svi[i].max_speed = speed; // ?? units
 
			}
 
		}	break;
 
		case 0x0C: { /* Cargo type */
 
			FOR_EACH_OBJECT {
 
				uint8 cargo = grf_load_byte(&buf);
 

	
 
				// XXX: Need to consult this with patchman yet.
 
#if 0
 
				// Documentation claims this is already the
 
				// per-landscape cargo type id, but newships.grf
 
				// assume otherwise.
 
				cargo = local_cargo_id_ctype[cargo];
 
#endif
 
				svi[i].cargo_type = cargo;
 
			}
 
		}	break;
 
		case 0x0D: {	/* Cargo capacity */
 
			FOR_EACH_OBJECT {
 
				uint16 capacity = grf_load_word(&buf);
 

	
 
				svi[i].capacity = capacity;
 
			}
 
		}	break;
 
		case 0x0F: {	/* Running cost factor */
 
			FOR_EACH_OBJECT {
 
				uint8 runcost = grf_load_byte(&buf);
 

	
 
				svi[i].running_cost = runcost;
 
			}
 
		} break;
 
		case 0x10: {	/* SFX */
 
			FOR_EACH_OBJECT {
 
				uint8 sfx = grf_load_byte(&buf);
 

	
 
				svi[i].sfx = sfx;
 
			}
 
		}	break;
 
		case 0x11: {	/* Cargos available for refitting */
 
			FOR_EACH_OBJECT {
 
				uint32 refit_mask = grf_load_dword(&buf);
 

	
 
				_engine_refit_masks[SHIP_ENGINES_INDEX + engine + i] = refit_mask;
 
			}
 
		}	break;
 
		case 0x12: { /* Callback TODO */
 
		case 0x12: /* Callback */
 
		case 0x13: /* Refit cost */
 
		case 0x14: /* Ocean speed fraction */
 
		case 0x15: /* Canal speed fraction */
 
		case 0x16: /* Retire vehicle early */
 
		{
 
			/* TODO */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
			ret = true;
 
		}	break;
 
		default:
 
			ret = true;
 
	}
 

	
 
	*bufp = buf;
 
	return ret;
 
}
 

	
 
static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
 
{
 
	AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine];
 
	byte *buf = *bufp;
 
	int i;
 
	bool ret = false;
 

	
 
	//printf("e %x prop %x?\n", engine, prop);
 
	switch (prop) {
 
		case 0x08: {	/* Sprite ID */
 
			FOR_EACH_OBJECT {
 
				uint8 spriteid = grf_load_byte(&buf);
 

	
 
				if (spriteid == 0xFF)
 
					spriteid = 0xFD; // ships have different custom id in the GRF file
 

	
 
				// This is currently not used but there's no reason
 
				// in not having it here for the future.
 
				if (spriteid == 0xFD && avi[i].image_index != 0xFD)
 
					_engine_original_sprites[AIRCRAFT_ENGINES_INDEX + engine + i] = avi[i].image_index;
 

	
 
				avi[i].image_index = spriteid;
 
			}
 
		}	break;
 
		case 0x09: {	/* Helicopter */
 
			FOR_EACH_OBJECT {
 
				uint8 heli = grf_load_byte(&buf);
 
				avi[i].subtype &= ~0x01; // remove old property
 
				avi[i].subtype |= (heli == 0) ? 0 : 1;
 
			}
 
		}	break;
 
		case 0x0A: {	/* Large */
 
			FOR_EACH_OBJECT {
 
				uint8 large = grf_load_byte(&buf);
 
				avi[i].subtype &= ~0x02; // remove old property
 
				avi[i].subtype |= (large == 1) ? 2 : 0;
 
			}
 
		}	break;
 
@@ -618,97 +635,104 @@ static bool AircraftVehicleChangeInfo(ui
 
			FOR_EACH_OBJECT {
 
				uint8 speed = grf_load_byte(&buf);
 

	
 
				avi[i].max_speed = speed; // ?? units
 
			}
 
		}	break;
 
		case 0x0D: {	/* Acceleration */
 
			FOR_EACH_OBJECT {
 
				uint8 accel = grf_load_byte(&buf);
 

	
 
				avi[i].acceleration = accel;
 
			}
 
		} break;
 
		case 0x0E: {	/* Running cost factor */
 
			FOR_EACH_OBJECT {
 
				uint8 runcost = grf_load_byte(&buf);
 

	
 
				avi[i].running_cost = runcost;
 
			}
 
		} break;
 
		case 0x0F: {	/* Passenger capacity */
 
			FOR_EACH_OBJECT {
 
				uint16 capacity = grf_load_word(&buf);
 

	
 
				avi[i].passenger_capacity = capacity;
 
			}
 
		}	break;
 
		case 0x11: {	/* Mail capacity */
 
			FOR_EACH_OBJECT {
 
				uint8 capacity = grf_load_byte(&buf);
 

	
 
				avi[i].mail_capacity = capacity;
 
			}
 
		}	break;
 
		case 0x12: {	/* SFX */
 
			FOR_EACH_OBJECT {
 
				uint8 sfx = grf_load_byte(&buf);
 

	
 
				avi[i].sfx = sfx;
 
			}
 
		}	break;
 
		case 0x13: {	/* Cargos available for refitting */
 
			FOR_EACH_OBJECT {
 
				uint32 refit_mask = grf_load_dword(&buf);
 

	
 
				_engine_refit_masks[AIRCRAFT_ENGINES_INDEX + engine + i] = refit_mask;
 
			}
 
		}	break;
 
		case 0x14: { /* Callback TODO */
 
		case 0x14: /* Callback */
 
		case 0x15: /* Refit cost */
 
		case 0x16: /* Retire vehicle early */
 
		{
 
			/* TODO */
 
			FOR_EACH_OBJECT {
 
				grf_load_byte(&buf);
 
			}
 
			ret = true;
 
		}	break;
 
		default:
 
			ret = true;
 
	}
 

	
 
	*bufp = buf;
 
	return ret;
 
}
 

	
 
static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int len)
 
{
 
	byte *buf = *bufp;
 
	int i;
 
	int ret = 0;
 

	
 
	/* This is one single huge TODO. It doesn't handle anything more than
 
	 * just waypoints for now. */
 

	
 
	//printf("sci %d %d [0x%02x]\n", stid, numinfo, prop);
 
	switch (prop) {
 
		case 0x08:
 
		{	/* Class ID */
 
			FOR_EACH_OBJECT {
 
				StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				uint32 classid;
 

	
 
				/* classid, for a change, is always little-endian */
 
				classid = *(buf++) << 24;
 
				classid |= *(buf++) << 16;
 
				classid |= *(buf++) << 8;
 
				classid |= *(buf++);
 

	
 
				switch (classid) {
 
					case 'DFLT':
 
						stat->sclass = STAT_CLASS_DFLT;
 
						break;
 
					case 'WAYP':
 
						stat->sclass = STAT_CLASS_WAYP;
 
						break;
 
					default:
 
						/* TODO: No support for custom
 
						 * classes for now, so stuff
 
						 * everything to the single
 
						 * default one. --pasky */
 
						stat->sclass = STAT_CLASS_DFLT;
 
						//stat->sclass = STAT_CLASS_CUSTOM;
 
						break;
0 comments (0 inline, 0 general)