// Update is called once per frame void Update() { Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); // RESOURCE SENSING if (Input.GetKeyDown("down")) { if (currentInventory < maxInventory) { // Debug.Log ("Pick up NPC or resource"); // picking up resource takes priority over NPC, because itherwise may interrupt NPC from doing work if (canLoadFood && currentKingScript.availableResources[0] > 0) { // Debug.Log("Pick up FOOD"); inventoryResources[0]++; currentKingScript.availableResources[0]--; currentKingScript.RemoveAndPositionResource(0); currentInventory++; } else if (canLoadWood && currentKingScript.availableResources[1] > 0) { // Debug.Log("Pick up WOOD"); inventoryResources[1]++; currentKingScript.availableResources[1]--; currentKingScript.RemoveAndPositionResource(1); currentInventory++; } else if (canLoadStone && currentKingScript.availableResources[2] > 0) { // Debug.Log("Pick up STONE"); inventoryResources[2]++; currentKingScript.availableResources[2]--; currentKingScript.RemoveAndPositionResource(2); currentInventory++; } else if (npcsInRange.Count > 0) { passengers.Add(npcsInRange[npcsInRange.Count - 1]); npcsInRange[npcsInRange.Count - 1].PickUp(); currentInventory++; } } else { Debug.Log("Inventory full"); } } if (Input.GetKeyDown("up")) { if (canLoadFood && inventoryResources[0] > 0) { // Debug.Log("Drop off FOOD"); inventoryResources[0]--; currentInventory--; currentKingScript.availableResources[0]++; currentKingScript.CreateAndPositionResource(0); currentKingScript.CheckResourceArrived(); // activate builder at front of queue to check and see if his resource has arrived, if not then go to the back of the queue } else if (canLoadWood && inventoryResources[1] > 0) { // Debug.Log("Drop off WOOD"); inventoryResources[1]--; currentInventory--; currentKingScript.availableResources[1]++; currentKingScript.CreateAndPositionResource(1); currentKingScript.CheckResourceArrived(); // activate builder at front of queue to check and see if his resource has arrived, if not then go to the back of the queue } else if (canLoadStone && inventoryResources[2] > 0) { // Debug.Log("Drop off STONE"); inventoryResources[2]--; currentInventory--; currentKingScript.availableResources[2]++; currentKingScript.CreateAndPositionResource(2); currentKingScript.CheckResourceArrived(); // activate builder at front of queue to check and see if his resource has arrived, if not then go to the back of the queue } else if (passengers.Count > 0 && currentKingScript != null) { NPC droppedOffNPC = passengers[passengers.Count - 1]; droppedOffNPC.gameObject.SetActive(true); droppedOffNPC.DropOff(currentKingScript.foodResourceStore.position, currentKingScript); // Drop NPC off at specific position on teh docks... food point for now passengers.RemoveAt(passengers.Count - 1); currentInventory--; } else { Debug.Log("Haven't got any NPCs in the inventory... or there's no currentKingScript"); } } transform.Translate(new Vector3(0.3f * input.x, 0, 0)); }
void CheckTask() { if (goingToFerry) { // Debug.Log ("Arrived at ferry"); kingScript.npcsWaitingForFerry.Add(this); goingToFerry = false; waitingForFerry = true; StartCoroutine(WaitAtFerry()); } else { if (occupation == 0) { if (carryingResource) { StartCoroutine(OffloadAtDocks()); } else { StartCoroutine(GatherWood()); } ; } else if (occupation == 1) { if (carryingResource) { StartCoroutine(OffloadAtDocks()); } else { StartCoroutine(GatherStone()); } ; } else if (occupation == 2) { if (carryingResource) { StartCoroutine(OffloadAtDocks()); } else { StartCoroutine(Farm()); } ; } // if its a builder (this is called once arriving at docks or build site depending on whether they're carrying a resource else if (occupation == 3) { // if a builder isn't carrying a resource then they will pick up appropriate resource from docks, then go to their build task if (!carryingResource) { // join the queue to get a resource if (!kingScript.resourceQueue.Contains(this)) { kingScript.resourceQueue.Add(this); } kingScript.CheckResourceArrived(); // activate builder at front of queue to check and see if his resource has arrived, if not then go to the back of the queue } // builder is carrying resource so they're here to build // or possibly they were trying to build another structure which was completed before builder arrived with resource.... in that case return teh resource else { if (!destinationPlatformScript.underConstruction) { destinationPlatformScript.underConstruction = true; } StartCoroutine(BuildSectionOfStructure()); // if (destinationPlatformScript.farming) { // StartCoroutine (BuildSectionOfStructure ()); // } else if (destinationPlatformScript.quarry) { // StartCoroutine (BuildSectionOfStructure ()); // } else if (destinationPlatformScript.mine) { // StartCoroutine (BuildSectionOfStructure ()); // } else if (destinationPlatformScript.housing) { // StartCoroutine (BuildSectionOfStructure ()); // } else if (destinationPlatformScript.workshop) { // StartCoroutine (BuildSectionOfStructure ()); // } else if (destinationPlatformScript.archery) { // StartCoroutine (BuildSectionOfStructure ()); // } } } else if (occupation == 4) { Patrol(); // check for enemies in Patrol function } else if (occupation == 5) { // if nobody is attacking, then parade, else... move to castle??? Parade(); } } }