Ejemplo n.º 1
0
        /// <summary>
        /// Public simply because of a bug in .NET
        /// Updates the heat conductivity according to the voxels we have.
        /// </summary>
        public void updateRho(Location loc)
        {
            int h, v;

            WorldDefinition.World.toHV(loc.x, loc.y, out h, out v);

            BaseRoad roadFound   = null;
            bool     hasMountain = false;

            // FIXME: this code shouldn't have the knowledge of any particular voxel type.
            for (int z = 0; z < WorldDefinition.World.Size.z; z++)
            {
                Voxel vxl = WorldDefinition.World[loc.x, loc.y, z];
                if (vxl is TrafficVoxel)
                {
                    roadFound = ((TrafficVoxel)vxl).road;
                }
                if (vxl is Terrain.MountainVoxel)
                {
                    hasMountain = true;
                }
            }

            bool hasSea = WorldDefinition.World.getGroundLevelFromHV(h, v) < WorldDefinition.World.WaterLevel;

            if (roadFound != null)
            {
                if (roadFound.Style.Type >= MajorRoadType.street)
                {
                    if (roadFound.Style.Sidewalk == SidewalkType.pavement)
                    {
                        rho[h, v] = RHO_ROAD;
                    }
                    else
                    {
                        rho[h, v] = (RHO_ROAD + RHO_BARE_LAND) / 2;
                    }
                }
                else
                {
                    rho[h, v] = RHO_BARE_LAND;
                }
            }
            else if (hasSea)
            {
                rho[h, v] = 0.03f;
            }
            else if (hasMountain)
            {
                rho[h, v] = 0.4f;
            }
            else
            {
                rho[h, v] = RHO_BARE_LAND;
            }
        }
Ejemplo n.º 2
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loc"></param>
        /// <returns></returns>
        public bool IsSelectable(Location loc)
        {
            // if there's any rail roads, fine
            if (BaseRoad.get(loc) != null)
            {
                return(true);
            }

            // or if we hit the ground
            if (WorldDefinition.World.GetGroundLevel(loc) >= loc.z)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loc"></param>
        /// <returns></returns>
        public bool CanBeBuilt(Location loc)
        {
            TrafficVoxel voxel = TrafficVoxel.get(loc);

            if (voxel == null)
            {
                return(false);
            }

            BaseRoad r = voxel.road;

            if (r == null)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        public override void Build(Location from, Location to)
        {
            Debug.Assert(CanBeBuilt(from, to));

            Direction d = from.getDirectionTo(to);

            Location here = from;

            while (true)
            {
                BaseRoad r = BaseRoad.get(here);
                if (r == null)
                {
                    RoadPattern p = RoadPattern.getStraight(d);
                    if (here == from)
                    {
                        p = RoadPattern.get((byte)(1 << (d.index / 2)));
                    }
                    if (here == to)
                    {
                        p = RoadPattern.get((byte)(1 << (d.opposite.index / 2)));
                    }

                    Create(TrafficVoxel.getOrCreate(here), p);
                }
                else
                {
                    if (here != from)
                    {
                        r.Attach(d.opposite);
                    }
                    if (here != to)
                    {
                        r.Attach(d);
                    }
                }

                if (here == to)
                {
                    return;
                }
                here = here.toward(to);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="here"></param>
        /// <param name="to"></param>
        public override void Remove(Location here, Location to)
        {
            if (here == to)
            {
                return;
            }

            Direction d = here.getDirectionTo(to);

            while (true)
            {
                BaseRoad r = BaseRoad.get(here);
                if (r != null)
                {
                    r.Detach(d, d.opposite);
                }

                if (here == to)
                {
                    return;
                }
                here = here.toward(to);
            }
        }