Exemplo n.º 1
0
bool MSWeaponArmory::loadWeapon(pugi::xml_node& xmlWeapon)
{
	r3d_assert(!xmlWeapon.empty());

	uint32_t itemID = xmlWeapon.attribute("itemID").as_uint();
	// check if we have that weapon in our database
	for(uint32_t i=0; i<m_NumWeaponsLoaded; ++i) // todo: change to hash table
	{
		if(m_WeaponArray[i]->m_itemID == itemID)
		{
			r3dOutToLog("Trying to load a weapon with id '%d' that is already loaded!", itemID);
			return false;
		}
	}
	if(m_NumWeaponsLoaded > MAX_NUMBER_WEAPONS-2)
	{
		r3dOutToLog("Trying to load more than maximum number of weapons. Maximum is '%d'\n", MAX_NUMBER_WEAPONS);
		return false;
	}

	WeaponConfig* weapon = new WeaponConfig(itemID);
	if(!weapon->loadBaseFromXml(xmlWeapon))
	{
		delete weapon;
		return false;
	}

	m_WeaponArray[m_NumWeaponsLoaded] = weapon;
	m_NumWeaponsLoaded++;
	return true;
}
distribution parse_distribution(pugi::xml_node node) {
    distribution dist;
    if (!node.empty()) {
        string type = node.attribute("type").value();
        if (type == "uniform") {
            size_t min = node.child("min").text().as_uint();
            size_t max = node.child("max").text().as_uint();
            dist.type = DISTRIBUTION::UNIFORM;
            dist.arg1 = min;
            dist.arg2 = max;
        } else if (type == "zipfian") {
            size_t n = node.child("n").text().as_uint();
            double alpha = node.child("alpha").text().as_double();
            dist.type = DISTRIBUTION::ZIPFIAN;
            dist.arg1 = n;
            dist.arg2 = alpha;
        } else if (type == "normal" or type == "gaussian") {
            double mean = node.child("mu").text().as_double();
            double stddev = node.child("sigma").text().as_double();
            dist.type = DISTRIBUTION::NORMAL;
            dist.arg1 = mean;
            dist.arg2 = stddev;
        }
    }
    return dist;
}
Exemplo n.º 3
0
bool MSWeaponArmory::loadGear(pugi::xml_node& xmlGear)
{
	r3d_assert(!xmlGear.empty());

	uint32_t itemID = xmlGear.attribute("itemID").as_uint();
	for(uint32_t i=0; i<m_NumGearLoaded; ++i) // todo: change to hash table
	{
		if(m_GearArray[i]->m_itemID == itemID)
		{
			r3dOutToLog("Trying to load a gear with id '%d' that is already loaded!", itemID);
			return false;
		}
	}
	if(m_NumGearLoaded > MAX_NUMBER_GEAR-2)
	{
		r3dOutToLog("Trying to load more than maximum number of gear. Maximum is '%d'\n", MAX_NUMBER_GEAR);
		return false;
	}

	GearConfig* gear = new GearConfig(itemID);
	// load base stuff, common for all versions
	if(!gear->loadBaseFromXml(xmlGear))
	{
		delete gear;
		return false;
	}

	m_GearArray[m_NumGearLoaded] = gear;
	m_NumGearLoaded++;

	return true;
}
Exemplo n.º 4
0
void CUserProfile::ParseBackpacks(pugi::xml_node& xmlItem)
{
	// enter into items list
	xmlItem = xmlItem.first_child();
	while(!xmlItem.empty())
	{
		uint32_t CharID  = xmlItem.attribute("CharID").as_uint();
		r3d_assert(CharID);
		
		bool found = true;
		for(int i=0; i<ProfileData.NumSlots; i++) 
		{
			if(ProfileData.ArmorySlots[i].LoadoutID == CharID) 
			{
				parseCharBackpack(xmlItem, ProfileData.ArmorySlots[i]);
				found = true;
				break;
			}
		}
		
		if(!found)
			r3dError("bad backpack data for charid %d", CharID);

		xmlItem = xmlItem.next_sibling();
	}
}
Exemplo n.º 5
0
void CUserProfile::ParseInventory(pugi::xml_node& xmlItem)
{
	ProfileData.NumItems = 0;

	// enter into items list
	xmlItem = xmlItem.first_child();
	while(!xmlItem.empty())
	{
		wiInventoryItem& itm = ProfileData.Inventory[ProfileData.NumItems++];
		r3d_assert(ProfileData.NumItems < wiUserProfile::MAX_INVENTORY_SIZE);

		parseInventoryItem(xmlItem, itm);

		xmlItem = xmlItem.next_sibling();
	}
}
Exemplo n.º 6
0
int32_t
GCConfigTest::parseGarbagePolicy(pugi::xml_node node)
{
	OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib);
	int32_t rt = 0;
	gp.namePrefix = NULL;
	gp.percentage = 0.0f;
	gp.frequency = "none";
	gp.structure = NULL;
	gp.accumulatedSize = 0;

	if (!node.empty()) {
		gp.namePrefix = node.attribute("namePrefix").value();
		if (0 == strcmp(gp.namePrefix, "")) {
			gp.namePrefix = "GARBAGE";
		}

		const char* percentageStr = node.attribute("percentage").value();
		if (0 == strcmp(percentageStr, "")) {
			percentageStr = "100";
		}
		gp.percentage = (float)atof(percentageStr);

		gp.frequency = node.attribute("frequency").value();
		if (0 == strcmp(gp.frequency, "")) {
			gp.frequency = "perRootStruct";
		}
		if ((0 != strcmp(gp.frequency, "perObject")) && (0 != strcmp(gp.frequency, "perRootStruct"))){
			rt = 1;
			omrtty_printf("%s:%d Invalid XML input: the valid value of attribute \"frequency\" is \"perObject\" or \"perRootStruct\".\n", __FILE__, __LINE__);
			goto done;
		}

		gp.structure = node.attribute("structure").value();
		if (0 == strcmp(gp.structure, "")) {
			gp.structure = "node";
		}
		if ((0 != strcmp(gp.structure, "node")) && (0 != strcmp(gp.structure, "tree"))){
			rt = 1;
			omrtty_printf("%s:%d Invalid XML input: the valid value of attribute \"structure\" is \"node\" or \"tree\".\n", __FILE__, __LINE__);
			goto done;
		}
	}

done:
	return rt;
}
Exemplo n.º 7
0
static void parseCharBackpack(pugi::xml_node xmlItem, wiCharDataFull& w)
{
	// enter into items list
	xmlItem = xmlItem.first_child();
	while(!xmlItem.empty())
	{
		wiInventoryItem itm;
		parseInventoryItem(xmlItem, itm);

		int slot = xmlItem.attribute("s").as_int();

		r3d_assert(slot >= 0 && slot < w.BackpackSize);
		r3d_assert(w.Items[slot].InventoryID == 0);
		w.Items[slot] = itm;

		xmlItem = xmlItem.next_sibling();
	}

	
	return;
}
Exemplo n.º 8
0
bool MSWeaponArmory::loadItem(pugi::xml_node& xmlItem)
{
	r3d_assert(!xmlItem.empty());

	uint32_t itemID = xmlItem.attribute("itemID").as_uint();
	for(uint32_t i=0; i<m_NumItemLoaded; ++i) // todo: change to hash table
	{
		if(m_ItemArray[i]->m_itemID == itemID)
		{
			r3dOutToLog("Trying to load an item with id '%d' that is already loaded!", itemID);
			return false;
		}
	}
	if(m_NumItemLoaded > MAX_NUMBER_ITEM-1)
	{
		r3dOutToLog("Trying to load more than maximum number of items. Maximum is '%d'\n", MAX_NUMBER_ITEM);
		return false;
	}

	ItemConfig* item = new ItemConfig(itemID);
	item->category = (STORE_CATEGORIES)xmlItem.attribute("category").as_int();

	const char* desc = xmlItem.child("Store").attribute("desc").value();
	r3d_assert(desc);
	item->m_Description = strdup(desc);
	item->m_StoreIcon = strdup(xmlItem.child("Store").attribute("icon").value());
	item->m_StoreName = strdup(xmlItem.child("Store").attribute("name").value());
	item->m_LevelRequired = xmlItem.child("Store").attribute("LevelRequired").as_int();
	item->m_StoreNameW = wcsdup(utf8ToWide(item->m_StoreName));
	item->m_DescriptionW = wcsdup(utf8ToWide(item->m_Description));

	if(!xmlItem.child("Model").empty())
		item->m_ModelPath = strdup(xmlItem.child("Model").attribute("file").value());

	m_ItemArray[m_NumItemLoaded] = item;
	m_NumItemLoaded++;

	return true;
}
Exemplo n.º 9
0
void CJobGetServerNotes::parseNotes(pugi::xml_node xmlNote)
{
	AllNotes.clear();

	// enter into items list
	xmlNote = xmlNote.first_child();
	while(!xmlNote.empty())
	{
		obj_Note::data_s note;
		note.NoteID     = xmlNote.attribute("NoteID").as_int();
		note.CreateDate = xmlNote.attribute("CreateDate").as_int64();
		note.ExpireMins = xmlNote.attribute("ExpireMins").as_int64();
		note.TextFrom   = xmlNote.attribute("TextFrom").value();
		note.TextSubj   = xmlNote.attribute("TextSubj").value();

		note.in_GamePos = r3dPoint3D(0, 0, 0);
		sscanf(xmlNote.attribute("GamePos").value(), "%f %f %f", &note.in_GamePos.x, &note.in_GamePos.y, &note.in_GamePos.z);
		
		AllNotes.push_back(note);
		xmlNote = xmlNote.next_sibling();
	}
	
	return;
}
Exemplo n.º 10
0
void output_geometry(const pugi::xml_node &input, const CoreMesh &mesh)
{
    if (input.empty()) {
        throw EXCEPT("No input for geometry output.");
    }

    string file;
    if (input.attribute("file").empty()) {
        file = "geom.py";
    }
    else {
        file = input.attribute("file").value();
    }

    int plane = input.attribute("plane").as_int(0);
    if ((plane < 0) || (plane >= (int)mesh.nz())) {
        throw EXCEPT("Invalid plane specified.");
    }

    ofstream out(file);

    // boilerplate
    out << "import cairo as cr" << std::endl;
    out << "import math" << std::endl;
    out << "import rays" << std::endl;
    out << std::endl;
    out << "twopi = math.pi*2" << std::endl;
    out << std::endl;
    out << "# set this to whichever angle of ray you want to show."
           " Negative value to disable."
        << std::endl;
    out << "angle = -1" << std::endl;
    out << std::endl;
    out << "mesh_lines = []" << std::endl;
    out << std::endl;
    out << "core_dims = [" << mesh.hx_core() << ", " << mesh.hy_core() << "]"
        << std::endl;
    out << "" << std::endl;
    out << "surface = cr.PDFSurface(\"geometry.pdf\", 720, 720)" << std::endl;
    out << "ctx = cr.Context(surface)" << std::endl;
    out << "ctx.scale(720/core_dims[0], -720/core_dims[1])" << std::endl;
    out << "ctx.translate(0, -core_dims[1])" << std::endl;
    out << "" << std::endl;

    // do all of the mesh stuff
    out << "ctx.set_line_width(0.001)" << std::endl;
    out << "" << std::endl;
    out << "ctx.set_source_rgb(0, 0, 0)" << std::endl;
    out << "" << std::endl;

    for (auto l : mesh.lines()) {
        out << "mesh_lines.append(" << l << ")" << std::endl;
    }

    // Draw the core lines
    out << "" << std::endl;
    out << "for l in mesh_lines:" << std::endl;
    out << "    p1 = l[0]" << std::endl;
    out << "    p2 = l[1]" << std::endl;
    out << "    ctx.move_to(p1[0], p1[1])" << std::endl;
    out << "    ctx.line_to(p2[0], p2[1])" << std::endl;

    out << std::endl;

    // Draw the pin meshes
    int ipin = 0;
    for (auto pin = mesh.begin(plane); pin != mesh.end(plane); ++pin) {
        out << "print \"drawing pin \" + str(" << ipin << ")" << std::endl;
        const PinMesh &pm = (*pin)->mesh();
        Point2 origin     = mesh.pin_origin(ipin);

        out << "ctx.translate(" << origin.x << ", " << origin.y << ")" << std::endl;

        out << pm.draw() << std::endl;
        out << "ctx.translate(" << -origin.x << ", " << -origin.y << ")" << std::endl
            << std::endl;
        ipin++;
    }

    out << std::endl;

    // Do ray output
    out << "if angle >= 0:" << std::endl;
    out << "    ctx.set_source_rgb(0, 0, 1)" << std::endl;
    out << "    rays.draw_rays(ctx, angle)" << std::endl;
    out << "" << std::endl;

    out << "surface.finish()" << std::endl;
    out << "" << std::endl;

    return;
}
Exemplo n.º 11
0
void CUserProfile::ParseLoadouts(pugi::xml_node& xmlItem)
{
	// reset current backpacks
	for(int i=0; i<ProfileData.NumSlots; i++) {
		for(int j=0; j<ProfileData.ArmorySlots[i].BackpackSize; j++) {
			ProfileData.ArmorySlots[i].Items[j].Reset();
		}
	}

	ProfileData.NumSlots = 0;
	
	// parse all slots
	xmlItem = xmlItem.first_child();
	while(!xmlItem.empty())
	{
		wiCharDataFull& w = ProfileData.ArmorySlots[ProfileData.NumSlots++];
		wiStats& st = w.Stats;
		if(ProfileData.NumSlots > wiUserProfile::MAX_LOADOUT_SLOTS)
			r3dError("more that 6 profiles!");

		w.LoadoutID   = xmlItem.attribute("CharID").as_uint();
		r3dscpy(w.Gamertag, xmlItem.attribute("Gamertag").value());
		w.Alive       = xmlItem.attribute("Alive").as_int();
		w.Hardcore    = xmlItem.attribute("Hardcore").as_int();
		st.XP         = xmlItem.attribute("XP").as_int();
		st.TimePlayed = xmlItem.attribute("TimePlayed").as_int();
		w.Health      = xmlItem.attribute("Health").as_float();
		w.Hunger      = xmlItem.attribute("Hunger").as_float();
		w.Thirst      = xmlItem.attribute("Thirst").as_float();
		w.Toxic       = xmlItem.attribute("Toxic").as_float();
		st.Reputation = xmlItem.attribute("Reputation").as_int();
		w.DeathUtcTime= xmlItem.attribute("DeathTime").as_int64();
		w.SecToRevive = xmlItem.attribute("SecToRevive").as_int();

		w.GameMapId   = xmlItem.attribute("GameMapId").as_int();
		w.GameServerId= xmlItem.attribute("GameServerId").as_int();
		w.GamePos = r3dPoint3D(0, 0, 0);
	    if (w.GameMapId == 5) // Colorado_pve
            sscanf(xmlItem.attribute("GamePos2").value(), "%f %f %f %f", &w.GamePos.x, &w.GamePos.y, &w.GamePos.z, &w.GameDir);
		else if (w.GameMapId == 6) // ATLANTA
            sscanf(xmlItem.attribute("GamePos3").value(), "%f %f %f %f", &w.GamePos.x, &w.GamePos.y, &w.GamePos.z, &w.GameDir);	
		else if (w.GameMapId == 8) // VALLEY
            sscanf(xmlItem.attribute("GamePos4").value(), "%f %f %f %f", &w.GamePos.x, &w.GamePos.y, &w.GamePos.z, &w.GameDir);	
		else	
		sscanf(xmlItem.attribute("GamePos").value(), "%f %f %f %f", &w.GamePos.x, &w.GamePos.y, &w.GamePos.z, &w.GameDir);
		w.GameFlags   = xmlItem.attribute("GameFlags").as_int();

		w.HeroItemID  = xmlItem.attribute("HeroItemID").as_int();
		w.HeadIdx     = xmlItem.attribute("HeadIdx").as_int();
		w.BodyIdx     = xmlItem.attribute("BodyIdx").as_int();
		w.LegsIdx     = xmlItem.attribute("LegsIdx").as_int();

		w.ClanID      = xmlItem.attribute("ClanID").as_int();
		w.GroupID      = xmlItem.attribute("GroupID").as_int();//ViruZ Group
		w.ClanRank    = xmlItem.attribute("ClanRank").as_int();
		r3dscpy(w.ClanTag, xmlItem.attribute("ClanTag").value());
		w.ClanTagColor= xmlItem.attribute("ClanTagColor").as_int();

		const char* attm1 = xmlItem.attribute("attm1").value();
		const char* attm2 = xmlItem.attribute("attm2").value();
		parseCharAttachments(attm1, w.Attachment[0]);
		parseCharAttachments(attm2, w.Attachment[1]);

		w.BackpackID   = xmlItem.attribute("BackpackID").as_uint();
		w.BackpackSize = xmlItem.attribute("BackpackSize").as_int();
		
		// trackable stats
		st.KilledZombies   = xmlItem.attribute("ts00").as_int();
		st.KilledSurvivors = xmlItem.attribute("ts01").as_int();
		st.KilledBandits   = xmlItem.attribute("ts02").as_int();

		// skill xp
		st.SkillXPPool = st.XP;

		//SkillSystem
		st.skillid0 = xmlItem.attribute("SkillID0").as_int();
		st.skillid1 = xmlItem.attribute("SkillID1").as_int();
		st.skillid2 = xmlItem.attribute("SkillID2").as_int();
		st.skillid3 = xmlItem.attribute("SkillID3").as_int();
		st.skillid4 = xmlItem.attribute("SkillID4").as_int();
		st.skillid5 = xmlItem.attribute("SkillID5").as_int();
		st.skillid6 = xmlItem.attribute("SkillID6").as_int();
		st.skillid7 = xmlItem.attribute("SkillID7").as_int();
		st.skillid8 = xmlItem.attribute("SkillID8").as_int();
		st.skillid9 = xmlItem.attribute("SkillID9").as_int();
		st.skillid10 = xmlItem.attribute("SkillID10").as_int();
		st.skillid11 = xmlItem.attribute("SkillID11").as_int();
		st.skillid12 = xmlItem.attribute("SkillID12").as_int();
		st.skillid13 = xmlItem.attribute("SkillID13").as_int();
		st.skillid14 = xmlItem.attribute("SkillID14").as_int();
		st.skillid15 = xmlItem.attribute("SkillID15").as_int();
		st.skillid16 = xmlItem.attribute("SkillID16").as_int();
		st.skillid17 = xmlItem.attribute("SkillID17").as_int();
		st.skillid18 = xmlItem.attribute("SkillID18").as_int();
		st.skillid19 = xmlItem.attribute("SkillID19").as_int();
		st.skillid20 = xmlItem.attribute("SkillID20").as_int();
		st.skillid21 = xmlItem.attribute("SkillID21").as_int();
		st.skillid22 = xmlItem.attribute("SkillID22").as_int();
		st.skillid23 = xmlItem.attribute("SkillID23").as_int();
		st.skillid24 = xmlItem.attribute("SkillID24").as_int();
		st.skillid25 = xmlItem.attribute("SkillID25").as_int();
		st.skillid26 = xmlItem.attribute("SkillID26").as_int();
		st.skillid27 = xmlItem.attribute("SkillID27").as_int();
		st.skillid28 = xmlItem.attribute("SkillID28").as_int();
		st.skillid29 = xmlItem.attribute("SkillID29").as_int();
		st.skillid30 = xmlItem.attribute("SkillID30").as_int();
		st.skillid31 = xmlItem.attribute("SkillID31").as_int();
		st.skillid32 = xmlItem.attribute("SkillID32").as_int();
		st.skillid33 = xmlItem.attribute("SkillID33").as_int();

		xmlItem = xmlItem.next_sibling();
	}
}