Esempio n. 1
0
void CraftManager::LoadRecipeFile(const char *filename)
{
	FileReader3 fr;
	if(fr.OpenFile(filename) != FileReader3::SUCCESS)
	{
		g_Logs.data->error("Error opening crafting recipe file:%v", filename);
		return;
	}
	fr.SetCommentChar(';');
	fr.ReadLine(); //Assume first line is header.
	while(fr.Readable() == true)
	{
		fr.ReadLine();
		int r = fr.MultiBreak("\t");
		if(r >= 2)
		{
			CraftRecipe entry;
			entry.mDesc = fr.BlockToStringC(0);
			entry.mInputCount = fr.BlockToIntC(1);
			entry.mOutputCount = fr.BlockToIntC(2);

			std::string line;

			line = fr.BlockToStringC(3);
			Util::TrimWhitespace(line);
			Util::ToLowerCase(line);
			Util::Split(line, "|", entry.mConditions);

			line = fr.BlockToStringC(4);
			Util::TrimWhitespace(line);
			Util::ToLowerCase(line);
			Util::Split(line, "|", entry.mActions);

			mRecipes.push_back(entry);
		}
	}
	fr.CloseFile();
}
Esempio n. 2
0
void SceneryPage::LoadSceneryFromFile(const char *fileName)
{
	FileReader3 fr;
	if(fr.OpenFile(fileName) != FileReader3::SUCCESS)
	{
		//g_Log.AddMessageFormat("Could not open file to load scenery: [%s]", fileName);
		return;
	}
	fr.SetCommentChar(';');
	SceneryObject prop;
	int propertyIndex = 0;
	int linkIndex = 0;

	while(fr.Readable() == true)
	{
		int r = fr.ReadLine();
		if(r == 0)
			continue;

		r = fr.MultiBreak("=,");
		fr.BlockToStringC(0, FileReader3::CASE_UPPER);
		if(strcmp(fr.CopyBuffer, "[ENTRY]") == 0)
		{
			if(prop.ID != 0)
			{
				if(prop.Name[0] == 0)
					prop.SetName("Untitled");
				AddProp(prop, false);
			}
			prop.Clear();
			propertyIndex = 0;
			linkIndex = 0;
		}
		else if(strcmp(fr.CopyBuffer, "ID") == 0)
			prop.ID = fr.BlockToIntC(1);
		else if(strcmp(fr.CopyBuffer, "ASSET") == 0)
		{
			//The asset string needs to be single broken.
			fr.SingleBreak("=");
			prop.SetAsset(fr.BlockToStringC(1));
		}
		else if(strcmp(fr.CopyBuffer, "NAME") == 0)
			prop.SetName(fr.BlockToStringC(1, 0));
		else if(strcmp(fr.CopyBuffer, "POS") == 0)
		{
			prop.LocationX = fr.BlockToFloatC(1);
			prop.LocationY = fr.BlockToFloatC(2);
			prop.LocationZ = fr.BlockToFloatC(3);
		}
		else if(strcmp(fr.CopyBuffer, "ORIENT") == 0)
		{
			prop.QuatX = fr.BlockToFloatC(1);
			prop.QuatY = fr.BlockToFloatC(2);
			prop.QuatZ = fr.BlockToFloatC(3);
			prop.QuatW = fr.BlockToFloatC(4);
		}
		else if(strcmp(fr.CopyBuffer, "SCALE") == 0)
		{
			prop.ScaleX = fr.BlockToFloatC(1);
			prop.ScaleY = fr.BlockToFloatC(2);
			prop.ScaleZ = fr.BlockToFloatC(3);
		}
		else if(strcmp(fr.CopyBuffer, "FLAGS") == 0)
			prop.Flags = fr.BlockToIntC(1);
		else if(strcmp(fr.CopyBuffer, "LAYER") == 0)
			prop.Layer = fr.BlockToIntC(1);
		else if(strcmp(fr.CopyBuffer, "PATROLSPEED") == 0)
			prop.patrolSpeed = fr.BlockToIntC(1);
		else if(strcmp(fr.CopyBuffer, "PATROLEVENT") == 0)
			prop.SetPatrolEvent(fr.BlockToStringC(1));
		else if(strcmp(fr.CopyBuffer, "PROPS_COUNT") == 0)
			prop.SetPropertyCount(fr.BlockToIntC(1));
		else if(strcmp(fr.CopyBuffer, "PROPERTY") == 0)
		{
			//Calling BlockToStringC() overwrites the previous copy, so we need yet another
			//copy buffer to hold one parameter while we get another.
			char buffer[256];
			Util::SafeCopy(buffer, fr.BlockToStringC(1), sizeof(buffer));
			prop.SetProperty(propertyIndex++, buffer, fr.BlockToIntC(2), fr.BlockToStringC(3)); 
		}
		else if(strcmp(fr.CopyBuffer, "LINKS_COUNT") == 0)
			prop.SetLinkCount(fr.BlockToIntC(1));
		else if(strcmp(fr.CopyBuffer, "LINK") == 0)
		{
			int propID = fr.BlockToIntC(1);
			int linkType = fr.BlockToIntC(2);
			if(propID != 0)   //Fix to prevent null props.
				prop.SetLink(linkIndex++, propID, linkType);
		}
		else if(strcmp(fr.CopyBuffer, "FACING") == 0)
		{
			//Degree rotation facing is generated by the log rips and is used
			//to more easily spawn creatures with predetermined directional
			//facings rather than trying to look at the quaternion rotation of
			//the spawnpoint prop itself.
			if(prop.CreateExtraData() == true)
				prop.extraData->facing = fr.BlockToIntC(1);
		}
		else if(prop.IsExtendedProperty(fr.BlockToStringC(0)) == true)
		{
			char buffer[256];
			Util::SafeCopy(buffer, fr.CopyBuffer, sizeof(buffer));
			prop.SetExtendedProperty(buffer, fr.BlockToStringC(1));
		}
		//BEGIN DEPRECATED, PROVIDED FOR COMPATIBILITY WITH OLD FILES
		else if(strcmp(fr.CopyBuffer, "PX") == 0)
			prop.LocationX = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "PY") == 0)
			prop.LocationY = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "PZ") == 0)
			prop.LocationZ = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "QX") == 0)
			prop.QuatX = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "QY") == 0)
			prop.QuatY = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "QZ") == 0)
			prop.QuatZ = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "QW") == 0)
			prop.QuatW = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "SX") == 0)
			prop.ScaleX = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "SY") == 0)
			prop.ScaleY = fr.BlockToFloatC(1);
		else if(strcmp(fr.CopyBuffer, "SZ") == 0)
			prop.ScaleZ = fr.BlockToFloatC(1);
		//END DEPRECATED
	}

	if(prop.ID != 0)
	{
		if(prop.Name[0] == 0)
			prop.SetName("Untitled");
		AddProp(prop, false);
	}

	fr.CloseFile();
	mHasSourceFile = true;
	//g_Log.AddMessageFormat("Loaded scenery file: [%s]", fileName);
}