// Use this for initialization public override void Start() { base.Start(); for (int i = 0; i < TileManager.width; i++) { TileBase tb = Core.theTM.tiles[i, iDepth]; tb.bWarning = true; if (tb.IsLizardy()) { TextTicker.AddLine("Warning: Humans are about to drill into our " + tb.printName); } } }
// 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; } }
// Update is called once per frame void Update() { // Update the counters if (humanSuspicionMeter != null) { humanSuspicionMeter.value = Player.thePlayer.fHumanSuspicion; } if (lizardInfiltrationMeter != null) { lizardInfiltrationMeter.value = Player.thePlayer.lizardsDisguisedAsHumans; } if (numMetal != null) { numMetal.text = "" + Player.thePlayer.metal; } if (numGems != null) { numGems.text = "" + Player.thePlayer.gems; } if (numMushrooms != null) { numMushrooms.text = "" + Player.thePlayer.mushrooms; } if (numMoney != null) { numMoney.text = "" + Player.thePlayer.money; } if (numDinosaurBones != null) { numDinosaurBones.text = "" + Player.thePlayer.dinosaurBones; } numBreeders.text = Core.theTM.GetNumBreeders() + "/" + Core.theTM.GetMaxNumBreeders(); numFarmers.text = Core.theTM.GetNumFarmers() + "/" + Core.theTM.GetMaxNumFarmers(); numTrappers.text = Core.theTM.GetNumTrappers() + "/" + Core.theTM.GetMaxNumTrappers(); numTailors.text = Core.theTM.GetNumTailors() + "/" + Core.theTM.GetMaxNumTailors(); numMisc.text = Core.theTM.GetNumMisc() + ""; nextTVBill.text = "Next TV Bill: $" + Mathf.FloorToInt(TVRoom.fTVBill); fTutorialTime += Time.deltaTime; float fscale = 1.0f + 0.5f * Mathf.Sin(fTutorialTime * 5.0f); tutorial.transform.localScale = new Vector3(fscale, fscale, fscale); // Update the mouse over text if (mouseOverElement != null) { mouseOverElement.enabled = showMouseOver; if (showMouseOver) { mouseOverElement.transform.position = Input.mousePosition; Text text = mouseOverElement.GetComponent <Text>(); text.text = mouseOverText; } } // Update the scroll prompt if (scrollPrompt != null) { bool bShow = (Camera.main.transform.position.y > 0.0f); scrollPrompt.enabled = bShow; fScrollPromptTime += Time.deltaTime * 5.0f; float scale = 1.0f + 0.1f * Mathf.Sin(fScrollPromptTime); scrollPrompt.transform.localScale = new Vector3(scale, scale, scale); } // Hide all highlights for (int ii = 0; ii < TileManager.width; ++ii) { for (int jj = 0; jj < TileManager.depth; ++jj) { TileBase thisTile = Core.theTM.tiles[ii, jj]; thisTile.bShouldBeHighlighted = false; } } if (isBuildingAThing || isDiggingATile || isFillingInATile || isMarkingATileAsPriority) { // Get the tile that the mouse is over (if any!) TileBase mousedOverTile = null; bool bHasClicked = (Input.GetAxis("Fire1") > 0.0f); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity); if (hit) { mousedOverTile = hit.collider.gameObject.GetComponent <TileBase>(); if (bHasClicked) { //Debug.Log("Clicked on " + hit.collider.gameObject.name); } } // Iterate through all tiles, check if they are valid for this action for (int ii = 0; ii < TileManager.width; ++ii) { for (int jj = 0; jj < TileManager.depth; ++jj) { TileBase thisTile = Core.theTM.tiles[ii, jj]; if ((isBuildingAThing && thisTile.CanBeBuiltOver() && thisTile.isConstructed && thisTile.replacingTile == null) || (isDiggingATile && thisTile.CanBeDug() && thisTile.replacingTile == null) || (isFillingInATile && thisTile.CanBeFilledIn() && thisTile.isConstructed) || (isMarkingATileAsPriority && thisTile.replacingTile != null && !thisTile.replacingTile.isConstructed)) { bool bValid = true; if (isBuildingAThing && thingToBuild == BUILD_ITEM.TRAP && thisTile.y > 0) { bValid = false; } // If digging a tile, also need to check the tile is adjacent to some other lizardy tile. if (isDiggingATile) { TileBase tileOnLeft = null; if (ii - 1 >= 0) { tileOnLeft = Core.theTM.tiles[ii - 1, jj]; } TileBase tileOnRight = null; if (ii + 1 < TileManager.width) { tileOnRight = Core.theTM.tiles[ii + 1, jj]; } TileBase tileAbove = null; if (jj - 1 >= 0) { tileAbove = Core.theTM.tiles[ii, jj - 1]; } TileBase tileBelow = null; if (jj + 1 < TileManager.depth) { tileBelow = Core.theTM.tiles[ii, jj + 1]; } if ((tileOnLeft == null || !tileOnLeft.IsLizardy() || !tileOnLeft.isConstructed) && (tileOnRight == null || !tileOnRight.IsLizardy() || !tileOnRight.isConstructed) && (tileAbove == null || !tileAbove.IsLizardy() || !tileAbove.isConstructed) && (tileBelow == null || !tileBelow.IsLizardy() || !tileBelow.isConstructed)) { bValid = false; } } if (bValid) { // Highlight tile. Also render extra highlight if moused-over. thisTile.bShouldBeHighlighted = true; // If we're mousing over this tile... if (mousedOverTile != null && mousedOverTile == thisTile) { // Render transparent version of some image to indicate mouse over //Instantiate<Sprite>(highlightSprite); // If we clicked on this tile, do the thing! if (bHasClicked) { if (isBuildingAThing) { //Debug.Log("Building a thing!"); int iMetalCost = 0; Resource.ResourceType type = Resource.ResourceType.METAL; TileBase.TileType eTileType = GetTileTypeAndCostToBuild(out iMetalCost, out type); TileBase newTile = null; switch (type) { case Resource.ResourceType.METAL: if (iMetalCost <= Player.thePlayer.metal) { //Player.thePlayer.metal -= iMetalCost; This gets done by lizards now! newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType, false, iMetalCost, type); } break; case Resource.ResourceType.GEMS: if (iMetalCost <= Player.thePlayer.gems) { //Player.thePlayer.metal -= iMetalCost; This gets done by lizards now! newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType, false, iMetalCost, type); } break; case Resource.ResourceType.BONES: if (iMetalCost <= Player.thePlayer.dinosaurBones) { //Player.thePlayer.metal -= iMetalCost; This gets done by lizards now! newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType, false, iMetalCost, type); } break; } if (newTile != null) { Plans p = Instantiate <Plans>(plansPrefab); p.x = thisTile.x; p.y = thisTile.y; p.sprite = newTile.GetComponent <SpriteRenderer>().sprite; p.InitSprites(); plans.Add(p); } else { TextTicker.AddLine("You can't build that. You need more " + (type == Resource.ResourceType.METAL ? "Metal" : (type == Resource.ResourceType.BONES ? "Bones" : "Gems"))); } } else if (isDiggingATile) { //Debug.Log("Digging a tile!"); TileBase.TileType eTileType = TileBase.TileType.EMPTY; TileBase newTile = Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType); Plans p = Instantiate <Plans>(plansPrefab); p.x = thisTile.x; p.y = thisTile.y; p.sprite = newTile.GetComponent <SpriteRenderer>().sprite; p.InitSprites(); plans.Add(p); } else if (isFillingInATile) { //Debug.Log("Filling in a tile!"); TileBase.TileType eTileType = TileBase.TileType.FILLED; Core.theTM.RequestNewTile(thisTile.x, thisTile.y, eTileType); Plans p = Instantiate <Plans>(plansPrefab); p.x = thisTile.x; p.y = thisTile.y; p.sprite = fillSprite; p.InitSprites(); plans.Add(p); } else if (isMarkingATileAsPriority) { //Debug.Log("Marking a tile as priority!"); if (thisTile.replacingTile != null) { thisTile.CancelBuild(); } } } } } } } } if (bHasClicked) { // When anything is clicked, return everything to the default state Reset(); } } }
// Update is called once per frame public override void Update() { base.Update(); switch (phase) { case Phase.MOVE: if (Mathf.Abs(transform.position.x - (iTargetX - TileManager.width / 2 + 0.5f)) > 0.1f) { // Walk to target transform.localPosition += new Vector3(Time.deltaTime * fSpeed * (bFlip ? -1.0f : 1.0f), 0.0f, 0.0f); } else { transform.localPosition = new Vector3(iTargetX - TileManager.width / 2 + 0.45f, 0.625f, -3.0f); SetAnim(unloadAnim); fTimeUntilNextPhase = 5.0f; phase = Phase.UNLOAD; } break; case Phase.UNLOAD: fTimeUntilNextPhase -= Time.deltaTime; if (fTimeUntilNextPhase <= 0.0f) { SetAnim(drillAnim); phase = Phase.DRILL; // Redo based on player depth and duration of game so far iTargetDepth = Random.Range(1, 7); // Spawn plans for (int i = 0; i < iTargetDepth; i++) { Transform plans = Instantiate <Transform>(drillPlansPrefab); plans.SetParent(transform); plans.localPosition = new Vector3(0.05f, -1.03125f - i, 0.2f); drillPlans.Add(plans); } Transform end = Instantiate <Transform>(drillPlansEndPrefab); end.SetParent(transform); end.localPosition = new Vector3(0.05f, -1.03125f - iTargetDepth, 0.2f); drillPlans.Add(end); drillBit = Instantiate <Transform>(drillBitEndPrefab); drillBit.SetParent(transform); drillBit.localPosition = new Vector3(0.05f, -0.625f, 0.1f); drillPlans.Add(drillBit); // Warn! for (int i = 0; i < iTargetDepth; i++) { TileBase tb = Core.theTM.GetTileBase(iTargetX, i); if (!tb.IsLizardy() && tb.Type() != TileBase.TileType.FILLED) { // Something solid is in the way iTargetDepth = i + 1; } tb.bWarning = true; if (tb.IsLizardy()) { TextTicker.AddLine("Warning: Humans are about to drill into our " + tb.printName); } } } break; case Phase.DRILL: // Do some drilling fDrillProgress += fDrillSpeed * Time.deltaTime; int iDrillProgress = Mathf.FloorToInt(fDrillProgress); float fRemainder = fDrillProgress - iDrillProgress; if (iDrillProgress >= drills.Count) { drills.Add(Instantiate <SpriteRenderer>(drillBitPrefab)); topDrill = drills[drills.Count - 1]; topDrill.transform.SetParent(transform); // We just hit a new spot. if (iDrillProgress >= 1) { if (!Core.theTM.HumanDigTile(iTargetX, iDrillProgress - 1)) { CeaseDrilling(); } } if (iDrillProgress > iTargetDepth) { CeaseDrilling(); } } for (int i = 0; i < drills.Count; i++) { drills[i].transform.localPosition = new Vector3(0.05f, -0.03125f - i - fRemainder, 0.1f); } drillBit.localPosition = new Vector3(0.05f, -0.625f - fDrillProgress, 0.1f); break; case Phase.LEAVE: transform.localPosition += new Vector3(Time.deltaTime * fSpeed * (bFlip ? -1.0f : 1.0f), 0.0f, 0.0f); if (transform.position.x > 12.0f || transform.position.x < -12.0f) { Destroy(gameObject); } break; } }