Ejemplo n.º 1
0
    public void Make_Prefab()
    {
        for (int i = 0; i < Road_Size; i++)
        {
            for (int j = 0; j < Road_Size; j++)
            {
                if (Array_Road[i, j] == null)
                {
                    RoadStatus[] roads = { null, null, null, null }; // ADWS
                    if (j - 1 >= 0)
                    {
                        roads[0] = Array_Road[i, j - 1];
                    }
                    if (j + 1 < Road_Size)
                    {
                        roads[1] = Array_Road[i, j + 1];
                    }
                    if (i - 1 >= 0)
                    {
                        roads[2] = Array_Road[i - 1, j];
                    }
                    if (i + 1 < Road_Size)
                    {
                        roads[3] = Array_Road[i + 1, j];
                    }

                    int index = -1;
                    for (int k = 0; k < 4; k++)
                    {
                        if (roads[k] != null)
                        {
                            if (roads[k].Is_Road() || (roads[k].Is_City() && !roads[k].bool_City))
                            {
                                index = 1;
                            }
                            else if (roads[k].Is_City())
                            {
                                index = 0;
                            }
                            else if (roads[k].Is_CrossRoad())
                            {
                                index = 2;
                            }
                        }
                    }

                    if (index == -1)
                    {
                        Debug.Log("From A From D From W From S All NULL! Error : Make_Prefab");
                    }

                    if (index == 1)
                    {
                        RoadStatus[] crossroads = { null, null, null, null };

                        if (j - 2 >= 0)
                        {
                            crossroads[0] = Array_Road[i, j - 2]; // A
                        }

                        if (j + 2 < Road_Size)
                        {
                            crossroads[1] = Array_Road[i, j + 2];
                        }

                        if (i - 2 >= 0)
                        {
                            crossroads[2] = Array_Road[i - 2, j];
                        }

                        if (i + 2 < Road_Size)
                        {
                            crossroads[3] = Array_Road[i + 2, j];
                        }

                        int cross_Index = -1;
                        for (int k = 0; k < 4; k++)
                        {
                            if (crossroads[k] != null)
                            {
                                if (crossroads[k].Is_Road() || (crossroads[k].Is_City() && !crossroads[k].bool_City))
                                {
                                    cross_Index = 1;
                                }
                                else if (crossroads[k].Is_City())
                                {
                                    cross_Index = 0;
                                }
                                else if (crossroads[k].Is_CrossRoad())
                                {
                                    cross_Index = 2;
                                }
                            }
                        }

                        if (cross_Index == -1)
                        {
                            Debug.Log("From A From D From W From S All NULL! Error : Make_Prefab");
                        }
                        else if (cross_Index == 0)
                        {
                            Array_Road[i, j]           = new RoadStatus(0);
                            Array_Road[i, j].bool_City = true;
                        }
                        else if (cross_Index == 2)
                        {
                            int Prefab_Number = RoadStatus.Compute_CrossRoad_Num(crossroads[0], crossroads[1], crossroads[2], crossroads[3],
                                                                                 roads[0], roads[1], roads[2], roads[3]);
                            if (Prefab_Number == -1)
                            {
                                Debug.Log("Compute Prefab Number Loss! Error : Init_Fill_CrossRoad");
                            }
                            else
                            {
                                Array_Road[i, j] = new RoadStatus(Prefab_Number);
                            }
                        }
                    }
                }
            }
        }

        for (int i = 0; i < Road_Size; i++)
        {
            for (int j = 0; j < Road_Size; j++)
            {
                if (Array_Road[i, j] == null)
                {
                    RoadStatus[] roads = { null, null, null, null }; // ADWS
                    if (j - 1 >= 0)
                    {
                        roads[0] = Array_Road[i, j - 1];
                    }
                    if (j + 1 < Road_Size)
                    {
                        roads[1] = Array_Road[i, j + 1];
                    }
                    if (i - 1 >= 0)
                    {
                        roads[2] = Array_Road[i - 1, j];
                    }
                    if (i + 1 < Road_Size)
                    {
                        roads[3] = Array_Road[i + 1, j];
                    }

                    int index = -1;
                    for (int k = 0; k < 4; k++)
                    {
                        if (roads[k] != null)
                        {
                            if (roads[k].Is_Road() || (roads[k].Is_City() && !roads[k].bool_City))
                            {
                                index = 1;
                            }
                            else if (roads[k].Is_City())
                            {
                                index = 0;
                            }
                            else if (roads[k].Is_CrossRoad())
                            {
                                index = 2;
                            }
                        }
                    }

                    if (index == -1)
                    {
                        Debug.Log("From A From D From W From S All NULL! Error : Make_Prefab");
                    }

                    if (index == 0 || index == 2)
                    {
                        int Prefab_Number = RoadStatus.Compute_Road_Num(roads[0], roads[1], roads[2], roads[3]);
                        if (Prefab_Number == -1)
                        {
                            Debug.Log("Compute Prefab Number Loss! Error : Init_Fill_CrossRoad");
                        }
                        else
                        {
                            Array_Road[i, j] = new RoadStatus(Prefab_Number);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    void Init_Fill_CrossRoad(int Angle)
    {
        int I_Start = 0;
        int J_Start = 0;

        if (Angle == 0 || Angle == 180)
        {
            I_Start = 1;
        }
        else
        {
            J_Start = 1;
        }
        for (int i = I_Start; i < Road_Size; i += 2)
        {
            for (int j = J_Start; j < Road_Size; j += 2)
            {
                RoadStatus[] crossroads = { null, null, null, null };

                if (j - 2 >= 0)
                {
                    crossroads[0] = Array_Road[i, j - 2]; // A
                }

                if (j + 2 < Road_Size)
                {
                    crossroads[1] = Array_Road[i, j + 2];
                }

                if (i - 2 >= 0)
                {
                    crossroads[2] = Array_Road[i - 2, j];
                }

                if (i + 2 < Road_Size)
                {
                    crossroads[3] = Array_Road[i + 2, j];
                }

                RoadStatus[] roads = { null, null, null, null };

                if (j - 1 >= 0)
                {
                    roads[0] = Array_Road[i, j - 1]; // A
                }

                if (j + 1 < Road_Size)
                {
                    roads[1] = Array_Road[i, j + 1];
                }

                if (i - 1 >= 0)
                {
                    roads[2] = Array_Road[i - 1, j];
                }

                if (i + 1 < Road_Size)
                {
                    roads[3] = Array_Road[i + 1, j];
                }

                int Prefab_Number = RoadStatus.Compute_CrossRoad_Num(crossroads[0], crossroads[1], crossroads[2], crossroads[3],
                                                                     roads[0], roads[1], roads[2], roads[3]);
                if (Prefab_Number == -1)
                {
                    Debug.Log("Compute Prefab Number Loss! Error : Init_Fill_CrossRoad");
                }
                else
                {
                    Array_Road[i, j] = new RoadStatus(Prefab_Number);
                }
            }
        }
    }