/** * 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 chopping block that we can chop our wood at PieShopOne[] blocks = (PieShopOne[])UnityEngine.GameObject.FindObjectsOfType(typeof(PieShopOne)); targetChoppingBlock = blocks[0]; target = targetChoppingBlock.gameObject; return(blocks[0] != null); }
// Update is called once per frame void Update() { PieShopOne[] blocks = (PieShopOne[])UnityEngine.GameObject.FindObjectsOfType(typeof(PieShopOne)); PieShopOne info = blocks[0]; if (info.open) { textFeild.text = "Open"; } else { textFeild.text = "Closed"; } }
/** * 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 void reset() { bought = false; targetChoppingBlock = null; startTime = 0; }