// TODO: Add functionality for adding tiles to previous tile queue private void FindTargetTile() { Hex[] adjacencyList = Hex.Neighbours(Grid.FindHexObject(attachedController.targetTileIndex).hex); int bestTile = 0; float bestWeight = 0; foreach (var tile in adjacencyList) { float currentWeight = 0; HexObject currentTile = Grid.FindHexObject(tile.cubeCoords); if (currentTile == null || prevTileIndices.Contains(currentTile.Index)) { continue; } if (currentTask.type == Tasks.Null) { currentWeight += Random.Range(0f, 1f); } else { currentWeight += HeatMapInfo.Instance.Field[currentTask.layer][currentTile.Index]; if (currentWeight >= 1f) { AddPrevTile(attachedController.targetTileIndex); attachedBase.SetCurrentTile(currentTile.Index); attachedController.SetTargetTile(currentTile.Index); taskReached = true; return; } } currentWeight += HeatMapInfo.Instance.Field[LayerType.Terrain][currentTile.Index]; if (currentWeight >= bestWeight) { bestWeight = currentWeight; bestTile = currentTile.Index; } } AddPrevTile(attachedController.targetTileIndex); attachedBase.SetCurrentTile(attachedController.targetTileIndex); attachedController.SetTargetTile(bestTile); }
private void Start() { attachedController = GetComponent <AgentSteering>(); attachedBase = GetComponent <AgentBase>(); attachedController.SetTargetTile(attachedBase.currentTileIndex); currentTask = new AgentTask(Tasks.Null, attachedBase); PrepTaskList(); UpdateAgent(); }