Пример #1
0
    //-----------------------------------------------------------------------------------------------
    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);
            }
        }
    }
Пример #2
0
    //-----------------------------------------------------------------------------------------------
    private WorkingMap ConstructActiveMapFromMapFormula(int indexIntoFormulaList)
    {
        MapFormula formulaToUse = m_influenceSystemRef.InfluenceMapFormulas[indexIntoFormulaList];
        WorkingMap activeMap    = formulaToUse.ConstructMapFromFormula();

        activeMap.Normalize();
        return(activeMap);
    }
Пример #3
0
    //-----------------------------------------------------------------------------------------------
    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();
    }
Пример #4
0
    //-----------------------------------------------------------------------------------------------
    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);
        }
    }