Ejemplo n.º 1
0
    public IEnumerator <Coroutine> LoadNatural(string path)
    {
        ClearNaturals();
        using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "natural.dat")))) {
            int header = reader.ReadInt32();
            if (header <= 0)
            {
                int counter = reader.ReadInt32();
                for (int i = 0; i < counter; i++)
                {
                    TriCoordinates coord  = TriCoordinates.Load(reader);
                    Natural        loaded = Natural.Load(reader);
                    if (loaded)
                    {
                        loaded.ID       = i;
                        loaded.Location = grid.GetCell(coord);
                        loaded.transform.SetParent(NaturalGroup);
                        AddNatural(loaded);
                        loaded.validateRotation();
                    }
//                    if (i % Strings.refreshLimit == 0) yield return null;
                }
            }
            else
            {
                Debug.LogWarning("Unknown naturals format " + header);
            }
        }
        yield return(null);
    }
Ejemplo n.º 2
0
    public virtual List <BuildState> GetBuildStatus(TriCoordinates coord, TriDirection dir)
    {
        List <BuildState> ret  = new List <BuildState>();
        TriGrid           grid = TriGrid.Instance;
        TriCell           cell = grid.GetCell(coord);
        int elev = cell.Elevation;

        ret.Add(new BuildState(cell.coordinates, cell.IsBuildable()));
        cell = grid.GetCell(coord).GetNeighbor(dir);
        ret.Add(new BuildState(cell.coordinates, cell.IsBuildable() && Mathf.Abs(cell.Elevation - elev) < 2));
        return(ret);
    }
Ejemplo n.º 3
0
    public Vector3 ClampPosition(Vector3 position)
    {
        clampXMin = grid.GetCell(new TriCoordinates(border, border)).Position.x;
        clampZMin = grid.GetCell(new TriCoordinates(border / 2, border / 2)).Position.z;
        clampXMax = grid.GetCell(new TriCoordinates(grid.cellCountX - border, grid.cellCountZ - border)).Position.x;
        clampZMax = grid.GetCell(new TriCoordinates(grid.cellCountX - border / 2, grid.cellCountZ - border / 2)).Position.z;
        float xMax =
            (grid.cellCountX - 0.5f) *
            (2f * TriMetrics.innerRadius);

        position.x = Mathf.Clamp(position.x, clampXMin, clampXMax);
        float zMax =
            (grid.cellCountZ - 1) *
            (1.5f * TriMetrics.outerRadius);

        position.z = Mathf.Clamp(position.z, clampZMin, clampZMax);
        return(position);
    }
Ejemplo n.º 4
0
    public static new BuildCommand Load(BinaryReader reader)
    {
        TriGrid      instance = TriGrid.Instance;
        TriCell      tCell    = instance.GetCell(TriCoordinates.Load(reader));
        TriDirection tDir     = (TriDirection)reader.ReadInt32();
        Entity       prefab   = TriIsland.GetBuildingPrefabs(reader.ReadInt32(), reader.ReadInt32(), 0);

        return(new BuildCommand(tCell, tDir, prefab));
    }
Ejemplo n.º 5
0
 TriCell GetRay()
 {
     if (camManager.GetNowActive())
     {
         return(grid.GetCell(camManager.GetNowActive().CameraView.ScreenPointToRay(Input.mousePosition)));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 6
0
    bool UpdateCurrentCell()
    {
        TriCell cell =
            grid.GetCell(Camera.main.ScreenPointToRay(Input.mousePosition));

        if (cell != currentCell)
        {
            currentCell = cell;
            return(true);
        }
        return(false);
    }
Ejemplo n.º 7
0
    public void CalculateTerrain()
    {
        Clear();
        TriGrid grid = TriGrid.Instance;

        result = selector.Prefab.GetBuildStatus(selector.nowCell.coordinates, selector.dir);
        if (selector.nowCell)
        {
            foreach (BuildState i in result)
            {
                RecalculateTerrain(grid.GetCell(i.coord), i.value);
                if (!i.value)
                {
                    Buildable = false;
                }
            }
        }

        Apply();
    }
Ejemplo n.º 8
0
    void SetClimateData(int cellIndex, float moisture, float clouds)
    {
        TriDirection d = TriDirection.VERT;
        TriCell      current, k;
        ClimateData  t;

        current = k = grid.GetCell(cellIndex);
        for (int i = 0; i < 6; i++)
        {
            if (!k)
            {
                break;
            }

            t                = new ClimateData();
            t.moisture       = moisture;
            t.clouds         = clouds;
            climate[k.Index] = t;

            k = k.GetNeighbor(d);
            if (current.inverted)
            {
                d = d.Next();
            }
            else
            {
                d = d.Previous();
            }
        }
    }
Ejemplo n.º 9
0
 TriCell GetCellUnderCursor()
 {
     return
         (triGrid.GetCell(Camera.main.ScreenPointToRay(Input.mousePosition)));
 }
Ejemplo n.º 10
0
 public void Load(string path)
 {
     ClearEntities();
     using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "natural.dat")))) {
         int header = reader.ReadInt32();
         if (header <= 0)
         {
             int counter = reader.ReadInt32();
             for (int i = 0; i < counter; i++)
             {
                 TriCoordinates coord  = TriCoordinates.Load(reader);
                 Natural        loaded = Natural.Load(reader);
                 if (loaded)
                 {
                     loaded.ID       = i;
                     loaded.Location = grid.GetCell(coord);
                     loaded.transform.SetParent(NaturalGroup);
                     AddNatural(loaded);
                     loaded.validateRotation();
                 }
             }
         }
         else
         {
             Debug.LogWarning("Unknown naturals format " + header);
         }
     }
     using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "building.dat")))) {
         int header = reader.ReadInt32();
         if (header <= 0)
         {
             int counter = reader.ReadInt32();
             for (int i = 0; i < counter; i++)
             {
                 TriCoordinates coord  = TriCoordinates.Load(reader);
                 Building       loaded = Building.Load(reader);
                 if (loaded)
                 {
                     loaded.ID                = i;
                     loaded.Location          = grid.GetCell(coord);
                     loaded.EntranceDirection = loaded.EntranceDirection;
                     loaded.Location.Statics  = loaded;
                     loaded.transform.SetParent(BuildingGroup);
                     AddBuilding(loaded);
                 }
             }
         }
         else
         {
             Debug.LogWarning("Unknown building format " + header);
         }
     }
     using (BinaryReader reader = new BinaryReader(File.OpenRead(Path.Combine(path, "unit.dat")))) {
         int header = reader.ReadInt32();
         if (header <= 0)
         {
             int counter = reader.ReadInt32();
             for (int i = 0; i < counter; i++)
             {
                 TriCoordinates coord  = TriCoordinates.Load(reader);
                 Unit           loaded = Unit.Load(reader);
                 if (loaded)
                 {
                     loaded.ID       = i;
                     loaded.Location = grid.GetCell(coord);
                     if (grid.GetCell(coord).Statics)
                     {
                         loaded.GetIn((Building)grid.GetCell(coord).Statics);
                     }
                     loaded.transform.SetParent(UnitGroup);
                     AddUnit(loaded);
                 }
             }
         }
         else
         {
             Debug.LogWarning("Unknown unit format " + header);
         }
     }
 }