//----------------------------------------------------------------------------------------------- public static void LoadMapFormulasIntoManager(InfluenceSystem manager) { XmlDocument dataAsXmlDoc = LoadXmlDocumentFromFile("Data/InfluenceMapFormulas"); if (dataAsXmlDoc == null) { return; } XmlNodeList formulaList = dataAsXmlDoc.GetElementsByTagName("MapFormula"); foreach (XmlNode formulaInfo in formulaList) { string formulaID = ""; if (!TryLoadRequiredAttributeFromXmlNode(formulaInfo, "FormulaID", ref formulaID)) { continue; } MapFormula newFormula = new MapFormula(formulaID); XmlNodeList operationList = formulaInfo.ChildNodes; PopulateMapFormulaFromXmlNodelist(newFormula, operationList); if (newFormula.OperationCount > 0) { manager.RegisterMapFormula(newFormula); } } }
//----------------------------------------------------------------------------------------------- public static void LoadBaseInfluenceMapsIntoManager(InfluenceSystem manager) { XmlDocument dataAsXmlDoc = LoadXmlDocumentFromFile("Data/BaseInfluenceMaps"); if (dataAsXmlDoc == null) { return; } XmlNodeList baseMapList = dataAsXmlDoc.GetElementsByTagName("BaseMap"); foreach (XmlNode baseMapInfo in baseMapList) { string influenceID = null; string objectTag = null; if (!TryLoadRequiredAttributeFromXmlNode(baseMapInfo, "InfluenceID", ref influenceID) || !TryLoadRequiredAttributeFromXmlNode(baseMapInfo, "ObjectTag", ref objectTag)) { continue; } manager.MakeAndRegisterBaseMap(influenceID, objectTag); } }
//----------------------------------------------------------------------------------------------- public static void LoadInfluenceTemplatesIntoManager(InfluenceSystem manager) { XmlDocument dataAsXmlDoc = LoadXmlDocumentFromFile("Data/InfluenceTemplates"); if (dataAsXmlDoc == null) { return; } XmlNodeList templateList = dataAsXmlDoc.GetElementsByTagName("InfluenceTemplate"); foreach (XmlNode templateInfo in templateList) { string influenceID = null; uint templateSize = 0U; if (!TryLoadRequiredAttributeFromXmlNode(templateInfo, "InfluenceID", ref influenceID) || !TryLoadRequiredAttributeFromXmlNode(templateInfo, "TemplateSize", ref templateSize)) { continue; } manager.MakeAndRegisterInfluenceTemplate(influenceID, templateSize); } }
//----------------------------------------------------------------------------------------------- public static void LoadInfluenceFunctionsIntoManager(InfluenceSystem manager) { XmlDocument dataAsXmlDoc = LoadXmlDocumentFromFile("Data/InfluenceFunctions"); if (dataAsXmlDoc == null) { return; } XmlNodeList functionList = dataAsXmlDoc.GetElementsByTagName("InfluenceFunction"); foreach (XmlNode functionInfo in functionList) { string influenceID = null; if (!TryLoadRequiredAttributeFromXmlNode(functionInfo, "InfluenceID", ref influenceID)) { continue; } float influenceMax = TryLoadXmlAttribute(functionInfo, "InfluenceMax", InfluenceFunction.DEFAULT_MAX_INFLUENCE); uint distanceMax = TryLoadXmlAttribute(functionInfo, "DistanceMax", InfluenceFunction.DEFAULT_MAX_DISTANCE); uint distanceMin = TryLoadXmlAttribute(functionInfo, "DistanceMin", InfluenceFunction.DEFAULT_MIN_DISTANCE); uint falloffExponent = TryLoadXmlAttribute(functionInfo, "FalloffExponent", InfluenceFunction.DEFAULT_FALLOFF_EXPONENT); manager.MakeAndRegisterInfluenceFunction(influenceID, influenceMax, distanceMax, distanceMin, falloffExponent); } }
//----------------------------------------------------------------------------------------------- private void GetAllReferencesAsNeeded() { if (m_strategyPlanner == null) { m_strategyPlanner = FindObjectOfType <StrategyPlanner>(); m_strategyPlanner.Awake(); m_strategyPlanner.Start(); } if (m_aiManager == null) { m_aiManager = FindObjectOfType <AIManager>(); m_aiManager.Awake(); } m_buttons = FindObjectsOfType <Button>(); if (m_influenceGameManager == null) { m_influenceGameManager = FindObjectOfType <InfluenceGameManager>(); } if (m_influenceSystemRef == null) { m_influenceSystemRef = InfluenceSystem.GetInstance(); } m_influenceGameManager.ReloadInfluenceMapData(); m_influenceGameManager.RegisterAllActiveInfluenceObjectsInScene(); m_influenceGameManager.UpdateInfluenceSystem(); }
//----------------------------------------------------------------------------------------------- private void GetInfluenceSystemReferenceIfNeeded() { if (m_influenceSystem != null) { return; } m_influenceSystem = InfluenceSystem.GetInstance(); }
//----------------------------------------------------------------------------------------------- public void GetInfluenceSystemReferencesIfNeeded() { if (m_influenceGameManager == null) { m_influenceGameManager = FindObjectOfType <InfluenceGameManager>(); } if (m_influenceSystemRef == null) { m_influenceSystemRef = InfluenceSystem.GetInstance(); } }
//----------------------------------------------------------------------------------------------- public override void Run() { OperatorParam influenceMapParamName = FindParamWithName("Influence"); // Can't exactly move if we don't have a goal if (influenceMapParamName == null) { return; } string[] mapIdentifiers = influenceMapParamName.Value.Split('_'); // Determine map type InfluenceSystem influenceSys = InfluenceSystem.GetInstance(); InfluenceMapPoint mapPoint; if (mapIdentifiers[0].Equals("Base", StringComparison.CurrentCultureIgnoreCase)) { WorkingMap queryMap = new WorkingMap(); queryMap.AddMap(influenceSys.GetInfluenceMapByIDWithTag(mapIdentifiers[1], mapIdentifiers[2])); queryMap.Normalize(); mapPoint = queryMap.GetPointOfHighestInfluence(); } else if (mapIdentifiers[0].Equals("Formula", StringComparison.CurrentCultureIgnoreCase)) { MapFormula formulaToUse = influenceSys.GetMapFormulaByID(mapIdentifiers[1]); WorkingMap queryMap = formulaToUse.ConstructMapFromFormula(); mapPoint = queryMap.GetPointOfHighestInfluence(); } else { throw new ArgumentException("Invalid name for influence map in move to operator!"); } InfluenceObjectWorldPoint worldPoint = influenceSys.ConvertMapPosToWorldPos(mapPoint); Vector2 newLocation = new Vector2(worldPoint.x, worldPoint.y); AgentToOperateOn.transform.position = newLocation; InfluenceGameManager influenceManager = GameObject.FindObjectOfType <InfluenceGameManager>(); influenceManager.UpdateInfluenceSystem(); }