public List <TileBase> GetAdjacentTiles(TileManager.TestTile del) { var adjacentTiles = new List <TileBase>(); TileBase testTile; testTile = Core.theTM.GetTileBase(x - 1, y); if (testTile != null && del(testTile)) { adjacentTiles.Add(testTile); } testTile = Core.theTM.GetTileBase(x + 1, y); if (testTile != null && del(testTile)) { adjacentTiles.Add(testTile); } testTile = Core.theTM.GetTileBase(x, y - 1); if (testTile != null && del(testTile)) { adjacentTiles.Add(testTile); } testTile = Core.theTM.GetTileBase(x, y + 1); if (testTile != null && del(testTile)) { adjacentTiles.Add(testTile); } return(adjacentTiles); }
public int GetNumTilesOfType(TileBase.TileType eType) { TileManager.TestTile del = delegate(TileBase tile) { return(tile.Type() == eType); }; return(GetTiles(del).Count); }
// Update is called once per frame public override void Update() { base.Update(); bool bWasInDangerOfStarving = AmInDangerOfStarving(); bool bWasInDangerOfBreaking = AmInDangerOfBreaking(); afNeeds[(int)Need.FOOD] -= 0.005f * Time.deltaTime; afNeeds[(int)Need.HUMAN_FOOD] -= 0.0025f * Time.deltaTime; afNeeds[(int)Need.ENTERTAINMENT] -= 0.0025f * Time.deltaTime; float minNeed = 0.0f; if (state == State.WORKING) { minNeed = 0.1f; } for (int i = 0; i < 3; i++) { afNeeds[i] = Mathf.Clamp(afNeeds[i], minNeed, 1.0f); } if (currentTask == null || currentTask.type != Task.Type.GO_MAD) { if (!bWasInDangerOfStarving && AmInDangerOfStarving()) { TextTicker.AddLine("<color=orange>" + lizardName + " is starving. Get them some food</color>"); AbandonTask(); if (state != State.IDLE) { SetState(State.IDLE); } } if (!bWasInDangerOfBreaking && AmInDangerOfBreaking()) { TextTicker.AddLine("<color=orange>" + lizardName + " is going mad. Get them some TV or fancy human food</color>"); AbandonTask(); if (state != State.IDLE) { SetState(State.IDLE); } } if (ShouldDie()) { AbandonTask(); TextTicker.AddLine("<color=red>" + lizardName + " died of starvation</color>"); Core.theTM.lizards[assignment].Remove(this); Destroy(); } if (ShouldGoMad()) { if (currentTask == null || currentTask.type != Task.Type.GO_MAD) { AbandonTask(); TextTicker.AddLine("<color=red>" + lizardName + " has gone mad and is trying to leave</color>"); SetAndLockAnim(climbAnim); currentTask = new Task(Task.Type.GO_MAD); DoTask(); } } } switch (state) { case State.IDLE: if (ShouldEat()) { // Check to see if there are reachable storerooms TileManager.TestTile del = delegate(TileBase tile) { return(tile.FindResource(Resource.ResourceType.MUSHROOMS) != null || tile.FindResource(Resource.ResourceType.HUMAN_FOOD) != null); }; var pathToFoods = Path.GetPath(currentTile.GetKVPair(), mgr.GetTiles(del)); if (pathToFoods != null) { TileBase targetTile = mgr.GetTileBase(pathToFoods.endX, pathToFoods.endY); foreach (Resource res in targetTile.clutteredResources) { if (!res.isClaimed && (res.type == Resource.ResourceType.MUSHROOMS || res.type == Resource.ResourceType.HUMAN_FOOD)) { res.Claim(this); break; } } if (claimed == null) { foreach (Resource res in targetTile.tidyResources) { if (res != null && !res.isClaimed && (res.type == Resource.ResourceType.MUSHROOMS || res.type == Resource.ResourceType.HUMAN_FOOD)) { res.Claim(this); break; } } } if (claimed != null) { AbandonTask(); SetState(State.RETRIEVING_RESOURCE); currentTask = new Task(Task.Type.EAT); SetPath(pathToFoods); break; } } } if (ShouldFindEntertainment()) { // Check to see if there are reachable storerooms TileManager.TestTile del = delegate(TileBase tile) { return(tile.Type() == TileBase.TileType.TVROOM); }; var pathToTV = Path.GetPath(currentTile.GetKVPair(), mgr.GetTiles(del)); if (pathToTV != null) { TileBase targetTile = mgr.GetTileBase(pathToTV.endX, pathToTV.endY); SetState(State.TRAVELLING_TO_TASK); currentTask = new Task(Task.Type.RELAX); currentTask.associatedTile = targetTile; currentTask.assignedLizard = this; SetPath(pathToTV); break; } } if (!AmInDangerOfStarving() && !AmInDangerOfBreaking()) { if (Player.thePlayer.pendingTasks[(int)assignment].Count != 0) { foreach (Task task in Player.thePlayer.pendingTasks[(int)assignment]) { // Check to see if this lizard can reach the task if (Path.GetPath(currentTile.GetKVPair(), task.associatedTile) != null) { currentTask = task; break; } } if (currentTask != null) { currentTask.assignedLizard = this; Player.thePlayer.pendingTasks[(int)assignment].Remove(currentTask); DoTask(); } break; } //Debug.Log("Calling GetPath to find dropped resources!"); var clutterPath = Path.GetPath(currentTile.GetKVPair(), mgr.GetClutteredTiles()); if (clutterPath != null) { // Check to see if there are reachable storerooms TileManager.TestTile del = delegate(TileBase tile) { return(tile.isConstructed && tile.Type() == TileBase.TileType.STORAGE && tile.NEmptyResourceSlots() > 0); }; //Debug.Log("Calling GetPath to check for a store room"); var storeroomPath = Path.GetPath(currentTile.GetKVPair(), mgr.GetTiles(del)); if (storeroomPath == null) { break; } SetState(State.RETRIEVING_RESOURCE); TileBase targetTile = mgr.GetTileBase(clutterPath.endX, clutterPath.endY); foreach (Resource res in targetTile.clutteredResources) { if (!res.isClaimed) { res.Claim(this); break; } } SetPath(clutterPath); break; } fIdleTime -= Time.deltaTime; if (!targetSet) { if (!currentTile.IsLizardy()) { TileManager.TestTile del = delegate(TileBase tile) { return(tile.IsLizardy()); }; if (!SetPath(Path.GetPath(currentTile.GetKVPair(), currentTile.GetAdjacentTiles(del)))) { AbandonTask(); TextTicker.AddLine("<color=red>" + lizardName + " was crushed</color>"); Core.theTM.lizards[assignment].Remove(this); Destroy(); } } else if (fIdleTime < 0) { SetTarget(GetTileCenter(currentTile) + new Vector3(Random.Range(-0.35f, 0.35f), 0.0f, 0.0f)); } } else if (Move()) { // Set a cooldown timer fIdleTime = Random.Range(1.0f, 5.0f); } } break; case State.TRAVELLING_TO_TASK: if (Move()) { if (currentTask.type == Task.Type.GO_MAD) { TextTicker.AddLine("<color=red>" + lizardName + " went mad and escaped!</color>"); Core.theTM.lizards[assignment].Remove(this); Player.thePlayer.AddSuspicion(25.0f); deathClip = null; Destroy(); } else { if (currentTask.associatedTile != null) { currentTask.associatedTile.SetTaskActive(true); } SetState(State.WORKING); } } break; case State.WORKING: switch (currentTask.type) { case Task.Type.BUILD: currentTask.UseResources(); if (currentTile.Build(this)) { FinishTask(); UI_HUD.instance.PlansFinished(currentTile.x, currentTile.y); if (currentTile.Type() == TileBase.TileType.FILLED) { } SetState(State.IDLE); } break; case Task.Type.BREED: if (currentTile is Hatchery) { if ((currentTile as Hatchery).Breed(this)) { FinishTask(); SetState(State.IDLE); } } break; case Task.Type.FARM: if (currentTile is MushroomFarm) { if ((currentTile as MushroomFarm).Farm()) { FinishTask(); SetState(State.IDLE); } } break; case Task.Type.TRAP: if (currentTile is Trap) { if ((currentTile as Trap).Farm()) { FinishTask(); SetState(State.IDLE); } } break; case Task.Type.TAILOR: if (currentTile is Tailor) { if ((currentTile as Tailor).Farm()) { FinishTask(); SetState(State.IDLE); } } break; case Task.Type.RELAX: if (currentTile is TVRoom) { afNeeds[(int)Need.ENTERTAINMENT] += 0.1f * Time.deltaTime; (currentTile as TVRoom).IncrementTVBill(0.1f * Time.deltaTime); if (afNeeds[(int)Need.ENTERTAINMENT] > 0.9f) { FinishTask(); SetState(State.IDLE); } } break; case Task.Type.SELL_RESOURCE: currentTask.UseResources(); int value = 0; foreach (KeyValuePair <Resource.ResourceType, int> count in currentTask.requiredResources) { value += Player.thePlayer.GetValue(count.Key) * count.Value; } Player.thePlayer.money += value; FinishTask(); // Maybe put in some animation stuff in time? James? // e.g. transport the resource up to the actual hut SetState(State.IDLE); break; case Task.Type.EAT: case Task.Type.WORK_ROOM: case Task.Type.GO_MAD: FinishTask(); break; } break; case State.RETRIEVING_RESOURCE: if (Move()) { if (currentTask == null) { // Find a storeroom with an empty slot TileManager.TestTile del = delegate(TileBase tile) { return(tile.Type() == TileBase.TileType.STORAGE && tile.NEmptyResourceSlots() > 0); }; //Debug.Log("Calling GetPath to go to a storeroom"); var storePath = Path.GetPath(currentTile.GetKVPair(), mgr.GetTiles(del)); if (storePath == null) { SetState(State.IDLE); break; } else { SetPath(storePath); } } else if (currentTask.associatedTile == null) { // No tile. Must be a self task switch (currentTask.type) { case Task.Type.EAT: Consume(claimed); break; default: Debug.Assert(false, "This task should have an associated tile"); break; } SetState(State.IDLE); return; } else { // Debug.Log("Calling GetPath to go to the target tile"); var tilePath = Path.GetPath(currentTile.GetKVPair(), currentTask.associatedTile); if (tilePath == null) { AbandonTask(); } else { SetPath(tilePath); } } if (claimed != null) { claimed.GiveToLizard(this); SetState(State.RETURNING_RESOURCE); } else { // Someone nicked it! SetState(State.IDLE); } } break; case State.RETURNING_RESOURCE: if (Move()) { if (currentTask == null) { //Debug.Log("Calling StoreResource"); carrying.PutInRoom(currentTile); SetState(State.IDLE); } else { currentTask.AddResource(carrying); DoTask(); } } break; } }