// 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; } }
// 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; }
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; } }
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; }
public void StartActionable(Actionable pActionable) { Actioner.AttemptAction(pActionable); }
public OrderInfo(Actionable subject = null, Actionable target = null) { this.subject = subject; this.target = target; }
void PerformSoloAction(Actionable actionable) { actionable.PerformAction(this); }
public override void Startup(Actionable actionable) { m_messType = actionable.GetComponent <SpriteRenderer>().sprite.name; GameManager.Instance.AddMess(m_messType); }
public Peabrain(Actionable actor) { this.actor = actor; }
public override void Startup(Actionable actionable) { // Nothing! }
public CharacterFactory(Actionable <ControllableActions> actionable, MoveComponent moveComponent) { this.actionable = actionable; this.moveComponent = moveComponent; camera = Camera.allCameras[0]; // Why doesn't Camera.main work? }
public static bool GetHashCodeTest([NotNull] Actionable actionable1, [NotNull] Actionable actionable2) { return(actionable1.GetHashCode() == actionable2.GetHashCode()); }
public override void Startup(Actionable actionable) { return; }
public void RemoveActionable(Actionable actionable) { remActionables.Add(actionable); actionable.enabled = false; }
///------------------------------------------------------------------------------------------------- /// \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; }
public override void Run(Actionable actionable, Actionable item, ActionController actionController) { // The messes are actually the things running the code... }
public static bool EqualsTest([NotNull] Actionable actionable1, Actionable actionable2) { return(actionable1.Equals(actionable2)); }
public abstract void Run(Actionable actionable, Actionable item, ActionController actionController);
public static bool EqualsTest_Object([NotNull] Actionable actionable, object obj) { return(actionable.Equals(obj)); }
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; }
// 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); } } }
public abstract void Startup(Actionable actionable);