ALERROR CRandomItems::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadFromXML // // Load from XML { ALERROR error; CString sCriteria = pDesc->GetAttribute(CRITERIA_ATTRIB); if (sCriteria.IsBlank()) { CString sAttributes = pDesc->GetAttribute(ATTRIBUTES_ATTRIB); if (sAttributes.IsBlank()) sAttributes = pDesc->GetAttribute(MODIFIERS_ATTRIB); sCriteria = strPatternSubst(CONSTLIT("%s %s"), pDesc->GetAttribute(CATEGORIES_ATTRIB), sAttributes); } CItem::ParseCriteria(sCriteria, &m_Criteria); m_sLevelFrequency = pDesc->GetAttribute(LEVEL_FREQUENCY_ATTRIB); m_iLevel = pDesc->GetAttributeInteger(LEVEL_ATTRIB); m_iLevelCurve = pDesc->GetAttributeInteger(LEVEL_CURVE_ATTRIB); m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB); if (error = m_Enhanced.InitFromXML(Ctx, pDesc)) return error; m_Table = NULL; m_iCount = 0; return NOERROR; }
ALERROR CSingleItem::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadFromXML // // Load from XML { ALERROR error; if (error = m_pItemType.LoadUNID(Ctx, pDesc->GetAttribute(ITEM_ATTRIB))) return error; m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB); m_bDebugOnly = pDesc->GetAttributeBool(DEBUG_ONLY_ATTRIB); if (m_pItemType.GetUNID() == 0) { CString sUNID = pDesc->GetAttribute(ITEM_ATTRIB); if (sUNID.IsBlank()) Ctx.sError = strPatternSubst(CONSTLIT("<Item> element missing item attribute.")); else Ctx.sError = strPatternSubst(CONSTLIT("Invalid item UNID: %s"), sUNID); return ERR_FAIL; } if (error = m_Enhanced.InitFromXML(Ctx, pDesc)) return error; return NOERROR; }
ALERROR CSingleDevice::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // LoadFromXML // // Load from XML { ALERROR error; // Load the item type CString sUNID = pDesc->GetAttribute(DEVICE_ID_ATTRIB); if (sUNID.IsBlank()) sUNID = pDesc->GetAttribute(ITEM_ATTRIB); if (error = m_pItemType.LoadUNID(Ctx, sUNID)) return error; if (m_pItemType.GetUNID() == 0) { Ctx.sError = strPatternSubst(CONSTLIT("<%s> element missing item attribute."), pDesc->GetTag()); return ERR_FAIL; } // Load the count m_Count.LoadFromXML(pDesc->GetAttribute(COUNT_ATTRIB)); if (m_Count.IsEmpty()) m_Count.SetConstant(1); // Load damage chance m_iDamaged = pDesc->GetAttributeInteger(DAMAGED_ATTRIB); // Load enhancement chance if (error = m_Enhanced.InitFromXML(Ctx, pDesc)) return error; // Load device position attributes if (pDesc->FindAttributeInteger(POS_Z_ATTRIB, &m_iPosZ)) { m_iPosAngle = pDesc->GetAttributeInteger(POS_ANGLE_ATTRIB); m_iPosRadius = pDesc->GetAttributeInteger(POS_RADIUS_ATTRIB); m_b3DPosition = true; m_bDefaultPos = false; } else if (pDesc->FindAttributeInteger(POS_ANGLE_ATTRIB, &m_iPosAngle)) { m_iPosRadius = pDesc->GetAttributeInteger(POS_RADIUS_ATTRIB); m_iPosZ = 0; m_b3DPosition = false; m_bDefaultPos = false; } else { m_iPosAngle = 0; m_iPosRadius = 0; m_iPosZ = 0; m_b3DPosition = false; m_bDefaultPos = true; } // Load fire arc attributes if (pDesc->FindAttributeInteger(MIN_FIRE_ARC_ATTRIB, &m_iMinFireArc)) { m_bOmnidirectional = false; m_iMaxFireArc = pDesc->GetAttributeInteger(MAX_FIRE_ARC_ATTRIB); m_bDefaultFireArc = false; } else if (pDesc->FindAttributeBool(OMNIDIRECTIONAL_ATTRIB, &m_bOmnidirectional)) { m_iMinFireArc = 0; m_iMaxFireArc = 0; m_bDefaultFireArc = false; } else { m_bOmnidirectional = false; m_iMinFireArc = 0; m_iMaxFireArc = 0; m_bDefaultFireArc = true; } // Linked fire options CString sLinkedFire; if (pDesc->FindAttribute(LINKED_FIRE_ATTRIB, &sLinkedFire)) { if (error = CDeviceClass::ParseLinkedFireOptions(Ctx, sLinkedFire, &m_dwLinkedFireOptions)) return error; m_bDefaultLinkedFire = false; } else { m_dwLinkedFireOptions = 0; m_bDefaultLinkedFire = true; } m_bSecondary = pDesc->GetAttributeBool(SECONDARY_WEAPON_ATTRIB); // Slot bonus if (pDesc->FindAttributeInteger(HP_BONUS_ATTRIB, &m_iSlotBonus)) m_bDefaultSlotBonus = false; else { m_iSlotBonus = 0; m_bDefaultSlotBonus = true; } // Load extra items CXMLElement *pItems = pDesc->GetContentElementByTag(ITEMS_TAG); if (pItems) { if (error = IItemGenerator::CreateFromXML(Ctx, pItems, &m_pExtraItems)) return error; } return NOERROR; }