/// <summary> /// extra custom functinos go in here. /// </summary> /// <param name="name"></param> /// <param name="args"></param> private void NCalcPulsarFunctions(string name, FunctionArgs args) { if (name == "Ability") { int index = 0; try { index = (int)args.Parameters[0].Evaluate(); ChainedExpression result = _design.ComponentDesignAbilities[index].Formula; if (result.Result == null) { result.Evaluate(); } MakeThisDependant(result); args.Result = result.Result; } catch (InvalidCastException e) { throw new Exception("Parameter must be an intiger. " + e); } catch (IndexOutOfRangeException e) { throw new Exception("This component does not have an ComponentAbilitySD at index " + index + ". " + e); } } if (name == "SetAbilityValue") //I might remove this.. { int index = 0; try { index = (int)args.Parameters[0].Evaluate(); ChainedExpression expression = _design.ComponentDesignAbilities[index].Formula; expression.SetResult = args.Parameters[1].Evaluate(); } catch (InvalidCastException e) { throw new Exception("Parameter must be an intiger. " + e); } catch (IndexOutOfRangeException e) { throw new Exception("This component does not have an ComponentAbilitySD at index " + index + ". " + e); } } if (name == "EnumDict") { string typeAsString = (string)args.Parameters[0].Evaluate(); Type type = Type.GetType(typeAsString); Type dictType = typeof(Dictionary <,>).MakeGenericType(type, typeof(double)); dynamic dict = Activator.CreateInstance(dictType); Type enumDictType = typeof(Dictionary <,>).MakeGenericType(typeof(string), type); dynamic enumConstants = Activator.CreateInstance(enumDictType); foreach (dynamic value in Enum.GetValues(type)) { enumConstants.Add(Enum.GetName(type, value), value); } foreach (var kvp in _designAbility.GuidDictionary) { dynamic key = enumConstants[(string)kvp.Key]; dict.Add(key, kvp.Value.DResult); } args.Result = dict; } if (name == "TechData") { Guid techGuid = Guid.Parse((string)args.EvaluateParameters()[0]); TechSD techSD = _staticDataStore.Techs[techGuid]; args.Result = TechProcessor.DataFormula(_factionTechDB, techSD); } //Returns the tech level for the given guid if (name == "TechLevel") { Guid techGuid = Guid.Parse((string)args.EvaluateParameters()[0]); if (_factionTechDB.ResearchedTechs.ContainsKey(techGuid)) { args.Result = _factionTechDB.ResearchedTechs[techGuid]; } else { args.Result = 0; } } //currently not used, but an future experiment to pass the CargoTypeSD as a parameter if (name == "CargoType") { Guid typeGuid = Guid.Parse((string)args.EvaluateParameters()[0]); CargoTypeSD typeSD = _staticDataStore.CargoTypes[typeGuid]; args.Result = typeSD; } //used for datablob args for when a guid is required as a parameter if (name == "GuidString") { Guid typeGuid = Guid.Parse((string)args.EvaluateParameters()[0]); args.Result = typeGuid; } //This sets the DatablobArgs. it's up to the user to ensure the right number of args for a specific datablob //The datablob will be the one defined in designAbility.DataBlobType //TODO document blobs and what args they take!! if (name == "DataBlobArgs") { if (_designAbility.DataBlobType == null) { throw new Exception("This Ability does not have a DataBlob defined! define a datablob for this ability!"); } //_designAbility.DataBlobArgs = new List<double>(); List <object> argList = new List <object>(); foreach (var argParam in args.Parameters) { ChainedExpression argExpression = new ChainedExpression(argParam, _designAbility, _factionTechDB, _staticDataStore); _isDependant = false; argExpression.Evaluate(); argList.Add(argExpression.Result); } _designAbility.DataBlobArgs = argList.ToArray(); args.Result = argList; } }
/// <summary> /// takes a ComponentSD staticData and turns it into a DesignDB /// </summary> /// <param name="component">the componentSD</param> /// <param name="factionTech">this factions TechDB</param> /// <param name="staticData">the game staticData</param> /// <returns></returns> public static ComponentDesign StaticToDesign(ComponentTemplateSD component, FactionTechDB factionTech, StaticDataStore staticData) { ComponentDesign design = new ComponentDesign(); design.Name = component.Name; design.Description = component.Description; design.MassFormula = new ChainedExpression(component.MassFormula, design, factionTech, staticData); design.VolumeFormula = new ChainedExpression(component.VolumeFormula, design, factionTech, staticData); design.CrewFormula = new ChainedExpression(component.CrewReqFormula, design, factionTech, staticData); design.HTKFormula = new ChainedExpression(component.HTKFormula, design, factionTech, staticData); design.ResearchCostFormula = new ChainedExpression(component.ResearchCostFormula, design, factionTech, staticData); design.BuildCostFormula = new ChainedExpression(component.BuildPointCostFormula, design, factionTech, staticData); design.MineralCostFormulas = new Dictionary <Guid, ChainedExpression>(); design.CreditCostFormula = new ChainedExpression(component.CreditCostFormula, design, factionTech, staticData); design.ComponentMountType = component.MountType; design.ConstructionType = component.ConstructionType; design.CargoTypeID = component.CargoTypeID; foreach (var kvp in component.MineralCostFormula) { design.MineralCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, design, factionTech, staticData)); } design.ComponentDesignAbilities = new List <ComponentDesignAbility>(); foreach (var abilitySD in component.ComponentAbilitySDs) { ComponentDesignAbility designAbility = new ComponentDesignAbility(design); designAbility.Name = abilitySD.Name; designAbility.Description = abilitySD.Description; designAbility.GuiHint = abilitySD.GuiHint; if (abilitySD.AbilityFormula != null) { designAbility.Formula = new ChainedExpression(abilitySD.AbilityFormula, designAbility, factionTech, staticData); } if (abilitySD.GuidDictionary != null) { designAbility.GuidDictionary = new Dictionary <object, ChainedExpression>(); if (designAbility.GuiHint == GuiHint.GuiTechSelectionList) { foreach (var kvp in abilitySD.GuidDictionary) { if (factionTech.ResearchedTechs.ContainsKey(Guid.Parse(kvp.Key.ToString()))) { TechSD techSD = staticData.Techs[Guid.Parse(kvp.Key.ToString())]; designAbility.GuidDictionary.Add(kvp.Key, new ChainedExpression(TechProcessor.DataFormula(factionTech, techSD).ToString(), designAbility, factionTech, staticData)); } } } else { foreach (var kvp in abilitySD.GuidDictionary) { designAbility.GuidDictionary.Add(kvp.Key, new ChainedExpression(kvp.Value, designAbility, factionTech, staticData)); } } } if (designAbility.GuiHint == GuiHint.GuiSelectionMaxMin) { designAbility.MaxValueFormula = new ChainedExpression(abilitySD.MaxFormula, designAbility, factionTech, staticData); designAbility.MinValueFormula = new ChainedExpression(abilitySD.MinFormula, designAbility, factionTech, staticData); designAbility.StepValueFormula = new ChainedExpression(abilitySD.StepFormula, designAbility, factionTech, staticData); } if (abilitySD.AbilityDataBlobType != null) { designAbility.DataBlobType = Type.GetType(abilitySD.AbilityDataBlobType); } design.ComponentDesignAbilities.Add(designAbility); } design.MassFormula.Evaluate(); design.SetCrew(); design.SetHTK(); design.SetResearchCost(); design.SetBuildCost(); design.SetMineralCosts(); return(design); }