Example #1
0
        private Plans PossiblePlans(Agent agent, DriveType driveType)
        {
            List <Mapping> possibleMappings = new List <Mapping>();

            foreach (MappingType mappingType in agent.availableMappingTypes)
            {
                Mapping possibleMapping = new Mapping(mappingType);

                // If MappingType needs an Entity Target - find best target based on TargetFactors
                // TODO: Return all targets each one as a seperate Mapping - so Utility Modifiers can decide between them
                if (mappingType.ForEntityType())
                {
                    Entity target = BestEntityTarget(agent, possibleMapping);
                    if (target == null)
                    {
                        continue;
                    }

                    possibleMapping.target = target;
                }

                // Check non-entity target ICs
                bool passedAllChecks = true;
                foreach (InputCondition inputCondition in mappingType.NonEntityTypeInputConditions())
                {
                    if (!inputCondition.inputConditionType.Check(inputCondition, agent, possibleMapping, null, false))
                    {
                        passedAllChecks = false;
                        break;
                    }
                }
                if (!passedAllChecks)
                {
                    continue;
                }

                if (mappingType.HasAnyInventoryTargets())
                {
                    // TODO: Move this conditional inits into Mapping constructor
                    possibleMapping.inventoryTargets = new List <Entity>();
                    for (int i = 0; i < mappingType.inputConditions.Count; i++)
                    {
                        possibleMapping.inventoryTargets.Add(null);
                    }

                    passedAllChecks = true;
                    for (int i = 0; i < mappingType.inputConditions.Count; i++)
                    {
                        InputCondition inputCondition = mappingType.inputConditions[i];
                        if (inputCondition.RequiresInventoryTarget() && possibleMapping.inventoryTargets[i] == null)
                        {
                            // Finally make sure we can find all of the InventoryTargets
                            if (!SetInventoryTargets(agent, possibleMapping, inputCondition))
                            {
                                passedAllChecks = false;
                                break;
                            }
                        }
                    }
                    if (!passedAllChecks)
                    {
                        continue;
                    }
                }

                // Passed all checks - add it as a possible state to transition into
                possibleMapping.isComplete = true;
                possibleMappings.Add(possibleMapping);
            }

            return(new Plans(driveType, possibleMappings));
        }
Example #2
0
        private Plans PossiblePlans(Agent agent, DriveType driveType, Mapping currentMapping)
        {
            ActionType actionType;

            // If there is a parent this is a GoTo Mapping that was added - use the parent's ActionType
            if (currentMapping.parent != null)
            {
                actionType = currentMapping.parent.mappingType.actionType;
            }
            else
            {
                actionType = currentMapping.mappingType.actionType;
            }

            List <Mapping> possibleMappings = new List <Mapping>();

            foreach (MappingType mappingType in agent.availableMappingTypes)
            {
                // Need to find the CurrentActionTypeICT and see if it matches
                InputCondition actionTypeIC = mappingType.inputConditions.Find(x => x.inputConditionType == currentActionTypeICT);
                if (actionTypeIC != null && actionTypeIC.levelTypes.Contains(currentMapping.mappingType.actionType))
                {
                    // This MT is a possible transition from current ActionType
                    // See if all the ICs pass
                    Mapping possibleMapping = new Mapping(mappingType);

                    // If MappingType needs an Entity Target - find best target based on TargetFactors
                    if (mappingType.ForEntityType())
                    {
                        Entity target = BestEntityTarget(agent, possibleMapping);
                        if (target == null)
                        {
                            continue;
                        }

                        possibleMapping.target = target;
                    }

                    // Check non-entity target ICs
                    bool passedAllChecks = true;
                    foreach (InputCondition inputCondition in mappingType.NonEntityTypeInputConditions())
                    {
                        if (!inputCondition.inputConditionType.Check(inputCondition, agent, possibleMapping, null, false))
                        {
                            passedAllChecks = false;
                            break;
                        }
                    }
                    if (!passedAllChecks)
                    {
                        continue;
                    }

                    if (mappingType.HasAnyInventoryTargets())
                    {
                        // TODO: Move this conditional inits into Mapping constructor
                        possibleMapping.inventoryTargets = new List <Entity>();
                        for (int i = 0; i < mappingType.inputConditions.Count; i++)
                        {
                            possibleMapping.inventoryTargets.Add(null);
                        }

                        passedAllChecks = true;
                        for (int i = 0; i < mappingType.inputConditions.Count; i++)
                        {
                            InputCondition inputCondition = mappingType.inputConditions[i];
                            if (inputCondition.RequiresInventoryTarget() && possibleMapping.inventoryTargets[i] == null)
                            {
                                // Finally make sure we can find all of the InventoryTargets
                                if (!SetInventoryTargets(agent, possibleMapping, inputCondition))
                                {
                                    passedAllChecks = false;
                                    break;
                                }
                            }
                        }
                        if (!passedAllChecks)
                        {
                            continue;
                        }
                    }

                    // Passed all checks - add it as a possible state to transition into
                    possibleMapping.isComplete = true;
                    possibleMappings.Add(possibleMapping);
                }
            }

            return(new Plans(driveType, possibleMappings));
        }