Exemplo n.º 1
0
BOOL FindMarkItem(CMarkup& markDoc, ST_MARKITEM& kvOut)
{
	while(markDoc.FindElem())
	{
		//tree node, set val to empty
		kvOut.strVal.Empty();
		kvOut.bIsPath = TRUE;
		ST_MARKITEM tmpItem;
		CString strAttKey;
		CString strAttVal;
		int nAttIdx = 0;
		while(markDoc.GetNthAttrib(nAttIdx, strAttKey, strAttVal))
		{
			tmpItem.mapAttrib[strAttKey] = strAttVal;
			++nAttIdx;
		}

		tmpItem.strKey = markDoc.GetTagName();
		tmpItem.strVal = markDoc.GetElemContent();
		markDoc.IntoElem();
		FindMarkItem(markDoc, tmpItem);
		markDoc.OutOfElem();

		kvOut.mapChildItem[tmpItem.strKey] = tmpItem;
	}

	return TRUE;
}
Exemplo n.º 2
0
Vehicle::Vehicle(const char * inputXml)
{
   CMarkup xml;
   xml.SetDoc (inputXml);
   xml.FindElem ();
   xml.IntoElem ();

   while (xml.FindElem ()) {
      std::string tag = xml.GetTagName ();
      if (tag == "vtypeidname") {
         vtypeidname_ = xml.GetData();
      }
      else if (tag == "vtypeid") {
         vtypeid_ = atoi (xml.GetData().c_str());
      }
      else if (tag == "color") {
         color_ = xml.GetData();
      }
      else if (tag == "heat") {
         heat_ = atoi (xml.GetData().c_str());
      }
      else if (tag == "location") {
         location_ = atoi (xml.GetData().c_str());
      }
      else if (tag == "myear") {
         myear_ = atoi (xml.GetData().c_str());
      }
      else if (tag == "id") {
         id_ = atoi (xml.GetData().c_str());
      }
   }
}
bool VectorOfFloatComplexType::ParseXMLInstance(const std::string& instance)
{ 
	CMarkup parser;
	parser.SetDoc(instance);
	parser.ResetPos();
	parser.FindElem();
	if(parser.GetTagName()!=name)
		return false;
	parser.IntoElem();	
	while(parser.FindElem())
	{
		std::string str=parser.GetTagName();
		std::string val=parser.GetSubDoc();
		Float* value_item=new Float(str);
		value_item->ParseXMLInstance(val);
		elements[0].AddValue(value_item);
	}
	return true;
}
Exemplo n.º 4
0
Shop::ShopItem::ShopItem(MCD_STR xmlstring, bool only_sell_legal,
                         bool increase_price_with_illegality)
 : price_(0), only_sell_legal_(only_sell_legal),
   increase_price_with_illegality_(increase_price_with_illegality),
   description_defined_(false)
{
   CMarkup xml;
   xml.SetDoc(xmlstring);
   xml.FindElem();
   xml.IntoElem();

   while (xml.FindElem())
   {
      std::string tag = xml.GetTagName();

      if (tag == "class")
      {
         if (xml.GetData() == "WEAPON")
            itemclass_ = WEAPON;
         else if (xml.GetData() == "CLIP")
            itemclass_ = CLIP;
         else if (xml.GetData() == "ARMOR")
            itemclass_ = ARMOR;
         else if (xml.GetData() == "LOOT")
            itemclass_ = LOOT;
      }
      else if (tag == "type")
         itemtypename_ = xml.GetData();
      else if (tag == "description")
      {
         description_ = xml.GetData();
         description_defined_ = true;
      }
      else if (tag == "price")
         price_ = atoi(xml.GetData().c_str());
      else if (tag == "sleeperprice")
	     sleeperprice_ = atoi(xml.GetData().c_str());
	  else if (tag == "letter")
      {
         letter_ = xml.GetData()[0];
         if (97 <= letter_ && letter_ <= 122) //Check it is a letter.
            letter_defined_ = true;
         else if (65 <= letter_ && letter_ <= 90)
         {
            letter_ += 32;
            letter_defined_ = true;
         }
         else if (letter_ == '!') //Allow special character.
            letter_defined_ = true;
      }
   }
}
Exemplo n.º 5
0
bool
ESDBXMLResponse::ParseXMLString(CString sXML, ESDBXMLRequestMan* pReqMan){
	CMarkup xmlDoc;
	if( !xmlDoc.SetDoc(sXML) )
		return false;

	if( !xmlDoc.FindElem() )
		return false;

	StringToIntArray*	pReqTypes	= ESDBXMLRequest::GetRequestTypes();
 	RequestType			reqType		= (RequestType)pReqTypes->GetValue(xmlDoc.GetTagName());
	if( reqType == RequestType::db_unknown )
		return false;

	if( !xmlDoc.IntoElem() )
		return false;

	// Fill params array. ######
	if( m_pParams )
		delete m_pParams;	
	m_pParams = new StringToStringArray();

	while( xmlDoc.FindElem() ){
		m_pParams->Add(xmlDoc.GetTagName(), xmlDoc.GetData());
		}
	// #########################

	int	nReqId	= atoi(m_pParams->GetValue("req_id"));
	ESDBXMLRequest* req	= pReqMan->GetRequestById(nReqId);
	if( req == NULL || req->GetResponse() != NULL )
		return false;

	// Attach to request object.
	m_pRequest = req;
	req->SetType	(reqType);
	req->SetResponse(this);
	return true;
	}
Exemplo n.º 6
0
Item::Item(const std::string& inputXml)
{
   CMarkup xml;
   xml.SetDoc(inputXml);
   xml.FindElem();
   xml.IntoElem();
   while(xml.FindElem())
   {
      std::string tag=xml.GetTagName();
      if(tag=="itemtypename") itemtypename_=xml.GetData();
      else if(tag=="itemtypeid") itemtypeid_=atoi(xml.GetData());
      else if(tag=="number") number_=atoi(xml.GetData());
   }
}
Exemplo n.º 7
0
LootType::LootType(MCD_STR xmlstring)
 : ItemType(xmlstring), stackable_(true),
   no_quick_fencing_(false), cloth_(false)
{
   CMarkup xml;
   xml.SetDoc(xmlstring);
   xml.FindElem();
   xml.IntoElem();

   while (xml.FindElem()) //Loop over all the elements inside the loottype element.
   {
      std::string element = xml.GetTagName();

      if (element == "stackable")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            stackable_ = true;
         else if (b == 0)
            stackable_ = false;
         /*else
            errorlog << "Invalid boolean value for loot type " << idname
                      << "::stackable: " << xml.GetData() << std::endl;*/
      }
      else if (element == "no_quick_fencing")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            no_quick_fencing_ = true;
         else if (b == 0)
            no_quick_fencing_ = false;
         /*else
            errorlog << "Invalid boolean value for loot type " << idname
                      << "::no_quick_fencing: " << xml.GetData() << std::endl;*/
      }
      else if (element == "cloth")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            cloth_ = true;
         else if (b == 0)
            cloth_ = false;
         /*else
            errorlog << "Invalid boolean value for loot type " << idname
                      << "::cloth: " << xml.GetData() << std::endl;*/
      }
   }
}
Exemplo n.º 8
0
ClipType::ClipType(MCD_STR xmlstring) : ItemType(xmlstring), ammo_(1)
{
   CMarkup xml;
   xml.SetDoc(xmlstring);
   xml.FindElem();
   xml.IntoElem();

   while(xml.FindElem()) //Loop over all the elements inside the cliptype element.
   {
      std::string element=xml.GetTagName();
      if(element=="ammo")
         ammo_=atoi(xml.GetData());
      /*else
         errorlog << "Unknown element for clip type " << idname() << ": " << element << endl;*/
   }
}
Exemplo n.º 9
0
Money::Money(const char * inputXml)
 : Item(inputXml)
{
   CMarkup xml;
   xml.SetDoc (inputXml);
   xml.FindElem ();
   xml.IntoElem ();
   
   while (xml.FindElem ())
   {
      std::string tag = xml.GetTagName ();
   
      if (tag == "amount")
         amount_ = atoi(xml.GetData().c_str());
   }
}
Exemplo n.º 10
0
Weapon::Weapon(const char * inputXml)
 : Item(inputXml)
{
   CMarkup xml;
   xml.SetDoc (inputXml);
   xml.FindElem ();
   xml.IntoElem ();
   
   while (xml.FindElem ())
   {
      std::string tag = xml.GetTagName ();
      
      if (tag == "loaded_cliptype")
         loaded_cliptype_ = xml.GetData();
      else if (tag == "ammo")
         ammo_ = atoi(xml.GetData().c_str());
   }
}
Exemplo n.º 11
0
/* Used by load() to create items of the correct class. */
Item* create_item(const std::string& inputXml)
{
   Item* it = NULL;
   CMarkup xml;
   xml.SetDoc(inputXml);
   xml.FindElem();
   string itemclass = xml.GetTagName();
   if (itemclass == "clip")
      it = new Clip(inputXml);
   else if (itemclass == "weapon")
      it = new Weapon(inputXml);
   else if (itemclass == "armor")
      it = new Armor(inputXml);
   else if (itemclass == "loot")
      it = new Loot(inputXml);
   else if (itemclass == "money")
      it = new Money(inputXml);

   return it;
}
Exemplo n.º 12
0
/**
调用此函数前需保证xml中已经通过FindElem()定位到当前元素。
*/
void CXmlElement::Load(CMarkup& xml)
{
	_name = xml.GetTagName();
	CString attrib_name, attrib_value;
	int i = 0;
	while(xml.GetNthAttrib(i, attrib_name, attrib_value))
	{
		_attributes.push_back(std::make_pair(attrib_name, attrib_value));
		++i;
	}
	_value = xml.GetData();
	if (_value.IsEmpty())
	{
		xml.IntoElem();
		while (xml.FindElem())
		{
			CXmlElement* element = new CXmlElement;
			element->Load(xml);
			_children.push_back(element);
		}
		xml.OutOfElem();
	}
}
Exemplo n.º 13
0
CreatureType::CreatureType(const std::string& xmlstring)
    : age_(18,57), alignment_public_mood_(true),
      attribute_points_(40),
      gender_liberal_(GENDER_RANDOM), gender_conservative_(GENDER_RANDOM),
      infiltration_(0), juice_(0), money_(20,40)
{
    for(int i=0; i<ATTNUM; i++)
        attributes_[i].set_interval(1,10);

    id_=number_of_creaturetypes++;

    CMarkup xml;
    xml.SetDoc(xmlstring);
    xml.FindElem();

    idname_=xml.GetAttrib("idname");
    if(!len(idname_))
    {
        idname_ = "LACKS IDNAME "+tostring(id_);
        xmllog.log("Creature type "+tostring(id_)+" lacks idname.");
    }
    type_=creaturetype_string_to_enum(idname_);

    xml.IntoElem();
    // Loop over all the elements inside the creaturetype element.
    while(xml.FindElem())
    {
        std::string element = xml.GetTagName();

        if (element == "alignment")
        {
            std::string alignment = xml.GetData();
            if (alignment == "PUBLIC MOOD")
                alignment_public_mood_ = true;
            else if (alignment == "LIBERAL")
            {
                alignment_ = ALIGN_LIBERAL;
                alignment_public_mood_ = false;
            }
            else if (alignment == "MODERATE")
            {
                alignment_ = ALIGN_MODERATE;
                alignment_public_mood_ = false;
            }
            else if (alignment == "CONSERVATIVE")
            {
                alignment_ = ALIGN_CONSERVATIVE;
                alignment_public_mood_ = false;
            }
            else
                xmllog.log("Invalid alignment for " + idname_ + ": " + alignment);
        }
        else if (element == "age")
        {
            std::string age = xml.GetData();
            if (age == "DOGYEARS")
                age_.set_interval(2,6);
            else if (age == "CHILD")
                age_.set_interval(7,10);
            else if (age == "TEENAGER")
                age_.set_interval(14,17);
            else if (age == "YOUNGADULT")
                age_.set_interval(18,35);
            else if (age == "MATURE")
                age_.set_interval(20,59);
            else if (age == "GRADUATE")
                age_.set_interval(26,59);
            else if (age == "MIDDLEAGED")
                age_.set_interval(35,59);
            else if (age == "SENIOR")
                age_.set_interval(65,94);
            else
                assign_interval(age_, age, idname_, element);
        }
        else if (element == "attribute_points")
            assign_interval(attribute_points_, xml.GetData(), idname_, element);
        else if (element == "attributes")
        {
            while(xml.FindChildElem())
            {
                int attribute = attribute_string_to_enum(xml.GetChildTagName());
                if (attribute != -1)
                    assign_interval(attributes_[attribute], xml.GetChildData(), idname_, element);
                else
                    xmllog.log("Unknown attribute in " + idname_ + ": " + xml.GetTagName());
            }
        }
        else if (element == "juice")
            assign_interval(juice_, xml.GetData(), idname_, element);
        else if (element == "gender")
        {
            int gender = gender_string_to_enum(xml.GetData());
            if (gender != -1 && gender != GENDER_WHITEMALEPATRIARCH)
                gender_liberal_ = gender_conservative_ = gender;
            else
                xmllog.log("Invalid gender for " + idname_ + ": " + xml.GetData());
        }
        else if (element == "infiltration")
            assign_interval(infiltration_, xml.GetData(), idname_, element);
        else if (element == "money")
            assign_interval(money_, xml.GetData(), idname_, element);
        else if (element == "skills")
        {
            while(xml.FindChildElem())
            {
                int skill = skill_string_to_enum(xml.GetChildTagName());
                if (skill != -1)
                    assign_interval(skills_[skill], xml.GetChildData(), idname_, element);
                else
                    xmllog.log("Unknown skill for " + idname_ + ": " + xml.GetChildTagName());
            }
        }
        else if (element == "armor")
        {
            if (getarmortype(xml.GetData()) != -1)
                armortypes_.push_back(xml.GetData());
            else
                xmllog.log("Invalid armor type for " + idname_ + ": " + xml.GetData());;
        }
        else if (element == "weapon")
        {
            //xml.SavePos("creature");
            weapons_and_clips_.push_back(WeaponsAndClips(xml, idname_));
            //xml.RestorePos("creature");
        }
        else if (element == "encounter_name")
            encounter_name_ = xml.GetData();
        else if (element == "type_name")
            type_name_ = xml.GetData();
        else
            xmllog.log("Unknown element for " + idname_ + ": " + element);
    }

    if (!len(type_name_))
    {
        xmllog.log("type_name not defined for " + idname_ + ".");
        type_name_ = "UNDEFINED";
    }
    // If no weapon type has been given then use WEAPON_NONE.
    if (!len(weapons_and_clips_))
        weapons_and_clips_.push_back(WeaponsAndClips("WEAPON_NONE", 1, "NONE", 0));
    // If no armor type has been given then use ARMOR_NONE.
    if (!len(armortypes_))
        armortypes_.push_back("ARMOR_NONE");
}
Exemplo n.º 14
0
attackst::attackst(MCD_STR xmlstring)
 : priority(1), ranged(false), thrown(false), uses_ammo(false),
   attack_description("assaults"), hit_description("striking"),
   always_describe_hit(false), hit_punctuation("."), skill(SKILL_CLUB),
   accuracy_bonus(0), number_attacks(1), successive_attacks_difficulty(0),
   strength_min(5), strength_max(10), random_damage(1), fixed_damage(1),
   bruises(false), tears(false), cuts(false), burns(false), shoots(false),
   bleeding(false), severtype(0), damages_armor(false), armorpiercing(0),
   no_damage_reduction_for_limbs_chance(0), can_backstab(false)
{
   CMarkup xml;
   xml.SetDoc(xmlstring);
   xml.FindElem();
   
   xml.IntoElem();

   while (xml.FindElem()) //Loop over all the elements inside the vehicletype element.
   {
      std::string element = xml.GetTagName();
   
      if (element == "priority")
         priority = atoi(xml.GetData().c_str());
      else if (element == "ranged")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            ranged = true;
         else if (b == 0)
            ranged = false;
         /*else
            errorlog << "Invalid boolean value for attack::ranged " << xml.GetData() << endl;*/
      }
      else if (element == "thrown")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            thrown = true;
         else if (b == 0)
            thrown = false;
         /*else
            errorlog << "Invalid boolean value for attack::thrown " << xml.GetData() << endl;*/
      }
      else if (element == "can_backstab")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            can_backstab = true;
         else if (b == 0)
            can_backstab = false;
      }
      else if (element == "ammotype")
      {
         ammotype = xml.GetData();
         uses_ammo = true;
      }
      else if (element == "attack_description")
         attack_description = xml.GetData();
      else if (element == "hit_description")
         hit_description = xml.GetData();
      else if (element == "always_describe_hit")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            always_describe_hit = true;
         else if (b == 0)
            always_describe_hit = false;
         /*else
            errorlog << "Invalid boolean value for attack::always_describe_hit: " << xml.GetData() << endl;*/
      }
      else if (element == "hit_punctuation")
         hit_punctuation = xml.GetData();
      else if (element == "skill")
      {
         int s = skill_string_to_enum(xml.GetData());
         if (s != -1)
            skill = s;
         /*else
            errorlog << "Invalid skill name for attack::skill: " << xml.GetData() << endl; */
      }
      else if (element == "accuracy_bonus")
         accuracy_bonus = atoi(xml.GetData().c_str());
      else if (element == "number_attacks")
         number_attacks = atoi(xml.GetData().c_str());
      else if (element == "successive_attacks_difficulty")
         successive_attacks_difficulty = atoi(xml.GetData().c_str());
      else if (element == "strength_min")
         strength_min = atoi(xml.GetData().c_str());
      else if (element == "strength_max")
         strength_max = atoi(xml.GetData().c_str());
      else if (element == "random_damage")
         random_damage = atoi(xml.GetData().c_str());
      else if (element == "fixed_damage")
         fixed_damage = atoi(xml.GetData().c_str());
      else if (element == "bruises")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            bruises = true;
         else if (b == 0)
            bruises = false;
         /*else
            errorlog << "Invalid boolean value for attack::bruises: " << xml.GetData() << endl;*/
      }
      else if (element == "tears")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            tears = true;
         else if (b == 0)
            tears = false;
         /*else
            errorlog << "Invalid boolean value for attack::tears: " << xml.GetData() << endl;*/
      }
      else if (element == "cuts")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            cuts = true;
         else if (b == 0)
            cuts = false;
         /*else
            errorlog << "Invalid boolean value for attack::cuts: " << xml.GetData() << endl;*/
      }
      else if (element == "burns")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            burns = true;
         else if (b == 0)
            burns = false;
         /*else
            errorlog << "Invalid boolean value for attack::burns: " << xml.GetData() << endl;*/
      }
      else if (element == "shoots")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            shoots = true;
         else if (b == 0)
            shoots = false;
         /*else
            errorlog << "Invalid boolean value for attack::shoots: " << xml.GetData() << endl;*/
      }
      else if (element == "bleeding")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            bleeding = true;
         else if (b == 0)
            bleeding = false;
         /*else
            errorlog << "Invalid boolean value for attack::bleeding: " << xml.GetData() << endl;*/
      }
      else if (element == "severtype")
      {
         int s = severtype_string_to_enum(xml.GetData());
         if (s != -1)
            severtype = s;
         /*else
            errorlog << "Invalid severtype for attack::severtype: " << xml.GetData() << endl; */
      }
      else if (element == "damages_armor")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            damages_armor = true;
         else if (b == 0)
            damages_armor = false;
         /*else
            errorlog << "Invalid boolean value for attack::damages_armor: " << xml.GetData() << endl;*/
      }
      else if (element == "armorpiercing")
         armorpiercing = atoi(xml.GetData().c_str());
      else if (element == "no_damage_reduction_for_limbs_chance")
         no_damage_reduction_for_limbs_chance = atoi(xml.GetData().c_str());
      else if (element == "critical")
      {
         xml.IntoElem();
         
         while (xml.FindElem())
         {
            element = xml.GetTagName();
            
            if (element == "chance")
               critical.chance = atoi(xml.GetData().c_str());
            else if (element == "hits_required")
               critical.hits_required = atoi(xml.GetData().c_str());
            else if (element == "random_damage")
            {
               critical.random_damage = atoi(xml.GetData().c_str());
               critical.random_damage_defined = true;
            }
            else if (element == "fixed_damage")
            {
               critical.fixed_damage = atoi(xml.GetData().c_str());
               critical.fixed_damage_defined = true;
            }
            else if (element == "severtype")
            {
               int s = severtype_string_to_enum(xml.GetData());
               if (s != -1)
               {
                  critical.severtype = s;
                  critical.severtype_defined = true;
               }
               /*else
                  errorlog << "Invalid severtype for attack::critical::severtype: " << xml.GetData() << endl; */
            }
            /*else
               errorlog << "Unknown element for attack::critical: " << element << endl; */
         }
         
         xml.OutOfElem();
      }
      else if (element == "fire")
      {
         xml.IntoElem();
         
         while (xml.FindElem())
         {
            element = xml.GetTagName();
            
            if (element == "chance")
               fire.chance = atoi(xml.GetData().c_str());
            else if (element == "chance_causes_debris")
               fire.chance_causes_debris = atoi(xml.GetData().c_str());
            /*else
               errorlog << "Unknown element for attack::fire: " << element << endl; */
         }
            
         xml.OutOfElem();
      }
      /*else
         errorlog << "Unknown element for attack: " << element << endl; */
   }
   
   if (!bruises && !tears && !cuts && !burns && !shoots)
      bruises = true; //If no type specified, then bruise.
}
Exemplo n.º 15
0
void ArmorType::init(const MCD_STR& xmlstring)
{
   CMarkup xml;
   xml.SetDoc(xmlstring);
   xml.FindElem();

   xml.IntoElem();

   while (xml.FindElem()) //Loop over all the elements inside the armortype element.
   {
      std::string element = xml.GetTagName();

      if (element == "make_difficulty")
         make_difficulty_ = atoi(xml.GetData().c_str());
      else if (element == "make_price")
         make_price_ = atoi(xml.GetData().c_str());
      else if (element == "deathsquad_legality")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            deathsquad_legality_ = true;
         else if (b == 0)
            deathsquad_legality_ = false;
         /*else
            errorlog << "Invalid boolean value for armor type " << idname()
                      << "::deathsquad_legality: " << xml.GetData() << std::endl;*/
      }
      else if (element == "can_get_bloody")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            can_get_bloody_ = true;
         else if (b == 0)
            can_get_bloody_ = false;
      }
      else if (element == "can_get_damaged")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            can_get_damaged_ = true;
         else if (b == 0)
            can_get_damaged_ = false;
      }
      else if (element == "armor")
      {
         xml.IntoElem();

         while (xml.FindElem())
         {
            element = xml.GetTagName();

            if (element == "body")
               armor_body_ = atoi(xml.GetData().c_str());
            else if (element == "head")
               armor_head_ = atoi(xml.GetData().c_str());
            else if (element == "limbs")
               armor_limbs_ = atoi(xml.GetData().c_str());
            else if (element == "fireprotection")
            {
               int b = stringtobool(xml.GetData());
               if (b == 1)
                  fireprotection_ = true;
               else if (b == 0)
                  fireprotection_ = false;
               /*else
                  errorlog << "Invalid boolean value for armor type " << idname()
                            << "::armor::fireprotection: " << xml.GetData() << std::endl;*/
            }
            /*else
               errorlog << "Unknown element for armor type " << idname()
                         << "::armor: " << element << endl;*/
         }
         xml.OutOfElem();
      }
      else if (element == "body_covering")
      {
         xml.IntoElem();

         while (xml.FindElem())
         {
            element = xml.GetTagName();

            if (element == "body")
            {
               int b = stringtobool(xml.GetData());
               if (b == 1)
                  cover_body_ = true;
               else if (b == 0)
                  cover_body_ = false;
               /*else
                  errorlog << "Invalid boolean value for armor type " << idname()
                            << "::body_covering::body: " << xml.GetData() << std::endl;*/
            }
            else if (element == "head")
            {
               int b = stringtobool(xml.GetData());
               if (b == 1)
                  cover_head_ = true;
               else if (b == 0)
                  cover_head_ = false;
               /*else
                  errorlog << "Invalid boolean value for armor type " << idname()
                            << "::body_covering::head: " << xml.GetData() << std::endl;*/
            }
            else if (element == "arms")
            {
               int b = stringtobool(xml.GetData());
               if (b == 1)
                  cover_arms_ = true;
               else if (b == 0)
                  cover_arms_ = false;
               /*else
                  errorlog << "Invalid boolean value for armor type " << idname()
                            << "::body_covering::arms: " << xml.GetData() << std::endl;*/
            }
            else if (element == "legs")
            {
               int b = stringtobool(xml.GetData());
               if (b == 1)
                  cover_legs_ = true;
               else if (b == 0)
                  cover_legs_ = false;
               /*else
                  errorlog << "Invalid boolean value for armor type " << idname()
                            << "::body_covering::legs: " << xml.GetData() << std::endl;*/
            }
            else if (element == "conceals_face")
            {
               int b = stringtobool(xml.GetData());
               if (b == 1)
                  conceal_face_ = true;
               else if (b == 0)
                  conceal_face_ = false;
               /*else
                  errorlog << "Invalid boolean value for armor type " << idname()
                            << "::body_covering::conceal_face: " << xml.GetData() << std::endl;*/
            }
            /*else
               errorlog << "Unknown element for armor type " << idname()
                         << "::armor: " << element << endl;*/
         }
         xml.OutOfElem();
      }
      else if (element == "shortname")
      {
         shortname_ = xml.GetData();
         shortname_defined_ = true;
         if (shortname_.length() > 14)
            shortname_.resize(14);
      }
      else if (element == "interrogation")
      {
         xml.IntoElem();

         while (xml.FindElem())
         {
            if (element == "basepower")
               interrogation_basepower_ = atoi(xml.GetData().c_str());
            else if (element == "assaultbonus")
               interrogation_assaultbonus_ = atoi(xml.GetData().c_str());
            else if (element == "drugbonus")
               interrogation_drugbonus_ = atoi(xml.GetData().c_str());
            /*else
             errorlog << "Unknown element for armor type " << idname()
                         << "::interrogation: " << element << endl;*/
         }

         xml.OutOfElem();
      }
      else if (element == "professionalism")
         professionalism_ = atoi(xml.GetData().c_str());
      else if (element == "conceal_weapon_size")
         conceal_weaponsize_ = atoi(xml.GetData().c_str());
      else if (element == "stealth_value")
         stealth_value_ = atoi(xml.GetData().c_str());
      else if (element == "mask")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            mask_ = true;
         else if (b == 0)
            mask_ = false;
      }
      else if (element == "surprise")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            surprise_mask_ = true;
         else if (b == 0)
            surprise_mask_ = false;
      }
      else if (element == "description")
         description_ = xml.GetData();
      /*else
         errorlog << "Unknown element for armor type " << idname() << ": " << element << endl;*/
   }

   if (!shortname_defined_ && name().length() <= 14)
      shortname_ = name();
}
Exemplo n.º 16
0
VehicleType::VehicleType(MCD_STR xmlstring)
 : /*idname_("UNDEFINED"), id_(-1),*/ year_startcurrent_(true), year_start_(0), //Default values
 year_randomuptocurrent_(false), year_addrandom_(0), year_add_(0), displaycolor_(true),
 longname_("UNDEFINED"), shortname_("UNDEF"), 
 steal_difficultytofind_(1), steal_juice_(0), steal_extraheat_(0),
 sensealarmchance_(0), touchalarmchance_(0), availableatshop_(true), price_(1234), sleeperprice_(1111), 
 armormidpoint_(50), lowarmormin_(4), lowarmormax_(6), higharmormin_(0), higharmormax_(2),
 drivebonus_(0), drivebonus_factor_(1), drivebonus_limit1_(8), drivebonus_limit2_(99), 
 dodgebonus_(0), dodgebonus_factor_(1), dodgebonus_limit1_(8), dodgebonus_limit2_(99), 
 attackbonus_driver_(-2), attackbonus_passenger_(0)
{
   id_ = number_of_vehicletypes++;

   CMarkup xmlfile;
   xmlfile.SetDoc(xmlstring);
   xmlfile.FindElem();

   idname_ = xmlfile.GetAttrib("idname");
   if (idname_ == "")
      idname_ = "LACKS IDNAME " + tostring(id_);

   xmlfile.IntoElem();

   while(xmlfile.FindElem()) //Loop over all the elements inside the vehicletype element.
   {
      std::string element = xmlfile.GetTagName();

      if (element == "year")
      {
         xmlfile.IntoElem();

         while(xmlfile.FindElem())
         {
            element = xmlfile.GetTagName();

            if (element == "start_at_current_year")
            {
               int b = stringtobool(xmlfile.GetData());
               if (b == 1)
                  year_startcurrent_ = true;
               else if (b == 0)
                  year_startcurrent_ = false;
               /*else
                  std::cerr << "Invalid boolean value for vehicle type " << idname
                            << "::year::start_at_current_year: " << xmlfile.GetData() << std::endl;*/
            }
            else if (element == "start_at_year")
               year_start_ = atoi(xmlfile.GetData());
            else if (element == "add_random_up_to_current_year")
            {
               int b = stringtobool(xmlfile.GetData());
               if (b == 1)
                  year_randomuptocurrent_ = true;
               else if (b == 0)
                  year_randomuptocurrent_ = false;
               /*else
                  std::cerr << "Invalid boolean value for vehicle type " << idname
                            << "::year::add_random_up_to_current_year: " << xmlfile.GetData() << std::endl;*/
            }
            else if (element == "add_random")
               year_addrandom_ = atoi(xmlfile.GetData());
            else if (element == "add")
               year_add_ = atoi(xmlfile.GetData());
            /*else
               std::cerr << "Unknown element for vehicle type " << idname << "::year: "
                         << element << std::endl;*/
         }

         xmlfile.OutOfElem();
      }
      else if (element == "colors")
      {
         xmlfile.IntoElem();
         //std::string color;
         while(xmlfile.FindElem())
         {
            element = xmlfile.GetTagName();

            if (element == "color")
            {
               color_.push_back(xmlfile.GetData());
            }
            else if (element == "display_color")
            {
               int b = stringtobool(xmlfile.GetData());
               if (b == 1)
                  displaycolor_ = true;
               else if (b == 0)
                  displaycolor_ = false;
               /*else
                  std::cerr << "Invalid boolean value for vehicle type " << idname
                            << "::colors::display_color: " << xmlfile.GetData() << std::endl;*/
            }
            /*else
               std::cerr << "Unknown element for vehicle type " << idname << "::colors: "
                         << element << std::endl;*/
         }
         xmlfile.OutOfElem();
      }
      else if (element == "drivebonus")
      {
         xmlfile.IntoElem();
         while(xmlfile.FindElem())
         {
            element = xmlfile.GetTagName();

            if (element == "base")
               drivebonus_ = atoi(xmlfile.GetData());
            else if (element == "skillfactor")
               drivebonus_factor_ = atof(xmlfile.GetData());
            else if (element == "softlimit")
               drivebonus_limit1_ = atoi(xmlfile.GetData());
            else if (element == "hardlimit")
               drivebonus_limit2_ = atoi(xmlfile.GetData());
            /*else
               std::cerr << "Unknown element for vehicle type " << idname << "::stealing: "
                         << element << std::endl;*/
         }
         xmlfile.OutOfElem();
      }
      else if (element == "dodgebonus")
      {
         xmlfile.IntoElem();
         while(xmlfile.FindElem())
         {
            element = xmlfile.GetTagName();

            if (element == "base")
               dodgebonus_ = atoi(xmlfile.GetData());
            else if (element == "skillfactor")
               dodgebonus_factor_ = atof(xmlfile.GetData());
            else if (element == "softlimit")
               dodgebonus_limit1_ = atoi(xmlfile.GetData());
            else if (element == "hardlimit")
               dodgebonus_limit2_ = atoi(xmlfile.GetData());
            /*else
               std::cerr << "Unknown element for vehicle type " << idname << "::stealing: "
                         << element << std::endl;*/
         }
         xmlfile.OutOfElem();
      }
      else if (element == "attackbonus")
      {
         xmlfile.IntoElem();
         while(xmlfile.FindElem())
         {
            element = xmlfile.GetTagName();

            if (element == "driver")
               attackbonus_driver_ = atoi(xmlfile.GetData());
            else if (element == "passenger")
               attackbonus_passenger_ = atoi(xmlfile.GetData());
            /*else
               std::cerr << "Unknown element for vehicle type " << idname << "::stealing: "
                         << element << std::endl;*/
         }
         xmlfile.OutOfElem();
      }
      else if (element == "longname")
         longname_ = xmlfile.GetData();
      else if (element == "shortname")
      {
         shortname_ = xmlfile.GetData();
         if (len(shortname_) > 7)
            shortname_.resize(7); //Only seven characters allowed for shortname_.
      }
      else if (element == "stealing")
      {
         xmlfile.IntoElem();
         while(xmlfile.FindElem())
         {
            element = xmlfile.GetTagName();

            if (element == "difficulty_to_find")
               steal_difficultytofind_ = atoi(xmlfile.GetData());
            else if (element == "juice")
               steal_juice_ = atoi(xmlfile.GetData());
            else if (element == "extra_heat")
               steal_extraheat_ = atoi(xmlfile.GetData());
            else if (element == "sense_alarm_chance")
               sensealarmchance_ = atoi(xmlfile.GetData());
            else if (element == "touch_alarm_chance")
               touchalarmchance_ = atoi(xmlfile.GetData());
            /*else
               std::cerr << "Unknown element for vehicle type " << idname << "::stealing: "
                         << element << std::endl;*/
         }
         xmlfile.OutOfElem();
      }
      else if (element == "armor")
      {
         xmlfile.IntoElem();
         while(xmlfile.FindElem())
         {
            element = xmlfile.GetTagName();

            if (element == "low_armor_min")
               lowarmormin_ = atoi(xmlfile.GetData());
            else if (element == "low_armor_max")
               lowarmormax_ = atoi(xmlfile.GetData());
            else if (element == "high_armor_min")
               higharmormin_ = atoi(xmlfile.GetData());
            else if (element == "high_armor_max")
               higharmormax_ = atoi(xmlfile.GetData());
            else if (element == "armor_midpoint")
               armormidpoint_ = atoi(xmlfile.GetData());
            /*else
               std::cerr << "Unknown element for vehicle type " << idname << "::stealing: "
                         << element << std::endl;*/
         }
         xmlfile.OutOfElem();
      }
      else if (element == "available_at_dealership")
      {
         int b = stringtobool(xmlfile.GetData());
         if (b == 1)
            availableatshop_ = true;
         else if (b == 0)
            availableatshop_ = false;
         /*else
            std::cerr << "Invalid boolean value for vehicle type " << idname
                      << "::available_at_dealership: " << xmlfile.GetData() << std::endl;*/
      }
      else if (element == "price")
         price_ = atoi(xmlfile.GetData());
      else if (element == "sleeperprice")
         sleeperprice_ = atoi(xmlfile.GetData());
      /*else
         std::cerr << "Unknown element for vehicle type " << idname << ": " << element
                   << std::endl;*/
   }

   if (len(color_) == 0)
      color_.push_back("Translucent"); //Default.

   //xmlfile.OutOfElem();
}
Exemplo n.º 17
0
WeaponType::WeaponType(MCD_STR xmlstring)
 : ItemType(xmlstring), name_sub_1_defined_(false), name_sub_2_defined_(false),
   name_future_sub_1_defined_(false), name_future_sub_2_defined_(false),
   shortname_("UNDEF"), shortname_defined_(false), shortname_future_defined_(false),
   shortname_sub_1_defined_(false), shortname_sub_2_defined_(false),
   shortname_future_sub_1_defined_(false), shortname_future_sub_2_defined_(false),
   can_take_hostages_(false), threatening_(false), can_threaten_hostages_(true),
   protects_against_kidnapping_(true),
   musical_attack_(false), instrument_(false), legality_(2), bashstrengthmod_(1),
   suspicious_(true), size_(15), can_graffiti_(false), auto_break_lock_(false)
{
   CMarkup xml;
   xml.SetDoc(xmlstring);
   xml.FindElem();
   
   xml.IntoElem();

   while (xml.FindElem()) //Loop over all the elements inside the weapontype element.
   {
      std::string element = xml.GetTagName();

      if (element == "shortname")
      {
         shortname_ = xml.GetData();
         shortname_defined_ = true;
      }
      else if (element == "shortname_future")
      {
         shortname_future_ = xml.GetData();
         shortname_future_defined_ = true;
      }
      else if (element == "name_sub_1")
      {
         name_sub_1_ = xml.GetData();
         name_sub_1_defined_ = true;
      }
      else if (element == "name_sub_2")
      {
         name_sub_2_ = xml.GetData();
         name_sub_2_defined_ = true;
      }
      else if (element == "name_future_sub_1")
      {
         name_future_sub_1_ = xml.GetData();
         name_future_sub_1_defined_ = true;
      }
      else if (element == "name_future_sub_2")
      {
         name_future_sub_2_ = xml.GetData();
         name_future_sub_2_defined_ = true;
      }
      else if (element == "shortname_sub_1")
      {
         shortname_sub_1_ = xml.GetData();
         shortname_sub_1_defined_ = true;
      }
      else if (element == "shortname_sub_2")
      {
         shortname_sub_2_ = xml.GetData();
         shortname_sub_2_defined_ = true;
      }
      else if (element == "shortname_future_sub_1")
      {
         shortname_future_sub_1_ = xml.GetData();
         shortname_future_sub_1_defined_ = true;
      }
      else if (element == "shortname_future_sub_2")
      {
         shortname_future_sub_2_ = xml.GetData();
         shortname_future_sub_2_defined_ = true;
      }
      else if (element == "can_take_hostages")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            can_take_hostages_ = true;
         else if (b == 0)
            can_take_hostages_ = false;
         /*else
            errorlog << "Invalid boolean value for weapon type " << idname()
                      << "::can_take_hostages: " << xml.GetData() << endl;*/
      }
      else if (element == "threatening")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            threatening_ = true;
         else if (b == 0)
            threatening_ = false;
         /*else
            errorlog << "Invalid boolean value for weapon type " << idname()
                      << "::threatening: " << xml.GetData() << endl;*/
      }
      else if (element == "can_threaten_hostages")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            can_threaten_hostages_ = true;
         else if (b == 0)
            can_threaten_hostages_ = false;
      }
      else if (element == "protects_against_kidnapping")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            protects_against_kidnapping_ = true;
         else if (b == 0)
            protects_against_kidnapping_ = false;
      }
      else if (element == "musical_attack")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            musical_attack_ = true;
         else if (b == 0)
            musical_attack_ = false;
         /*else
            errorlog << "Invalid boolean value for weapon type " << idname()
                      << "::musical_attack: " << xml.GetData() << endl;*/
      }
      else if (element == "instrument")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            instrument_ = true;
         else if (b == 0)
            instrument_ = false;
         /*else
            errorlog << "Invalid boolean value for weapon type " << idname()
                      << "::instrument: " << xml.GetData() << endl;*/
      }
      else if (element == "graffiti")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            can_graffiti_ = true;
         else if (b == 0)
            can_graffiti_ = false;
         /*else
            errorlog << "Invalid boolean value for weapon type " << idname()
                      << "::graffiti: " << xml.GetData() << endl;*/
      }
      else if (element == "legality")
         legality_ = atoi(xml.GetData().c_str());
      else if (element == "bashstrengthmod")
         bashstrengthmod_ = atoi(xml.GetData().c_str()) / 100.0;
      else if (element == "auto_break_locks")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            auto_break_lock_ = true;
         else if (b == 0)
            auto_break_lock_ = false;
         /*else
            errorlog << "Invalid boolean value for weapon type " << idname()
                      << "::auto_break_locks: " << xml.GetData() << endl;*/
      }
      else if (element == "suspicious")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            suspicious_ = true;
         else if (b == 0)
            suspicious_ = false;
         /*else
            errorlog << "Invalid boolean value for weapon type " << idname()
                      << "::suspicious: " << xml.GetData() << endl;*/
      }
      else if (element == "size")
         size_ = atoi(xml.GetData().c_str());
      else if (element == "attack")
      {
         attackst* attack = new attackst(xml.GetSubDoc());

         vector<attackst*>::iterator it = attacks_.begin();
         while (it != attacks_.end() && attack->priority >= (*it)->priority)
            ++it;
         attacks_.insert(it,attack);
      }
      /*else
         errorlog << "Unknown element for weapon type " << idname()
                   << ": " << element << endl;*/
   }
   
   if (!shortname_defined_)
   {
      if ((uses_ammo() && name().length() <= 9)
          || name().length() <= 14)
         shortname_ = name();
   }
   else
   {
      if (shortname_.length() > 9 && uses_ammo())
         shortname_.resize(9);
      else if (shortname_.length() > 14)
         shortname_.resize(14);
   }

}
Exemplo n.º 18
0
void Shop::init(const MCD_STR &xmlstring)
{
   CMarkup xml;
   xml.SetDoc(xmlstring);
   xml.FindElem();
   xml.IntoElem();

   while (xml.FindElem())
   {
      std::string tag = xml.GetTagName();

      if (tag == "only_sell_legal_items")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            only_sell_legal_ = true;
         else if (b == 0)
            only_sell_legal_ = false;
      }
      else if (tag == "fullscreen")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            fullscreen_ = true;
         else if (b == 0)
            fullscreen_ = false;
      }
      else if (tag == "allow_selling")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            allow_selling_ = true;
         else if (b == 0)
            allow_selling_ = false;
      }
      else if (tag == "increase_prices_with_illegality")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            increase_prices_with_illegality_ = true;
         else if (b == 0)
            increase_prices_with_illegality_ = false;
      }
      else if (tag == "department")
      {
         options_.push_back(new Shop(xml.GetSubDoc(), fullscreen_, only_sell_legal_,
                                     increase_prices_with_illegality_));
      }
      else if (tag == "entry")
         description_ = xml.GetData();
      else if (tag == "exit")
         exit_ = xml.GetData();
      else if (tag == "sell_masks")
      {
         int b = stringtobool(xml.GetData());
         if (b == 1)
            sell_masks_ = true;
         else if (b == 0)
            sell_masks_ = false;
      }
      else if (tag == "letter")
      {
         letter_ = xml.GetData()[0];
         if (97 <= letter_ && letter_ <= 122) //Check it is a letter.
            letter_defined_ = true;
         else if (65 <= letter_ && letter_ <= 90)
         {
            letter_ += 32;
            letter_defined_ = true;
         }
         else if (letter_ == '!') //Allow special character.
            letter_defined_ = true;
      }
      else if (tag == "item")
         options_.push_back(new ShopItem(xml.GetSubDoc(), only_sell_legal_,
                            increase_prices_with_illegality_));
   }


}