Exemple #1
0
    public override void Gen(SortedSet <GenElement> queue)
    {
        if (intercepted)
        {
            return;
        }

        void CheckAndSubmit(Vector2 dir)
        {
            Vector2 nxtPos = segment.to + cfg.RandRot(dir);
            float   pop    = GenUtil.GetPop(nxtPos);

            if (Range(0f, 1f) < pop)
            {
                queue.Add(new GenTown(segment.to, dir, time));
            }
        }

        CheckAndSubmit(segment.dir.Len(cfg.randLen));
        CheckAndSubmit(segment.dir.RotHalfPi().Len(cfg.randLen));
        CheckAndSubmit((-segment.dir).RotHalfPi().Len(cfg.randLen));
    }
Exemple #2
0
    public override void Gen(SortedSet <GenElement> queue)
    {
        if (intercepted)
        {
            return;
        }

        void BranchHighway(Vector2 dir, int cooldown, int time)
        {
            var nxtPos = segment.to + cfg.RandRot(dir);

            queue.Add(new GenHighway(new Segment(segment.to, nxtPos), GenUtil.GetPop(nxtPos), cooldown, this.time + time));
        }

        // ----------------------------------------------------------------------------------------
        // Left and right highway extension.
        // ----------------------------------------------------------------------------------------

        bool leftBranched  = false;
        bool rightBranched = false;

        if (branchCooldown <= 0 && Range(0f, 2f / (-1 - branchCooldown)) <= population)
        {
            BranchHighway(segment.dir.RotHalfPi() * cfg.randLen, cfg.randBranchCooldown, cfg.randForwardTime);
            branchCooldown += cfg.randBranchCooldown;
            leftBranched    = true;
        }

        if (branchCooldown <= 0 && Range(0f, 2f / (-1 - branchCooldown)) <= population)
        {
            BranchHighway((-segment.dir).RotHalfPi() * cfg.randLen, cfg.randBranchCooldown, cfg.randForwardTime);
            branchCooldown += cfg.randBranchCooldown;
            rightBranched   = true;
        }

        // ----------------------------------------------------------------------------------------
        // Forward highway extension.
        // ----------------------------------------------------------------------------------------

        var lst = new List <(float pop, Vector2 pos)>(2 * cfg.sampleCount + 1);

        void SubmitToList(Vector2 nxtDir)
        {
            Vector2 nxtPos = segment.to + nxtDir;

            lst.Add((GenUtil.GetPop(nxtPos), nxtPos));
        }

        // Sample all potentional points, take the max
        for (int i = -cfg.sampleCount; i <= cfg.sampleCount; i++)
        {
            SubmitToList(cfg.RandRot(segment.dir.Rot(cfg.sampleAngle * Mathf.Deg2Rad * i / cfg.sampleCount)));
        }
        // Sort for selection.
        lst.Sort((w, e) => (e.pop - population).Abs().CompareTo((w.pop - population).Abs()));
        // Add forward extension to the queue.
        BranchHighway(segment.to.To(lst[0].pos).Len(cfg.randLen), branchCooldown - 1, cfg.randForwardTime);

        // ----------------------------------------------------------------------------------------
        // Branch downtown roads.
        // ----------------------------------------------------------------------------------------

        if (!leftBranched && Range(0f, 1f) < population)
        {
            var nxtDir = segment.dir.RotHalfPi();
            queue.Add(new GenTown(segment.to, nxtDir, time));
        }

        if (!rightBranched && Range(0f, 1f) < population)
        {
            var nxtDir = (-segment.dir).RotHalfPi();
            queue.Add(new GenTown(segment.to, nxtDir, time));
        }
    }
Exemple #3
0
 public GenTown(Vector2 from, Vector2 dir, int baseTime)
 {
     segment.from = from;
     segment.to   = from + dir.Len(cfg.randLen);
     this.time    = baseTime + cfg.GetTime(GenUtil.GetPop(segment.to));
 }