Example #1
0
 override public void SetBasement(SurfaceBlock b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     //#setStructureData
     basement      = b;
     innerPosition = new SurfaceRect(pos.x, pos.y, innerPosition.size);
     if (model == null)
     {
         SetModel();
     }
     b.AddStructure(this);
     // isbasement check deleted
     //---
     if (!addedToClassList)
     {
         corns.Add(this);
         addedToClassList = true;
         if (((existingPlantsMask >> CROP_CORN_ID) & 1) != 1)
         {
             int val = 1;
             val = val << CROP_CORN_ID;
             existingPlantsMask += val;
         }
     }
 }
 public void CreateSelectedBuilding()
 {
     if (chosenStructure.placeInCenter)
     {
         if (observingSurface.artificialStructures == 0)
         {
             CreateSelectedBuilding((byte)(SurfaceBlock.INNER_RESOLUTION / 2 - chosenStructure.innerPosition.size / 2), (byte)(SurfaceBlock.INNER_RESOLUTION / 2 - chosenStructure.innerPosition.size / 2));
         }
         else
         {
             buildIntersectionSubmit.SetActive(true);
         }
     }
     else
     {
         if (chosenStructure is Farm)
         {
             int         size = SurfaceBlock.INNER_RESOLUTION;
             SurfaceRect sr   = chosenStructure.innerPosition;
             CreateSelectedBuilding((byte)(size / 2 - sr.size / 2), (byte)(size / 2 - sr.size / 2));
         }
         else
         {
             PrepareConstructionPlane();     // включает плоскость, отключает окно выбора строений
         }
     }
 }
    // public void IntersectionSubmit_No() - just deactivate the panel
    public void ConstructingPlaneTouch(Vector3 pos)
    {
        Vector2 mappos = observingSurface.WorldToMapCoordinates(pos);
        byte    size = SurfaceBlock.INNER_RESOLUTION;
        byte    x = (byte)(mappos.x * size), z = (byte)(mappos.y * size);

        if (chosenStructure == null)
        {
            return;
        }
        SurfaceRect sr = chosenStructure.innerPosition;

        // корректировка :
        if (x + sr.size >= size)
        {
            x = (byte)(size - sr.size);
        }
        if (z + chosenStructure.innerPosition.size >= size)
        {
            z = (byte)(size - sr.size);
        }
        constructingPlaneTouchPos = new Vector2Int(x, z);

        if (observingSurface.IsAnyBuildingInArea(new SurfaceRect(x, z, sr.size)))
        {
            buildIntersectionSubmit.SetActive(true);
        }
        else
        {
            CreateSelectedBuilding(x, z);
        }
    }
Example #4
0
    override public void SetBasement(Plane b, PixelPosByte pos)
    {
        if (b == null)
        {
            return;
        }
        basement    = b;
        surfaceRect = new SurfaceRect(pos.x, pos.y, surfaceRect.size);
        if (spriter == null && modelHolder == null)
        {
            SetModel();
        }
        b.AddStructure(this);

        if (!typeRegistered)
        {
            GameMaster.realMaster.mainChunk.InitializeNature().RegisterNewLifeform(type);
            typeRegistered = true;
        }

        if (!subscribedToVisibilityEvent)
        {
            basement.visibilityChangedEvent += this.SetVisibility;
            subscribedToVisibilityEvent      = true;
            oaksCount++;
        }
    }
Example #5
0
    public static Vector3 GetLocalPosition(SurfaceRect sr)
    {
        float res  = INNER_RESOLUTION;
        float xpos = sr.x + sr.size / 2f;
        float zpos = sr.z + sr.size / 2f;

        return(new Vector3((xpos / res - 0.5f) * QUAD_SIZE, -QUAD_SIZE / 2f, ((1 - zpos / res) - 0.5f) * QUAD_SIZE));
    }
Example #6
0
    public void SetData(Settlement.SettlementStructureType i_type, byte i_level, Settlement i_settlement)
    {
        type = i_type;
        if (i_type == Settlement.SettlementStructureType.House)
        {
            level = i_level;
        }
        else
        {
            level = 1;
        }
        if (level >= Settlement.FIRST_EXTENSION_LEVEL)
        {
            if (level < Settlement.SECOND_EXTENSION_LEVEL)
            {
                surfaceRect = new SurfaceRect(0, 0, 2 * CELLSIZE);
            }
            else
            {
                surfaceRect = new SurfaceRect(0, 0, 3 * CELLSIZE);
            }
        }
        else
        {
            surfaceRect = new SurfaceRect(0, 0, CELLSIZE);
        }
        switch (type)
        {
        case Settlement.SettlementStructureType.House:
            switch (level)
            {
            case 8: value = 576; break;

            case 7: value = 504; break;

            case 6: value = 432f; break;

            case 5: value = 192f; break;

            case 4: value = 152f; break;

            case 3: value = 112f; break;

            case 2: value = 18f; break;

            default: value = 10f; break;
            }
            break;

        case Settlement.SettlementStructureType.Garden:
        case Settlement.SettlementStructureType.Shop:
            value = 1f;
            break;
        }
        settlement = i_settlement;        // может быть null
    }
Example #7
0
 public void UnsetBasement()
 {
     if (isBasement & basement != null & subscribedToChunkUpdate)
     {
         basement.myChunk.ChunkUpdateEvent -= ChunkUpdated;
         subscribedToChunkUpdate            = false;
     }
     basement      = null;
     innerPosition = new SurfaceRect(0, 0, innerPosition.size);
 }
Example #8
0
 public void ChangeInnerPosition(SurfaceRect sr)
 {
     if (basement != null)
     {
         return;
     }
     else
     {
         innerPosition = sr;
     }
 }
Example #9
0
    public override bool Equals(object obj)
    {
        // Check for null values and compare run-time types.
        if (obj == null || GetType() != obj.GetType())
        {
            return(false);
        }

        SurfaceRect p = (SurfaceRect)obj;

        return((x == p.x) & (z == p.z) & (size == p.size));
    }
Example #10
0
    protected void PrepareMultiblockStructure(SurfaceBlock b, PixelPosByte pos)
    {
        basement      = b;
        innerPosition = new SurfaceRect(pos.x, pos.y, innerPosition.x_size, innerPosition.z_size);
        b.AddStructure(this);
        Chunk myChunk = basement.myChunk;

        for (byte i = 1; i < additionalHeight; i++)
        {
            myChunk.BlockByStructure(b.pos.x, (byte)(b.pos.y + i), b.pos.z, this);
        }
    }
 public void PrepareContainer(float i_maxhp, ResourceContainer rc, bool i_isArtificial, byte size, GameObject i_model)
 {
     PrepareStructure();
     maxHp                           = i_maxhp;
     innerPosition                   = new SurfaceRect(0, 0, size);
     isArtificial                    = i_isArtificial;
     i_model.transform.parent        = transform;
     i_model.transform.localPosition = Vector3.zero;
     // вращение не устанавливать
     resourceCount = rc.volume;
     mainResource  = rc.type;
 }
Example #12
0
 override public void SetBasement(Plane b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     basement    = b;
     surfaceRect = new SurfaceRect(pos.x, pos.y, 1);
     if (model == null)
     {
         SetModel();
     }
     b.AddStructure(this);
 }
Example #13
0
 /// <summary>
 /// Do not use directly, use "Set Basement" instead
 /// </summary>
 /// <param name="s">S.</param>
 /// <param name="pos">Position.</param>
 public void AddCellStructure(Structure s, PixelPosByte pos)
 {
     if (s == null)
     {
         return;
     }
     if (map[pos.x, pos.y] == true)
     {
         int i = 0;
         while (i < surfaceObjects.Count)
         {
             if (surfaceObjects[i] == null)
             {
                 surfaceObjects.RemoveAt(i); continue;
             }
             SurfaceRect sr = surfaceObjects[i].innerPosition;
             if (sr.x <= pos.x && sr.z <= pos.y && sr.x + sr.size >= pos.x && sr.z + sr.size >= pos.y)
             {
                 if (surfaceObjects[i].indestructible)
                 {
                     s.Annihilate(true);
                     return;
                 }
                 else
                 {
                     surfaceObjects[i].Annihilate(true);
                     break;
                 }
             }
             i++;
         }
     }
     surfaceObjects.Add(s);
     s.transform.parent        = transform;
     s.transform.localPosition = GetLocalPosition(new SurfaceRect(pos.x, pos.y, 1));
     s.transform.localRotation = Quaternion.Euler(0, s.modelRotation * 45, 0);
     if (visibilityMask == 0)
     {
         s.SetVisibility(false);
     }
     else
     {
         s.SetVisibility(true);
     }
     if (s.isArtificial)
     {
         artificialStructures++;
     }
     CellsStatusUpdate();
 }
Example #14
0
 override public void SetBasement(Plane b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     //#setStructureData
     basement    = b;
     surfaceRect = new SurfaceRect(pos.x, pos.y, surfaceRect.size);
     if (transform.childCount == 0)
     {
         SetModel();
     }
     b.AddStructure(this);
 }
Example #15
0
    /// <summary>
    /// Do not use directly, use "Set Basement" instead
    /// </summary>
    /// <param name="s">S.</param>
    public void AddStructure(Structure s)
    { // with autoreplacing
        if (s == null)
        {
            return;
        }
        if (s.surfaceRect.x > INNER_RESOLUTION | s.surfaceRect.z > INNER_RESOLUTION)
        {
            return;
        }
        if (structures == null)
        {
            structures = new List <Structure>();
        }
        if (s.surfaceRect.size == 1 && s.surfaceRect.size == 1)
        {
            AddCellStructure(s);
            return;
        }

        if (fulfillStatus != FullfillStatus.Empty)
        {
            SurfaceRect sr = s.surfaceRect;
            int         i  = 0;
            if (sr == SurfaceRect.full)
            {// destroy everything there
                ClearSurface(PlaneAnnihilationOrder.ClearByStructure);
            }
            else
            {
                Structure se;
                while (i < structures.Count)
                {
                    se = structures[i];
                    if (se != null)
                    {
                        if (se.surfaceRect.Intersect(sr))
                        {
                            se.Annihilate(StructureAnnihilationOrder.GetReplacingOrder(se.isArtificial));
                        }
                    }
                    i++;
                }
            }
        }
        SetStructureTransform(s);
        RecalculateSurface();
    }
Example #16
0
 override public void SetBasement(Plane b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     //#setStructureData
     if (lodComponent != null && basement != null)
     {
         lodComponent.ChangeBasement(b);
     }
     basement    = b;
     surfaceRect = new SurfaceRect(pos.x, pos.y, surfaceRect.size);
     b.AddStructure(this);
     SetModel();
 }
Example #17
0
 override public void SetBasement(SurfaceBlock b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     basement      = b;
     innerPosition = new SurfaceRect(pos.x, pos.y, xsize_to_set, zsize_to_set);
     b.AddStructure(new SurfaceObject(innerPosition, this));
     myChunk = basement.myChunk;
     for (byte i = 1; i < height; i++)
     {
         myChunk.BlockByStructure(b.pos.x, (byte)(b.pos.y + i), b.pos.z, this);
     }
     myChunk.AddLifePower(GameMaster.START_LIFEPOWER);
 }
    override public void SetBasement(Plane p, PixelPosByte pos)
    {
        if (p == null)
        {
            return;
        }
        //
        basement = p;
        if (transform.childCount == 0)
        {
            var fi = basement.faceIndex;
            if (fi == Block.SURFACE_FACE_INDEX || fi == Block.UP_FACE_INDEX || fi == Block.CEILING_FACE_INDEX || fi == Block.DOWN_FACE_INDEX)
            {
                model       = Instantiate(Resources.Load <GameObject>("Structures/Column"));
                surfaceRect = new SurfaceRect(0, 0, 4);
                surfaceRect = new SurfaceRect((byte)(PlaneExtension.INNER_RESOLUTION / 2 - surfaceRect.size / 2), (byte)(PlaneExtension.INNER_RESOLUTION / 2 - surfaceRect.size / 2), surfaceRect.size);
            }
            else
            {
                model = Instantiate(Resources.Load <GameObject>("Structures/ColumnEdge"));
                switch (fi)
                {
                case Block.FWD_FACE_INDEX: model.transform.rotation = Quaternion.Euler(0f, 180f, 0f); break;

                case Block.RIGHT_FACE_INDEX: model.transform.rotation = Quaternion.Euler(0f, -90f, 0f); break;

                case Block.LEFT_FACE_INDEX: model.transform.rotation = Quaternion.Euler(0f, 90f, 0f); break;

                case Block.BACK_FACE_INDEX: model.transform.rotation = Quaternion.Euler(Vector3.zero); break;
                }
                surfaceRect = SurfaceRect.full;
            }
            model.transform.parent        = transform;
            model.transform.localPosition = Vector3.zero;
            if (!PoolMaster.useDefaultMaterials)
            {
                PoolMaster.ReplaceMaterials(model);
            }
        }
        placeInCenter = true;
        basement.AddStructure(this);
        //
        if (!GameMaster.loading)
        {
            IPlanableSupportClass.AddBlockRepresentation(this, basement, ref myBlock, true);
        }
    }
    public bool Intersect(SurfaceRect sr)
    {
        int leftX = -1, rightX = -1;

        if (x > sr.x)
        {
            leftX = x;
        }
        else
        {
            leftX = sr.x;
        }
        if (x + size > sr.x + sr.size)
        {
            rightX = sr.x + sr.size;
        }
        else
        {
            rightX = x + size;
        }
        if (leftX < rightX)
        {
            int topZ = -1, downZ = -1;
            if (z > sr.z)
            {
                downZ = z;
            }
            else
            {
                downZ = sr.z;
            }
            if (z + size > sr.z + sr.size)
            {
                topZ = sr.z + sr.size;
            }
            else
            {
                topZ = z + size;
            }
            return(topZ > downZ);
        }
        else
        {
            return(false);
        }
    }
Example #20
0
 /// <summary>
 /// Do not use directly, use "Set Basement" instead
 /// </summary>
 /// <param name="s">S.</param>
 public void AddStructure(Structure s)
 { // with autoreplacing
     if (s == null)
     {
         return;
     }
     if (s.surfaceRect.x > INNER_RESOLUTION | s.surfaceRect.z > INNER_RESOLUTION)
     {
         return;
     }
     if (structures == null)
     {
         structures = new List <Structure>();
     }
     if (s.surfaceRect.size == 1 && s.surfaceRect.size == 1)
     {
         AddCellStructure(s);
         return;
     }
     if (fullfillStatus != FullfillStatus.Empty)
     {
         SurfaceRect sr = s.surfaceRect;
         int         i  = 0;
         if (sr == SurfaceRect.full)
         {                                     // destroy everything there
             ClearSurface(false, true, false); // false так как не нужна лишняя проверка
         }
         else
         {
             while (i < structures.Count)
             {
                 if (structures[i] != null)
                 {
                     if (structures[i].surfaceRect.Intersect(sr))
                     {
                         structures[i].Annihilate(false, true, !s.isArtificial);
                     }
                 }
                 i++;
             }
         }
     }
     SetStructureTransform(s);
     RecalculateSurface();
 }
Example #21
0
 public bool IsAnyBuildingInArea(SurfaceRect sa)
 {
     if (extension != null)
     {
         return(extension.IsAnyBuildingInArea(sa));
     }
     else
     {
         if (mainStructure != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Example #22
0
 public bool[,] GetBooleanMap()
 {
     map = new bool[INNER_RESOLUTION, INNER_RESOLUTION];
     for (int i = 0; i < INNER_RESOLUTION; i++)
     {
         for (int j = 0; j < INNER_RESOLUTION; j++)
         {
             map[i, j] = false;
         }
     }
     haveSupportingStructure = false;
     artificialStructures    = 0;
     if (surfaceObjects.Count != 0)
     {
         int a = 0;
         while (a < surfaceObjects.Count)
         {
             Structure s = surfaceObjects[a];
             if (s.isArtificial)
             {
                 artificialStructures++;
             }
             if (s.isBasement)
             {
                 haveSupportingStructure = true;
             }
             SurfaceRect sr = s.innerPosition;
             //if (sr.x_size != 1 && sr.z_size != 1) print (surfaceObjects[a].name+ ' '+ sr.x_size.ToString() + ' ' + sr.z_size.ToString());
             int i = 0, j = 0;
             while (j < sr.size & sr.x + i < INNER_RESOLUTION)
             {
                 while (i < sr.size & sr.z + j < INNER_RESOLUTION)
                 {
                     map[sr.x + i, sr.z + j] = true;
                     i++;
                 }
                 i = 0; // обнуляй переменные !
                 j++;
             }
             a++;
         }
     }
     return(map);
 }
Example #23
0
    /// <summary>
    /// Do not use directly, use "Set Basement" instead
    /// </summary>
    public void AddCellStructure(Structure s)
    {
        if (s == null)
        {
            return;
        }
        byte x = s.surfaceRect.x, z = s.surfaceRect.z;

        if (map[x * INNER_RESOLUTION + z] == true)
        {
            int       i = 0;
            Structure es;
            while (i < structures.Count)
            {
                es = structures[i];
                if (es == null)
                {
                    structures.RemoveAt(i); continue;
                }
                SurfaceRect sr = es.surfaceRect;
                if (sr.x <= x & sr.z <= z & sr.x + sr.size > x & sr.z + sr.size > z)
                {
                    if (es.indestructible)
                    {
                        s.Annihilate(StructureAnnihilationOrder.SystemDestruction);
                        return;
                    }
                    else
                    {
                        es.Annihilate(StructureAnnihilationOrder.GetReplacingOrder(es.isArtificial));
                        break;
                    }
                }
                i++;
            }
        }
        SetStructureTransform(s);
        RecalculateSurface();
    }
Example #24
0
 // в финальном виде копипастить в потомков
 protected void SetStructureData(SurfaceBlock b, PixelPosByte pos)
 {
     //#setStructureData
     basement      = b;
     innerPosition = new SurfaceRect(pos.x, pos.y, innerPosition.size);
     if (transform.childCount == 0)
     {
         SetModel();
     }
     b.AddStructure(this);
     if (isBasement)
     {
         if (!subscribedToChunkUpdate)
         {
             basement.myChunk.ChunkUpdateEvent += ChunkUpdated;
             subscribedToChunkUpdate            = true;
         }
         if (basement is CaveBlock)
         {
             basement.myChunk.ReplaceBlock(basement.pos, BlockType.Surface, basement.material_id, false);
         }
         if (basement.pos.y + 1 < Chunk.CHUNK_SIZE)
         {
             ChunkPos npos       = new ChunkPos(basement.pos.x, basement.pos.y + 1, basement.pos.z);
             Block    upperBlock = basement.myChunk.GetBlock(npos.x, npos.y, npos.z);
             if (upperBlock == null)
             {
                 basement.myChunk.AddBlock(npos, BlockType.Surface, ResourceType.CONCRETE_ID, false);
             }
         }
         else
         {
             GameObject g = PoolMaster.GetRooftop(this);
             g.transform.parent        = basement.transform;
             g.transform.localPosition = Vector3.up * Block.QUAD_SIZE / 2f;
             g.name = "block ceiling";
         }
     }
 }
Example #25
0
    /// <summary>
    /// Do not use directly, use "Set Basement" instead
    /// </summary>
    public void AddCellStructure(Structure s)
    {
        if (s == null)
        {
            return;
        }
        byte x = s.surfaceRect.x, z = s.surfaceRect.z;

        if (map[x * INNER_RESOLUTION + z] == true)
        {
            int i = 0;
            while (i < structures.Count)
            {
                if (structures[i] == null)
                {
                    structures.RemoveAt(i); continue;
                }
                SurfaceRect sr = structures[i].surfaceRect;
                if (sr.x <= x & sr.z <= z & sr.x + sr.size > x & sr.z + sr.size > z)
                {
                    if (structures[i].indestructible)
                    {
                        s.Annihilate(false, false, false);
                        return;
                    }
                    else
                    {
                        structures[i].Annihilate(false, false, false);
                        break;
                    }
                }
                i++;
            }
        }
        SetStructureTransform(s);
        RecalculateSurface();
    }
Example #26
0
 override public void SetBasement(Plane b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     basement    = b;
     surfaceRect = new SurfaceRect(pos.x, pos.y, surfaceRect.size);
     if (!GameMaster.loading)
     {
         float f = Random.value;
         if (f > 0.5f)
         {
             if (f > 0.75f)
             {
                 modelRotation = 6;
             }
             else
             {
                 modelRotation = 4;
             }
         }
         else
         {
             if (f < 0.25f)
             {
                 modelRotation = 2;
             }
         }
     }
     if (transform.childCount == 0)
     {
         SetModel();
     }
     basement.AddStructure(this);
 }
Example #27
0
 override public void SetBasement(Plane b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     basement    = b;
     surfaceRect = new SurfaceRect(pos.x, pos.y, surfaceRect.size);
     if (spriter == null)
     {
         SetModel();
     }
     b.AddStructure(this);
     if (!addedToClassList)
     {
         oaks.Add(this);
         addedToClassList = true;
         if (!typeRegistered)
         {
             GameMaster.realMaster.mainChunk.GetNature().RegisterNewLifeform(type);
             typeRegistered = true;
         }
     }
 }
Example #28
0
    public bool IsAnyBuildingInArea(SurfaceRect sa)
    {
        if (surfaceObjects == null || surfaceObjects.Count == 0)
        {
            return(false);
        }
        bool found = false;

        foreach (Structure suro in surfaceObjects)
        {
            if (!suro.isArtificial)
            {
                continue;
            }
            int minX = -1, maxX = -1, minZ = -1, maxZ = -1;
            if (sa.x > suro.innerPosition.x)
            {
                minX = sa.x;
            }
            else
            {
                minX = suro.innerPosition.x;
            }
            if (sa.x + sa.size < suro.innerPosition.x + suro.innerPosition.size)
            {
                maxX = sa.x + sa.size;
            }
            else
            {
                maxX = suro.innerPosition.x + suro.innerPosition.size;
            }
            if (minX >= maxX)
            {
                continue;
            }
            if (sa.z > suro.innerPosition.z)
            {
                minZ = sa.z;
            }
            else
            {
                minZ = suro.innerPosition.z;
            }
            if (sa.z + sa.size < suro.innerPosition.z + suro.innerPosition.size)
            {
                maxZ = sa.z + sa.size;
            }
            else
            {
                maxZ = suro.innerPosition.z + suro.innerPosition.size;
            }
            if (minZ >= maxZ)
            {
                continue;
            }
            else
            {
                found = true; break;
            }
        }
        return(found);
    }
Example #29
0
 static SurfaceRect()
 {
     one  = new SurfaceRect(0, 0, 1);
     full = new SurfaceRect(0, 0, SurfaceBlock.INNER_RESOLUTION);
 }
Example #30
0
 public Vector3 GetLocalPosition(SurfaceRect sr)
 {
     return(GetLocalPosition(sr.x + sr.size / 2f, sr.z + sr.size / 2f));
 }