private void PlantSeedsAI() { if (_hasBoughtSeeds == false) { if (Map.storeTiles[TileX, TileY]) { _hasBoughtSeeds = true; } else if (path.count == 0) { Pathing.WalkTo(TileX, TileY, 40, Pathing.IsStore, path); if (path.count == 0) { intention = Intention.None; } } } else if (Pathing.IsReadyForPlant(TileX, TileY)) { path.Clear(); var seed = Mathf.FloorToInt(Mathf.PerlinNoise(TileX / 10f, TileY / 10f) * 10) + Map.seedOffset; Map.SpawnPlant(TileX, TileY, seed); } else { if (path.count == 0) { if (NoRandom.value < .1f) { intention = Intention.None; } else { var tileHash = Pathing.SearchForOne(TileX, TileY, 25, Pathing.IsNavigableDefault, Pathing.IsReadyForPlant, Pathing.fullMapZone); if (tileHash != -1) { int tileX, tileY; Pathing.Unhash(tileHash, out tileX, out tileY); Pathing.AssignLatestPath(path, tileX, tileY); } else { intention = Intention.None; } } } } }
void TillGroundAI() { if (foundTillingZone == false) { int width = Random.Range(1, 8); int height = Random.Range(1, 8); int minX = tileX + Random.Range(-10, 10 - width); int minY = tileY + Random.Range(-10, 10 - height); if (minX < 0) { minX = 0; } if (minY < 0) { minY = 0; } if (minX + width >= Farm.instance.mapSize.x) { minX = Farm.instance.mapSize.x - 1 - width; } if (minY + height >= Farm.instance.mapSize.y) { minY = Farm.instance.mapSize.y - 1 - height; } bool blocked = false; for (int x = minX; x <= minX + width; x++) { for (int y = minY; y <= minY + height; y++) { GroundState groundState = Farm.groundStates[x, y]; if (groundState != GroundState.Default && groundState != GroundState.Tilled) { blocked = true; break; } if (Farm.tileRocks[x, y] != null || Farm.storeTiles[x, y]) { blocked = true; break; } } if (blocked) { break; } } if (blocked == false) { tillingZone = new RectInt(minX, minY, width, height); foundTillingZone = true; } else { if (Random.value < .2f) { intention = Intention.None; } } } else { Debug.DrawLine(new Vector3(tillingZone.min.x, .1f, tillingZone.min.y), new Vector3(tillingZone.max.x + 1f, .1f, tillingZone.min.y), Color.green); Debug.DrawLine(new Vector3(tillingZone.max.x + 1f, .1f, tillingZone.min.y), new Vector3(tillingZone.max.x + 1f, .1f, tillingZone.max.y + 1f), Color.green); Debug.DrawLine(new Vector3(tillingZone.max.x + 1f, .1f, tillingZone.max.y + 1f), new Vector3(tillingZone.min.x, .1f, tillingZone.max.y + 1f), Color.green); Debug.DrawLine(new Vector3(tillingZone.min.x, .1f, tillingZone.max.y + 1f), new Vector3(tillingZone.min.x, .1f, tillingZone.min.y), Color.green); if (IsTillableInZone(tileX, tileY)) { path.Clear(); Farm.TillGround(tileX, tileY); } else { if (path.count == 0) { int tileHash = Pathing.SearchForOne(tileX, tileY, 25, Pathing.IsNavigableDefault, Pathing.IsTillable, tillingZone); if (tileHash != -1) { int tileX, tileY; Pathing.Unhash(tileHash, out tileX, out tileY); Pathing.AssignLatestPath(path, tileX, tileY); } else { intention = Intention.None; } } } } }
private void TillGroundAi() { if (_foundTillingZone == false) { var width = NoRandom.Range(1, 8); var height = NoRandom.Range(1, 8); var minX = TileX + NoRandom.Range(-10, 10 - width); var minY = TileY + NoRandom.Range(-10, 10 - height); if (minX < 0) { minX = 0; } if (minY < 0) { minY = 0; } if (minX + width >= Map.instance.mapVector.x) { minX = Map.instance.mapVector.x - 1 - width; } if (minY + height >= Map.instance.mapVector.y) { minY = Map.instance.mapVector.y - 1 - height; } var blocked = false; for (var x = minX; x <= minX + width; x++) { for (var y = minY; y <= minY + height; y++) { var groundState = Map.groundStates[x, y]; if (groundState != GroundState.Default && groundState != GroundState.Tilled) { blocked = true; break; } if (Map.tileRocks[x, y] != null || Map.storeTiles[x, y]) { blocked = true; break; } } if (blocked) { break; } } if (blocked == false) { _tillingZone = new RectInt(minX, minY, width, height); _foundTillingZone = true; } else { if (NoRandom.value < .2f) { intention = Intention.None; } } } else { Debug.DrawLine(new Vector3(_tillingZone.min.x, .1f, _tillingZone.min.y), new Vector3(_tillingZone.max.x + 1f, .1f, _tillingZone.min.y), Color.green); Debug.DrawLine(new Vector3(_tillingZone.max.x + 1f, .1f, _tillingZone.min.y), new Vector3(_tillingZone.max.x + 1f, .1f, _tillingZone.max.y + 1f), Color.green); Debug.DrawLine(new Vector3(_tillingZone.max.x + 1f, .1f, _tillingZone.max.y + 1f), new Vector3(_tillingZone.min.x, .1f, _tillingZone.max.y + 1f), Color.green); Debug.DrawLine(new Vector3(_tillingZone.min.x, .1f, _tillingZone.max.y + 1f), new Vector3(_tillingZone.min.x, .1f, _tillingZone.min.y), Color.green); if (IsTillableInZone(TileX, TileY)) { path.Clear(); Map.TillGround(TileX, TileY); } else { if (path.count != 0) { return; } var tileHash = Pathing.SearchForOne(TileX, TileY, 25, Pathing.IsNavigableDefault, Pathing.IsTillable, _tillingZone); if (tileHash != -1) { int tileX, tileY; Pathing.Unhash(tileHash, out tileX, out tileY); Pathing.AssignLatestPath(path, tileX, tileY); } else { intention = Intention.None; } } } }