Ejemplo n.º 1
0
    private RingSector CreateNewSector(int i)
    {
        var availableTypes = MapPoint.GetAvailablePointsType(ascension);

        var        pos   = GetSectorPosition(i);
        int        x     = Random.Range(0, availableTypes.Count);
        var        inpos = GetSectorPosition(i);
        byte       ring  = DefineRing(pos.y);
        RingSector rs;

        if (availableTypes[x] != MapMarkerType.Star)
        {
            MapPoint centralPoint = MapPoint.CreatePointOfType(
                pos.x,
                pos.y,
                availableTypes[x]
                );
            rs = new RingSector(centralPoint, Environment.GetEnvironment(ascension, pos.y));
            AddPoint(centralPoint, true);
        }
        else
        {
            var      e        = Environment.GetEnvironment(ascension, pos.y);
            SunPoint sunpoint = new SunPoint(
                pos.x,
                pos.y,
                e.horizonColor
                );
            rs = new RingSector(sunpoint, e);
            AddPoint(sunpoint, true);
        }
        mapSectors[i] = rs;
        actionsHash++;
        return(rs);
    }
Ejemplo n.º 2
0
    public void Prepare()
    {
        transform.position = Vector3.up * 0.1f;

        rotationSpeed    = new float[RINGS_COUNT];
        rotationSpeed[0] = (Random.value - 0.5f) * MAX_RINGS_ROTATION_SPEED;
        rotationSpeed[1] = (Random.value - 0.5f) * MAX_RINGS_ROTATION_SPEED;
        rotationSpeed[2] = (Random.value - 0.5f) * MAX_RINGS_ROTATION_SPEED;
        rotationSpeed[3] = (Random.value - 0.5f) * MAX_RINGS_ROTATION_SPEED;
        rotationSpeed[4] = (Random.value - 0.5f) * MAX_RINGS_ROTATION_SPEED;
        ringsRotation    = new float[RINGS_COUNT];

        mapPoints = new List <MapPoint>();
        int sectorsCount = 0;

        for (int i = 0; i < RINGS_COUNT; i++)
        {
            sectorsCount += (int)(360f / sectorsDegrees[i]);
        }
        mapSectors      = new RingSector[sectorsCount];
        ascension       = GameConstants.ASCENSION_STARTVALUE;
        ascensionTarget = ascension;
        //start sector:
        byte ring = RINGS_COUNT / 2;

        sectorsCount = (int)(360f / sectorsDegrees[ring]);
        int min = 0;

        for (int i = 0; i < ring; i++)
        {
            min += (int)(360f / sectorsDegrees[i]);
        }
        int startSectorIndex = Random.Range(min, min + sectorsCount);

        Vector2    startPos    = GetSectorPosition(startSectorIndex);
        var        sunPoint    = new SunPoint(startPos.x, startPos.y, Color.white);
        RingSector startSector = new RingSector(sunPoint, Environment.defaultEnvironment);

        startSector.SetFertility(false);
        mapSectors[startSectorIndex] = startSector;
        Vector2 dir = Quaternion.AngleAxis(Random.value * 360, Vector3.forward) * Vector2.up;
        float   xpos = startPos.x + dir.x * 0.25f * sectorsDegrees[ring], ypos = startPos.y + dir.y * 0.25f * (ringsBorders[ring] - ringsBorders[ring + 1]);

        cityPoint = MapPoint.CreatePointOfType(
            xpos, //angle
            ypos,
            MapPointType.MyCity
            );
        mapPoints.Add(cityPoint); // CITY_POINT_INDEX = 0
        mapPoints.Add(sunPoint);
        //
        starsTypesArray = new BitArray((int)Environment.EnvironmentPreset.TotalCount, false);
        starsTypesArray[(int)Environment.EnvironmentPreset.Default] = true;
        createNewStars = true;
        //
        actionsHash = 0;
        prepared    = true;
        //зависимость : Load()
    }
Ejemplo n.º 3
0
    private RingSector CreateNewSector(int i)
    {
        MapPointType type; Path p;

        ProgressionMaster.DefinePointOfInterest(this, out type, out p);
        var        pos = GetSectorPosition(i);
        RingSector rs;

        if (type != MapPointType.Star)
        {
            var poi = new PointOfInterest(pos.x, pos.y, type, p);
            rs = new RingSector(poi, Environment.GetEnvironment(ascension, pos.y));
            AddPoint(poi, true);
        }
        else
        {
            var e           = Environment.GetEnvironment(ascension, pos.y);
            int presetIndex = (int)e.presetType;
            if (starsTypesArray[presetIndex])
            {
                return(null);
            }
            else
            {
                SunPoint sunpoint = new SunPoint(
                    pos.x,
                    pos.y,
                    e.GetMapColor()
                    );
                rs = new RingSector(sunpoint, e);
                AddPoint(sunpoint, true);
                starsTypesArray[presetIndex] = true;
                createNewStars = false;
                for (int j = 0; j < (int)Environment.EnvironmentPreset.TotalCount; j++)
                {
                    if ((Environment.EnvironmentPreset)j == Environment.EnvironmentPreset.Custom)
                    {
                        continue;
                    }
                    else
                    {
                        if (starsTypesArray[j] == false)
                        {
                            createNewStars = true;
                            break;
                        }
                    }
                }
            }
        }
        mapSectors[i] = rs;
        actionsHash++;
        return(rs);
    }
Ejemplo n.º 4
0
    private void RemoveSector(byte arrayIndex)
    {
        RingSector rs = mapSectors[arrayIndex];

        if (rs != null)
        {
            if (rs.centralPoint != null)
            {
                RemovePoint(rs.centralPoint, true);
            }
            if (rs.innerPointsIDs.Count > 0)
            {
                MapPoint p = null;
                foreach (var mp in rs.innerPointsIDs)
                {
                    p = GetMapPointByID(mp.Value);
                    if (!p.DestructionTest())
                    {
                        RemovePoint(p, false);
                    }
                }
                rs.innerPointsIDs.Clear();
            }
            if (mapPoints.Count > 0)
            {
                int      x = arrayIndex, i = 0;
                MapPoint mp = null;
                while (i < mapPoints.Count)
                {
                    mp = mapPoints[i];
                    if (mp == null)
                    {
                        mapPoints.RemoveAt(i);
                        continue;
                    }
                    else
                    {
                        x = DefineSectorIndex(mp.angle, mp.ringIndex);
                        if (x == arrayIndex)
                        {
                            if (!mp.DestructionTest())
                            {
                                RemovePoint(mp, true);
                            }
                        }
                        i++;
                    }
                }
            }
            mapSectors[arrayIndex] = null;
            actionsHash++;
        }
    }
Ejemplo n.º 5
0
    public void FORCED_CreatePointOfInterest()
    {
        int x            = GetCurrentSectorIndex() + 1;
        var pos          = GetSectorPosition(x);
        var centralPoint = MapPoint.CreatePointOfType(
            pos.x,
            pos.y,
            MapPointType.Island
            );

        mapSectors[x] = new RingSector(centralPoint, Environment.GetEnvironment(ascension, pos.y));
        AddPoint(centralPoint, true);
    }
Ejemplo n.º 6
0
    public bool Search()
    {
        int        x  = Random.Range(0, mapSectors.Length);
        RingSector rs = mapSectors[x];

        if (rs == null)
        {
            return(CreateNewSector(x) != null);
        }
        else
        {
            return(UpdateSector(x));
        }
    }
Ejemplo n.º 7
0
    public static RingSector[] StaticLoad(System.IO.FileStream fs)
    {
        var data = new byte[4];

        fs.Read(data, 0, 4);
        int      count = System.BitConverter.ToInt32(data, 0), readVal1 = -1, readVal2 = -1;
        var      sectors        = new RingSector[count];
        MapPoint f_centralPoint = null;
        var      gmap           = GameMaster.realMaster.globalMap;

        for (int i = 0; i < count; i++)
        {
            readVal1 = fs.ReadByte();
            if (readVal1 == 0)
            {
                continue;
            }
            else
            {
                data = new byte[14];
                fs.Read(data, 0, data.Length);
                readVal1       = System.BitConverter.ToInt32(data, 0);
                readVal2       = System.BitConverter.ToInt32(data, 4);
                f_centralPoint = gmap.GetMapPointByID(readVal2);

                var rs = new RingSector(readVal1, f_centralPoint, (Environment.EnvironmentPreset)data[8]);
                readVal1 = System.BitConverter.ToInt32(data, 9);
                if (readVal1 > 0)
                {
                    data = new byte[5 * readVal1 + 1]; // byte + int
                    fs.Read(data, 0, data.Length);
                    for (int j = 0; j < readVal1; j++)
                    {
                        rs.innerPointsIDs.Add(data[j * 5], System.BitConverter.ToInt32(data, 5 * j + 1));
                    }
                }
                rs.fertile = data[data.Length - 1] == 1;

                if (f_centralPoint != null)
                {
                    sectors[i] = rs;
                }
            }
        }
        data = new byte[4];
        fs.Read(data, 0, 4);
        lastFreeID = System.BitConverter.ToInt32(data, 0);
        return(sectors);
    }
Ejemplo n.º 8
0
    public void RemoveSector(RingSector rs)
    {
        RingSector srs = null;
        int        sid = rs.ID;

        for (byte i = 0; i < mapSectors.Length; i++)
        {
            srs = mapSectors[i];
            if (srs != null && srs.ID == sid)
            {
                RemoveSector(i);
                return;
            }
        }
    }
Ejemplo n.º 9
0
 private void AddSector(RingSector rs, byte index, bool forced)
 {
     if (mapSectors[index] != null & !forced)
     {
         return;
     }
     else
     {
         if (mapSectors[index] != null)
         {
             RemoveSector(index);
         }
         mapSectors[index] = rs;
     }
 }
Ejemplo n.º 10
0
    private void AddNewSector(byte index, MapPointType mtype, Environment e)
    {
        if (mapSectors[index] != null)
        {
            RemoveSector(index);
        }
        Vector2  spos   = GetSectorPosition(index);
        MapPoint mpoint = MapPoint.CreatePointOfType(spos.x, spos.y, mtype);

        AddPoint(mpoint, false);
        RingSector rs = new RingSector(mpoint, e);

        mapSectors[index] = rs;
        actionsHash++;
    }
Ejemplo n.º 11
0
    public void Load(System.IO.Stream fs, int saveSystemVersion)
    {
        var data = new byte[40];

        fs.Read(data, 0, data.Length);
        rotationSpeed    = new float[RINGS_COUNT];
        rotationSpeed[0] = System.BitConverter.ToSingle(data, 0);
        rotationSpeed[1] = System.BitConverter.ToSingle(data, 4);
        rotationSpeed[2] = System.BitConverter.ToSingle(data, 8);
        rotationSpeed[3] = System.BitConverter.ToSingle(data, 12);
        rotationSpeed[4] = System.BitConverter.ToSingle(data, 16);
        ringsRotation    = new float[RINGS_COUNT];
        ringsRotation[0] = System.BitConverter.ToSingle(data, 20);
        ringsRotation[1] = System.BitConverter.ToSingle(data, 24);
        ringsRotation[2] = System.BitConverter.ToSingle(data, 28);
        ringsRotation[3] = System.BitConverter.ToSingle(data, 32);
        ringsRotation[4] = System.BitConverter.ToSingle(data, 36);
        if (!prepared)
        {
            transform.position = Vector3.up * 0.1f;
            actionsHash        = 1;
        }
        if (mapPoints == null)
        {
            mapPoints = new List <MapPoint>();
        }
        else
        {
            mapPoints.Clear();
        }
        mapPoints = MapPoint.LoadPoints(fs);
        foreach (var p in mapPoints)
        {
            if (p.type == MapPointType.MyCity)
            {
                cityPoint = p;
                break;
            }
        }

        data = new byte[4];
        fs.Read(data, 0, 4);
        ascension = System.BitConverter.ToSingle(data, 0);

        mapSectors = RingSector.StaticLoad(fs);
        RecalculateStarsArray();
        prepared = true;
    }
Ejemplo n.º 12
0
    public void Save(System.IO.Stream fs)
    {
        fs.Write(System.BitConverter.GetBytes(rotationSpeed[0]), 0, 4); // 0 - 3
        fs.Write(System.BitConverter.GetBytes(rotationSpeed[1]), 0, 4); // 4 - 7
        fs.Write(System.BitConverter.GetBytes(rotationSpeed[2]), 0, 4); // 8 - 11
        fs.Write(System.BitConverter.GetBytes(rotationSpeed[3]), 0, 4); // 12 - 15
        fs.Write(System.BitConverter.GetBytes(rotationSpeed[4]), 0, 4); // 16 - 19

        fs.Write(System.BitConverter.GetBytes(ringsRotation[0]), 0, 4); // 20 - 23
        fs.Write(System.BitConverter.GetBytes(ringsRotation[1]), 0, 4); // 24 - 27
        fs.Write(System.BitConverter.GetBytes(ringsRotation[2]), 0, 4); // 28 - 31
        fs.Write(System.BitConverter.GetBytes(ringsRotation[3]), 0, 4); // 32 - 35
        fs.Write(System.BitConverter.GetBytes(ringsRotation[4]), 0, 4); // 36 - 39

        int realCount = 0;
        var savedata  = new List <byte>();

        if (mapPoints.Count > 0)
        {
            foreach (MapPoint mp in mapPoints)
            {
                if (mp.type != MapPointType.FlyingExpedition)
                {
                    savedata.AddRange(mp.Save());
                    realCount++;
                }
            }
        }
        fs.Write(System.BitConverter.GetBytes(realCount), 0, 4);
        if (realCount > 0)
        {
            var saveArray = savedata.ToArray();
            fs.Write(saveArray, 0, saveArray.Length);
        }
        fs.Write(System.BitConverter.GetBytes(MapPoint.nextID), 0, 4);    //зависимость : mapPoint.LoadPoints()
        fs.Write(System.BitConverter.GetBytes(ascension), 0, 4);

        RingSector.StaticSave(fs, mapSectors);
    }