Exemplo n.º 1
0
        public override void StartScenario()
        {
            hbuilder       = scenario.hexBuilder;
            conditionQuest = new ConditionQuest(
                new SimpleCondition[3] {
                SimpleCondition.GetDummyCondition(null),    // colonists
                SimpleCondition.GetDummyCondition(null),    // energy
                SimpleCondition.GetDummyCondition(null)     // income
            },
                colony,
                false,
                QuestIcon.FoundationRouteIcon
                );
            conditionQuest.steps[0] = localizer.colonistsLabel;
            conditionQuest.steps[1] = localizer.islandStatsLabel;
            conditionQuest.steps[2] = localizer.lowerlandStatsLabel;

            scenario.StartQuest(conditionQuest);
            scenarioQuest.FillText(localizer.GetQuestData(FoundationScenarioStep.Finish));
            //
            conditionWindow = scenarioUI.ShowConditionPanel(0, conditionQuest, null);
            conditionWindow.SetMainIcon(UIController.iconsTexture, UIController.GetIconUVRect(Icons.FoundationRoute));
            //
            UIController.GetCurrent().updateEvent += this.Check;
            scenarioUI.ChangeAnnouncementText(localizer.GetAnnounceTitle(FoundationScenarioStep.Finish, WINDOW_INFO_0));
            scenarioUI.ShowAnnouncePanel();
            //
            colony.populationUpdateEvent += this.CitizensUpdate;
            //
            Check();
        }
Exemplo n.º 2
0
 public override void StopScenario()
 {
     if (hexBuilder != null)
     {
         hexBuilder.ClearDecorations();
         hexBuilder = null;
     }
     if (scenarioUI != null)
     {
         scenarioUI.DisableCanvas();
         scenarioUI = null;
     }
 }
Exemplo n.º 3
0
    public void WorldChange(EventWorldChanged e)
    {
        if (!builder)
        {
            Debug.LogWarning("Hex Builder not provided to spawner: " + name + ", using first responder: " + e.parent.name);
            builder = e.parent;
        }

        if (e.parent == builder)
        {
            path = CalculateAI(builder, startY);
            UpdateLineRender();
        }
    }
Exemplo n.º 4
0
 private void SetHexBuilder()
 {
     hexBuilder = new HexBuilder(this);
 }
Exemplo n.º 5
0
    public static List <Vector2Int> CalculateAI(HexBuilder builder, int startY, Vector2Int?newTile = null)
    {
        Debug.Assert(builder?.world != null, "Hex Builder World not yet initialized");

        bool[,] world      = new bool[builder.world.GetLength(0), builder.world.GetLength(1)];
        bool[,] isPossible = new bool[world.GetLength(0), world.GetLength(1)];

        for (int x = 0; x < world.GetLength(0); x++)
        {
            for (int y = 0; y < world.GetLength(1); y++)
            {
                world[x, y] = !builder.world[x, y] || builder.world[x, y].BlocksNavigation();
            }
        }

        if (newTile != null && newTile.Value.x < world.GetLength(0) && newTile.Value.y < world.GetLength(1))
        {
            world[newTile.Value.x, newTile.Value.y] = true;
        }

        for (int x = 0; x < world.GetLength(0); x++)
        {
            for (int y = 0; y < world.GetLength(1); y++)
            {
                if (x == 0)
                {
                    isPossible[x, y] = !world[x, y];
                }
                else
                {
                    isPossible[x, y] = !world[x, y] && isPossible[x - 1, y];
                }
            }
        }

        for (int pass = 0; pass < isPossible.GetLength(1); pass++)
        {
            for (int x = 0; x < world.GetLength(0); x++)
            {
                for (int y = 0; y < world.GetLength(1); y++)
                {
                    if (x == 0 || isPossible[x, y])
                    {
                        continue;
                    }
                    else
                    {
                        isPossible[x, y] = !world[x, y] && (isPossible[x - 1, y] || (y > 0 && isPossible[x, y - 1]) || (y < isPossible.GetLength(1) - 1 && isPossible[x, y + 1]));
                    }
                }
            }
        }

        bool isPossibleAtAll = false;

        for (int y = 0; y < world.GetLength(1); y++)
        {
            if (isPossible[isPossible.GetLength(0) - 1, y])
            {
                isPossibleAtAll = true;
                break;
            }
        }

        List <Vector2Int> aiPoints = new List <Vector2Int>();

        int[,] numbers = new int[isPossible.GetLength(0) + 1, isPossible.GetLength(1)];

        if (isPossibleAtAll)
        {
            for (int gx = 0; gx < numbers.GetLength(0); gx++)
            {
                for (int y = 0; y < numbers.GetLength(1); y++)
                {
                    numbers[gx, y] = 25565;
                }
            }

            Queue <Vector2Int> pointQ = new Queue <Vector2Int>();
            for (int y = startY; y >= 0; y--)
            {
                numbers[0, y] = startY - y;
                pointQ.Enqueue(new Vector2Int(0, y));
            }
            for (int y = startY + 1; y < numbers.GetLength(1); y++)
            {
                numbers[0, y] = y - startY;
                pointQ.Enqueue(new Vector2Int(0, y));
            }

            while (pointQ.Count > 0)
            {
                ProcessPoint(pointQ, isPossible, numbers, pointQ.Dequeue());
            }

            int shortestY = 0;
            for (int y = 1; y < numbers.GetLength(1); y++)
            {
                if (numbers[numbers.GetLength(0) - 1, y] < numbers[numbers.GetLength(0) - 1, shortestY])
                {
                    shortestY = y;
                }
            }

            int py = shortestY;
            int x  = numbers.GetLength(0) - 1;
            List <Vector2Int> path = new List <Vector2Int>();

            while (numbers[x, py] != 0)
            {
                int lowest = numbers[x, py];
                int lx = x, ly = py;

                foreach (Cardinal side in Cardinal.SIDES)
                {
                    if (side.chk(numbers, x, py))
                    {
                        if (numbers[x + side.x, py + side.y] < lowest)
                        {
                            lowest = numbers[x + side.x, py + side.y];
                            lx     = x + side.x;
                            ly     = py + side.y;
                            break;
                        }
                    }
                }

                path.Add(new Vector2Int(x - 1, py));
                if (path.Count > numbers.Length)
                {
                    break;
                }
                x  = lx;
                py = ly;
            }

            path.Reverse();
            aiPoints.AddRange(path);
            aiPoints.Add(new Vector2Int(aiPoints[aiPoints.Count - 1].x + 1, aiPoints[aiPoints.Count - 1].y));

            return(aiPoints.Where(val => val.x >= 0 && val.y >= 0 && val.x < world.GetLength(0) && val.y < world.GetLength(1)).ToList());
        }

        return(null);
    }
Exemplo n.º 6
0
 public EventWorldChanged(HexBuilder parent)
 {
     this.parent = parent;
 }