Exemplo n.º 1
0
    // Determines what hit the floor, and then performs the appropriate action
    private IEnumerator handleCollision(Collision collision)
    {
        // Log what collided
        Debug.Log("A " + collision.transform.name + " hit a plank.");

        // Determine if the collider is an actionable object (bird/pig)
        Actionable actionableObj = collision.gameObject.GetComponent <Actionable>();

        if (actionableObj != null)
        {
            Debug.Log(collision.transform.name + " is actionable!");
            // Retrieve its collision handler and execute it
            IEnumerator collisionHandler = actionableObj.HandlePlankCollision(collision).GetEnumerator();
            while (collisionHandler.MoveNext())
            {
                yield return(collisionHandler.Current);
            }
        }

        yield return(null);
    }
    internal void executeActionable(Actionable actionable)
    {
        switch (actionable.action)
        {
        case Actionable.ACTION.DRAIN:
            action = 0;

            break;

        case Actionable.ACTION.FILL:
            action = 1;

            break;

        case Actionable.ACTION.REPAIR:
            action = 2;
            CrackBehaviour crack = actionable.gameObject.GetComponent <CrackBehaviour>();

            crack.Repair(actionable, this);

            break;
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    private void Update()
    {
        var actionable = GetActionablesUtility.GetActionableForHighlight(ToolCtrl.GetToolBase(), transform);

        if (actionable == null)
        {
            HighlightedObject = null;
            PreviousActionable?.RemoveHighlight();
        }

        else if (actionable != PreviousActionable)
        {
            actionable.SetHighlight(HighlightShader);
            HighlightedObject = actionable.gameObject;
            PreviousActionable?.RemoveHighlight();
        }
        //if (actionable != null)
        //{
        //    actionable.SetHighlight(HighlightShader);
        //    HighlightedObject = actionable.gameObject;
        //}

        PreviousActionable = actionable;
    }
Exemplo n.º 4
0
    public override void Run(Actionable actionable, Actionable item, ActionController actionController)
    {
        if (item == null)
        {
            Debug.LogError("Swap is not supposed to happen with no other item...");
        }
        if (item != actionController.activeItem)
        {
            Debug.LogError("Right now, I'm not sure if this is supposed to happen.");
        }

        if (actionController.activeItem != actionable)
        {
            actionable.transform.parent        = actionController.transform;
            actionable.transform.localPosition = Vector3.zero;
            actionable.transform.localRotation = Quaternion.identity;

            item.transform.parent = null;
            actionController.heldItems.Remove(item);

            actionController.heldItems.Add(actionable);
            actionController.activeItem = actionable;
        }
    }
Exemplo n.º 5
0
 public ActionInfo(Architect subjectArchitect = null, Architect targetArchitect = null, Actionable subject = null, Actionable target = null)
 {
     this.subjectArchitect = subjectArchitect;
     this.targetArchitect  = targetArchitect;
     this.subject          = subject;
     this.target           = target;
 }
Exemplo n.º 6
0
 public void StartActionable(Actionable pActionable)
 {
     Actioner.AttemptAction(pActionable);
 }
Exemplo n.º 7
0
 public OrderInfo(Actionable subject = null, Actionable target = null)
 {
     this.subject = subject;
     this.target  = target;
 }
Exemplo n.º 8
0
 void PerformSoloAction(Actionable actionable)
 {
     actionable.PerformAction(this);
 }
Exemplo n.º 9
0
 public override void Startup(Actionable actionable)
 {
     m_messType = actionable.GetComponent <SpriteRenderer>().sprite.name;
     GameManager.Instance.AddMess(m_messType);
 }
Exemplo n.º 10
0
 public Peabrain(Actionable actor)
 {
     this.actor = actor;
 }
Exemplo n.º 11
0
 public override void Startup(Actionable actionable)
 {
     // Nothing!
 }
Exemplo n.º 12
0
 public CharacterFactory(Actionable <ControllableActions> actionable, MoveComponent moveComponent)
 {
     this.actionable    = actionable;
     this.moveComponent = moveComponent;
     camera             = Camera.allCameras[0]; // Why doesn't Camera.main work?
 }
Exemplo n.º 13
0
 public static bool GetHashCodeTest([NotNull] Actionable actionable1, [NotNull] Actionable actionable2)
 {
     return(actionable1.GetHashCode() == actionable2.GetHashCode());
 }
Exemplo n.º 14
0
 public override void Startup(Actionable actionable)
 {
     return;
 }
Exemplo n.º 15
0
 public void RemoveActionable(Actionable actionable)
 {
     remActionables.Add(actionable);
     actionable.enabled = false;
 }
Exemplo n.º 16
0
        ///-------------------------------------------------------------------------------------------------
        /// \fn public MAction(Actionable actionable, ActionParameters_t toolParameters)
        ///
        /// \brief Constructor
        ///
        /// \param actionable     The actionable.
        /// \param toolParameters Options for controlling the tool.
        ///-------------------------------------------------------------------------------------------------

        public MAction(Actionable actionable,
                       ActionParameters_t toolParameters)
        {
            this.actionable       = actionable;
            this.actionParameters = toolParameters;
        }
Exemplo n.º 17
0
 public override void Run(Actionable actionable, Actionable item, ActionController actionController)
 {
     // The messes are actually the things running the code...
 }
Exemplo n.º 18
0
 public static bool EqualsTest([NotNull] Actionable actionable1, Actionable actionable2)
 {
     return(actionable1.Equals(actionable2));
 }
Exemplo n.º 19
0
 public abstract void Run(Actionable actionable, Actionable item, ActionController actionController);
Exemplo n.º 20
0
 public static bool EqualsTest_Object([NotNull] Actionable actionable, object obj)
 {
     return(actionable.Equals(obj));
 }
Exemplo n.º 21
0
 public override void Run(Actionable actionable, Actionable item, ActionController actionController)
 {
     GameManager.Instance.RemoveMess(m_messType);
     Destroy(actionable.gameObject);
 }
 public OrderlyInteractionAction(Actionable pActionable)
 {
     Action = pActionable;
 }
    public void SetAction(Actionable action)
    {
        this.action = action;

        this.textRenderer.text = action.actionName;
    }
Exemplo n.º 24
0
    // Traza un plan para seguir más adelante
    // Este método contiene el algoritmo principal
    private void CreatePlan()
    {
        this.plan.Clear();
        var worldState = WorldState.Current;

        #region Ordenar acciones por consecuencias abstractas

        Dictionary <Action, float> actionConvenience = new Dictionary <Action, float>();

        Architect mostConvenientTargetArchitect = null;
        var       maximumConvenience            = -Mathf.Infinity;

        // Exploramos todas las acciones sin entrar en detalle, para obtener una primera aproximación acerca de
        // qué acciones resultarían en un estado del mundo más favorable

        ActionInfo abstractInfo = new ActionInfo(subjectArchitect: this);
        foreach (var action in Actions.GetAll())
        {
            foreach (var targetArchitect in GameManager.Instance.architectContainer.GetComponentsInChildren <Architect>())
            {
                if (targetArchitect.Defeated)
                {
                    continue;
                }

                // Aplicamos las consecuencias sobre una copia del estado del mundo para comparar
                var nextWorldState = worldState.Clone();
                abstractInfo.targetArchitect = targetArchitect;
                action.ApplyConsequences(abstractInfo, nextWorldState);
                var convenience = this.profile.GetConvenienceFor(nextWorldState);

                if (convenience > maximumConvenience)
                {
                    maximumConvenience            = convenience;
                    mostConvenientTargetArchitect = targetArchitect;
                }
            }

            // Esta es la conveniencia más alta posible que esta acción puede ofrecer
            actionConvenience[action] = maximumConvenience;
        }

        List <Action> possibleActions = new List <Action>(Actions.GetAll());
        #endregion

        #region Escoger posibles Actionables sujetos
        HashSet <Actionable> possibleSubjectActionables = new HashSet <Actionable>();

        // Son posibles sujetos todos los ejércitos y todas las celdas bajo nuestro control

        possibleSubjectActionables.UnionWith(this.Nation.Armies);
        possibleSubjectActionables.UnionWith(this.Nation.Cells);
        #endregion

        #region Escoger posibles Actionables objetivos
        HashSet <Actionable> possibleTargetActionables = new HashSet <Actionable>();

        // Son objetivos posibles todas las casillas adyacentes al territorio conquistado, todos los ejércitos de los rivales,
        // y los 16 ejércitos enemigos más cercanos

        possibleTargetActionables.UnionWith(this.Nation.FindAdjacentUnclaimedCellsInWorldState(worldState));

        foreach (var rival in this.rivals)
        {
            possibleTargetActionables.UnionWith(rival.Nation.Armies);
        }

        var nearbyEnemies = new Army[16];
        foreach (var army in this.Nation.Armies)
        {
            this.FindClosestEnemiesToCell(army.CurrentCell, nearbyEnemies);
            possibleTargetActionables.UnionWith(nearbyEnemies);
        }

        // En la búsqueda de posibles objetivos, es posible que se haya colado algún valor nulo. Lo eliminamos

        possibleTargetActionables.Remove(null);
        #endregion

        Dictionary <Action, PlanUnit> possiblePlanUnits = new Dictionary <Action, PlanUnit>();


        for (var i = 0; i < possibleActions.Count; i++)
        {
            var action = possibleActions[i];

            #region Encontrar combinación de sujeto y objetivo más conveniente
            Actionable mostConvenientSubject = null;
            Actionable mostConvenientTarget  = null;
            Order      mostConvenientOrder   = null;
            var        bestConvenience       = -Mathf.Infinity;

            foreach (var subject in possibleSubjectActionables)
            {
                // Si el sujeto no puede participar en la acción, pasamos al siguiente directamente
                if (action.RequiredSubjectType != null && subject.GetType() != action.RequiredSubjectType)
                {
                    continue;
                }

                foreach (var target in possibleTargetActionables)
                {
                    // Si el objetivo no puede participar en la acción, pasamos al siguiente directamente
                    if (action.RequiredTargetType != null && target.GetType() != action.RequiredTargetType)
                    {
                        continue;
                    }

                    // ¿Qué orden tendríamos que seguir para ejecutar esta acción, dados el sujeto y el objetivo indicados?

                    var order = action.GetOrderForActionable(new ActionInfo(
                                                                 subjectArchitect: this,
                                                                 subject: subject,
                                                                 targetArchitect: target is Army ? ((Army)target).Nation.Architect : ((Cell)target).Nation?.Architect,
                                                                 target: target), worldState);

                    // Es posible que el objetivo no pueda participar en la orden
                    if (order.RequiredTargetType != null && target.GetType() != order.RequiredTargetType)
                    {
                        continue;
                    }

                    // ¿Es este el combo orden + sujeto + objetivo más conveniente que hemos encontrado harta ahora?
                    var convenience = this.profile.GetConvenienceFor(subject, order, target, worldState);
                    if (convenience > bestConvenience)
                    {
                        mostConvenientSubject = subject;
                        mostConvenientTarget  = target;
                        mostConvenientOrder   = order;
                        bestConvenience       = convenience;
                    }
                }
            }
            #endregion

            // Si al menos hemos dado con una orden válida, generamos unidad de plan con los datos más óptimos que hemos encontrado
            // y actualizamos la conveniencia de la acción con los nuevos datos que tenemos
            if (mostConvenientOrder != null)
            {
                PlanUnit planUnitForThisAction = new PlanUnit(action, mostConvenientOrder,
                                                              new OrderInfo(subject: mostConvenientSubject, target: mostConvenientTarget));

                possiblePlanUnits[action]  = planUnitForThisAction;
                actionConvenience[action] += bestConvenience;

                // Si no la hemos encontrado, esta acción es completamente inviable y su conveniencia es mínima
            }
            else
            {
                actionConvenience[action] = -Mathf.Infinity;
            }
        }

        // Ordenamos las acciones ahora que sabemos con más precisión qué conveniencia tienen
        possibleActions.Sort((a, b) => Mathf.RoundToInt(actionConvenience[b] - actionConvenience[a]));

        // Asignamos unidades de plan a cada ejército. Como las acciones están ordenadas de más a menos convenientes,
        // iremos asignando unidades en efectividad decreciente
        HashSet <Army> assignedArmies = new HashSet <Army>();
        foreach (var action in possibleActions)
        {
            if (!possiblePlanUnits.ContainsKey(action))
            {
                continue;
            }
            var planUnit = possiblePlanUnits[action];

            // Si el ejército al que asignaríamos esta orden está ocioso, se la asignamos. Si no, es que ya tiene una más efectiva
            if (!assignedArmies.Contains(planUnit.orderInfo.subject as Army))
            {
                plan.Add(planUnit);
                assignedArmies.Add(planUnit.orderInfo.subject as Army);
            }
        }
    }
Exemplo n.º 25
0
 public abstract void Startup(Actionable actionable);