/// <summary> /// Get random composition variant /// </summary> /// <param name="size"></param> /// <returns></returns> private ComboArmyCompositionVariant get_random_composition_variant(ComboArmyComposition composition) { if (composition == null) { composition = ca_parser_.Compositions.Find( delegate(ComboArmyComposition c) { return(c.Size == size_); } ); } if (composition == null || composition.Variants.Count == 0) { return(null); } double[] chances = new double[composition.Variants.Count]; int i = 0; foreach (ComboArmyCompositionVariant v in composition.Variants) { chances[i++] = v.Chance; } int rnd = Randomizer.Choice(chances, 100); return(composition.Variants[rnd]); }
/// <summary> /// Generate place holders for monsters in army /// </summary> private void gen_placeholders(ComboArmyComposition composition) { ComboArmyCompositionVariant v = get_random_composition_variant(composition); if (v != null) { foreach (string r in v.References) //add traits for each reference { ComboArmyComposition comp = ca_parser_.Compositions.Find( delegate(ComboArmyComposition c) { return(c.Name == r); } ); gen_placeholders(comp); } foreach (MonsterTraits mt in v.Traits) //add traits for variant { placeholders_.Add(new MonsterPlaceHolder(mt)); } } if (composition == null && placeholders_.Count == 0) { placeholders_.Add(new MonsterPlaceHolder(MonsterTraits.Any)); } }
/// <summary> /// initialization /// </summary> private void parse(XmlElement xml_data) { if (xml_data == null || xml_data.ChildNodes.Count < 3 || xml_data.ChildNodes[2].ChildNodes.Count == 0) { throw new Exception("ComboArmyInfo section not found"); } else { foreach (XmlNode node in xml_data.ChildNodes[2].ChildNodes) { ComboArmyComposition c = new ComboArmyComposition(node); if (c.IsParseOK) { compositions_.Add(c); } } } }