示例#1
0
void PlayerStatistics::swab()
{
	mousePixels = swabdword(mousePixels);
	mouseClicks = swabdword(mouseClicks);
	keyPresses = swabdword(keyPresses);
	
	numCommands = swabdword(numCommands);
	unitCommands = swabdword(unitCommands);
}
SS3OPiece* CS3OParser::LoadPiece(unsigned char* buf, int offset,S3DModel* model)
{
	model->numobjects++;

	SS3OPiece* piece = SAFE_NEW SS3OPiece;
	piece->type = MODELTYPE_S3O;

	Piece* fp = (Piece*)&buf[offset];
	fp->swap(); // Does it matter we mess with the original buffer here? Don't hope so.

	piece->offset.x = fp->xoffset;
	piece->offset.y = fp->yoffset;
	piece->offset.z = fp->zoffset;
	piece->primitiveType = fp->primitiveType;
	piece->name = (char*)&buf[fp->name];

	int vertexPointer=fp->vertices;
	for(int a=0;a<fp->numVertices;++a){
		((Vertex*)&buf[vertexPointer])->swap();  // Does it matter we mess with the original buffer here?
		piece->vertices.push_back(*(SS3OVertex*)&buf[vertexPointer]);
/*		piece->vertices.back().normal.x=piece->vertices.back().pos.x;
		piece->vertices.back().normal.y=piece->vertices.back().pos.y;
		piece->vertices.back().normal.z=piece->vertices.back().pos.z;
		piece->vertices.back().normal.Normalize();*/
		vertexPointer+=sizeof(Vertex);
	}
	int vertexTablePointer=fp->vertexTable;
	for(int a=0;a<fp->vertexTableSize;++a){
		int num = swabdword(*(int*)&buf[vertexTablePointer]);
		piece->vertexDrawOrder.push_back(num);
		vertexTablePointer += sizeof(int);

		if(num==-1 && a!=fp->vertexTableSize-1){		//for triangle strips
			piece->vertexDrawOrder.push_back(num);

			num = swabdword(*(int*)&buf[vertexTablePointer]);
			piece->vertexDrawOrder.push_back(num);
		}
	}

	piece->isEmpty = false;//piece->vertexDrawOrder.empty(); 
	piece->vertexCount = piece->vertices.size();
	int childPointer = fp->childs;
	for(int a=0;a<fp->numChilds;++a){
		piece->childs.push_back(LoadPiece(buf,swabdword(*(int*)&buf[childPointer]),model));
		childPointer += sizeof(int);
	}
	return piece;
}
示例#3
0
void CSm3ReadMap::LoadFeatureData()
{
		// returns MapFeatureInfo[GetNumFeatures()]
	std::string fd = GetMapDefParser().SGetValueDef(std::string(),"map\\featuredata");
	if (!fd.empty()) {
		CFileHandler fh(fd);
		if (!fh.FileExists())
			throw content_error("Failed to open feature data file: " + fd);

		unsigned char version;
		fh.Read(&version, 1);

		if (version > 0)
			throw content_error("Map feature data has incorrect version, you are probably using an outdated spring version.");

		unsigned int nf;
		fh.Read(&nf, 4);
		numFeatures = swabdword(nf);

		featureInfo = new MapFeatureInfo[numFeatures];
		for (unsigned int a=0;a<numFeatures;a++) {
			MapFeatureInfo& fi = featureInfo[a];
			fh.Read(&fi.featureType, 4);
			fh.Read(&fi.pos, 12);
			fh.Read(&fi.rotation, 4);

			fi.featureType = swabdword(fi.featureType);
			fi.pos.x = swabfloat(fi.pos.x);
			fi.pos.y = swabfloat(fi.pos.y);
			fi.pos.z = swabfloat(fi.pos.z);
			fi.rotation = swabfloat(fi.rotation);
		}
	}/* //testing features...
	else {
		featureTypes.push_back(new std::string("TreeType0"));

		numFeatures = 1000;
		featureInfo = new MapFeatureInfo[numFeatures];

		for (int a=0;a<numFeatures;a++) {
			MapFeatureInfo& fi = featureInfo[a];
			fi.featureType = featureTypes.size()-1;
			fi.pos.x = gs->randFloat() * width * SQUARE_SIZE;
			fi.pos.z = gs->randFloat() * height * SQUARE_SIZE;
			fi.rotation = 0.0f;
		}
	}*/
}
/** @brief Write the CTeam::Statistics at the current position in the file. */
void CDemoRecorder::WriteTeamStats()
{
	if (fileHeader.numTeams == 0)
		return;

	int pos = recordDemo.tellp();

	// Write array of dwords indicating number of CTeam::Statistics per team.
	for (std::vector< std::vector< CTeam::Statistics > >::iterator it = teamStats.begin(); it != teamStats.end(); ++it) {
		unsigned int c = swabdword(it->size());
		recordDemo.write((char*)&c, sizeof(unsigned int));
	}

	// Write big array of CTeam::Statistics.
	for (std::vector< std::vector< CTeam::Statistics > >::iterator it = teamStats.begin(); it != teamStats.end(); ++it) {
		for (std::vector< CTeam::Statistics >::iterator it2 = it->begin(); it2 != it->end(); ++it2) {
			CTeam::Statistics& stats = *it2;
			stats.swab();
			recordDemo.write((char*)&stats, sizeof(CTeam::Statistics));
		}
	}
	teamStats.clear();

	fileHeader.teamStatSize = (int)recordDemo.tellp() - pos;
}
void TeamStatistics::swab()
{
	metalUsed        = swabfloat(metalUsed);
	energyUsed       = swabfloat(energyUsed);
	metalProduced    = swabfloat(metalProduced);
	energyProduced   = swabfloat(energyProduced);
	metalExcess      = swabfloat(metalExcess);
	energyExcess     = swabfloat(energyExcess);
	metalReceived    = swabfloat(metalReceived);
	energyReceived   = swabfloat(energyReceived);
	metalSent        = swabfloat(metalSent);
	energySent       = swabfloat(energySent);
	damageDealt      = swabfloat(damageDealt);
	damageReceived   = swabfloat(damageReceived);
	unitsProduced    = swabdword(unitsProduced);
	unitsDied        = swabdword(unitsDied);
	unitsReceived    = swabdword(unitsReceived);
	unitsSent        = swabdword(unitsSent);
	unitsCaptured    = swabdword(unitsCaptured);
	unitsOutCaptured = swabdword(unitsOutCaptured);
	unitsKilled      = swabdword(unitsKilled);
}
示例#6
0
CCobFile::CCobFile(CFileHandler &in, string name)
{
	char *cobdata = NULL;

	this->name = name;

	//Figure out size needed and allocate it
	int size = in.FileSize();

	// Handle errors (this is fairly fatal..)
	if (size < 0) {
		logOutput.Print("Could not find script for unit %s", name.c_str());
		exit(0);
	}

	cobdata = new char[size];

	//Read the entire thing, we will need it
	in.Read(cobdata, size);

	//Time to parse
	COBHeader ch;
	READ_COBHEADER(ch,cobdata);

	for (int i = 0; i < ch.NumberOfScripts; ++i) {
		int ofs;
		
		ofs = *(int *)&cobdata[ch.OffsetToScriptNameOffsetArray + i * 4];
		ofs = swabdword(ofs);
		string s = &cobdata[ofs];
		scriptNames.push_back(s);

		ofs = *(int *)&cobdata[ch.OffsetToScriptCodeIndexArray + i * 4];
		ofs = swabdword(ofs);
		scriptOffsets.push_back(ofs);
	}

	//Check for zero-length scripts
	for (int i = 0; i < ch.NumberOfScripts - 1; ++i) {
		scriptLengths.push_back(scriptOffsets[i + 1] - scriptOffsets[i]);
	}
	scriptLengths.push_back(ch.TotalScriptLen - scriptOffsets[ch.NumberOfScripts - 1]);

	for (int i = 0; i < ch.NumberOfPieces; ++i) {
		int ofs;

		ofs = *(int *)&cobdata[ch.OffsetToPieceNameOffsetArray + i * 4];
		ofs = swabdword(ofs);
		string s = StringToLower(&cobdata[ofs]);
		pieceNames.push_back(s);
	}

	int code_octets = size - ch.OffsetToScriptCode;
	int code_ints = (code_octets) / 4 + 4;
	code = new int[code_ints];
	memcpy(code, &cobdata[ch.OffsetToScriptCode], code_octets);
	for (int i = 0; i < code_ints; i++) {
		code[i] = swabdword(code[i]);
	}

	numStaticVars = ch.NumberOfStaticVars;

	// If this is a TA:K script, read the sound names
	if (ch.VersionSignature == 6) {
		for (int i = 0; i < ch.NumberOfSounds; ++i) {
			int ofs;
			ofs = *(int *)&cobdata[ch.OffsetToSoundNameArray + i * 4];
			/* TODO This probably isn't correct. */
			ofs = swabdword(ofs);
			string s = &cobdata[ofs];

			// Load the wave file and store the ID for future use
			s = "sounds/" + s + ".wav";
			sounds.push_back(sound->GetWaveId(s));
		}
	}

	delete[] cobdata;

	//Create a reverse mapping (name->int)
	for (unsigned int i = 0; i < scriptNames.size(); ++i) {
		scriptMap[scriptNames[i]] = i;
	}

	//Map common function names to indicies
	scriptIndex.resize(COBFN_Last + COB_MaxWeapons * 5);
	scriptIndex[COBFN_Create] = getFunctionId("Create");
	scriptIndex[COBFN_StartMoving] = getFunctionId("StartMoving");
	scriptIndex[COBFN_StopMoving] = getFunctionId("StopMoving");
	scriptIndex[COBFN_Activate] = getFunctionId("Activate");
	scriptIndex[COBFN_Killed] = getFunctionId("Killed");
	scriptIndex[COBFN_Deactivate] = getFunctionId("Deactivate");
	scriptIndex[COBFN_SetDirection] = getFunctionId("SetDirection");
	scriptIndex[COBFN_SetSpeed] = getFunctionId("SetSpeed");
	scriptIndex[COBFN_RockUnit] = getFunctionId("RockUnit");
	scriptIndex[COBFN_HitByWeapon] = getFunctionId("HitByWeapon");
	scriptIndex[COBFN_MoveRate0] = getFunctionId("MoveRate0");
	scriptIndex[COBFN_MoveRate1] = getFunctionId("MoveRate1");
	scriptIndex[COBFN_MoveRate2] = getFunctionId("MoveRate2");
	scriptIndex[COBFN_MoveRate3] = getFunctionId("MoveRate3");
	scriptIndex[COBFN_SetSFXOccupy] = getFunctionId("setSFXoccupy");

	// Also add the weapon aiming stuff
	for (int i = 0; i < COB_MaxWeapons; ++i) {
		char buf[15];
		sprintf(buf, "Weapon%d", i + 1);
		string weapon(buf);
		sprintf(buf, "%d", i + 1);
		string weap(buf);
		scriptIndex[COBFN_QueryPrimary + i] = getFunctionId("Query" + weapon);
		scriptIndex[COBFN_AimPrimary + i] = getFunctionId("Aim" + weapon);
		scriptIndex[COBFN_AimFromPrimary + i] = getFunctionId("AimFrom" + weapon);
		scriptIndex[COBFN_FirePrimary + i] = getFunctionId("Fire" + weapon);
		scriptIndex[COBFN_EndBurst + i] = getFunctionId("EndBurst" + weap);

		// If new-naming functions are not found, we need to support the old naming scheme
		if (i > 2)
			continue;
		switch (i) {
			case 0: weapon = "Primary"; break;
			case 1: weapon = "Secondary"; break;
			case 2: weapon = "Tertiary"; break;
		}

		if (scriptIndex[COBFN_QueryPrimary + i] == -1)
			scriptIndex[COBFN_QueryPrimary + i] = getFunctionId("Query" + weapon);
		if (scriptIndex[COBFN_AimPrimary + i] == -1)
			scriptIndex[COBFN_AimPrimary + i] = getFunctionId("Aim" + weapon);
		if (scriptIndex[COBFN_AimFromPrimary + i] == -1)
			scriptIndex[COBFN_AimFromPrimary + i] = getFunctionId("AimFrom" + weapon);
		if (scriptIndex[COBFN_FirePrimary + i] == -1)
			scriptIndex[COBFN_FirePrimary + i] = getFunctionId("Fire" + weapon);
	}
}
示例#7
0
SS3OPiece* CS3OParser::LoadPiece(S3DModel* model, SS3OPiece* parent, unsigned char* buf, int offset)
{
	model->numPieces++;

	Piece* fp = (Piece*)&buf[offset];
	fp->swap(); // Does it matter we mess with the original buffer here? Don't hope so.

	SS3OPiece* piece = new SS3OPiece();
		piece->type = MODELTYPE_S3O;
		piece->mins = DEF_MIN_SIZE;
		piece->maxs = DEF_MAX_SIZE;
		piece->offset.x = fp->xoffset;
		piece->offset.y = fp->yoffset;
		piece->offset.z = fp->zoffset;
		piece->primitiveType = fp->primitiveType;
		piece->name = (char*) &buf[fp->name];
		piece->parent = parent;
		piece->vertices.reserve(fp->numVertices);
		piece->vertexDrawOrder.reserve((size_t)(fp->vertexTableSize * 1.1f)); //1.1f is just a guess (check below)

	// retrieve each vertex
	int vertexOffset = fp->vertices;

	for (int a = 0; a < fp->numVertices; ++a) {
		Vertex* v = reinterpret_cast<Vertex*>(&buf[vertexOffset]);
			v->swap();
		SS3OVertex* sv = reinterpret_cast<SS3OVertex*>(&buf[vertexOffset]);
			sv->normal.ANormalize();

		piece->vertices.push_back(*sv);
		vertexOffset += sizeof(Vertex);
	}


	// retrieve the draw order for the vertices
	int vertexTableOffset = fp->vertexTable;

	for (int a = 0; a < fp->vertexTableSize; ++a) {
		const int vertexDrawIdx = swabdword(*(int*) &buf[vertexTableOffset]);

		piece->vertexDrawOrder.push_back(vertexDrawIdx);
		vertexTableOffset += sizeof(int);
	}


	piece->isEmpty = piece->vertexDrawOrder.empty();
	piece->goffset = piece->offset + ((parent != NULL)? parent->goffset: ZeroVector);

	piece->SetVertexTangents();
	piece->SetMinMaxExtends();

	model->mins.x = std::min(piece->mins.x, model->mins.x);
	model->mins.y = std::min(piece->mins.y, model->mins.y);
	model->mins.z = std::min(piece->mins.z, model->mins.z);
	model->maxs.x = std::max(piece->maxs.x, model->maxs.x);
	model->maxs.y = std::max(piece->maxs.y, model->maxs.y);
	model->maxs.z = std::max(piece->maxs.z, model->maxs.z);

	const float3 cvScales = piece->maxs - piece->mins;
	const float3 cvOffset =
		(piece->maxs - piece->goffset) +
		(piece->mins - piece->goffset);

	piece->SetCollisionVolume(new CollisionVolume("box", cvScales, cvOffset * 0.5f, CollisionVolume::COLVOL_HITTEST_CONT));


	int childTableOffset = fp->childs;

	for (int a = 0; a < fp->numChilds; ++a) {
		int childOffset = swabdword(*(int*) &buf[childTableOffset]);

		SS3OPiece* childPiece = LoadPiece(model, piece, buf, childOffset);
		piece->childs.push_back(childPiece);

		childTableOffset += sizeof(int);
	}

	return piece;
}