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"); }
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. }