예제 #1
0
파일: Port.cs 프로젝트: Volday/NPlanet
    public void Respawn()
    {
        planet = GameObject.FindGameObjectWithTag("Planet");
        ship   = planet.GetComponent <Teams>().ship;
        if (partOfPlanet.GetNeighbors()[0].teamIndex == -1)
        {
            partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[0];
        }
        else
        {
            if (partOfPlanet.GetNeighbors()[1].teamIndex == -1)
            {
                partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[1];
            }
            else
            {
                partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[2];
            }
        }

        ship              = Instantiate(ship, partOfPlanetForSpawn.GetPart().transform.position, Quaternion.identity);
        carrier           = ship.GetComponent <Ship>();
        carrier.teamIndex = teamIndex;
        ship.GetComponent <Ship>().Spawn(partOfPlanetForSpawn, this);
        planet.GetComponent <Teams>().teams[teamIndex].carriers.Add(carrier);
        carrier.rngMoveCooldown = Random.Range(1, 20);
    }
예제 #2
0
파일: Teams.cs 프로젝트: Volday/NPlanet
 public void UpdateCountriesDFS(List <PartOfPlanet> partsOfPlanetPast, Country newCountry, PartOfPlanet current)
 {
     newCountry.parts.Add(current);
     current.country = newCountry;
     partsOfPlanetPast.Add(current);
     for (int t = 0; t < current.GetNeighbors().Count; t++)
     {
         if (partsOfPlanetPast.IndexOf(current.GetNeighbors()[t]) == -1 && partsOfPlanet.IndexOf(current.GetNeighbors()[t]) != -1)
         {
             UpdateCountriesDFS(partsOfPlanetPast, newCountry, current.GetNeighbors()[t]);
         }
     }
 }
예제 #3
0
    public void MoveToTarget(GameObject target)
    {
        toMove.Clear();
        PartOfPlanet        partOfPlanetOfTarget = new PartOfPlanet();
        GameObject          planet = GameObject.FindGameObjectWithTag("Planet");
        List <PartOfPlanet> water  = planet.GetComponent <Teams>().water;
        Dictionary <PartOfPlanet, PartOfPlanet> roads = new Dictionary <PartOfPlanet, PartOfPlanet>();
        List <PartOfPlanet>  passed = new List <PartOfPlanet>();
        Queue <PartOfPlanet> qp     = new Queue <PartOfPlanet>();

        qp.Enqueue(currentPart);
        bool         alreadyFind     = false;
        PartOfPlanet currentPartAtQP = qp.Peek();

        passed.Add(currentPartAtQP);
        while (qp.Count > 0)
        {
            currentPartAtQP = qp.Dequeue();
            for (int t = 0; t < 3; t++)
            {
                if (currentPartAtQP.GetNeighbors()[t].GetPart() == target)
                {
                    alreadyFind          = true;
                    partOfPlanetOfTarget = currentPartAtQP.GetNeighbors()[t];
                    roads.Add(currentPartAtQP.GetNeighbors()[t], currentPartAtQP);
                    break;
                }
                else
                {
                    if (currentPartAtQP.GetNeighbors()[t].teamIndex == -1 && passed.IndexOf(currentPartAtQP.GetNeighbors()[t]) == -1)
                    {
                        qp.Enqueue(currentPartAtQP.GetNeighbors()[t]);
                        roads.Add(currentPartAtQP.GetNeighbors()[t], currentPartAtQP);
                        passed.Add(currentPartAtQP.GetNeighbors()[t]);
                    }
                }
            }
            if (alreadyFind)
            {
                break;
            }
        }
        if (alreadyFind)
        {
            while (true)
            {
                if (roads.ContainsKey(partOfPlanetOfTarget) && roads[partOfPlanetOfTarget] != null)
                {
                    toMove.Add(roads[partOfPlanetOfTarget]);
                    partOfPlanetOfTarget = roads[partOfPlanetOfTarget];
                }
                else
                {
                    break;
                }
            }
        }
    }
예제 #4
0
파일: wheelPort.cs 프로젝트: Volday/NPlanet
 public override void Create(PartOfPlanet partOfPlanet, int teamIndex)
 {
     if (partOfPlanet.GetNeighbors()[0].teamIndex == -1 || partOfPlanet.GetNeighbors()[1].teamIndex == -1 || partOfPlanet.GetNeighbors()[2].teamIndex == -1)
     {
         GameObject planet = GameObject.FindGameObjectWithTag("Planet");
         if (planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].money >= 100000)
         {
             planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].money -= 100000;
             portFull = planet.GetComponent <Teams>().portFull;
             GameObject created = Instantiate(portFull, partOfPlanet.GetPart().transform.position, Quaternion.identity);
             planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].buildings.Add(created.GetComponent <Building>());
             created.GetComponent <Port>().partOfPlanet = partOfPlanet;
             partOfPlanet.full     = true;
             partOfPlanet.building = created.GetComponent <Building>();
             created.GetComponent <Building>().partOfPlanet = partOfPlanet;
             created.GetComponent <Building>().teamIndex    = teamIndex;
         }
     }
 }
예제 #5
0
파일: Teams.cs 프로젝트: Volday/NPlanet
    void Start()
    {
        for (int t = 0; t < teams.Length; t++)
        {
            teams[t].material.SetColor("o", teams[t].color);
            teams[t].teamIndex = t;
        }

        PlanetFormer planetFormer = gameObject.GetComponent <PlanetFormer>();

        mainland = new List <PartOfPlanet>();
        water    = new List <PartOfPlanet>();
        for (int t = 0; t < planetFormer.partsOfPlanet.Count; t++)
        {
            water.Add(planetFormer.partsOfPlanet[t]);
        }
        Queue <PartOfPlanet> qp = new Queue <PartOfPlanet>();

        for (int t = 0; t < startPartsCount; t++)
        {
            int newIndex = Random.Range(0, planetFormer.partsOfPlanet.Count);
            if (mainland.IndexOf(planetFormer.partsOfPlanet[newIndex]) == -1)
            {
                mainland.Add(planetFormer.partsOfPlanet[newIndex]);
                water.Remove(planetFormer.partsOfPlanet[newIndex]);
                qp.Enqueue(planetFormer.partsOfPlanet[newIndex]);
            }
            else
            {
                t--;
            }
        }

        for (int t = 0; t < mainlandCount - startPartsCount; t++)
        {
            if (qp.Count > 0)
            {
                PartOfPlanet partOfPlanet   = qp.Dequeue();
                bool         neighborsCheck = false;
                for (int i = 0; i < partOfPlanet.GetNeighbors().Count; i++)
                {
                    if (mainland.IndexOf(partOfPlanet.GetNeighbors()[i]) == -1)
                    {
                        neighborsCheck = true;
                        if (Random.Range(0, 2) == 0)
                        {
                            mainland.Add(partOfPlanet.GetNeighbors()[i]);
                            water.Remove(partOfPlanet.GetNeighbors()[i]);
                            qp.Enqueue(partOfPlanet.GetNeighbors()[i]);
                        }
                        else
                        {
                            t--;
                        }
                        qp.Enqueue(partOfPlanet);
                        break;
                    }
                }
                if (!neighborsCheck)
                {
                    t--;
                }
            }
            else
            {
                break;
            }
        }

        for (int t = 0; t < teams.Length; t++)
        {
            teams[t].population = 0;
            int          rngIndex          = Random.Range(0, mainland.Count);
            PartOfPlanet startPartOfPlanet = mainland[rngIndex];
            teams[t].SetPartsOfPlanet(startPartOfPlanet, mainland, mainlandCount / teams.Length - 1, t);
        }

        for (int t = 0; t < teams.Length; t++)
        {
            for (int i = 0; i < teams[t].GetPartsOfPlanet().Count; i++)
            {
                teams[t].GetPartsOfPlanet()[i].GetPart().GetComponent <MeshRenderer>().sharedMaterial = teams[t].material;
            }
        }

        for (int t = 0; t < teams.Length; t++)
        {
            teams[t].UpdateCountries(teams);
            teams[t].countries.Clear();
        }

        for (int t = 0; t < teams.Length; t++)
        {
            teams[t].UpdateCountries(teams);
            teams[t].countries.Clear();
        }

        for (int t = 0; t < teams.Length; t++)
        {
            teams[t].UpdateCountries(teams);
        }

        for (int t = 0; t < teams.Length; t++)
        {
            teams[t].money = startMoney;
            if (t != 0)
            {
                teams[t].money -= Random.Range(1000, 15000);
            }
            for (int i = 0; i < teams[t].countries.Count; i++)
            {
                teams[t].countries[i].population = startPopulationAtPart * teams[t].countries[i].parts.Count;
                teams[t].population += startPopulationAtPart * teams[t].countries[i].parts.Count;
            }
        }

        for (int t = 0; t < teams.Length; t++)
        {
            teams[t].UpdateColor();
        }
    }