Пример #1
0
        // Returns the index of the first OutputChangeType that matches the InputConditionType or -1 if no matches
        public int OutputChangeTypeMatch(InputCondition inputCondition, MappingType inputConditionMappingType, List <EntityType> allEntityTypes)
        {
            for (int i = 0; i < outputChanges.Count; i++)
            {
                OutputChange outputChange = outputChanges[i];

                if (inputCondition.inputConditionType == null)
                {
                    Debug.LogError("MappingType " + inputConditionMappingType.name + " has an InputCondition with no InputConditionType.  Please Fix.");
                    return(-1);
                }
                if (outputChange.outputChangeType == null)
                {
                    Debug.LogError("MappingType " + name + " has an OutputChange with no OutputChangeType.  Please Fix.");
                    return(-1);
                }
                if (inputCondition.inputConditionType.matchingOCTs != null &&
                    inputCondition.inputConditionType.matchingOCTs.Contains(outputChange.outputChangeType) &&
                    outputChange.outputChangeType.PreMatch(outputChange, this, inputCondition, inputConditionMappingType, allEntityTypes))
                {
                    return(i);
                }
            }
            return(-1);
        }
Пример #2
0
        public bool AnyInventoryGroupingMatches(MappingType mappingType, List <EntityType> entityTypes)
        {
            List <TypeGroup>  groupings = InventoryTypeGroups(mappingType, out List <int> indexesToSet);
            List <EntityType> matches   = TypeGroup.InAllTypeGroups(groupings, entityTypes, true);

            return(matches != null && matches.Count > 0);
        }
Пример #3
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            List <InputCondition> inputConditionsFromOC = outputChangeMappingType.EntityTypeInputConditions();
            List <EntityType>     entityTypes           = TypeGroup.PossibleEntityTypes(inputConditionsFromOC, agent.memoryType.GetKnownEntityTypes(agent));

            if (inputConditionMappingType.AnyEntityTypeMatchesTypeGroups(entityTypes) &&
                inputCondition.levelType == outputChange.levelType)
            {
                // Same EntityType and same TagType - match adding tag to needing tag and removing tag to can't have tag
                if (!outputChange.boolValue &&
                    ((HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.DoesNotHaveOwnerTag ||
                     (HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.DoesNotHaveTag))
                {
                    return(true);
                }
                else if (outputChange.boolValue &&
                         ((HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.HasTagButNotOwner ||
                          (HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.HasTagIgnoreOwnership ||
                          (HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.HasTagIsOwner))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #4
0
        public override bool PreMatch(OutputChange outputChange, MappingType outputChangeMappingType, InputCondition inputCondition,
                                      MappingType inputConditionMappingType, List <EntityType> allEntityTypes)
        {
            // Matches OtherInventoryAmountICT
            // This needs to be giving the corrent EntityType (InventoryGroupings) based on what the ICT needs (InventoryGroupings)
            if (outputChange.inventoryTypeGroupMatchIndex == -1)
            {
                return(false);
            }

            InputCondition   outputChangeInputCondition = outputChangeMappingType.inputConditions[outputChange.inventoryTypeGroupMatchIndex];
            List <TypeGroup> groupings = outputChangeInputCondition.InventoryTypeGroups(outputChangeMappingType, out List <int> indexesToSet);

            // groupings is now the EntityTypes that are possible to be given
            List <EntityType> entityTypes = TypeGroup.InAllTypeGroups(groupings, allEntityTypes);

            // See if any of these EntityTypes matches what the IC of OtherInventoryAmountICT needs
            bool inventoryGroupMatches = inputCondition.AnyInventoryGroupingMatches(inputConditionMappingType, entityTypes);

            // Also need to make sure that possible EntityTypes from both MappingTypes have some overlap
            bool groupMatches = outputChangeMappingType.AnyEntityTypeMatchesTypeGroups(inputConditionMappingType, allEntityTypes);

            if (inventoryGroupMatches && groupMatches)
            {
                return(true);
            }
            return(false);
        }
Пример #5
0
        // Figure out how close to get to the target when doing a GoTo action
        public override float GetArriveDistance(Agent agent, Entity target, Mapping mapping)
        {
            // Chain of priority for distance: MappingType > ActionType > InputOutputType - default to 1.5
            MappingType mappingType = mapping.mappingType;
            float       distance    = 2.5f;

            if (mappingType.maxDistanceAsInput > 0)
            {
                distance = mappingType.maxDistanceAsInput;
            }
            else if (mappingType.actionType.maxDistanceAsInput > 0)
            {
                distance = mappingType.actionType.maxDistanceAsInput;
            }
            else if (mappingType.outputChanges != null && mappingType.outputChanges.Count > 0 &&
                     mappingType.outputChanges[0].outputChangeType.name == "NearEntityOCT" &&
                     mapping.parent != null && mapping.parent.mappingType.actionType.maxDistanceAsInput > 0)
            {
                distance = mapping.parent.mappingType.actionType.maxDistanceAsInput;
            }
            else if (target != null && target.entityType.maxDistanceAsInput > 0)
            {
                distance = target.entityType.maxDistanceAsInput;
            }
            else if (target != null && target.entityType.maxDistanceAsInput > 0)
            {
                distance = target.entityType.maxDistanceAsInput;
            }

            //Debug.Log("GetArriveDistance for " + passedInTarget.name + " Distance = " + distance);
            return(distance);
        }
Пример #6
0
        public OutputChange Previous(MappingType mappingType)
        {
            int index = mappingType.outputChanges.IndexOf(this);

            if (index == 0)
            {
                return(null);
            }
            return(mappingType.outputChanges[index - 1]);
        }
Пример #7
0
        public OutputChange Next(MappingType mappingType)
        {
            int index = mappingType.outputChanges.IndexOf(this);

            if (index + 1 == mappingType.outputChanges.Count)
            {
                return(null);
            }
            return(mappingType.outputChanges[index + 1]);
        }
Пример #8
0
 public Mapping(MappingType mappingType)
 {
     this.mappingType  = mappingType;
     target            = null;
     inventoryTargets  = null;
     parent            = null;
     children          = null;
     reasonForChildren = null;
     childIndex        = 0;
     isComplete        = false;
 }
Пример #9
0
        public override bool PreMatch(OutputChange outputChange, MappingType outputChangeMappingType, InputCondition inputCondition,
                                      MappingType inputConditionMappingType, List <EntityType> allEntityTypes)
        {
            // The EntityType being created need match with the ICMT's EntityType TypeGroup Target
            List <TypeGroup> typeGroups = inputConditionMappingType.EntityTypeGroupings();

            if (outputChange.entityType.InAllTypeGroups(typeGroups))
            {
                return(true);
            }
            return(false);
        }
Пример #10
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            List <InputCondition> inputConditionsFromOC = outputChangeMappingType.EntityTypeInputConditions();
            List <EntityType>     entityTypes           = TypeGroup.PossibleEntityTypes(inputConditionsFromOC, agent.memoryType.GetKnownEntityTypes(agent));

            if (inputConditionMappingType.AnyEntityTypeMatchesTypeGroups(entityTypes))
            {
                return(true);
            }
            return(false);
        }
Пример #11
0
        public override bool PreMatch(OutputChange outputChange, MappingType outputChangeMappingType, InputCondition inputCondition,
                                      MappingType inputConditionMappingType, List <EntityType> allEntityTypes)
        {
            // This OTC can change the drive level positive or negative for the agent or a drive level for its target agent
            if (outputChange.targetType == OutputChange.TargetType.ToSelf)
            {
                // Match this to DriveLevelICTs that are checking this agent's Drive Levels (boolValue == false)
                // Need the change amount to push the level towards the ICTs min-max range

                // No access the game state since this is run before to cache the IC to MT matches
                // If DriveLevelICT fails do we want to push the level up or down to fix it?
                // With a middle range (40-60) we have no way to know unless we know the agent's level
                // if its end ranges though (0-10 or 90-100) we do know
                // Switch to have a floatValue and say <= or >=

                // Or have runtime checks - have it match both increase and decrease
                // then check agent's drive level and filter out one of them

                if (inputCondition.levelType == outputChange.levelType && !inputCondition.boolValue)
                {
                    if (inputCondition.max == 100)
                    {
                        // The ICT wants a high drive level - Make sure OCT is pushing the value up
                        if (outputChange.valueType == OutputChange.ValueType.FloatValue && outputChange.floatValue > 0 ||
                            outputChange.valueType == OutputChange.ValueType.ActionSkillCurve && outputChange.actionSkillCurve.max > 0)
                        {
                            return(true);
                        }
                    }
                    else if (inputCondition.min == 0)
                    {
                        // The ICT wants a low drive level - Make sure OCT is pushing the value up
                        if (outputChange.valueType == OutputChange.ValueType.FloatValue && outputChange.floatValue < 0 ||
                            outputChange.valueType == OutputChange.ValueType.ActionSkillCurve && outputChange.actionSkillCurve.min < 0)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        // Not sure - we need to know agent's level so we need to do a runtime check
                        return(true);
                    }

                    return(false);
                }
            }
            else
            {
                // TODO: What does a Drive Level change to target agent match with?
            }
            return(false);
        }
Пример #12
0
        public void CreateICToMTDictionary()
        {
            if (settings.driveLevelICT == null)
            {
                return;
            }

            fixesInputCondition        = new Dictionary <InputCondition, List <FixInputCondition> >();
            fakeDriveLevelMappingTypes = new Dictionary <DriveType, MappingType>();

            // TODO: Will this work in runtime?
            List <MappingType> allMappingTypes = new List <MappingType>();

            string[] guids = AssetDatabase.FindAssets("t:MappingType");
            foreach (string guid in guids)
            {
                allMappingTypes.Add((MappingType)AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
            }

            List <DriveType> allDriveTypes = new List <DriveType>();

            guids = AssetDatabase.FindAssets("t:DriveType");
            foreach (string guid in guids)
            {
                allDriveTypes.Add((DriveType)AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
            }

            // Add in Drive InputConditions that don't exist in the MappingTypes (Goals)
            foreach (DriveType driveType in allDriveTypes)
            {
                MappingType mappingType = ScriptableObject.CreateInstance <MappingType>();
                mappingType.name = "AutoGeneratedFor" + driveType.name;
                InputCondition inputCondition = new InputCondition(driveType, settings.driveLevelICT, false);
                mappingType.inputConditions = new List <InputCondition>()
                {
                    inputCondition
                };
                fakeDriveLevelMappingTypes.Add(driveType, mappingType);

                FindMatchingMappingTypes(inputCondition, mappingType, allMappingTypes);
            }

            foreach (MappingType mappingType in allMappingTypes)
            {
                foreach (InputCondition inputCondition in mappingType.inputConditions)
                {
                    FindMatchingMappingTypes(inputCondition, mappingType, allMappingTypes);
                }
            }

            Debug.Log("ICT to MappingType Lookup Dictionary Created.");
        }
Пример #13
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            // This matches WorldObjectStateICT
            List <InputCondition> inputConditionsFromOC = outputChangeMappingType.EntityTypeInputConditions();
            List <EntityType>     entityTypes           = TypeGroup.PossibleEntityTypes(inputConditionsFromOC, agent.memoryType.GetKnownEntityTypes(agent));

            if (inputConditionMappingType.AnyEntityTypeMatchesTypeGroups(entityTypes) &&
                outputChange.stringValue == inputCondition.stringValue)
            {
                return(true);
            }
            return(false);
        }
Пример #14
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            // Trying to match with ItemAmountICT with this (InventoryPickupOCT)
            // So make sure InventoryGrouping from ItemAmountICT overlaps with the Grouping for InventoryPickupOCT
            List <EntityType> entityTypes = TypeGroup.PossibleEntityTypes(outputChangeMappingType.inputConditions,
                                                                          agent.memoryType.GetKnownEntityTypes(agent));

            if (inputCondition.GetInventoryTypeGroup().AnyMatches(entityTypes))
            {
                return(true);
            }
            return(false);
        }
Пример #15
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            return(true);

            /*
             * List<InputCondition> inputConditionsFromOC = outputChangeMappingType.EntityTypeInputConditions();
             * List<EntityType> entityTypes = Grouping.PossibleEntityTypes(inputConditionsFromOC, agent.memoryType.GetKnownEntityTypes(agent));
             *
             * if (inputConditionMappingType.AnyEntityTypeMatchesGroupings(entityTypes) &&
             *  outputChange.boolValue == inputCondition.boolValue)
             *  return true;
             * return false;
             */
        }
Пример #16
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            // This matches with InventoryAmountICT
            // Matches the InventoryAmountICT InventoryGroup with this OC's InventoryGroup
            InputCondition   outputChangeInputCondition = outputChangeMappingType.inputConditions[outputChange.inventoryTypeGroupMatchIndex];
            List <TypeGroup> groupings = outputChangeInputCondition.InventoryTypeGroups(outputChangeMappingType, out List <int> indexesToSet);

            // Groupings is now the EntityTypes that are possible to be taken
            // Need to use allEntityTypes in world since agent may be trying to get an EntityType this is in inventory
            List <EntityType> entityTypes = TypeGroup.InAllTypeGroups(groupings, agent.totalAIManager.allEntityTypes);

            if (inputCondition.AnyInventoryGroupingMatches(inputConditionMappingType, entityTypes))
            {
                return(true);
            }
            return(false);
        }
Пример #17
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            // Matches OtherInventoryAmountICT
            // This needs to be giving the corrent EntityType (InventoryGroupings) based on what the ICT needs (InventoryGroupings)
            InputCondition   outputChangeInputCondition = outputChangeMappingType.inputConditions[outputChange.inventoryTypeGroupMatchIndex];
            List <TypeGroup> groupings = outputChangeInputCondition.InventoryTypeGroups(outputChangeMappingType, out List <int> indexesToSet);

            // groupings is now the EntityTypes that are possible to be given
            List <EntityType> entityTypes = TypeGroup.InAllTypeGroups(groupings, agent.memoryType.GetKnownEntityTypes(agent, true));

            // See if any of these EntityTypes matches what the IC of OtherInventoryAmountICT needs
            if (inputCondition.AnyInventoryGroupingMatches(inputConditionMappingType, entityTypes))
            {
                return(true);
            }
            return(false);
        }
Пример #18
0
 private void ResetNoPlans()
 {
     noPlansMappingType = agentType.defaultNoPlansMappingType;
     foreach (AgentTypeOverride agentTypeOverride in entityTypeOverrides)
     {
         if (agentTypeOverride != null && agentTypeOverride.defaultNoPlansMappingType != null)
         {
             noPlansMappingType = agentTypeOverride.defaultNoPlansMappingType;
         }
     }
     noneDriveType = agentType.defaultNoPlansDriveType;
     foreach (AgentTypeOverride agentTypeOverride in entityTypeOverrides)
     {
         if (agentTypeOverride != null && agentTypeOverride.defaultNoPlansDriveType != null)
         {
             noneDriveType = agentTypeOverride.defaultNoPlansDriveType;
         }
     }
 }
Пример #19
0
        public virtual Mapping CreateGoToMapping(Mapping mapping)
        {
            MappingType mappingType = CreateInstance <MappingType>();

            mappingType.inputConditions          = new List <InputCondition>();
            mappingType.outputChanges            = new List <OutputChange>();
            mappingType.actionType               = mapping.mappingType.goToActionType;
            mappingType.selectors                = mapping.mappingType.goToSelectors;
            mappingType.overrideDefaultSelectors = mapping.mappingType.overrideDefaultGoToSelectors;
            mappingType.name = mappingType.actionType.name + (mapping.target == null ? "Location" : mapping.target.name);

            Mapping goToMapping = new Mapping(mappingType)
            {
                target     = mapping.target,
                parent     = mapping,
                isComplete = true
            };

            return(goToMapping);
        }
Пример #20
0
        static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions opt)
        {
            if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(MappingType))
            {
                MappingType mappingType = AssetDatabase.LoadAssetAtPath <MappingType>(path);
                ActionType  actionType  = mappingType.actionType;

                if (actionType != null)
                {
                    if (actionType.mappingTypes.Contains(mappingType))
                    {
                        actionType.mappingTypes.Remove(mappingType);
                        EditorUtility.SetDirty(actionType);
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                    }
                }
            }
            return(AssetDeleteResult.DidNotDelete);
        }
Пример #21
0
        // Returns true if this and mappingType have any EntityTypes that match both
        public bool AnyEntityTypeMatchesTypeGroups(MappingType mappingType, List <EntityType> entityTypes)
        {
            List <TypeGroup> typeGroups = EntityTypeGroupings(true);

            if (typeGroups.Count == 0)
            {
                return(false);
            }

            List <TypeGroup> otherTypeGroups = mappingType.EntityTypeGroupings(true);

            if (otherTypeGroups.Count == 0)
            {
                return(false);
            }

            List <TypeGroup>  combinedTypeGroups = typeGroups.Union(otherTypeGroups).Distinct().ToList();
            List <EntityType> matches            = TypeGroup.InAllTypeGroups(combinedTypeGroups, entityTypes, true);

            return(matches != null && matches.Count > 0);
        }
Пример #22
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            foreach (string path in importedAssets)
            {
                if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(MappingType))
                {
                    MappingType mappingType = AssetDatabase.LoadAssetAtPath <MappingType>(path);
                    ActionType  actionType  = mappingType.actionType;

                    if (actionType != null)
                    {
                        if (!actionType.mappingTypes.Contains(mappingType))
                        {
                            actionType.mappingTypes.Add(mappingType);
                            EditorUtility.SetDirty(actionType);
                            AssetDatabase.SaveAssets();
                            AssetDatabase.Refresh();
                        }
                    }
                }
            }
        }
Пример #23
0
        // Updates fixesInputCondition with any MappingTypes that resolve the inputCondition
        private void FindMatchingMappingTypes(InputCondition inputCondition, MappingType inputConditionMappingType, List <MappingType> allMappingTypes)
        {
            foreach (MappingType outputChangeMappingType in allMappingTypes)
            {
                // Current limitation is that MT can only be in a plan tree once (Due to relying on IC for Dicts)
                // So it makes sense to prevent this - not sure if you would ever want an MT to link to itself?
                if (outputChangeMappingType == inputConditionMappingType)
                {
                    continue;
                }

                // Ask outputChangeMappingType if it has any matching OutputChanges
                int outputChangeIndex = outputChangeMappingType.OutputChangeTypeMatch(inputCondition, inputConditionMappingType, allEntityTypes);
                if (outputChangeIndex != -1)
                {
                    FixInputCondition fixInputCondition = new FixInputCondition()
                    {
                        mappingType       = outputChangeMappingType,
                        outputChangeIndex = outputChangeIndex
                    };

                    if (!fixesInputCondition.ContainsKey(inputCondition))
                    {
                        // New entry in dictionary - inputCondition has not been seen before
                        List <FixInputCondition> fixInputConditions = new List <FixInputCondition>()
                        {
                            fixInputCondition
                        };
                        fixesInputCondition.Add(inputCondition, fixInputConditions);
                    }
                    else
                    {
                        fixesInputCondition[inputCondition].Add(fixInputCondition);
                    }
                }
            }
        }
Пример #24
0
 public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                            InputCondition inputCondition, MappingType inputConditionMappingType)
 {
     return(false);
 }
Пример #25
0
 public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                            InputCondition inputCondition, MappingType inputConditionMappingType)
 {
     // TODO: Handle middle ranges
     return(true);
 }
Пример #26
0
        // Returns all Groupings that this InventoryGrouping needs to match based on sharesInventoryGroupWith
        // TODO: Have a way to ignore the indexesToSet - don't always need it
        public List <TypeGroup> InventoryTypeGroups(MappingType mappingType, out List <int> indexesToSet)
        {
            indexesToSet = new List <int>();
            if (!inputConditionType.typeInfo.usesInventoryTypeGroup)
            {
                return(null);
            }

            List <TypeGroup> groupings = new List <TypeGroup>()
            {
                GetInventoryTypeGroup()
            };

            // See if this shares InventoryGroupings with any other IC
            // See if inputCondition shares its InventoryGrouping with any other ICs
            int thisIndex = -1;

            int[] sharesWith = new int[mappingType.inputConditions.Count];

            for (int i = 0; i < mappingType.inputConditions.Count; i++)
            {
                InputCondition inputCondition = mappingType.inputConditions[i];
                if (inputCondition.inputConditionType.typeInfo.usesInventoryTypeGroupShareWith)
                {
                    sharesWith[i] = inputCondition.sharesInventoryTypeGroupWith;
                }
                else
                {
                    sharesWith[i] = -1;
                }

                if (inputCondition == this)
                {
                    thisIndex = i;
                    indexesToSet.Add(i);
                }
            }

            // Need to know if this sharesWith or if any other ICs share with this one
            for (int i = 0; i < mappingType.inputConditions.Count; i++)
            {
                if (sharesWith[i] == thisIndex)
                {
                    groupings.Add(mappingType.inputConditions[i].GetInventoryTypeGroup());
                    indexesToSet.Add(i);
                }
                else if (i == thisIndex && sharesWith[i] != -1)
                {
                    groupings.Add(mappingType.inputConditions[sharesWith[i]].GetInventoryTypeGroup());
                    indexesToSet.Add(sharesWith[i]);
                }
            }

            if (groupings.Any(x => x == null))
            {
                Debug.LogError("MappingType " + mappingType.name + " Has null InventoryGroupings in ICs that need them.  Please fix.");
                return(null);
            }

            return(groupings);
        }
Пример #27
0
 public int Index(MappingType mappingType)
 {
     return(mappingType.outputChanges.IndexOf(this));
 }
Пример #28
0
 public virtual bool PreMatch(OutputChange outputChange, MappingType outputChangeMappingType, InputCondition inputCondition,
                              MappingType inputConditionMappingType, List <EntityType> allEntityTypes)
 {
     return(true);
 }
Пример #29
0
 public abstract bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                            InputCondition inputCondition, MappingType inputConditionMappingType);
Пример #30
0
 public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                            InputCondition inputCondition, MappingType inputConditionMappingType)
 {
     // All matching needed is done in PreMatch (since the specific EntityType being created needs to be specified)
     return(true);
 }