Exemplo n.º 1
0
 /// <summary>
 /// Checks the name of a child element and sets the appropriate
 /// value in a Unit object where needed. This method is used by
 /// both getAllUnits and getUnitById
 /// </summary>
 /// <param name="item"></param>
 /// <param name="child"></param>
 private static void getElement(Unit item, XmlElement child)
 {
     string name = child.Name;
     // Things for storing values!
     string resource;
     float value;
     int row, column, page;
     XmlNodeList protoAction;
     // Now, which tag is this?
     switch (name)
     {
         case "DBID":
             item.DBID = int.Parse(child.InnerText);
             break;
         case "DisplayNameID":
             item.displayNameID = int.Parse(child.InnerText);
             break;
         case "EditorNameID":
             item.editorNameID = int.Parse(child.InnerText);
             break;
         case "RolloverTextID":
             item.rolloverTextID = int.Parse(child.InnerText);
             break;
         case "ShortRolloverTextID":
             item.shortRolloverTextID = int.Parse(child.InnerText);
             break;
         case "ObstructionRadiusX":
             item.obstructionRadiusX = float.Parse(child.InnerText);
             break;
         case "ObstructionRadiusZ":
             item.obstructionRadiusZ = float.Parse(child.InnerText);
             break;
         case "MaxVelocity":
             item.maxVelocity = float.Parse(child.InnerText);
             break;
         case "MovementType":
             item.movementType = child.InnerText;
             break;
         case "AnimFile":
             item.animFile = child.InnerText;
             break;
         case "Lifespan":
             item.lifespan = float.Parse(child.InnerText);
             break;
         case "LOS":
             item.LOS = float.Parse(child.InnerText);
             break;
         case "Icon":
             item.icon = child.InnerText;
             break;
         case "PortraitIcon":
             item.portraitIcon = child.InnerText;
             break;
         case "DecayDelay":
             item.decayDelay = float.Parse(child.InnerText);
             break;
         case "DecayDuration":
             item.decayDuration = float.Parse(child.InnerText);
             break;
         case "MaxRunVelocity":
             item.maxRunVelocity = float.Parse(child.InnerText);
             break;
         case "TrainPoints":
             item.trainPoints = float.Parse(child.InnerText);
             break;
         case "IdleTimeout":
             item.idleTimeout = float.Parse(child.InnerText);
             break;
         case "InitialHitpoints":
             item.initialHitpoints = float.Parse(child.InnerText);
             break;
         case "MaxHitpoints":
             item.maxHitpoints = float.Parse(child.InnerText);
             break;
         case "UnitAIType":
             item.unitAIType = child.InnerText;
             break;
         case "TurnRate":
             item.turnRate = float.Parse(child.InnerText);
             break;
         case "MinimapColor":
             item.minimapRed = float.Parse(child.Attributes.GetNamedItem("red").InnerText);
             item.minimapBlue = float.Parse(child.Attributes.GetNamedItem("blue").InnerText);
             item.minimapGreen = float.Parse(child.Attributes.GetNamedItem("green").InnerText);
             break;
         case "MinimapIcon":
             item.minimapIcon = child.InnerText;
             break;
         case "ImpactType":
             item.impactType = child.InnerText;
             break;
         case "Bounty":
             item.bounty = float.Parse(child.InnerText);
             break;
         case "GathererLimit":
             item.gathererLimit = int.Parse(child.InnerText);
             break;
         case "SubCiv":
             item.subCiv = child.InnerText;
             break;
         case "BuildPoints":
             item.buildPoints = float.Parse(child.InnerText);
             break;
         case "BuildingWorkRate":
             item.buildingWorkRate = float.Parse(child.InnerText);
             break;
         case "Armor":
             item.armorType = child.Attributes.GetNamedItem("type").InnerText;
             item.armorValue = float.Parse(child.Attributes.GetNamedItem("value").InnerText);
             break;
         case "PopulationCapAddition":
             item.populationCapAddition = int.Parse(child.InnerText);
             break;
         case "AllowedAge":
             item.allowedAge = int.Parse(child.InnerText);
             break;
         case "CorpseDecalTime":
             item.corpseDecalTime = float.Parse(child.InnerText);
             break;
         case "CorpseDecayDelay":
             item.corpseDecayDelay = float.Parse(child.InnerText);
             break;
         case "AnimStateMachine":
             item.animStateMachine = child.InnerText;
             break;
         case "Tactics":
             item.tactics = child.InnerText;
             break;
         case "ProjectileProtoUnit":
             item.projectileProtoUnit = child.InnerText;
             break;
         case "FormationCategory":
             item.formationCategory = child.InnerText;
             break;
         case "PhysicsInfo":
             item.physicsInfo = child.InnerText;
             break;
         case "BuildLimit":
             item.builderLimit = int.Parse(child.InnerText);
             break;
         case "BuildBounty":
             item.buildBounty = float.Parse(child.InnerText);
             break;
         case "MaxContainted":
             item.maxContained = int.Parse(child.InnerText);
             break;
         case "PopulationCount":
             item.populationCount = int.Parse(child.InnerText);
             break;
         case "DeadReplacement":
             item.deadReplacement = child.InnerText;
             break;
         case "DeadReplacementLifespan":
             item.deadReplacementLifespan = int.Parse(child.InnerText);
             break;
         case "PlacementFile":
             item.placementFile = child.InnerText;
             break;
         case "InitialResource":
             item.initialResourceAmount = float.Parse(child.InnerText);
             item.initialResourceType = child.Attributes.GetNamedItem("resourcetype").InnerText;
             break;
         case "ResourceSubType":
             item.resourceSubType = child.InnerText;
             break;
         case "BuilderLimit":
             item.builderLimit = int.Parse(child.InnerText);
             break;
         case "AutoAttackRange":
             item.autoAttackRange = float.Parse(child.InnerText);
             break;
         case "WanderDistance":
             item.wanderDistance = int.Parse(child.InnerText);
             break;
         case "ResourceDecay":
             item.resourceDecay = float.Parse(child.InnerText);
             break;
         case "SocketUnitType":
             item.socketUnitType = child.InnerText;
             break;
         case "ScoreValue":
             item.scoreValue = float.Parse(child.InnerText);
             break;
         case "InitialUnitAIStance":
             item.initialUnitAIStance = child.InnerText;
             break;
         case "AllowedHeightVariance":
             item.allowedHeightVariance = float.Parse(child.InnerText);
             break;
         case "RechargeTime":
             item.rechargeTime = float.Parse(child.InnerText);
             break;
         case "CarryCapacity":
             resource = child.Attributes.GetNamedItem("resourcetype").InnerText;
             value = float.Parse(child.InnerText);
             ResourceValue carry = new ResourceValue(resource, value);
             item.carryCapacity.Add(carry);
             break;
         case "Cost":
             resource = child.Attributes.GetNamedItem("resourcetype").InnerText;
             value = float.Parse(child.InnerText);
             ResourceValue cost = new ResourceValue(resource, value);
             item.cost.Add(cost);
             break;
         case "Train":
             if (child.HasAttribute("row"))
                 row = int.Parse(child.Attributes.GetNamedItem("row").InnerText);
             else
                 row = -1;
             if (child.HasAttribute("page"))
                 page = int.Parse(child.Attributes.GetNamedItem("page").InnerText);
             else
                 page = -1;
             if (child.HasAttribute("column"))
                 column = int.Parse(child.Attributes.GetNamedItem("column").InnerText);
             else
                 column = -1;
             resource = child.InnerText;
             TrainTech train = new TrainTech(row, page, column, resource);
             item.train.Add(train);
             break;
         case "Command":
             if (child.HasAttribute("page"))
                 page = int.Parse(child.Attributes.GetNamedItem("page").InnerText);
             else
                 page = -1;
             if (child.HasAttribute("column"))
                 column = int.Parse(child.Attributes.GetNamedItem("column").InnerText);
             else
                 column = -1;
             resource = child.InnerText;
             Command command = new Command(page, column, resource);
             item.command.Add(command);
             break;
         case "Tech":
             row = int.Parse(child.Attributes.GetNamedItem("row").InnerText);
             page = int.Parse(child.Attributes.GetNamedItem("page").InnerText);
             column = int.Parse(child.Attributes.GetNamedItem("column").InnerText);
             resource = child.InnerText;
             TrainTech tech = new TrainTech(row, page, column, resource);
             item.tech.Add(tech);
             break;
         case "UnitType":
             item.unitType.Add(child.InnerText);
             break;
         case "Flag":
             item.flags.Add(child.InnerText);
             break;
         case "Contain":
             item.contain.Add(child.InnerText);
             break;
         case "ProtoAction":
             // This is a bit more complex! We have to do
             // a separate loop and switch for this as it contains
             // its own values and possible multiple values to boot.
             protoAction = child.ChildNodes;
             // Create a new ProtoAction object to work
             // with...
             ProtoAction action = new ProtoAction();
             // Now loop through the values
             foreach (XmlNode property in protoAction)
             {
                 // Get the name of this property.
                 string propertyName = property.Name;
                 // Now, switch based on the property name
                 switch (propertyName)
                 {
                     case "Name":
                         action.name = property.InnerText;
                         break;
                     case "Damage":
                         action.damage = float.Parse(property.InnerText);
                         break;
                     case "DamageType":
                         action.damageType = property.InnerText;
                         break;
                     case "MinRange":
                         action.minRange = float.Parse(property.InnerText);
                         break;
                     case "MaxRange":
                         action.maxRange = float.Parse(property.InnerText);
                         break;
                     case "ROF":
                         action.ROF = float.Parse(property.InnerText);
                         break;
                     case "DamageCap":
                         action.damageCap = float.Parse(property.InnerText);
                         break;
                     case "DamageBonus":
                         resource = property.Attributes.GetNamedItem("type").InnerText;
                         value = float.Parse(property.InnerText);
                         ResourceValue damageBonus = new ResourceValue(resource, value);
                         action.damageBonus.Add(damageBonus);
                         break;
                     case "DamageArea":
                         action.damageArea = float.Parse(property.InnerText);
                         break;
                     case "DamageFlags":
                         action.damageFlags = property.InnerText;
                         break;
                     case "Projectile":
                         action.projectile = property.InnerText;
                         break;
                     case "Rate":
                         resource = property.Attributes.GetNamedItem("type").InnerText;
                         value = float.Parse(property.InnerText);
                         ResourceValue rate = new ResourceValue(resource, value);
                         action.rate.Add(rate);
                         break;
                     case "Active":
                         action.active = int.Parse(property.InnerText);
                         break;
                     case "Type":
                         action.type = property.InnerText;
                         break;
                     case "Accuracy":
                         action.accuracy = float.Parse(property.InnerText);
                         break;
                     case "NumberProjectiles":
                         action.numberProjectiles = int.Parse(property.InnerText);
                         break;
                     case "MaxHeight":
                         action.maxHeight = float.Parse(property.InnerText);
                         break;
                 }
             }
             // Now add the action!
             item.protoAction.Add(action);
             break;
     }
 }
Exemplo n.º 2
0
        public bool addUnit(Unit item)
        {
            try
            {
                // Create new unit to work with!
                XmlElement newUnit = protoFile.CreateElement("Unit");

                // Now that we've got the new unit we can create elements
                // to go in it (if needed).
                XmlAttribute name = protoFile.CreateAttribute("name");
                name.InnerText = item.name;
                newUnit.Attributes.Append(name);

                XmlAttribute id = protoFile.CreateAttribute("id");
                id.InnerText = item.ID.ToString();
                newUnit.Attributes.Append(id);

                if (item.allowedAge > -1) // int
                {
                    XmlElement allowedAge = protoFile.CreateElement("AllowedAge");
                    allowedAge.InnerText = item.allowedAge.ToString();
                    newUnit.AppendChild(allowedAge);
                }
                if (item.allowedHeightVariance > -1) // float
                {
                    XmlElement allowedHeightVariance = protoFile.CreateElement("AllowedHeightVariance");
                    allowedHeightVariance.InnerText = item.allowedHeightVariance.ToString(fltMod);
                    newUnit.AppendChild(allowedHeightVariance);
                }
                if (item.animFile != "") // string
                {
                    XmlElement animFile = protoFile.CreateElement("AnimFile");
                    animFile.InnerText = item.animFile;
                    newUnit.AppendChild(animFile);
                }
                if (item.animStateMachine != "") // string
                {
                    XmlElement animStateMachine = protoFile.CreateElement("AnimStateMachine");
                    animStateMachine.InnerText = item.animStateMachine;
                    newUnit.AppendChild(animStateMachine);
                }
                if (item.armorType != "" && item.armorValue > -1) // string & float
                {
                    XmlElement armor = protoFile.CreateElement("Armor");
                    XmlAttribute armorType = protoFile.CreateAttribute("type");
                    armorType.InnerText = item.armorType;
                    armor.Attributes.Append(armorType);
                    XmlAttribute armorValue = protoFile.CreateAttribute("value");
                    armorValue.InnerText = item.armorValue.ToString(fltMod);
                    armor.Attributes.Append(armorValue);
                    newUnit.AppendChild(armor);
                }
                if (item.autoAttackRange > -1) // float
                {
                    XmlElement autoAttackRange = protoFile.CreateElement("AutoAttackRange");
                    autoAttackRange.InnerText = item.autoAttackRange.ToString(fltMod);
                    newUnit.AppendChild(autoAttackRange);
                }
                if (item.bounty > -1) // float
                {
                    XmlElement bounty = protoFile.CreateElement("Bounty");
                    bounty.InnerText = item.bounty.ToString(fltMod);
                    newUnit.AppendChild(bounty);
                }
                if (item.buildBounty > -1) // float
                {
                    XmlElement buildBounty = protoFile.CreateElement("BuildBounty");
                    buildBounty.InnerText = item.buildBounty.ToString(fltMod);
                    newUnit.AppendChild(buildBounty);
                }
                if (item.builderLimit > -1) // int
                {
                    XmlElement builderLimit = protoFile.CreateElement("BuilderLimit");
                    builderLimit.InnerText = item.builderLimit.ToString();
                    newUnit.AppendChild(builderLimit);
                }
                if (item.buildingWorkRate > -1) // float
                {
                    XmlElement buildingWorkRate = protoFile.CreateElement("BuildingWorkRate");
                    buildingWorkRate.InnerText = item.buildingWorkRate.ToString(fltMod);
                    newUnit.AppendChild(buildingWorkRate);
                }
                if (item.buildLimit > -1) // int
                {
                    XmlElement buildLimit = protoFile.CreateElement("BuildLimit");
                    buildLimit.InnerText = item.buildLimit.ToString();
                    newUnit.AppendChild(buildLimit);
                }
                if (item.buildPoints > -1) // float
                {
                    XmlElement buildPoints = protoFile.CreateElement("BuildPoints");
                    buildPoints.InnerText = item.buildPoints.ToString(fltMod);
                    newUnit.AppendChild(buildPoints);
                }
                if (item.carryCapacity.Count > 0) // List<ResourceValue>
                {
                    foreach (ResourceValue entry in item.carryCapacity)
                    {
                        XmlElement carryCapacity = protoFile.CreateElement("CarryCapacity");
                        carryCapacity.InnerText = entry.value.ToString(fltMod);
                        XmlAttribute carryResource = protoFile.CreateAttribute("resourcetype");
                        carryResource.InnerText = entry.resourceType;
                        carryCapacity.Attributes.Append(carryResource);
                        newUnit.AppendChild(carryCapacity);
                    }
                }
                if (item.command.Count > 0) // List<Command>
                {
                    foreach (Command entry in item.command)
                    {
                        XmlElement command = protoFile.CreateElement("Command");
                        command.InnerText = entry.value;
                        XmlAttribute commandPage = protoFile.CreateAttribute("page");
                        commandPage.InnerText = entry.page.ToString();
                        command.Attributes.Append(commandPage);
                        XmlAttribute commandColumn = protoFile.CreateAttribute("column");
                        commandColumn.InnerText = entry.column.ToString();
                        command.Attributes.Append(commandColumn);
                        newUnit.AppendChild(command);
                    }
                }
                if (item.contain.Count > 0) // List<string>
                {
                    foreach (string entry in item.contain)
                    {
                        XmlElement contain = protoFile.CreateElement("Contain");
                        contain.InnerText = entry;
                        newUnit.AppendChild(contain);
                    }
                }
                if (item.corpseDecalTime > -1) // float
                {
                    XmlElement corpseDecalTime = protoFile.CreateElement("CorpseDecalTime");
                    corpseDecalTime.InnerText = item.corpseDecalTime.ToString(fltMod);
                    newUnit.AppendChild(corpseDecalTime);
                }
                if (item.corpseDecayDelay > -1) // float
                {
                    XmlElement corpseDecayDelay = protoFile.CreateElement("CorpseDecayDelay");
                    corpseDecayDelay.InnerText = item.corpseDecayDelay.ToString(fltMod);
                    newUnit.AppendChild(corpseDecayDelay);
                }
                if (item.cost.Count > 0) // List<ResourceValue>
                {
                    foreach (ResourceValue entry in item.cost)
                    {
                        XmlElement cost = protoFile.CreateElement("Cost");
                        cost.InnerText = entry.value.ToString(fltMod);
                        XmlAttribute costResource = protoFile.CreateAttribute("resourcetype");
                        costResource.InnerText = entry.resourceType;
                        cost.Attributes.Append(costResource);
                        newUnit.AppendChild(cost);
                    }
                }
                if (item.DBID > -1) // int
                {
                    XmlElement dbid = protoFile.CreateElement("DBID");
                    dbid.InnerText = item.DBID.ToString();
                    newUnit.AppendChild(dbid);
                }
                if (item.deadReplacement != "") // string
                {
                    XmlElement deadReplacement = protoFile.CreateElement("DeadReplacement");
                    deadReplacement.InnerText = item.deadReplacement;
                    newUnit.AppendChild(deadReplacement);
                }
                if (item.deadReplacementLifespan > -1) // int
                {
                    XmlElement deadReplacementLifespan = protoFile.CreateElement("DeadReplacementLifespan");
                    deadReplacementLifespan.InnerText = item.deadReplacementLifespan.ToString();
                    newUnit.AppendChild(deadReplacementLifespan);
                }
                if (item.decayDelay > -1 && item.decayDuration > -1) // float & float
                {
                    XmlElement decay = protoFile.CreateElement("Decay");
                    XmlAttribute decayDelay = protoFile.CreateAttribute("delay");
                    decayDelay.InnerText = item.decayDelay.ToString(fltMod);
                    decay.Attributes.Append(decayDelay);
                    XmlAttribute decayDuration = protoFile.CreateAttribute("duration");
                    decayDuration.InnerText = item.decayDuration.ToString(fltMod);
                    decay.Attributes.Append(decayDuration);
                    newUnit.AppendChild(decay);
                }
                if (item.displayNameID > -1) // int
                {
                    XmlElement displayNameID = protoFile.CreateElement("DisplayNameID");
                    displayNameID.InnerText = item.displayNameID.ToString();
                    newUnit.AppendChild(displayNameID);
                }
                if (item.editorNameID > -1) // int
                {
                    XmlElement editorNameID = protoFile.CreateElement("EditorNameID");
                    editorNameID.InnerText = item.editorNameID.ToString();
                    newUnit.AppendChild(editorNameID);
                }
                if (item.flags.Count > 0) // List<string>
                {
                    foreach (string entry in item.flags)
                    {
                        XmlElement flag = protoFile.CreateElement("Flag");
                        flag.InnerText = entry;
                        newUnit.AppendChild(flag);
                    }
                }
                if (item.formationCategory != "") // string
                {
                    XmlElement formationCategory = protoFile.CreateElement("FormationCategory");
                    formationCategory.InnerText = item.formationCategory;
                    newUnit.AppendChild(formationCategory);
                }
                if (item.gathererLimit > -1) // int
                {
                    XmlElement gathererLimit = protoFile.CreateElement("GathererLimit");
                    gathererLimit.InnerText = item.gathererLimit.ToString();
                    newUnit.AppendChild(gathererLimit);
                }
                if (item.icon != "") // string
                {
                    XmlElement icon = protoFile.CreateElement("Icon");
                    icon.InnerText = item.icon;
                    newUnit.AppendChild(icon);
                }
                if (item.idleTimeout > -1) // float
                {
                    XmlElement idleTimeout = protoFile.CreateElement("IdleTimeout");
                    idleTimeout.InnerText = item.idleTimeout.ToString(fltMod);
                    newUnit.AppendChild(idleTimeout);
                }
                if (item.impactType != "") // string
                {
                    XmlElement impactType = protoFile.CreateElement("ImpactType");
                    impactType.InnerText = item.impactType;
                    newUnit.AppendChild(impactType);
                }
                if (item.initialHitpoints > -1) // float
                {
                    XmlElement initialHitpoints = protoFile.CreateElement("InitialHitpoints");
                    initialHitpoints.InnerText = item.initialHitpoints.ToString(fltMod);
                    newUnit.AppendChild(initialHitpoints);
                }
                if (item.initialResourceAmount > -1 && item.initialResourceType != "") // float & string
                {
                    XmlElement initialResource = protoFile.CreateElement("InitialResource");
                    initialResource.InnerText = item.initialResourceAmount.ToString(fltMod);
                    XmlAttribute resourceType = protoFile.CreateAttribute("resourcetype");
                    resourceType.InnerText = item.initialResourceType;
                    initialResource.Attributes.Append(resourceType);
                    newUnit.AppendChild(initialResource);
                }
                if (item.initialUnitAIStance != "") // string
                {
                    XmlElement initialUnitAIStance = protoFile.CreateElement("InitialUnitAIStance");
                    initialUnitAIStance.InnerText = item.initialUnitAIStance;
                    newUnit.AppendChild(initialUnitAIStance);
                }
                if (item.lifespan > -1) // float
                {
                    XmlElement lifespan = protoFile.CreateElement("Lifespan");
                    lifespan.InnerText = item.lifespan.ToString(fltMod);
                    newUnit.AppendChild(lifespan);
                }
                if (item.LOS > -1) // float
                {
                    XmlElement LOS = protoFile.CreateElement("LOS");
                    LOS.InnerText = item.LOS.ToString(fltMod);
                    newUnit.AppendChild(LOS);
                }
                if (item.maxContained > -1) // int
                {
                    XmlElement maxContained = protoFile.CreateElement("MaxContained");
                    maxContained.InnerText = item.maxContained.ToString();
                    newUnit.AppendChild(maxContained);
                }
                if (item.maxHitpoints > -1) // float
                {
                    XmlElement maxHitpoints = protoFile.CreateElement("MaxHitpoints");
                    maxHitpoints.InnerText = item.maxHitpoints.ToString(fltMod);
                    newUnit.AppendChild(maxHitpoints);
                }
                if (item.maxRunVelocity > -1) // float
                {
                    XmlElement maxRunVelocity = protoFile.CreateElement("MaxRunVelocity");
                    maxRunVelocity.InnerText = item.maxRunVelocity.ToString(fltMod);
                    newUnit.AppendChild(maxRunVelocity);
                }
                if (item.maxVelocity > -1) // float
                {
                    XmlElement maxVelocity = protoFile.CreateElement("MaxVelocity");
                    maxVelocity.InnerText = item.maxVelocity.ToString(fltMod);
                    newUnit.AppendChild(maxVelocity);
                }
                if (item.minimapBlue > -1 && item.minimapGreen > -1 && item.minimapRed > -1) // 3x float
                {
                    XmlElement minimapColor = protoFile.CreateElement("MinimapColor");
                    XmlAttribute red = protoFile.CreateAttribute("red");
                    red.InnerText = item.minimapRed.ToString(fltMod);
                    minimapColor.Attributes.Append(red);
                    XmlAttribute blue = protoFile.CreateAttribute("blue");
                    blue.InnerText = item.minimapBlue.ToString(fltMod);
                    minimapColor.Attributes.Append(blue);
                    XmlAttribute green = protoFile.CreateAttribute("green");
                    green.InnerText = item.minimapGreen.ToString(fltMod);
                    minimapColor.Attributes.Append(green);
                    newUnit.AppendChild(minimapColor);
                }
                if (item.minimapIcon != "") // string
                {
                    XmlElement minimapIcon = protoFile.CreateElement("MinimapIcon");
                    minimapIcon.InnerText = item.minimapIcon;
                    newUnit.AppendChild(minimapIcon);
                }
                if (item.movementType != "") // string
                {
                    XmlElement movementType = protoFile.CreateElement("MovementType");
                    movementType.InnerText = item.movementType;
                    newUnit.AppendChild(movementType);
                }
                if (item.obstructionRadiusX > -1) // float
                {
                    XmlElement obstructionRadiusX = protoFile.CreateElement("ObstructionRadiusX");
                    obstructionRadiusX.InnerText = item.obstructionRadiusX.ToString(fltMod);
                    newUnit.AppendChild(obstructionRadiusX);
                }
                if (item.obstructionRadiusZ > -1) // float
                {
                    XmlElement obstructionRadiusZ = protoFile.CreateElement("ObstructionRadiusZ");
                    obstructionRadiusZ.InnerText = item.obstructionRadiusZ.ToString(fltMod);
                    newUnit.AppendChild(obstructionRadiusZ);
                }
                if (item.physicsInfo != "") // string
                {
                    XmlElement physicsInfo = protoFile.CreateElement("PhysicsInfo");
                    physicsInfo.InnerText = item.physicsInfo;
                    newUnit.AppendChild(physicsInfo);
                }
                if (item.placementFile != "") // string
                {
                    XmlElement placementFile = protoFile.CreateElement("PlacementFile");
                    placementFile.InnerText = item.placementFile;
                    newUnit.AppendChild(placementFile);
                }
                if (item.populationCapAddition > -1) // int
                {
                    XmlElement populationCapAddition = protoFile.CreateElement("PopulationCapAddition");
                    populationCapAddition.InnerText = item.populationCapAddition.ToString();
                    newUnit.AppendChild(populationCapAddition);
                }
                if (item.populationCount > -1) // int
                {
                    XmlElement populationCount = protoFile.CreateElement("PopulationCount");
                    populationCount.InnerText = item.populationCount.ToString();
                    newUnit.AppendChild(populationCount);
                }
                if (item.portraitIcon != "") // string
                {
                    XmlElement portraitIcon = protoFile.CreateElement("PortraitIcon");
                    portraitIcon.InnerText = item.portraitIcon;
                    newUnit.AppendChild(portraitIcon);
                }
                if (item.projectileProtoUnit != "") // string
                {
                    XmlElement projectileProtoUnit = protoFile.CreateElement("ProjectileProtoUnit");
                    projectileProtoUnit.InnerText = item.projectileProtoUnit;
                    newUnit.AppendChild(projectileProtoUnit);
                }
                if (item.protoAction.Count > 0) // List<ProtoAction>
                {
                    foreach (ProtoAction entry in item.protoAction)
                    {
                        XmlElement protoAction = protoFile.CreateElement("ProtoAction");

                        if (entry.accuracy > -1) // float
                        {
                            XmlElement accuracy = protoFile.CreateElement("Accuracy");
                            accuracy.InnerText = entry.accuracy.ToString(fltMod);
                            protoAction.AppendChild(accuracy);
                        }
                        if (entry.active > -1) // int
                        {
                            XmlElement active = protoFile.CreateElement("Active");
                            active.InnerText = entry.active.ToString();
                            protoAction.AppendChild(active);
                        }
                        if (entry.damage > -1) // float
                        {
                            XmlElement damage = protoFile.CreateElement("Damage");
                            damage.InnerText = entry.damage.ToString(fltMod);
                            protoAction.AppendChild(damage);
                        }
                        if (entry.damageArea > -1) // float
                        {
                            XmlElement damageArea = protoFile.CreateElement("DamageArea");
                            damageArea.InnerText = entry.damageArea.ToString(fltMod);
                            protoAction.AppendChild(damageArea);
                        }
                        if (entry.damageBonus.Count > 0) // List<ResourceValue)
                        {
                            foreach (ResourceValue bonus in entry.damageBonus)
                            {
                                XmlElement damageBonus = protoFile.CreateElement("DamageBonus");
                                damageBonus.InnerText = bonus.value.ToString(fltMod);
                                XmlAttribute bonusResource = protoFile.CreateAttribute("type");
                                bonusResource.InnerText = bonus.resourceType;
                                damageBonus.Attributes.Append(bonusResource);
                                newUnit.AppendChild(damageBonus);
                            }
                        }
                        if (entry.damageCap > -1) // float
                        {
                            XmlElement damageCap = protoFile.CreateElement("DamageCap");
                            damageCap.InnerText = entry.damageCap.ToString(fltMod);
                            protoAction.AppendChild(damageCap);
                        }
                        if (entry.damageFlags != "") // string
                        {
                            XmlElement damageFlags = protoFile.CreateElement("DamageFlags");
                            damageFlags.InnerText = entry.damageFlags;
                            protoAction.AppendChild(damageFlags);
                        }
                        if (entry.damageType != "") // string
                        {
                            XmlElement damageType = protoFile.CreateElement("DamageType");
                            damageType.InnerText = entry.damageType;
                            protoAction.AppendChild(damageType);
                        }
                        if (entry.maxHeight > -1) // float
                        {
                            XmlElement maxHeight = protoFile.CreateElement("MaxHeight");
                            maxHeight.InnerText = entry.maxHeight.ToString(fltMod);
                            protoAction.AppendChild(maxHeight);
                        }
                        if (entry.maxRange > -1) // float
                        {
                            XmlElement maxRange = protoFile.CreateElement("MaxRange");
                            maxRange.InnerText = entry.maxRange.ToString(fltMod);
                            protoAction.AppendChild(maxRange);
                        }
                        if (entry.minRange > -1) // float
                        {
                            XmlElement minRange = protoFile.CreateElement("MinRange");
                            minRange.InnerText = entry.minRange.ToString(fltMod);
                            protoAction.AppendChild(minRange);
                        }
                        if (entry.name != "") // string
                        {
                            XmlElement entryName = protoFile.CreateElement("Name");
                            entryName.InnerText = entry.name;
                            protoAction.AppendChild(entryName);
                        }
                        if (entry.numberProjectiles > -1) // int
                        {
                            XmlElement numberProjectiles = protoFile.CreateElement("NumberProjectiles");
                            numberProjectiles.InnerText = entry.numberProjectiles.ToString();
                            protoAction.AppendChild(numberProjectiles);
                        }
                        if (entry.projectile != "") // string
                        {
                            XmlElement projectile = protoFile.CreateElement("Projectile");
                            projectile.InnerText = entry.projectile;
                            protoAction.AppendChild(projectile);
                        }
                        if (entry.rate.Count > 0) // List<ResourceValue>
                        {
                            foreach (ResourceValue rateItem in entry.damageBonus)
                            {
                                XmlElement rate = protoFile.CreateElement("Rate");
                                rate.InnerText = rateItem.value.ToString(fltMod);
                                XmlAttribute rateResource = protoFile.CreateAttribute("type");
                                rateResource.InnerText = rateItem.resourceType;
                                rate.Attributes.Append(rateResource);
                                newUnit.AppendChild(rate);
                            }
                        }
                        if (entry.ROF > -1) // float
                        {
                            XmlElement ROF = protoFile.CreateElement("ROF");
                            ROF.InnerText = entry.ROF.ToString(fltMod);
                            protoAction.AppendChild(ROF);
                        }
                        if (entry.type != "") // string
                        {
                            XmlElement type = protoFile.CreateElement("Type");
                            type.InnerText = entry.type;
                            protoAction.AppendChild(type);
                        }
                        newUnit.AppendChild(protoAction);
                    }
                }
                if (item.rechargeTime > -1) // float
                {
                    XmlElement rechargeTime = protoFile.CreateElement("RechargeTime");
                    rechargeTime.InnerText = item.rechargeTime.ToString(fltMod);
                    newUnit.AppendChild(rechargeTime);
                }
                if (item.resourceDecay > -1) // float
                {
                    XmlElement resourceDecay = protoFile.CreateElement("ResourceDecay");
                    resourceDecay.InnerText = item.resourceDecay.ToString(fltMod);
                    newUnit.AppendChild(resourceDecay);
                }
                if (item.resourceSubType != "") // string
                {
                    XmlElement resourceSubType = protoFile.CreateElement("ResourceSubType");
                    resourceSubType.InnerText = item.resourceSubType;
                    newUnit.AppendChild(resourceSubType);
                }
                if (item.rolloverTextID > -1) // int
                {
                    XmlElement rolloverTextID = protoFile.CreateElement("RolloverTextID");
                    rolloverTextID.InnerText = item.rolloverTextID.ToString();
                    newUnit.AppendChild(rolloverTextID);
                }
                if (item.scoreValue > -1) // float
                {
                    XmlElement scoreValue = protoFile.CreateElement("ScoreValue");
                    scoreValue.InnerText = item.scoreValue.ToString(fltMod);
                    newUnit.AppendChild(scoreValue);
                }
                if (item.shortRolloverTextID > -1) // int
                {
                    XmlElement shortRolloverTextID = protoFile.CreateElement("ShortRolloverTextID");
                    shortRolloverTextID.InnerText = item.shortRolloverTextID.ToString();
                    newUnit.AppendChild(shortRolloverTextID);
                }
                if (item.socketUnitType != "") // string
                {
                    XmlElement socketUnitType = protoFile.CreateElement("SocketUnitType");
                    socketUnitType.InnerText = item.socketUnitType;
                    newUnit.AppendChild(socketUnitType);
                }
                if (item.subCiv != "") // string
                {
                    XmlElement subCiv = protoFile.CreateElement("SubCiv");
                    subCiv.InnerText = item.subCiv;
                    newUnit.AppendChild(subCiv);
                }
                if (item.tactics != "") // string
                {
                    XmlElement tactics = protoFile.CreateElement("Tactics");
                    tactics.InnerText = item.tactics;
                    newUnit.AppendChild(tactics);
                }
                if (item.tech.Count > 0) // List<TrainTech>
                {
                    foreach (TrainTech entry in item.tech)
                    {
                        XmlElement tech = protoFile.CreateElement("Tech");
                        tech.InnerText = entry.value;
                        XmlAttribute row = protoFile.CreateAttribute("row");
                        row.InnerText = entry.row.ToString(fltMod);
                        tech.Attributes.Append(row);
                        XmlAttribute page = protoFile.CreateAttribute("page");
                        page.InnerText = entry.page.ToString(fltMod);
                        tech.Attributes.Append(page);
                        XmlAttribute column = protoFile.CreateAttribute("column");
                        column.InnerText = entry.column.ToString(fltMod);
                        tech.Attributes.Append(column);
                        newUnit.AppendChild(tech);
                    }
                }
                if (item.train.Count > 0) // List<TrainTech>
                {
                    foreach (TrainTech entry in item.train)
                    {
                        XmlElement train = protoFile.CreateElement("Train");
                        train.InnerText = entry.value;
                        XmlAttribute row = protoFile.CreateAttribute("row");
                        row.InnerText = entry.row.ToString(fltMod);
                        train.Attributes.Append(row);
                        XmlAttribute page = protoFile.CreateAttribute("page");
                        page.InnerText = entry.page.ToString(fltMod);
                        train.Attributes.Append(page);
                        XmlAttribute column = protoFile.CreateAttribute("column");
                        column.InnerText = entry.column.ToString(fltMod);
                        train.Attributes.Append(column);
                        newUnit.AppendChild(train);
                    }
                }
                if (item.trainPoints > -1) // float
                {
                    XmlElement trainPoints = protoFile.CreateElement("TrainPoints");
                    trainPoints.InnerText = item.trainPoints.ToString(fltMod);
                    newUnit.AppendChild(trainPoints);
                }
                if (item.turnRate > -1) // float
                {
                    XmlElement turnRate = protoFile.CreateElement("TurnRate");
                    turnRate.InnerText = item.turnRate.ToString(fltMod);
                    newUnit.AppendChild(turnRate);
                }
                if (item.unitAIType != "") // string
                {
                    XmlElement unitAIType = protoFile.CreateElement("UnitAIType");
                    unitAIType.InnerText = item.unitAIType;
                    newUnit.AppendChild(unitAIType);
                }
                if (item.unitType.Count > 0) // List<String>
                {
                    foreach (string entry in item.unitType)
                    {
                        XmlElement unitType = protoFile.CreateElement("UnitType");
                        unitType.InnerText = entry;
                        newUnit.AppendChild(unitType);
                    }
                }
                if (item.wanderDistance > -1) // int
                {
                    XmlElement wanderDistance = protoFile.CreateElement("WanderDistance");
                    wanderDistance.InnerText = item.wanderDistance.ToString();
                    newUnit.AppendChild(wanderDistance);
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// <para>Updates a unit within the proto file.</para>
 /// </summary>
 /// <param name="item">The unit to update</param>
 /// <returns>True if successful, otherwise false</returns>
 public bool setUnitByID(Unit item)
 {
     bool itemExists = false;
     try
     {
         XmlNodeList allUnits = protoFile.GetElementsByTagName("Unit");
         foreach (XmlElement unit in allUnits)
         {
             if (int.Parse(unit.Attributes.GetNamedItem("id").InnerText) == item.ID)
             {
                 // This is the unit we're supposed to be setting values to!
                 itemExists = true;
                 // First of all let's drop the unit from the XML file,
                 // then create a new one!
                 protoFile.DocumentElement.RemoveChild(unit);
                 if (!addUnit(item))
                     throw new Exception();
                 // Have we managed all of that without
                 // throwing an exception?
                 return true;
             }
         }
         // Did the item not exist?
         if (!itemExists)
         {
             return false;
         }
     }
     catch (Exception e)
     {
         return false;
     }
     // Did it all go wrong somewhere?
     return false;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Gets an individual unit from the current proto file and
 /// returns it in a Unit object
 /// </summary>
 /// <param name="ID">Unique ID for the unit required</param>
 /// <returns>The requested unit or null if an exception
 /// has occurred</returns>
 public Unit getUnitById(int ID)
 {
     try
     {
         XmlNodeList allUnits = protoFile.GetElementsByTagName("Unit");
         if (allUnits.Count > 0)
         {
             foreach (XmlNode current in allUnits)
             {
                 if (int.Parse(current.Attributes.GetNamedItem("id").InnerText) == ID)
                 {
                     // Create a new item to insert relevant values into!
                     Unit item = new Unit();
                     // Basic elements such as name and ID
                     item.name = current.Attributes.GetNamedItem("name").InnerText;
                     item.ID = int.Parse(current.Attributes.GetNamedItem("id").InnerText);
                     // Now check for the presence of each possible child
                     // node within the current element!
                     XmlNodeList children = current.ChildNodes;
                     foreach (XmlElement child in children)
                     {
                         getElement(item, child);
                     }
                     // We've got through all of that,
                     // return the item we've created!
                     return item;
                 }
             }
         }
     }
     catch (Exception e)
     {
         return null;
     }
     return null;
 }