Exemple #1
0
        public void AnalyzeGameTerrain(StrategicObjective chosenStrategicObjective, AISpawnStrategy aiSpawnStrategy)
        {
            //declaramos la lisa de pequeños comandos que realizara la ia
            List <AITaskCommand> aiTaskCommands = new List <AITaskCommand>();

            LevelController levelController = Object.FindObjectOfType <LevelController>();

            Entity[] IAcontrolledEntities    = levelController.AIEntities.ToArray();
            Entity[] playerControlledEntites = levelController.PlayerEntities.ToArray();

            //check your controlled entities and see the influences they have in their surroundings
            //en funcion del objetivo estrategico se fijaran las tareas que podran ser de un tipo o de otro.
            for (int i = 0; i < IAcontrolledEntities.Length; i++)
            {
                AnalyzeSurroundingInfluences(aiTaskCommands, chosenStrategicObjective, IAcontrolledEntities[i], playerControlledEntites, levelController);
            }

            Debug.Log(aiTaskCommands.Count);
            _tasksAllocator.OnTaskCommandsReceived(aiTaskCommands, IAcontrolledEntities, aiSpawnStrategy);
        }
Exemple #2
0
        private void AnalyzeSurroundingInfluences(List <AITaskCommand> aiTaskCommands,
                                                  StrategicObjective chosenStrategicObjective, Entity analyzedEntity,
                                                  Entity[] playerControlledEntites, LevelController levelController)
        {
            AbstractNPCBrain analyzedNpc = analyzedEntity.GetComponent <AbstractNPCBrain>();

            if (analyzedNpc != null) // es una entidad con brain, es decir, no es un muro
            {
                //get node of the entity in the influence map
                // look in a ring
                InfluenceMap.Node node          = _influenceMapComponent.GetNodeAtLocation(analyzedNpc.transform.position);
                List <Node>       influenceData = _influenceMapComponent.GetKRingsOfNodes(node, chosenStrategicObjective.SampleRadius);

                Entity chosenTarget = chosenStrategicObjective.DecideBasedOnInfluenceData(analyzedNpc, influenceData, playerControlledEntites, levelController);

                if (chosenTarget == null && !(analyzedNpc is Troop))
                {
                    return;
                }
                if (chosenTarget == null && analyzedNpc is Troop) //no hay nadie a quien atacar o mejorar, pues movemos.
                {
                    Debug.Log("trying to move");
                    aiTaskCommands.Add(new MoveAITaskCommand(analyzedNpc));
                }
                else if (chosenTarget.owner == Entity.Owner.AI)
                {
                    //mejorar
                    Debug.Log("trying to upgrade");
                    aiTaskCommands.Add(new UpgradeAITaskCommand(chosenTarget));
                }
                else if (chosenTarget.owner == Entity.Owner.Player)
                {
                    Debug.Log("trying to attack");
                    aiTaskCommands.Add(new AttackAITaskCommand(analyzedNpc, chosenTarget));
                }
            }
            else // es un muro
            {
                return;
            }
        }
        public void EvaluateGameState()
        {
            List <Entity> AIEntitiesInPlayerSide     = castEntitiesOwner(_levelController.AIEntities, PlayerType.Player);
            List <Entity> PlayerEntitiesInPlayerSide = castEntitiesOwner(_levelController.PlayerEntities, PlayerType.Player);

            List <Entity> AIEntitiesInAISide     = castEntitiesOwner(_levelController.AIEntities, PlayerType.Player);
            List <Entity> PlayerEntitiesInAISide = castEntitiesOwner(_levelController.PlayerEntities, PlayerType.Player);

            entitiesValueAI     = CalculateValueEntities(_levelController.AIEntities);
            entitiesValuePlayer = CalculateValueEntities(_levelController.PlayerEntities);

            entitiesNumberAI     = _levelController.AIEntities.Count;
            entitiesNumberPlayer = _levelController.PlayerEntities.Count;

            entitiesValueAIOwnedPlayer     = CalculateValueEntities(AIEntitiesInPlayerSide);
            entitiesValuePlayerOwnedPlayer = CalculateValueEntities(PlayerEntitiesInPlayerSide);

            entitiesValueAIOwnedAI     = CalculateValueEntities(AIEntitiesInAISide);
            entitiesValuePlayerOwnedAI = CalculateValueEntities(PlayerEntitiesInAISide);

            Debug.Log(entitiesValueAI + ", " + entitiesValuePlayer + ", " + entitiesNumberAI + ", " + entitiesNumberPlayer + ", " + entitiesValueAIOwnedPlayer + ", " + entitiesValuePlayerOwnedPlayer + ", " + entitiesValueAIOwnedAI + ", " + entitiesValuePlayerOwnedAI);

            if (entitiesValueAI >= entitiesValuePlayer)
            {
                if (entitiesNumberAI >= entitiesNumberPlayer)
                {
                    if (entitiesValueAIOwnedPlayer >= entitiesValuePlayerOwnedPlayer)
                    {
                        _strategicObjective = GetOrAddComponent <AttackBaseObjective>();
                        _spawnStrategy      = new AISpawnStrategy(new List <EntityBloodCost>
                        {
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Tank),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Launcher),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Launcher)
                        });
                    }
                    else
                    {
                        _strategicObjective = GetOrAddComponent <AttackTroopsObjective>();
                        //Spawnear tropas baratas
                        _spawnStrategy = new AISpawnStrategy(new List <EntityBloodCost>
                        {
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Prisioner),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Prisioner),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Launcher),
                        });
                    }
                }
                else
                {
                    _strategicObjective = GetOrAddComponent <AttackTroopsObjective>();
                    //Spawnear tropas baratas
                    _spawnStrategy = new AISpawnStrategy(new List <EntityBloodCost>
                    {
                        EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Prisioner),
                        EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Prisioner),
                        EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Launcher),
                    });
                }
            }
            else
            {
                if (entitiesNumberAI >= entitiesNumberPlayer)
                {
                    _strategicObjective = GetOrAddComponent <AttackTroopsObjective>();
                    //Spawn defensas
                    _spawnStrategy = new AISpawnStrategy(new List <EntityBloodCost>
                    {
                        EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Turret),
                        EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Tank),
                        EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Tank)
                    });
                }
                else
                {
                    if (entitiesValueAIOwnedAI >= entitiesValuePlayerOwnedAI)
                    {
                        _strategicObjective = GetOrAddComponent <AttackTroopsObjective>();
                        //Spawnear tropas baratas
                        _spawnStrategy = new AISpawnStrategy(new List <EntityBloodCost>
                        {
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Prisioner),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Prisioner),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Launcher)
                        });
                    }
                    else
                    {
                        _strategicObjective = GetOrAddComponent <AttackTroopsObjective>();
                        //Spawn torretas
                        _spawnStrategy = new AISpawnStrategy(new List <EntityBloodCost>
                        {
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Turret),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Tank),
                            EntitySpawnCostInfo.EntitySpawnCosts.Find((x) => x.entity == ENTITY.Prisioner)
                        });
                    }
                }
            }

            _analyzer.AnalyzeGameTerrain(_strategicObjective, _spawnStrategy);
            Debug.Log("Chosen Strategic Objective: " + _strategicObjective);
        }