public override bool perform(GameObject agent) { WaterTrough[] waters = (WaterTrough[])UnityEngine.GameObject.FindObjectsOfType(typeof(WaterTrough)); WaterTrough water = waters[0]; water.level = 3; eaten = true; return(true); }
/** * Some actions need to use data from the world state to determine if they are able to run. These preconditions are called procedural preconditions. * Need to check there is food available * **/ public override bool checkProceduralPrecondition(GameObject agent) { // find the nearest supply pile that has spare logs WaterTrough[] supplyPiles = (WaterTrough[])UnityEngine.GameObject.FindObjectsOfType(typeof(WaterTrough)); WaterTrough closest = supplyPiles[0]; targetChoppingBlock = closest; target = targetChoppingBlock.gameObject; return(closest != null); }
/** * Key-Value data that will feed the GOAP actions and system while planning. */ public HashSet <KeyValuePair <string, object> > getWorldState() { HashSet <KeyValuePair <string, object> > worldData = new HashSet <KeyValuePair <string, object> >(); worldData.Add(new KeyValuePair <string, object>("hasEnoughMoney", (bag.money >= 5))); worldData.Add(new KeyValuePair <string, object>("eat", (bag.eaten))); worldData.Add(new KeyValuePair <string, object>("hasPie", (bag.hasPie))); worldData.Add(new KeyValuePair <string, object>("hasMilk", (bag.hasMilk))); worldData.Add(new KeyValuePair <string, object>("storeMilk", (bag.storedMilk))); PieShopOne[] p1 = (PieShopOne[])UnityEngine.GameObject.FindObjectsOfType(typeof(PieShopOne)); PieShopOne info1 = p1[0]; worldData.Add(new KeyValuePair <string, object>("pieShopOneOpen", (info1.open))); PieShopTwo[] p2 = (PieShopTwo[])UnityEngine.GameObject.FindObjectsOfType(typeof(PieShopTwo)); PieShopTwo info2 = p2[0]; worldData.Add(new KeyValuePair <string, object>("pieShopTwoOpen", (info2.open))); ACow[] cows = (ACow[])UnityEngine.GameObject.FindObjectsOfType(typeof(ACow)); ACow theCow = cows[0]; Grass[] grasses = (Grass[])UnityEngine.GameObject.FindObjectsOfType(typeof(Grass)); worldData.Add(new KeyValuePair <string, object>("grassAvailable", (grasses.Length > 0))); WaterTrough[] waters = (WaterTrough[])UnityEngine.GameObject.FindObjectsOfType(typeof(WaterTrough)); WaterTrough water = waters[0]; worldData.Add(new KeyValuePair <string, object>("waterAvailable", (water.level > 0))); worldData.Add(new KeyValuePair <string, object>("cowHasMilk", (theCow.stomach.hasMilk()))); FreePie[] freePies = (FreePie[])UnityEngine.GameObject.FindObjectsOfType(typeof(FreePie)); worldData.Add(new KeyValuePair <string, object>("freePieAvailable", (freePies.Length > 0))); return(worldData); }
public override bool perform(GameObject agent) { CowStomach stomach = (CowStomach)agent.GetComponent(typeof(CowStomach)); stomach.waterDrunk += 10; WaterTrough[] waters = (WaterTrough[])UnityEngine.GameObject.FindObjectsOfType(typeof(WaterTrough)); WaterTrough water = waters[0]; bool drank = water.takeDrink(); if (drank == false) { finishedAction = true; return(false); } finishedAction = true; return(true); }
public override bool checkProceduralPrecondition(GameObject agent) { WaterTrough[] supplyPiles = (WaterTrough[])UnityEngine.GameObject.FindObjectsOfType(typeof(WaterTrough)); WaterTrough closest = null; float closestDist = 0; foreach (WaterTrough supply in supplyPiles) { if (closest == null) { // first one, so choose it for now closest = supply; closestDist = (supply.gameObject.transform.position - agent.transform.position).magnitude; } else { // is this one closer than the last? float dist = (supply.gameObject.transform.position - agent.transform.position).magnitude; if (dist < closestDist) { // we found a closer one, use it closest = supply; closestDist = dist; } } } if (closest == null) { return(false); } targetWaterTrough = closest; target = targetWaterTrough.gameObject; return(closest != null); }
public override void reset() { finishedAction = false; targetWaterTrough = null; }
public override void reset() { eaten = false; targetChoppingBlock = null; startTime = 0; }