Changeset - r6147:29bca9cbe66b
[Not reviewed]
master
0 3 0
peter1138 - 18 years ago 2007-02-24 23:20:21
peter1138@openttd.org
(svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
3 files changed with 26 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -3704,12 +3704,35 @@ static void ClearTemporaryNewGRFData(voi
 
	/* Clear the list of spritegroups */
 
	free(_cur_grffile->spritegroups);
 
	_cur_grffile->spritegroups = NULL;
 
	_cur_grffile->spritegroups_count = 0;
 
}
 

	
 
static void BuildCargoTranslationMap()
 
{
 
	memset(_cur_grffile->cargo_map, 0xFF, sizeof(_cur_grffile->cargo_map));
 

	
 
	for (CargoID c = 0; c < NUM_CARGO; c++) {
 
		const CargoSpec *cs = GetCargo(c);
 
		if (!cs->IsValid()) continue;
 

	
 
		if (_cur_grffile->cargo_max == 0) {
 
			/* Default translation table, so just a straight mapping to bitnum */
 
			_cur_grffile->cargo_map[c] = cs->bitnum;
 
		} else {
 
			/* Check the translation table for this cargo's label */
 
			for (uint i = 0; i < _cur_grffile->cargo_max; i++) {
 
				if (cs->label == _cur_grffile->cargo_list[i]) {
 
					_cur_grffile->cargo_map[c] = i;
 
					break;
 
				}
 
			}
 
		}
 
	}
 
}
 

	
 
static void InitNewGRFFile(const GRFConfig *config, int sprite_offset)
 
{
 
	GRFFile *newfile;
 

	
 
	newfile = GetFileByFilename(config->filename);
 
	if (newfile != NULL) {
 
@@ -4029,12 +4052,13 @@ void LoadNewGRF(uint load_index, uint fi
 
			if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename);
 

	
 
			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
 
			LoadNewGRFFile(c, slot++, stage);
 
			if (stage == GLS_ACTIVATION) {
 
				ClearTemporaryNewGRFData();
 
				BuildCargoTranslationMap();
 
				DEBUG(sprite, 2, "Currently %i sprites are loaded", _cur_spriteid);
 
			}
 
		}
 
	}
 

	
 
	// Pre-calculate all refit masks after loading GRF files
src/newgrf.h
Show inline comments
 
@@ -61,12 +61,13 @@ typedef struct GRFFile {
 
	uint param_end; /// one more than the highest set parameter
 

	
 
	GRFLabel *label; ///< Pointer to the first label. This is a linked list, not an array.
 

	
 
	uint8 cargo_max;
 
	CargoLabel *cargo_list;
 
	uint8 cargo_map[NUM_CARGO];
 
} GRFFile;
 

	
 
extern GRFFile *_first_grffile;
 

	
 
extern SpriteID _signal_base;
 
extern SpriteID _coast_base;
src/newgrf_engine.cpp
Show inline comments
 
@@ -605,13 +605,13 @@ static uint32 VehicleGetVariable(const R
 
			 *     translated if a translation table has been installed.
 
			 * ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F.
 
			 * cccc - the cargo class value of the cargo transported by the vehicle.
 
			 */
 
			const CargoSpec *cs = GetCargo(v->cargo_type);
 

	
 
			return (cs->classes << 16) | (cs->weight << 8) | cs->bitnum;
 
			return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type];
 
		}
 

	
 
		case 0x48: return GetVehicleTypeInfo(v->engine_type); /* Vehicle Type Info */
 

	
 
		/* Variables which use the parameter */
 
		case 0x60: /* Count consist's engine ID occurance */
0 comments (0 inline, 0 general)