Example #1
0
    public void CreateWorldMeshes(World world)
    {
        GameObject pointObject = Instantiate(PointPrefab);                          //instantiate one point prefab

        Vector3[] verts   = pointObject.GetComponent <MeshFilter>().mesh.vertices;  //get its mesh verts
        int[]     indices = pointObject.GetComponent <MeshFilter>().mesh.triangles; //get its triangles

        for (int y = 0; y < 180; y++)
        {
            for (int x = 0; x < 360; x++)
            {
                InfectionPoint point = world.infectionPoints[y][x];
                if (point != null)
                {
                    point.vertIndex = vertIndex;
                    vertIndex      += verts.Length;
                    AppendPointVertices(pointObject, verts, indices, point);
                    if (meshVertices.Count + verts.Length > 65000) //once we get past 65k, cut an object
                    {
                        CreateObject();
                    }
                }
            }
        }

        CreateObject();
        Destroy(pointObject);
        isReady = true;
    }
Example #2
0
    private void LoadInfectionPoints()
    {
        CountryData[] countries = loader.LoadJSON("WorldData").Countries;
        foreach (CountryData countryData in countries)
        {
            foreach (CountryPoint countryPoint in countryData.Points)
            {
                InfectionPoint pt = Instantiate(infectionPointPrefab, gameObject.transform);
                infectionPoints[countryPoint.y + 90][countryPoint.x + 180] = pt;

                pt.x               = countryPoint.x;
                pt.y               = countryPoint.y;
                pt.infection       = countryPoint.infection;
                pt.population      = countryPoint.population;
                pt.totalPopulation = (long)(totalPopulation * pt.population * .006f);
                pt.countryName     = countryData.Name;
                pt.regionName      = countryData.RegionName;
                pt.world           = this;
                pt.healthCare      = countryPoint.healthCare - 0.1f;
                pt.adjacentInfectionPointIndexes = GetAdjacentInfectionPointIndexes(countryPoint.x + 180, countryPoint.y + 90);
                pt.temperatureFactor             = (Mathf.Abs(Mathf.Abs(pt.y) - 45f) / 45f) * .25f; //should be range from 0 to .25
                pt.isAirport = countryPoint.isAirport;
                if (pt.isAirport)
                {
                    airports.Add(pt);
                }
            }
        }
        globe.CreateWorldMeshes(this);
    }
Example #3
0
    void LaunchAirplane()
    {
        float airplaneRoll = Random.Range(0f, population);

        if (airplaneRoll >= airplaneTravelChance * population)
        {
            return;
        }

        InfectionPoint destination = world.GetRandomAirport();

        if (destination != null)
        {
            Airplane airplane = Instantiate(airplanePrefab, world.globe.Earth.transform);
            airplane.globe       = world.globe;
            airplane.source      = this;
            airplane.destination = destination;
            //Debug.Log("Airplane has taken off from " + countryName + " bound for " + destination.countryName);
            if (Random.value < infection && virus != null)
            {
                airplane.Infect(virus);
                Debug.Log("INFECTED! Airplane");
            }
            airplane.TakeOff();
        }
    }
Example #4
0
 private void InfectionPoint_OnInfectionPointUpdated(InfectionPoint point)
 {
     if (globe.isReady)
     {
         //UnityEngine.Debug.Log(point.infectedPopulationDelta + " infected in " + point.countryName + ". New Total: " + point.infectedPopulation + "(" + point.infection + ")");
         infectedPopulation += point.infectedPopulationDelta;
         globe.UpdateInfectionPointColor(point);
     }
 }
Example #5
0
    // Use this for initialization
    void Start()
    {
        for (int y = 0; y < 180; y++)
        {
            infectionPoints[y] = new InfectionPoint[360];
        }

        InfectionPoint.OnInfectionPointUpdated += InfectionPoint_OnInfectionPointUpdated;
        LoadInfectionPoints();
    }
Example #6
0
 private void InfectionPoint_OnInfectionPointUpdated(InfectionPoint point)
 {
     if (infectedCountries.Count == 0)
     {
         AddNewsFeed("A new virus has been introduced in " + point.countryName);
     }
     if (!infectedCountries.Contains(point.countryName))
     {
         AddNewsFeed("The virus has spread to " + point.countryName);
         infectedCountries.Add(point.countryName);
     }
 }
Example #7
0
    void InfectAdjacent()
    {
        float adjacentRoll = Random.Range(0f, population);

        if (adjacentRoll >= adjacentTravelChance * population * infection)
        {
            return;
        }

        int            travelPoint   = Random.Range(0, adjacentInfectionPointIndexes.Count - 1);
        int            y             = adjacentInfectionPointIndexes[travelPoint] / 360;
        int            x             = adjacentInfectionPointIndexes[travelPoint] % 360;
        InfectionPoint adjacentPoint = world.infectionPoints[y][x];

        if (adjacentPoint != null)
        {
            adjacentPoint.Infect(virus);
        }
    }
Example #8
0
    public void UpdateInfectionPointColor(InfectionPoint point)
    {
        if (point == null)
        {
            return;
        }

        Color      newColor    = Colors.Evaluate(point.Infection);
        int        objectIndex = (point.vertIndex / 65000);                                       //which object is it in
        VertGroup  vertGroup   = EarthVertGroupParent.transform.GetChild(objectIndex).GetComponent <VertGroup>();
        GameObject obj         = EarthVertGroupParent.transform.GetChild(objectIndex).gameObject; //get the object it is in
        int        indexStart  = point.vertIndex % 65000;

        Color[] colors = vertGroup.colors;
        for (int i = indexStart; i < indexStart + 20; i++)
        {
            colors[i] = newColor;
        }
        vertGroup.colors = colors;
    }
Example #9
0
    public InfectionPoint GetRandomInfectionPoint(string RegionName)
    {
        List <InfectionPoint> countryPoints = new List <InfectionPoint>();

        for (int y = 0; y < 180; y++)
        {
            for (int x = 0; x < 360; x++)
            {
                InfectionPoint p = infectionPoints[y][x];

                if (p != null && p.regionName == RegionName)
                {
                    countryPoints.Add(p);
                }
            }
        }

        if (countryPoints.Count > 0)
        {
            return(countryPoints[UnityEngine.Random.Range(0, countryPoints.Count)]);
        }

        return(null);
    }
Example #10
0
 private void SetPosition(InfectionPoint point)
 {
     transform.localPosition = globe.GetGlobePosition(point.x, point.y) * 1.01f;
     transform.localRotation = Quaternion.LookRotation(transform.localPosition, globe.Earth.transform.up);
     transform.Rotate(new Vector3(0, 90, 0));
 }
Example #11
0
    private void AppendPointVertices(GameObject pointObject, Vector3[] verts, int[] indices, InfectionPoint infectionPoint)
    {
        Color   valueColor    = Colors.Evaluate(infectionPoint.Infection);
        Vector3 pos           = GetGlobePosition(infectionPoint.x, infectionPoint.y);
        int     prevVertCount = meshVertices.Count;

        pointObject.transform.parent     = Earth.transform;
        pointObject.transform.position   = pos;
        pointObject.transform.localScale = new Vector3(1, 1, Mathf.Max(0.001f, infectionPoint.population * ValueScaleMultiplier));
        pointObject.transform.LookAt(pos * 2);

        for (int k = 0; k < verts.Length; k++)
        {
            meshVertices.Add(pointObject.transform.TransformPoint(verts[k]));
            meshColors.Add(valueColor);
        }

        for (int k = 0; k < indices.Length; k++)
        {
            meshIndices.Add(prevVertCount + indices[k]);
        }
    }