File diff r5867:de68577800e6 → r5868:bc3e720ec5f7
src/newgrf.cpp
Show inline comments
 
@@ -206,28 +206,28 @@ static GRFFile *GetFileByFilename(const 
 

	
 
typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len);
 

	
 
#define FOR_EACH_OBJECT for (i = 0; i < numinfo; i++)
 

	
 
static void dewagonize(int condition, int engine)
 
{
 
	EngineInfo *ei = &_engine_info[engine];
 
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
 

	
 
	if (condition != 0) {
 
		ei->unk2 &= ~0x80;
 
		rvi->flags &= ~2;
 
		rvi->railveh_type = RAILVEH_SINGLEHEAD;
 
	} else {
 
		ei->unk2 |= 0x80;
 
		rvi->flags |= 2;
 
		rvi->railveh_type = RAILVEH_WAGON;
 
	}
 
}
 

	
 
static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
 
{
 
	EngineInfo *ei = &_engine_info[engine];
 
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
 
	byte *buf = *bufp;
 
	int i;
 
	bool ret = false;
 

	
 
	switch (prop) {
 
@@ -256,36 +256,36 @@ static bool RailVehicleChangeInfo(uint e
 
			FOR_EACH_OBJECT {
 
				uint16 speed = grf_load_word(&buf);
 
				if (speed == 0xFFFF) speed = 0;
 

	
 
				rvi[i].max_speed = speed;
 
			}
 
			break;
 

	
 
		case 0x0B: /* Power */
 
			FOR_EACH_OBJECT {
 
				uint16 power = grf_load_word(&buf);
 

	
 
				if (rvi[i].flags & RVI_MULTIHEAD) power /= 2;
 
				if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) power /= 2;
 

	
 
				rvi[i].power = power;
 
				dewagonize(power, engine + i);
 
			}
 
			break;
 

	
 
		case 0x0D: /* Running cost factor */
 
			FOR_EACH_OBJECT {
 
				uint8 runcostfact = grf_load_byte(&buf);
 

	
 
				if (rvi[i].flags & RVI_MULTIHEAD) runcostfact /= 2;
 
				if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) runcostfact /= 2;
 

	
 
				rvi[i].running_cost_base = runcostfact;
 
			}
 
			break;
 

	
 
		case 0x0E: /* Running cost base */
 
			FOR_EACH_OBJECT {
 
				uint32 base = grf_load_dword(&buf);
 

	
 
				switch (base) {
 
					case 0x4C30: rvi[i].running_cost_class = 0; break;
 
					case 0x4C36: rvi[i].running_cost_class = 1; break;
 
@@ -306,37 +306,37 @@ static bool RailVehicleChangeInfo(uint e
 
				 * as an array index, so we need it to be half the original value. */
 
				if (spriteid < 0xFD) spriteid >>= 1;
 

	
 
				rvi[i].image_index = spriteid;
 
			}
 
			break;
 

	
 
		case 0x13: /* Dual-headed */
 
			FOR_EACH_OBJECT {
 
				uint8 dual = grf_load_byte(&buf);
 

	
 
				if (dual != 0) {
 
					if (!(rvi[i].flags & RVI_MULTIHEAD)) {
 
					if (rvi[i].railveh_type != RAILVEH_MULTIHEAD) {
 
						// adjust power and running cost if needed
 
						rvi[i].power /= 2;
 
						rvi[i].running_cost_base /= 2;
 
					}
 
					rvi[i].flags |= RVI_MULTIHEAD;
 
					rvi[i].railveh_type = RAILVEH_MULTIHEAD;
 
				} else {
 
					if (rvi[i].flags & RVI_MULTIHEAD) {
 
					if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) {
 
						// adjust power and running cost if needed
 
						rvi[i].power *= 2;
 
						rvi[i].running_cost_base *= 2;
 
					}
 
					rvi[i].flags &= ~RVI_MULTIHEAD;
 
					rvi[i].railveh_type = RAILVEH_SINGLEHEAD;
 
				}
 
			}
 
			break;
 

	
 
		case 0x14: /* Cargo capacity */
 
			FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x15: /* Cargo type */
 
			FOR_EACH_OBJECT {
 
				uint8 ctype = grf_load_byte(&buf);
 

	
 
@@ -3579,25 +3579,25 @@ static void CalculateRefitMasks(void)
 

	
 
		if (cargo_allowed[engine] != 0) {
 
			// Build up the list of cargo types from the set cargo classes.
 
			for (i = 0; i < lengthof(cargo_classes); i++) {
 
				if (HASBIT(cargo_allowed[engine], i)) mask |= cargo_classes[i];
 
				if (HASBIT(cargo_disallowed[engine], i)) not_mask |= cargo_classes[i];
 
			}
 
		} else {
 
			// Don't apply default refit mask to wagons or engines with no capacity
 
			if (xor_mask == 0 && (
 
						GetEngine(engine)->type != VEH_Train || (
 
							RailVehInfo(engine)->capacity != 0 &&
 
							!(RailVehInfo(engine)->flags & RVI_WAGON)
 
							RailVehInfo(engine)->railveh_type != RAILVEH_WAGON
 
						)
 
					)) {
 
				xor_mask = _default_refitmasks[GetEngine(engine)->type - VEH_Train];
 
			}
 
		}
 
		_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _landscape_global_cargo_mask[_opt.landscape];
 
	}
 
}
 

	
 
/* Here we perform initial decoding of some special sprites (as are they
 
 * described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
 
 * partial implementation yet). */
 
@@ -3792,12 +3792,13 @@ void LoadNewGRF(uint load_index, uint fi
 
				DEBUG(sprite, 2, "Currently %i sprites are loaded", _cur_spriteid);
 
			}
 
		}
 
	}
 

	
 
	// Pre-calculate all refit masks after loading GRF files
 
	CalculateRefitMasks();
 
}