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;
}
bool populate_from_xml(vector<Type*>& types,string file,Log& log)
{
   CMarkup xml;
   if(!xml.Load(string(artdir)+file))
   { // File is missing or not valid XML.
      addstr("Failed to load "+file+"!",log);

      getkey();

      // Will cause abort here or else if file is missing all unrecognized types
      // loaded from a saved game will be deleted. Also, you probably don't want
      // to play with a whole category of things missing anyway. If the file
      // does not have valid xml, then behaviour is kind of undefined so it's
      // best to abort then too.
      return false;
   }

   xml.FindElem();
   xml.IntoElem();
   while(xml.FindElem()) types.push_back(new Type(xml.GetSubDoc()));
   return true;
}
bool populate_masks_from_xml(vector<ArmorType*>& masks,string file,Log& log)
{
   CMarkup xml;
   if(!xml.Load(string(artdir)+file))
   { //File is missing or not valid XML.
      addstr("Failed to load "+file+"!",log);

      getkey();

      return false; //Abort.
   }

   xml.FindElem();
   xml.IntoElem();
   int defaultindex;
   if(xml.FindElem("default")) defaultindex=getarmortype(xml.GetData());
   else
   {
      addstr("Default missing for masks!",log);

      getkey();

      return false; //Abort.
   }
   if(defaultindex==-1)
   {
      addstr("Default for masks is not a known armor type!",log);

      getkey();

      return false; //Abort.
   }

   xml.ResetMainPos();
   while(xml.FindElem("masktype")) armortype.push_back(new ArmorType(*armortype[defaultindex],xml.GetSubDoc()));
   return true;
}
Exemple #4
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);
   }

}
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_));
   }


}