private bool CompetenceElementsHandler(CompetenceElement competenceElement) { int numSensesNeeded = 0; foreach (Sense sense in competenceElement.Senses) { numSensesNeeded = CheckSense(numSensesNeeded, sense); } if (numSensesNeeded == competenceElement.Senses.Count) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, competenceElement.Name, "CE"); PlanElement elementToBeTriggered = competenceElement.TriggerableElement; if (elementToBeTriggered is Competence) { CompetenceHandler((Competence)elementToBeTriggered); } else if (elementToBeTriggered is ActionPattern) { ActionPatternHandler((ActionPattern)elementToBeTriggered); } else { TriggerAction((Action)elementToBeTriggered); } return(true); } else { return(false); } }
private void DriveElementsHandler(List <DriveElement> driveElements) { foreach (DriveElement driveElement in driveElements) { if (Time.time >= driveElement.NextCheck) { driveElement.UpdateNextCheck(); int numSensesNeeded = 0; foreach (Sense trigger in driveElement.Senses) { numSensesNeeded = CheckSense(numSensesNeeded, trigger); } if (numSensesNeeded == driveElement.Senses.Count) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, driveElement.Name, "DE"); PlanElement elementToBeTriggered = driveElement.TriggerableElement; if (elementToBeTriggered is Competence) { CompetenceHandler((Competence)elementToBeTriggered); } else if (elementToBeTriggered is ActionPattern) { ActionPatternHandler((ActionPattern)elementToBeTriggered); } else if (elementToBeTriggered is Action) { TriggerAction((Action)elementToBeTriggered); } } } } }
private void CGotHome() { agentBehaviours.IsGoingHome = false; canBeEaten = false; agentBehaviours.isHome = true; if (agentBehaviours.HasHomeNotBuilt()) { if (agentBehaviours.HasRock()) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "CE-ReadyToBuild", "CE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "BuildHouse", "A"); agentBehaviours.BuildHouse(); } } else { if (agentBehaviours.IsGoingToProcreate) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-IsHome", "DE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "C-Procreate", "C"); agentBehaviours.Procreate(); agentBehaviours.StayHome(); } else { agentBehaviours.StayHome(); } } }
private void CEatFood(bool isEmergency) { if (agentBehaviours.HasFood()) { if (isEmergency) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "CE-HasFood", "CE"); } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-HasFood", "DE"); } agentBehaviours.EatFood(); } else { if (isEmergency) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "CE-GoGetFood", "CE"); } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-GoGetFood", "DE"); } agentBehaviours.GoToFood(); } }
/** -----------ACTIONS----------- */ internal void GoToFood() { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "GoToNearestFood", "A"); isHome = false; isGatheringFood = true; agentNavigator.GoToFood(); }
internal void GoToRock() { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "GoGetRock", "A"); isHome = false; isGatheringRock = true; agentNavigator.GoToRocks(); }
internal void GoToHome() { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "GoHome", "A"); isGoingHome = true; if (home != null) { agentNavigator.GoHome(home); } }
private void TriggerAction(Action action) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, action.Name, "A"); try { behaviourLibrary.ExecuteAction(action); } catch (System.Exception error) { Debug.LogError("Actions: " + action.Name + " produced error: " + error); } }
public void ConnectABOD3() { if (ABOD3_Bridge.GetInstance().AttemptToConnect()) { abod3text.SetActive(true); abod3text.GetComponent <TMPro.TextMeshProUGUI>().text = "Connection established to ABOD3 on port 3000"; } else { abod3text.SetActive(true); abod3text.GetComponent <TMPro.TextMeshProUGUI>().text = "Connection could not be established"; } }
internal void EatFood() { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "EatFood", "A"); staminaLevel = staminaLevel + 2; if (staminaLevel > 15) { staminaLevel = 15; } hasFood = false; }
private void CTryToProcreate() { if (agentBehaviours.HasHomeNotBuilt()) { agentBehaviours.GoToHome(); } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-HasHome", "DE"); agentBehaviours.GoToProcreate(); agentBehaviours.GoToHome(); } }
private void CBuildBridge() { if (!isNight) { if (agentBehaviours.HasRock()) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-HasRocks", "DE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "GoNearestBridgeSite", "A"); agentBehaviours.GoToBridge(); } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-HasNoRocks", "DE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "GoGetRock", "A"); agentBehaviours.GoToRock(); } } }
private void CompetenceHandler(Competence competence) { Sense goal = competence.Goals[0]; if (CheckSense(0, goal) == 0) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, competence.Name, "C"); int numCEActivated = 0; foreach (CompetenceElement competenceElement in competence.Elements) { if (CompetenceElementsHandler(competenceElement)) { numCEActivated = numCEActivated + 1; } } } }
void OnTriggerEnter(Collider collidedObject) { try { if ((collidedObject.gameObject != null) && (gameObject != null) && (agentBehaviours != null)) { if (collidedObject.gameObject.Equals(agentBehaviours.Home) && isNight) { if (!agentBehaviours.HasHomeNotBuilt()) { canBeEaten = false; } else { canBeEaten = true; } agentBehaviours.StayHome(); } if (collidedObject.gameObject.tag.Equals("Food") && agentBehaviours.IsGatheringFood) { agentBehaviours.GatherFood(); } else if (collidedObject.gameObject.tag.Equals("Rock") && agentBehaviours.IsGatheringRock) { agentBehaviours.GatherRock(); } else if (collidedObject.gameObject.tag.Equals("BridgeNotAvailable") && agentBehaviours.IsBuildingBridge) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-ReadyToBuild", "DE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "BuildBridge", "A"); agentBehaviours.BuildBridge(); } else if (collidedObject.gameObject.Equals(agentBehaviours.Home) && agentBehaviours.IsGoingHome) { CGotHome(); } } } catch (System.Exception e) // REALLY BAD FIX! { Debug.LogError(e); } }
private void ActionSelection() { if (isNight) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "D-Survive", "D"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-IsNight", "DE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "RunHome", "A"); agentBehaviours.GoToHome(); } else if (agentBehaviours.IsStarving()) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "D-Survive", "D"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-EatFood", "DE"); CEatFood(true); } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "D-DailyLife", "D"); switch (worksIndex) { case 0: ABOD3_Bridge.GetInstance().AletForElement(botNumber, "D-EatFood", "D"); CEatFood(false); break; case 1: ABOD3_Bridge.GetInstance().AletForElement(botNumber, "D-BuildBridges", "D"); CBuildBridge(); break; case 2: ABOD3_Bridge.GetInstance().AletForElement(botNumber, "D-BuildHome", "D"); CHomeBuilding(); break; case 3: ABOD3_Bridge.GetInstance().AletForElement(botNumber, "D-Procreate", "D"); CTryToProcreate(); break; } } }
private void DrivesHandler() { int currentPriority = -1; foreach (DriveCollection drive in drives) { if (currentPriority != -1) // Avoid extra loops for lower priority items. { if (currentPriority < drive.Priority) { continue; } } if (currentPriority == -1 || currentPriority == drive.Priority) { if (drive.Senses.Count != 0) { int numSensesNeeded = 0; foreach (Sense goal in drive.Senses) { numSensesNeeded = CheckSense(numSensesNeeded, goal); } if (numSensesNeeded == drive.Senses.Count) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, drive.Name, "D"); DriveElementsHandler(drive.DriveElements); currentPriority = drive.Priority; } } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, drive.Name, "D"); DriveElementsHandler(drive.DriveElements); currentPriority = drive.Priority; } } } }
internal void Procreate() { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "C-Procreate", "C"); isGoingToProcreate = false; isHome = true; if (home != null) { home.GetComponent <HouseScript>().UpdateAgentReproduction(canProcreate); } if ((home.GetComponent <HouseScript>()).CanReproduce()) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "CE-HasEnoughEnergy", "CE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "AttemptProcreation", "A"); int dieRoll = UnityEngine.Random.Range(0, 100); staminaLevel--; if (dieRoll < PROCREATE_CHANCE) { staminaLevel--; AgentsCreator agentsCreator = transform.parent.gameObject.GetComponent("AgentsCreator") as AgentsCreator; agentsCreator.BornAgent(transform.position); } } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "CE-NotEnoughEnergy", "CE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "StayHome", "A"); } if (home != null) { home.GetComponent <HouseScript>().UpdateAgentReproduction(false); } }
private void CHomeBuilding() { if (agentBehaviours.HasHomeNotBuilt()) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-DoesNotHaveHome", "DE"); ABOD3_Bridge.GetInstance().AletForElement(botNumber, "C-BuildHome", "C"); if (agentBehaviours.HasRock()) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "CE-HasRock", "CE"); agentBehaviours.GoToHome(); } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "CE-HasNoRocks", "CE"); agentBehaviours.GoToRock(); } } else { ABOD3_Bridge.GetInstance().AletForElement(botNumber, "DE-HasHome", "DE"); agentBehaviours.GoToHome(); } }
public void MakeUnselected() { ABOD3_Bridge.GetInstance().ChangeSelectedBot(0); gameObject.GetComponent <SpriteOutline>().enabled = false; }
public void MakeSelected() { ABOD3_Bridge.GetInstance().ChangeSelectedBot(botNumber); gameObject.GetComponent <SpriteOutline>().enabled = true; }
public void MakeSelectedAgent() { ABOD3_Bridge.GetInstance().ChangeSelectedBot(botNumber); }
private void ActionPatternHandler(ActionPattern actionPattern) { ABOD3_Bridge.GetInstance().AletForElement(botNumber, actionPattern.Name, "AP"); StartCoroutine(ExecuteActionPattern(actionPattern, 0)); }