public override void reset() { done = false; milked = false; targetChoppingBlock = null; startTime = 0; }
/** * 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 ACow[] blocks = (ACow[])UnityEngine.GameObject.FindObjectsOfType(typeof(ACow)); targetChoppingBlock = blocks[0]; target = targetChoppingBlock.gameObject; return(blocks[0] != null); }
public override bool perform(GameObject agent) { FarmersBag bag = (FarmersBag)agent.GetComponent(typeof(FarmersBag)); bag.eaten = false; milked = true; ACow[] theCows = (ACow[])UnityEngine.GameObject.FindObjectsOfType(typeof(ACow)); ACow aCow = theCows[0]; aCow.stomach.takeMilk(); return(true); }
/** * 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() { targetChoppingBlock = null; startTime = 0; done = false; }