Exemple #1
0
    public void Load()
    {
        int radius = 7;

        if (radius > 0)
        {
            AddLoc(new HexLoc(0, 0));
            for (int fRadius = 1; fRadius <= radius; fRadius++)
            {
                //Set initial hex grid location
                HexLoc loc = new HexLoc(fRadius, -fRadius);
                HexDir dir = (HexDir)2;
                //Find data for each hex in the ring (each ring has 6 more hexes than the last)
                for (int fHex = 0; fHex < 6 * fRadius; fHex++)
                {
                    AddLoc(loc);
                    //Finds next hex in ring
                    loc = loc.MoveTo(dir);
                    if (loc.x == 0 || loc.y == 0 || loc.x == -loc.y)
                    {
                        dir++;
                    }
                }
            }
        }
        foreach (HexTile t in locs.Values)
        {
            t.FindConnections();
        }
    }
Exemple #2
0
        private void decorate()
        {
            for (int x = 0; x < w.size; x++)
            {
                for (int y = 0; y < w.size; y++)
                {
                    // Set EV value
                    HexLoc loc = new HexLoc(x, y);
                    if (w.map [loc].node != null)
                    {
                        setEv(w.map[loc], 1.0f);
                    }

                    // Colorize the World
                    Color c = w.map [loc].b.GetColor() + new Color(.9f, .9f, .9f, 1);
                    foreach (Hex h in w.map[loc].Neighbors())
                    {
                        c += h.b.GetColor();
                    }
                    c   = (c / 6) * 1.15f;
                    c.a = 1;
                    w.map [loc].SetColor(c);
                    //UnityEngine.Debug.Log (c);
                }
            }
            UnityEngine.Debug.Log("Decorated world");
        }
    public HexLoc MoveTo(HexDir dir)
    {
        dir = MoveDirFix(dir);
        HexLoc moveTo = new HexLoc(this.x, this.y);

        if ((int)dir == 0)
        {
            moveTo.x++;
            moveTo.y--;
        }
        if ((int)dir == 1)
        {
            moveTo.x++;
        }
        if ((int)dir == 2)
        {
            moveTo.y++;
        }
        if ((int)dir == 3)
        {
            moveTo.x--;
            moveTo.y++;
        }
        if ((int)dir == 4)
        {
            moveTo.x--;
        }
        if ((int)dir == 5)
        {
            moveTo.y--;
        }
        moveTo.z = (int)(0 - (moveTo.x + moveTo.y));
        return(moveTo);
    }
Exemple #4
0
        void genRivers(int count, int length)
        {
            int c = 0;

            while (c < count)
            {
                int x = Random.Range(0, w.size); int y = Random.Range(0, w.size);
                if (inBounds(new Vector2(x, y), RIVER_SPAWN_BOUNDS))
                {
                    continue;
                }

                int    dir = UnityEngine.Random.Range(0, 5);
                HexLoc loc = new HexLoc(x, y);
                for (int i = 0; i < length; i++)
                {
                    int step = (Random.Range(0, 2) + dir) % 6;
                    while (!w.map.ContainsKey(loc.Neighbor(step)))
                    {
                        step += 1;
                    }
                    w.map[loc].b = Biome.Ocean;
                    loc          = loc.Neighbor(step);
                }

                genLake(x, y, 2);
                c++;
            }
            //Debug.Log (System.String.Format ("Generated {0} rivers", count));
        }
Exemple #5
0
        public override WorldMap GetMap(GameManager gm)
        {
            WorldMap world = SaveManager.LoadLevel(GameManager.l, "forest", gm);

            // TUTORIAL TRIGGERS
            int i = 0;

            HexLoc[] tlocs = new HexLoc[] {
                new HexLoc(0, 3, -3),
                new HexLoc(2, 2, -4),
                new HexLoc(3, 4, -7),
                new HexLoc(6, 8, -14),
                new HexLoc(7, 9, -16),
                new HexLoc(12, 11, -23),
                new HexLoc(23, 2, -25),
            };


            foreach (HexLoc hl in tlocs)
            {
                TutorialTrigger tt = new GameObject("Tutorial Trigger").AddComponent <TutorialTrigger>();
                tt.init(world.map[hl]);
                tt.id = i;

                i++;
            }

            return(world);
        }
Exemple #6
0
        void genBiomes()
        {
            Dictionary <Vector2, Biome> seeds = new Dictionary <Vector2, Biome> ();
            int steps  = w.size / bsize;
            int bcount = System.Enum.GetNames(typeof(Biome)).Length;

            for (int x = 0; x < steps; x++)
            {
                for (int y = 0; y < steps; y++)
                {
                    int i = Random.Range(bsize * x, bsize * (x + 1));
                    int j = Random.Range(bsize * y, bsize * (y + 1));
                    seeds.Add(new Vector2(i, j), (Biome)Random.Range(0, bcount - 1));
                }
            }

            List <Vector2> keys = new List <Vector2> (seeds.Keys);

            for (int x = 0; x < w.size; x++)
            {
                for (int y = 0; y < w.size; y++)
                {
                    HexLoc loc = new HexLoc(x, y);
                    w.makeHex(loc);

                    Biome b = seeds [getNearest(new Vector2(x, y), keys)];
                    w.map [loc].b = b;
                }
            }
            //Debug.Log("Generated biomes");
        }
Exemple #7
0
        public void makeUnit(Actor p, HexLoc loc)
        {
            Unit u = new GameObject("Unit").AddComponent <Unit> ();

            u.init(p, this, map [loc]);

            units.Add(u);
            UnityEngine.Debug.Log("Added Unit at " + loc.ToString());
        }
Exemple #8
0
        void genLake(int x, int y, int size)
        {
            HexLoc loc = new HexLoc(x, y);

            w.map [loc].b = Biome.Ocean;
            foreach (Hex h in w.map[loc].Neighbors())
            {
                h.b = Biome.Ocean;
            }
        }
Exemple #9
0
        public void makeHex(HexLoc l)
        {
            var obj = new GameObject(l.ToString());

            obj.transform.parent = hFolder.transform;

            Hex h = obj.AddComponent <Hex>();

            h.init(this, l);
            map.Add(l, h);
        }
Exemple #10
0
        public Hex addHex(HexLoc hl)
        {
            Hex h = new GameObject("Hex " + hl.ToString()).AddComponent <Hex> ();

            h.init(this, hl);

            h.transform.parent = hexes.transform;

            map.Add(hl, h);
            return(h);
        }
Exemple #11
0
        public Hex GetHexAtMouse()
        {
            Vector3 worldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            HexLoc  l        = w.l.PixelHex(worldPos);

            if (w.map.ContainsKey(l))
            {
                Hex h = w.map [l];
                return(h);
            }
            return(null);
        }
Exemple #12
0
        public void makeMiasma(HexLoc loc, int aggression)
        {
            if (map [loc].miasma != null)
            {
                return;
            }

            Miasma m = new GameObject("Miasma").AddComponent <Miasma> ();

            m.init(this, map [loc], aggression);

            UnityEngine.Debug.Log("Added Miasma at " + loc.ToString());
        }
Exemple #13
0
        public void makeNode(HexLoc loc)
        {
            var obj = new GameObject("Node");

            obj.transform.parent = nFolder.transform;

            Node n = obj.AddComponent <Node>();

            n.init(map [loc]);
            map [loc].node = n;

            nodes.Add(n);
            //UnityEngine.Debug.Log ("Generated node at " + pos);
        }
Exemple #14
0
        public List <Hex> Neighbors()
        {
            List <Hex> n = new List <Hex>();

            for (int i = 0; i < 6; i++)
            {
                HexLoc l = loc.Neighbor(i);
                if (w.map.ContainsKey(l))
                {
                    n.Add(w.map[l]);
                }
            }

            return(n);
        }
Exemple #15
0
        public void init(WorldMap w, HexLoc loc)
        {
            this.loc = loc;
            this.w   = w;
            this.transform.position = GameManager.l.HexPixel(loc);

            tileType = TileType.Normal;
            triggers = new List <Trigger>();
            selected = false;

            model = new GameObject("Hex Model").AddComponent <HexModel> ();
            model.init(this);

            model.transform.parent  = transform;
            transform.localPosition = GameManager.l.HexPixel(loc);
        }
Exemple #16
0
        public void init(WorldMap wm, HexLoc loc)
        {
            this.wm  = wm;
            this.loc = loc;
            units    = new List <Unit>();

            var obj = new GameObject("Hex Model");

            obj.transform.parent = transform;
            model = obj.AddComponent <HexModel>();
            model.init(this);

            transform.localPosition = wm.l.HexPixel(loc);

            this.ev      = 0;
            this.scanned = false;
        }
Exemple #17
0
        void genCorruption(int count, int aggression)
        {
            int c = 0;

            while (c < count)
            {
                int    x = Random.Range(0, w.size); int y = Random.Range(0, w.size);
                HexLoc loc = new HexLoc(x, y);
                if ((w.map[loc].b == Biome.Ocean) || (inBounds(new Vector2(x, y), INNER_SPAWN_BOUNDS)) || (!inBounds(new Vector2(x, y), OUTER_SPAWN_BOUNDS)))
                {
                    continue;
                }

                Miasma m = new GameObject("Miasma").AddComponent <Miasma> ();
                m.init(w, w.map [loc], aggression);
                c++;
            }

            //Debug.Log (System.String.Format ("Generated {0} corruption seeds", count));
        }
Exemple #18
0
    void AddLoc(HexLoc loc)
    {
        int        randHeight = Random.Range(0, 3);
        int        yRot       = Random.Range(0, 6) * 60;
        Quaternion rot        = Quaternion.Euler(0, yRot, 0);
        Vector3    worldLoc   = loc.ToWorld() + (Vector3.up * randHeight * 0.25f);
        HexTile    t          = (Instantiate(Resources.Load("Tile"), worldLoc, rot) as GameObject).GetComponent <HexTile>();

        t.height           = randHeight;
        t.transform.parent = transform;
        t.loc = loc;
        locs.Add(loc, t);
        for (int i = randHeight - 1; i >= 0; i--)
        {
            HexLoc     newLoc    = loc;
            Vector3    worldLoc2 = newLoc.ToWorld() + (Vector3.up * i * 0.25f);
            GameObject nt        = Instantiate(Resources.Load("TileBlank"), worldLoc2, Quaternion.identity) as GameObject;
            nt.transform.parent = t.transform;
        }
    }
Exemple #19
0
        void genPlayer()
        {
            WarpGate b1 = new GameObject("WarpGate1").AddComponent <WarpGate>();

            b1.init(player, w.map[new HexLoc((int)spawn.x, (int)spawn.y)]);
            b1.power = 50;


            int c = 0;

            while (c < 2)
            {
                HexLoc loc = new HexLoc((int)spawn.x + Random.Range(-1, 1), (int)spawn.y + Random.Range(-1, 1));
                if (w.map[loc].units.Count == 0 && w.map[loc].b.Passable())
                {
                    w.makeUnit(player, loc);
                    //Unit u = new GameObject("Unit" + c).AddComponent<Unit>();
                    //u.init(player, w, w.map[loc]);
                    c++;
                }
            }
            //Debug.Log (System.String.Format ("Generated Player at {0}", spawn));
        }
Exemple #20
0
 public void FocusCam(HexLoc loc)
 {
     transform.position = loc.ToWorld();
 }
Exemple #21
0
        void Update()
        {
            if (Time.frameCount < lastUpdate + 10)
            {
                return;
            }

            lastUpdate = Time.frameCount;

            look = w.l.PixelHex(pc.transform.position);

            desertC   = 0;
            forestC   = 0;
            mountainC = 0;
            oceanC    = 0;
            jungleC   = 0;
            plainsC   = 0;

            total = 0;

            foreach (KeyValuePair <HexLoc, Hex> kv in w.map)
            {
                if (kv.Key.Distance(look) < 5)
                {
                    total++;
                    if (kv.Value.revealed)
                    {
                        switch (kv.Value.b)
                        {
                        case Biome.Highlands:
                            mountainC++;
                            break;

                        case Biome.Plains:
                            plainsC++;
                            break;

                        case Biome.Forest:
                            forestC++;
                            break;

                        case Biome.Ocean:
                            oceanC++;
                            break;

                        case Biome.Desert:
                            desertC++;
                            break;

                        case Biome.Jungle:
                            jungleC++;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            // Number of hexes 5 distance away from the center hex.
            // Includes center hex (probably).
            // When all tiles contribute some sound, this can be
            // all the counts added together.

            //print(String.Format("desert {0}, forerst {1}, mountain {2}, ocean {3}, total {4}", desertC / total, forestC / total, mountainC / total, oceanC / total, total));

            ftotal = (float)total;

            desertAU.volume   = desertC / ftotal * masterGain * 0.8f; // Gain decided by sound designer.
            forestAU.volume   = forestC / ftotal * masterGain;
            mountainAU.volume = mountainC / ftotal * masterGain;
            oceanAU.volume    = oceanC / ftotal * masterGain;
            jungleAU.volume   = jungleC / ftotal * masterGain;
            plainsAU.volume   = plainsC / ftotal * masterGain;
        }
Exemple #22
0
 public HexTile GetTile(HexLoc h)
 {
     return(locs.ContainsKey(h) ? locs[h] : null);
 }
Exemple #23
0
 public void AddObject(HexLoc h, GameObject o)
 {
     occupiedTiles.Add(h, o);
 }
Exemple #24
0
 public void Add(HexLoc a, HexLoc b)
 {
     cons.Add(new UnorderedPair <HexLoc>(a, b));
 }