void MakeWide(float x1, float y1, float x2, float y2, float w)
        {
            Vector2 a = new Vector2(x1, y1);
            Vector2 b = new Vector2(x2, y2);
            Vector2 c = b - a;

            c.Normalize();
            c.Set(-c.y, c.x);
            Vector2 d = new Vector2(c.x, c.y);

            d *= -1;
            c *= w;
            d *= w;

            for (float t = 0; t < 1; t += 0.1f)
            {
                Vector2 aa = new Vector2(a.x, a.y);
                Vector2 ab = new Vector2(a.x, a.y);
                aa += c * t;
                ab += d * t;

                river.tex.SetPixel((int)aa.x, (int)aa.y, Color.black);
                river.tex.SetPixel((int)ab.x, (int)ab.y, Color.black);


                int xx1 = (int)aa.x / river.resizeFactor;
                int yy1 = (int)aa.y / river.resizeFactor;
                int xx2 = (int)ab.x / river.resizeFactor;
                int yy2 = (int)ab.y / river.resizeFactor;


                RMTile tla = river.map.GetTile(xx1, yy1);
                RMTile tlb = river.map.GetTile(xx2, yy2);

                if (tla != null)
                {
                    if (tla.showsAs != TYPE.ROAD && tla.markedAs != TYPE.BUILDING)
                    {
                        tla.markedAs = TYPE.WATER;
                        tla.showsAs  = TYPE.WATER;
                    }
                }

                if (tlb != null)
                {
                    if (tlb.showsAs != TYPE.ROAD && tlb.markedAs != TYPE.BUILDING)
                    {
                        tlb.markedAs = TYPE.WATER;
                        tlb.showsAs  = TYPE.WATER;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Init()
        {
            Rect    rect  = new Rect(0, 0, CHUNK_WIDTH * 32, CHUNK_HEIGHT * 32);
            Vector2 pivot = new Vector2(0, 0);

            texture            = new Texture2D(CHUNK_WIDTH * 32, CHUNK_HEIGHT * 32, NYDISpriteManager.DEFAULT_TEXTURE_FORMAT, false);
            texture.filterMode = FilterMode.Point;

            sprite      = Sprite.Create(texture, rect, pivot, 32);
            sprite.name = "sprite::chunk_" + x + "_" + y;

            for (int xx = 0; xx < CHUNK_WIDTH; xx += 1)
            {
                for (int yy = 0; yy < CHUNK_HEIGHT; yy += 1)
                {
                    Tile t = new Tile(world, this, TileType.TYPES["empty"], xx, yy);
                    tiles[xx, yy] = t;
                    t.cbRegisterOnChanged(OnTileChanged);
                    t.cbRegisterOnChanged(world.OnTileChanged);
                    t.cbRegisterOnItemChanged(world.OnInventoryItemChangedOnTile);
                    t.cbRegisterOnItemChanged(OnInventoryItemChangedOnTile);
                    //tiles[x, y].room = rooms[0];
                    world.outside.AssignTile(t);

                    //float xf = ((float)t.world_x + world.xSeed) * world.noiseFactor;
                    //float yf = ((float)t.world_y + world.ySeed) * world.noiseFactor;
                    RMTile rm = World.current.citymap.GetTile(t.world_x, t.world_y);
                    int    n  = rm.h;
                    //float n2 = World.current.SimplexNoise(((float)t.world_x), ((float)t.world_y),World.current.oreZ);
                    //float n = (n1 + n2) / 2;
                    //int j = Mathf.FloorToInt(n * (float)TileType.countNatural);

                    if (rm.showsAs == TYPE.BUILDING)
                    {
                        t.SetType(TileType.TYPES["concrete"]);
                        if (rm.btype == BUILDING_TYPE.EDGE)
                        {
                            t.SetType(TileType.TYPES["building_edge"]);
                        }
                        else if (rm.btype == BUILDING_TYPE.INSIDE)
                        {
                            t.SetType(TileType.TYPES["building_interior"]);
                        }
                    }
                    else if (rm.showsAs == TYPE.ROAD)
                    {
                        t.SetType(TileType.TYPES["concrete"]);
                    }
                    else if (rm.showsAs == TYPE.WATER)
                    {
                        t.SetType(TileType.TYPES["water"]);
                    }
                    else
                    {
                        foreach (string k in TileType.TYPES.Keys)
                        {
                            TileType tempT = TileType.TYPES[k];



                            if (tempT.name != "empty")
                            {
                                if (n == tempT.heightIndex)
                                {
                                    t.SetType(tempT);

                                    if (tempT.varieties.Count == 0)
                                    {
                                    }
                                    else
                                    {
                                        foreach (string variety in tempT.varieties.Keys)
                                        {
                                            TileType vt   = TileType.TYPES[variety];
                                            float    A    = tempT.varieties[variety].Item1;
                                            float    B    = tempT.varieties[variety].Item2;
                                            float    na   = World.current.SimplexNoise(((float)t.world_x), ((float)t.world_y), A);
                                            float    nb   = World.current.SimplexNoise(((float)t.world_x), ((float)t.world_y), B);
                                            float    navg = (na + nb) / 2f;
                                            if ((navg >= 0.95f && navg <= 1f) || (navg >= 0.05f && navg <= 0.1f))
                                            {
                                                t.SetType(vt);
                                                break;
                                            }
                                        }
                                    }



                                    break;
                                }
                            }
                        }
                    }
                }
            }

            for (int xx = 0; xx < CHUNK_WIDTH; xx += 1)
            {
                for (int yy = 0; yy < CHUNK_HEIGHT; yy += 1)
                {
                    tiles[xx, yy].SetNeighbours(true);

                    Tile t = tiles[xx, yy];
                    if (t.type.name != "empty" && t.type.name != "water")
                    {
                        if (Funcs.Chance100(1))
                        {
                            if (InstalledItem.trashPrototypes.Count > 0)
                            {
                                string        trashItemName = InstalledItem.GetRandomTrashItemName();
                                InstalledItem proto         = InstalledItem.GetPrototype(trashItemName);

                                if (proto != null)
                                {
                                    if (proto.canSpawnOnTileTypeList.Count > 0)
                                    {
                                        if (!proto.canSpawnOnTileTypeList.Contains(t.type.name))
                                        {
                                            continue;
                                        }
                                    }

                                    //Debug.Log("I will spawn a " + (trashItemName == null ? "null" : trashItemName));
                                    world.PlaceInstalledItem(trashItemName, t, true);
                                }
                            }
                        }
                        else if (Funcs.fChance(0.08f))
                        {
                            InventoryItem item = InventoryItem.GetRandomSpawnItem();
                            if (item != null)
                            {
                                string type = item.type;
                                int    qty  = UnityEngine.Random.Range(1, InventoryItem.GetStackSize(type) + 1);
                                if (Funcs.fChance(item.spawnsOnChunkGenchance * 100))
                                {
                                    world.PlaceTileInventoryItem(type, t, qty);
                                }
                            }
                        }
                        else if (Funcs.fChance(0.05f))
                        {
                            World.current.CreateEntityAtTile(t, "entities::chicken");
                        }
                    }
                }
            }
            SetNeighbourChunks();
        }