//----------------------------------------------------------------------------------------------- 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); } } }
//----------------------------------------------------------------------------------------------- private WorkingMap ConstructActiveMapFromMapFormula(int indexIntoFormulaList) { MapFormula formulaToUse = m_influenceSystemRef.InfluenceMapFormulas[indexIntoFormulaList]; WorkingMap activeMap = formulaToUse.ConstructMapFromFormula(); activeMap.Normalize(); return(activeMap); }
//----------------------------------------------------------------------------------------------- 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(); }
//----------------------------------------------------------------------------------------------- private static void PopulateMapFormulaFromXmlNodelist(MapFormula formula, XmlNodeList operationList) { foreach (XmlNode operationInfo in operationList) { string opTypeAsString = ""; if (!TryLoadRequiredAttributeFromXmlNode(operationInfo, "Type", ref opTypeAsString)) { continue; } // Depending on the type, we may be able to early out eInfluenceOpType opType = MapOperation.GetOpTypeForString(opTypeAsString); if (opType == eInfluenceOpType.INVALID_INFLUENCE_OP) { Debug.Log("Operation has invalid type attribute."); continue; } // Don't need to grab a map for normalizing if (opType == eInfluenceOpType.INFLUENCE_OP_NORMALIZE) { formula.AddOperationInstruction(opType, 1f, null, null); continue; } string influenceID = ""; string objectTag = ""; if (!TryLoadRequiredAttributeFromXmlNode(operationInfo, "InfluenceID", ref influenceID) || !TryLoadRequiredAttributeFromXmlNode(operationInfo, "ObjectTag", ref objectTag)) { continue; } float opWeight = TryLoadXmlAttribute(operationInfo, "Weight", MapOperation.DEFAULT_OPERATION_WEIGHT); string caseInsensitiveInfluenceID = influenceID.ToLower(); string caseInsensitiveObjectTag = objectTag.ToLower(); formula.AddOperationInstruction(opType, opWeight, caseInsensitiveInfluenceID, caseInsensitiveObjectTag); } }