// Update is called once per frame void Update() { if (Time.time - durration_stemp > dur_delta) { StateCalculator(); if (doing is idle.searching) { buildSelfState(); // printToDebug("running", 56); if (path.Count == 0) { // printToDebug("case 1 ", 59); // printToDebug("Before Astar", 61); path = algo.runASTARonState(currentState, StateMap); if (path == null) { printToDebug("error case , path not found ", 65); } else { //printToDebug("path count" + path.Count, 67); // printToDebug("After Astar", 68); } } else { //printToDebug("case 2 ", 68); Node next = path[path.Count - 1]; path.RemoveAt(path.Count - 1); if (next != null) { // printToDebug("IN change", 68); // currentState.getStart().printNode("current start at NPC"); int oldx = npcObject.getX(); int oldy = npcObject.getY(); setAvatarDirection(oldx, oldy, next.getX(), next.getY()); // next.printNode("next tile in NPC"); npcObject.setMapLocation(next.getX(), next.getY(), manager.size); manager.UpdateNPCPlaces(oldx, oldy, npcObject.getX(), npcObject.getY()); } } } else if (doing is idle.using_activity) { //printToDebug("using activity", 102); //printToDebug("activity counter: " + activity_counter,103); activity_counter--; } decreaseNeeds(); npcPrintStatus(); manager.RealeaseLockWorldUpdate(); durration_stemp = Time.time; } playAnimation(); }
private void initTheActivities() { activ_list = new ArrayList(); int i, j; foreach (GameObject go in GameObject.FindGameObjectsWithTag("fun")) { Debug.Log("fun"); ActivityObject ob = go.GetComponent <ActivityObject>(); ob.setNeed(activities.fun); i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); while (physicalMap.getpathMapValue(i, j) is house.wall || physicalMap.getpathMapValue(i + 1, j) is house.wall || physicalMap.getpathMapValue(i + 1, j + 1) is house.wall || physicalMap.getpathMapValue(i, j + 1) is house.wall || physicalMap.getpathMapValue(i - 1, j) is house.wall || physicalMap.getpathMapValue(i - 1, j - 1) is house.wall || physicalMap.getpathMapValue(i, j - 1) is house.wall) { i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); } worldMap[i, j] = house.unavailable_floor; ob.setMapLocation(i, j, size); ob.setUpdateable(); go.gameObject.transform.position = ob.getLocation(); dict.Add(go, go.GetComponentInChildren <Renderer>()); activ_list.Add(go); } //set the entrences objects foreach (GameObject go in GameObject.FindGameObjectsWithTag("bladder")) { Debug.Log("bladder"); ActivityObject ob = go.GetComponent <ActivityObject>(); ob.setNeed(activities.bladder); i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); while (physicalMap.getpathMapValue(i, j) is house.wall || physicalMap.getpathMapValue(i + 1, j) is house.wall || physicalMap.getpathMapValue(i + 1, j + 1) is house.wall || physicalMap.getpathMapValue(i, j + 1) is house.wall || physicalMap.getpathMapValue(i - 1, j) is house.wall || physicalMap.getpathMapValue(i - 1, j - 1) is house.wall || physicalMap.getpathMapValue(i, j - 1) is house.wall ) { i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); } worldMap[i, j] = house.unavailable_floor; ob.setMapLocation(i, j, size); ob.setUpdateable(); go.gameObject.transform.position = ob.getLocation(); dict.Add(go, go.GetComponentInChildren <Renderer>()); activ_list.Add(go); } foreach (GameObject go in GameObject.FindGameObjectsWithTag("hunger")) { Debug.Log("hunger"); ActivityObject ob = go.GetComponent <ActivityObject>(); ob.setNeed(activities.hunger); i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); while (physicalMap.getpathMapValue(i, j) is house.wall || physicalMap.getpathMapValue(i + 1, j) is house.wall || physicalMap.getpathMapValue(i + 1, j + 1) is house.wall || physicalMap.getpathMapValue(i, j + 1) is house.wall || physicalMap.getpathMapValue(i - 1, j) is house.wall || physicalMap.getpathMapValue(i - 1, j - 1) is house.wall || physicalMap.getpathMapValue(i, j - 1) is house.wall) { i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); } worldMap[i, j] = house.unavailable_floor; ob.setMapLocation(i, j, size); ob.setUpdateable(); go.gameObject.transform.position = ob.getLocation(); dict.Add(go, go.GetComponentInChildren <Renderer>()); activ_list.Add(go); } foreach (GameObject go in GameObject.FindGameObjectsWithTag("hygiene")) { Debug.Log("hygiene"); ActivityObject ob = go.GetComponent <ActivityObject>(); ob.setNeed(activities.hygiene); i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); while (physicalMap.getpathMapValue(i, j) is house.wall || physicalMap.getpathMapValue(i + 1, j) is house.wall || physicalMap.getpathMapValue(i + 1, j + 1) is house.wall || physicalMap.getpathMapValue(i, j + 1) is house.wall || physicalMap.getpathMapValue(i - 1, j) is house.wall || physicalMap.getpathMapValue(i - 1, j - 1) is house.wall || physicalMap.getpathMapValue(i, j - 1) is house.wall) { i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); } worldMap[i, j] = house.unavailable_floor; ob.setMapLocation(i, j, size); ob.setUpdateable(); go.gameObject.transform.position = ob.getLocation(); dict.Add(go, go.GetComponentInChildren <Renderer>()); activ_list.Add(go); } foreach (GameObject go in GameObject.FindGameObjectsWithTag("energy")) { Debug.Log("energy"); ActivityObject ob = go.GetComponent <ActivityObject>(); ob.setNeed(activities.energy); i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); while (physicalMap.getpathMapValue(i, j) is house.wall || physicalMap.getpathMapValue(i + 1, j) is house.wall || physicalMap.getpathMapValue(i + 1, j + 1) is house.wall || physicalMap.getpathMapValue(i, j + 1) is house.wall || physicalMap.getpathMapValue(i - 1, j) is house.wall || physicalMap.getpathMapValue(i - 1, j - 1) is house.wall || physicalMap.getpathMapValue(i, j - 1) is house.wall) { i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); } worldMap[i, j] = house.unavailable_floor; ob.setMapLocation(i, j, size); ob.setUpdateable(); go.gameObject.transform.position = ob.getLocation(); dict.Add(go, go.GetComponentInChildren <Renderer>()); activ_list.Add(go); } foreach (GameObject go in GameObject.FindGameObjectsWithTag("social")) { Debug.Log("social"); ActivityObject ob = go.GetComponent <ActivityObject>(); ob.setNeed(activities.social); i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); while (physicalMap.getpathMapValue(i, j) is house.wall || physicalMap.getpathMapValue(i + 1, j) is house.wall || physicalMap.getpathMapValue(i + 1, j + 1) is house.wall || physicalMap.getpathMapValue(i, j + 1) is house.wall || physicalMap.getpathMapValue(i - 1, j) is house.wall || physicalMap.getpathMapValue(i - 1, j - 1) is house.wall || physicalMap.getpathMapValue(i, j - 1) is house.wall) { i = Random.Range(2, layout.getSize() - 2); j = Random.Range(2, layout.getSize() - 2); } worldMap[i, j] = house.unavailable_floor; ob.setMapLocation(i, j, size); NPCObject npc = go.GetComponent <NPCObject>(); ob.setUpdateable(); go.gameObject.transform.position = ob.getLocation(); dict.Add(go, go.GetComponentInChildren <Renderer>()); activ_list.Add(go); } Debug.Log("all activities" + activ_list.Count); }