void Initialise()
    {
        shapegenerator = new ShapeGenerator(shapesettings);
        if (meshfilters == null || meshfilters.Length == 0)
        {
            meshfilters = new MeshFilter[6];
        }
        terrainFaces = new SphereTerrain[6];

        //Vectors for positioning the Sides
        Vector3[] directions = { Vector3.up, Vector3.down, Vector3.left, Vector3.right, Vector3.forward, Vector3.back };

        //6 sides of a cube (sphere)
        for (int i = 0; i < 6; i++)
        {
            if (meshfilters[i] == null)
            {
                GameObject meshObj = new GameObject("mesh");//create a mesh
                meshObj.transform.parent = transform;

                meshObj.AddComponent <MeshRenderer>().sharedMaterial = new Material(Shader.Find("Standard"));
                meshfilters[i]            = meshObj.AddComponent <MeshFilter>();
                meshfilters[i].sharedMesh = new Mesh();
            }
            terrainFaces[i] = new SphereTerrain(shapegenerator, meshfilters[i].sharedMesh, resolution, directions[i]);
        }
    }
Esempio n. 2
0
 public Vertex(int index, Vector3 loc, SphereTerrain parent)
 {
     this.parent = parent;
     this.index  = index;
     this.vert   = loc;
     height      = 0;
     isEditable  = true;
     this.biome  = SphereTerrain.DESERT_BIOME;
     this.color  = SphereTerrain.yellows [Random.Range(0, SphereTerrain.yellows.Count)];
     resource    = null;
     neighbors   = null;
 }
Esempio n. 3
0
    bool rayHitPlane(Vector3 from, Vector3 dir, SphereTerrain sTerrain, out Vector3 hitPoint)
    {
        if (!GeometryTool.RayHitPlane(from, dir, sTerrain.getPlaneNormal(), sTerrain.getPlanePoint(), out hitPoint))
        {
            return(false);
        }

        var localHitPoint = sTerrain.transform.InverseTransformPoint(hitPoint);
        var half          = 1023.0f * 0.5f;
        var inRect        = Mathf.Abs(localHitPoint.x) < half && Mathf.Abs(localHitPoint.z) < half;

        controller.hitOnPlane.position = inRect ? hitPoint : Vector3.zero;
        return(inRect);
    }
Esempio n. 4
0
        public void Construct(ProjectileTracerView projectileTracer, SphereTerrain terrain, IFactory <Vector3, float, ProjectileInfluence> projectileInfluenceFactory,
                              Vector3 sourcePosition, Vector3 direction, float force)
        {
            this.projectileTracer           = projectileTracer;
            this.terrain                    = terrain;
            this.projectileInfluenceFactory = projectileInfluenceFactory;
            this.sourcePosition             = sourcePosition;
            this.direction                  = direction;
            this.force = force;

            transform.position = sourcePosition;
            previousPosition   = transform.position;

            projectileTracer.Clear();
            projectileTracer.AddPoint(sourcePosition);
        }
Esempio n. 5
0
    // Use this for initialization
    void Start()
    {
        if (buildingLocations == null)
        {
            buildingLocations = new List <Vertex> ();
        }
        freeBois = new List <SmolMan>();
        busyBois = new List <SmolMan>();
        if (huts == null)
        {
            huts = new List <Vertex> ();
        }
        goods = new Dictionary <string, int> ();
        SphereTerrain terrain = FindObjectOfType <SphereTerrain> ();

        setCampfireVertex(terrain.getVertex(terrain.findIndexOfNearest(gameObject.transform.position)));
        AddBois(5);
        GetComponent <TierController>().FireBuilt();
    }
Esempio n. 6
0
 void OnEnable()
 {
     behavior = (SphereTerrain)target;
 }
Esempio n. 7
0
    /// <summary>
    /// Constucts the era at the end of each tier and clears all bois of their responsabilities.
    /// </summary>
    public void ConstructEra()
    {
        myCommunity.FreeBois();
        SphereTerrain terrain = FindObjectOfType <SphereTerrain> ();

        switch (curTier)
        {
        case (1):
            //10 bois
            myCommunity.FreeBois();
            myCommunity.AddBois(5);
            //2 huts
            for (int i = 0; i < 3; i++)
            {
                Vertex v = myCommunity.ChooseNextBuildingLocation();
                if (v != null)
                {
                    terrain.buildAtIndex(v.getIndex(), "wood_house");
                    myCommunity.addHut(v);
                }
            }
            //lithic workshop
            Vertex litho = myCommunity.ChooseNextBuildingLocation();
            if (litho != null)
            {
                terrain.buildAtIndex(litho.getIndex(), "stonecraft_house");
                myCommunity.addBuilding(litho);
            }
            //well
            Vertex well = myCommunity.ChooseNextBuildingLocation();
            if (well != null)
            {
                terrain.buildAtIndex(well.getIndex(), "well");
                myCommunity.addBuilding(well);
            }
            //unlock wheat and iron
            (GameObject.Find("HUD").GetComponent(typeof(ResourceFooBar)) as ResourceFooBar).UnlockWheat();
            (GameObject.Find("HUD").GetComponent(typeof(ResourceFooBar)) as ResourceFooBar).UnlockIron();
            break;

        case (2):
            //20 bois
            for (int i = 0; i < 2; i++)
            {
                Vertex v = myCommunity.ChooseNextBuildingLocation();
                if (v != null)
                {
                    terrain.buildAtIndex(v.getIndex(), "wood_house");
                    myCommunity.addHut(v);
                }
            }
            myCommunity.FreeBois();
            myCommunity.AddBois(10);
            //granary
            Vertex granary = myCommunity.ChooseNextBuildingLocation();
            if (granary != null)
            {
                terrain.buildAtIndex(granary.getIndex(), "granary");
                myCommunity.addBuilding(granary);
            }
            //mill
            Vertex mill = myCommunity.ChooseNextBuildingLocation();
            if (mill != null)
            {
                terrain.buildAtIndex(mill.getIndex(), "windmill");
                myCommunity.addBuilding(mill);
            }
            //smelter
            Vertex smelter = myCommunity.ChooseNextBuildingLocation();
            if (smelter != null)
            {
                terrain.buildAtIndex(smelter.getIndex(), "smelter");
                myCommunity.addBuilding(smelter);
            }
            //unlock coal
            (GameObject.Find("HUD").GetComponent(typeof(ResourceFooBar)) as ResourceFooBar).UnlockCoal();
            break;

        case (3):
            //40 bois
            //2 hut
            for (int i = 0; i < 2; i++)
            {
                Vertex v = myCommunity.ChooseNextBuildingLocation();
                if (v != null)
                {
                    terrain.buildAtIndex(v.getIndex(), "wood_house");
                    myCommunity.addHut(v);
                }
            }
            myCommunity.FreeBois();
            myCommunity.AddBois(20);
            //blast furnace
            Vertex blast = myCommunity.ChooseNextBuildingLocation();
            if (blast != null)
            {
                terrain.buildAtIndex(blast.getIndex(), "blast_furnace");
                myCommunity.addBuilding(blast);
            }
            //castle
            Vertex castle = myCommunity.ChooseNextBuildingLocation();
            if (castle != null)
            {
                terrain.buildAtIndex(castle.getIndex(), "tower");
                myCommunity.addBuilding(castle);
            }
            //unlock sand
            (GameObject.Find("HUD").GetComponent(typeof(ResourceFooBar)) as ResourceFooBar).UnlockSand();
            break;

        case (4):
            //80 bois
            //3 huts
            for (int i = 0; i < 3; i++)
            {
                Vertex v = myCommunity.ChooseNextBuildingLocation();
                if (v != null)
                {
                    terrain.buildAtIndex(v.getIndex(), "wood_house");
                    myCommunity.addHut(v);
                }
            }
            myCommunity.FreeBois();
            myCommunity.AddBois(40);
            //observatory
            Vertex observatory = myCommunity.ChooseNextBuildingLocation();
            if (observatory != null)
            {
                terrain.buildAtIndex(observatory.getIndex(), "observatory");
                myCommunity.addBuilding(observatory);
            }
            //university
            Vertex university = myCommunity.ChooseNextBuildingLocation();
            if (university != null)
            {
                terrain.buildAtIndex(university.getIndex(), "temple");
                myCommunity.addBuilding(university);
            }
            //unlock copper
            (GameObject.Find("HUD").GetComponent(typeof(ResourceFooBar)) as ResourceFooBar).UnlockCopper();
            break;

        case (5):
            //160 bois
            myCommunity.FreeBois();
            myCommunity.AddBois(80);
            //factory
            Vertex factory = myCommunity.ChooseNextBuildingLocation();
            if (factory != null)
            {
                terrain.buildAtIndex(factory.getIndex(), "factory");
                myCommunity.addBuilding(factory);
            }
            //remove huts, replace
            for (int i = 0; i < myCommunity.getHuts().Count; i++)
            {
                myCommunity.getHuts() [i].removeResource();
                myCommunity.getHuts() [i].setIsEditable(true);
                terrain.buildAtIndex(myCommunity.getHuts() [i].getIndex(), "apartment");
            }
            //+ 4 more apartments
            for (int i = 0; i < 4; i++)
            {
                Vertex v = myCommunity.ChooseNextBuildingLocation();
                if (v != null)
                {
                    terrain.buildAtIndex(v.getIndex(), "apartment");
                    myCommunity.addBuilding(v);
                }
            }
            //unlock oil
            (GameObject.Find("HUD").GetComponent(typeof(ResourceFooBar)) as ResourceFooBar).UnlockOil();
            break;

        case (6):
            //320 bois
            for (int i = 0; i < 8; i++)
            {
                Vertex v = myCommunity.ChooseNextBuildingLocation();
                if (v != null)
                {
                    terrain.buildAtIndex(v.getIndex(), "apartment");
                    myCommunity.addBuilding(v);
                }
            }
            myCommunity.FreeBois();
            myCommunity.AddBois(160);
            //gas refinery
            Vertex gas = myCommunity.ChooseNextBuildingLocation();
            if (gas != null)
            {
                terrain.buildAtIndex(gas.getIndex(), "refinery");
                myCommunity.addBuilding(gas);
            }
            //labs
            Vertex lab = myCommunity.ChooseNextBuildingLocation();
            if (lab != null)
            {
                terrain.buildAtIndex(lab.getIndex(), "lab");
                myCommunity.addBuilding(lab);
            }
            //unlock deiton
            (GameObject.Find("HUD").GetComponent(typeof(ResourceFooBar)) as ResourceFooBar).UnlockDieton();
            break;

        case (7):
            //same number of bois
            Vertex launchSite = myCommunity.ChooseNextBuildingLocation();
            if (launchSite != null)
            {
                GameObject bigOlBoy   = Resources.Load("prefabs/bigspacefucker") as GameObject;
                GameObject realBigBoy = Instantiate(bigOlBoy, transform.TransformPoint(launchSite.getSphereVector() * 1.3f), Quaternion.identity);
                realBigBoy.GetComponent <Rigidbody> ().velocity = transform.TransformPoint(launchSite.getSphereVector()).normalized * 0.5f;
            }
            else
            {
                GameObject bigOlBoy   = Resources.Load("prefabs/bigspacefucker") as GameObject;
                GameObject realBigBoy = Instantiate(bigOlBoy, transform.TransformPoint(myCommunity.getCampfireVertex().getSphereVector() * 1.3f), Quaternion.identity);
                realBigBoy.GetComponent <Rigidbody> ().velocity = transform.TransformPoint(myCommunity.getCampfireVertex().getSphereVector()).normalized * 0.5f;
            }
            break;

        default:
            //5 bois
            //fire
            break;
        }
    }
Esempio n. 8
0
    public void FireBuilt()
    {
        curTier++;
        GameObject g = GameObject.Find("TierNum");

        if (g != null)
        {
            Text t = g.GetComponent <Text> ();
            if (t != null)
            {
                t.text = curTier.ToString();
            }
        }
        g = GameObject.Find("TierName");
        if (g != null)
        {
            g.GetComponent <ToggleEraText> ().ChangeEraText(curTier);
        }
        ResourceController cont    = GetComponent <ResourceController>();
        SphereTerrain      terrain = FindObjectOfType <SphereTerrain> ();

        for (int i = 0; i < terrain.vertices.Length; i++)
        {
            Vertex v = terrain.vertices[i];

            if (v.getBiome() == SphereTerrain.WATER_BIOME)
            {
                cont.WaterMade(v);
            }
            if (v.getBiome() == SphereTerrain.STONE_BIOME)
            {
                cont.StoneMade(v);
            }
            if (v.getBiome() == SphereTerrain.OIL_BIOME)
            {
                cont.OilMade(v);
            }
            if (v.getResource() != null)
            {
                if (v.getResource().name.Contains("Forest"))
                {
                    cont.TreeMade(v);
                }
                if (v.getResource().name.Contains("Sand"))
                {
                    cont.SandMade(v);
                }
                if (v.getResource().name.Contains("Wheat"))
                {
                    cont.WheatMade(v);
                }
                if (v.getResource().name.Contains("Iron"))
                {
                    cont.IronMade(v);
                }
                if (v.getResource().name.Contains("Copper"))
                {
                    cont.CopperMade(v);
                }
                if (v.getResource().name.Contains("Coal"))
                {
                    cont.CoalMade(v);
                }
            }
        }
    }
Esempio n. 9
0
    public void IncreaseTier()
    {
        if (CheckTier())
        {
            ConstructEra();
            curTier++;
            GameObject g = GameObject.Find("TierNum");
            if (g != null)
            {
                Text t = g.GetComponent <Text> ();
                if (t != null)
                {
                    t.text = curTier.ToString();
                }
            }
            g = GameObject.Find("TierName");
            if (g != null)
            {
                g.GetComponent <ToggleEraText> ().ChangeEraText(curTier);
                g.GetComponent <ToggleEraText> ().firstTimeInTier = true;
            }
            ResourceController cont    = GetComponent <ResourceController>();
            SphereTerrain      terrain = FindObjectOfType <SphereTerrain> ();
            for (int i = 0; i < terrain.vertices.Length; i++)
            {
                Vertex v = terrain.vertices[i];

                if (v.getBiome() == SphereTerrain.WATER_BIOME)
                {
                    cont.WaterMade(v);
                }
                if (v.getBiome() == SphereTerrain.STONE_BIOME)
                {
                    cont.StoneMade(v);
                }
                if (v.getBiome() == SphereTerrain.OIL_BIOME)
                {
                    cont.OilMade(v);
                }
                if (v.getResource() != null)
                {
                    if (v.getResource().name.Contains("Forest"))
                    {
                        cont.TreeMade(v);
                    }
                    if (v.getResource().name.Contains("Sand"))
                    {
                        cont.SandMade(v);
                    }
                    if (v.getResource().name.Contains("Wheat"))
                    {
                        cont.WheatMade(v);
                    }
                    if (v.getResource().name.Contains("Iron"))
                    {
                        cont.IronMade(v);
                    }
                    if (v.getResource().name.Contains("Copper"))
                    {
                        cont.CopperMade(v);
                    }
                    if (v.getResource().name.Contains("Coal"))
                    {
                        cont.CoalMade(v);
                    }
                }
            }
            //TODO: check if we want all resources present in the spheremap
            tierIncreaseEvent.Invoke();
        }
    }
Esempio n. 10
0
    void Start()
    {
        topTerrain     = this.sphereTerrains[0];
        bottomTerrain  = this.sphereTerrains[1];
        backTerrain    = this.sphereTerrains[2];
        rightTerrain   = this.sphereTerrains[3];
        forwardTerrain = this.sphereTerrains[4];
        leftTerrain    = this.sphereTerrains[5];

        instance          = this;
        drawHeightCameras = transform.parent.GetComponentsInChildren <DrawHeightCamera>();

        topCamera     = drawHeightCameras[0];
        bottomCamera  = drawHeightCameras[1];
        backCamera    = drawHeightCameras[2];
        rightCamera   = drawHeightCameras[3];
        forwardCamera = drawHeightCameras[4];
        leftCamera    = drawHeightCameras[5];

        var U = Vector2.right;
        var V = Vector2.up;

        // top
        topCamera.stitchingUp.neibhborU        = U;
        topCamera.stitchingUp.neibhborV        = V;
        topCamera.stitchingUp.neibhborOriginal = V;

        topCamera.stitchingDown.neibhborU        = U;
        topCamera.stitchingDown.neibhborV        = V;
        topCamera.stitchingDown.neibhborOriginal = -V;

        topCamera.stitchingRight.neibhborU        = V;
        topCamera.stitchingRight.neibhborV        = -U;
        topCamera.stitchingRight.neibhborOriginal = 2 * U;

        topCamera.stitchingLeft.neibhborU        = -V;
        topCamera.stitchingLeft.neibhborV        = U;
        topCamera.stitchingLeft.neibhborOriginal = -U + V;

        // back
        backCamera.stitchingUp.neibhborU        = U;
        backCamera.stitchingUp.neibhborV        = V;
        backCamera.stitchingUp.neibhborOriginal = V;

        backCamera.stitchingDown.neibhborU        = U;
        backCamera.stitchingDown.neibhborV        = V;
        backCamera.stitchingDown.neibhborOriginal = -V;

        backCamera.stitchingRight.neibhborU        = U;
        backCamera.stitchingRight.neibhborV        = V;
        backCamera.stitchingRight.neibhborOriginal = U;

        backCamera.stitchingLeft.neibhborU        = U;
        backCamera.stitchingLeft.neibhborV        = V;
        backCamera.stitchingLeft.neibhborOriginal = -U;

        // right
        rightCamera.stitchingUp.neibhborU        = -V;
        rightCamera.stitchingUp.neibhborV        = U;
        rightCamera.stitchingUp.neibhborOriginal = 2 * V;

        rightCamera.stitchingDown.neibhborU        = V;
        rightCamera.stitchingDown.neibhborV        = -U;
        rightCamera.stitchingDown.neibhborOriginal = U - V;

        rightCamera.stitchingRight.neibhborU        = -U;//修正
        rightCamera.stitchingRight.neibhborV        = -V;
        rightCamera.stitchingRight.neibhborOriginal = 2 * U + V;

        rightCamera.stitchingLeft.neibhborU        = U;
        rightCamera.stitchingLeft.neibhborV        = V;
        rightCamera.stitchingLeft.neibhborOriginal = -U;

        // left
        leftCamera.stitchingUp.neibhborU        = V;
        leftCamera.stitchingUp.neibhborV        = -U;
        leftCamera.stitchingUp.neibhborOriginal = U + V;

        leftCamera.stitchingDown.neibhborU        = -V;
        leftCamera.stitchingDown.neibhborV        = U;
        leftCamera.stitchingDown.neibhborOriginal = Vector2.zero;

        leftCamera.stitchingRight.neibhborU        = U;
        leftCamera.stitchingRight.neibhborV        = V;
        leftCamera.stitchingRight.neibhborOriginal = U;

        leftCamera.stitchingLeft.neibhborU        = -U;// 修正
        leftCamera.stitchingLeft.neibhborV        = -V;
        leftCamera.stitchingLeft.neibhborOriginal = V;

        // bottom
        bottomCamera.stitchingUp.neibhborU        = U;
        bottomCamera.stitchingUp.neibhborV        = V;
        bottomCamera.stitchingUp.neibhborOriginal = V;

        bottomCamera.stitchingDown.neibhborU        = U;
        bottomCamera.stitchingDown.neibhborV        = V;
        bottomCamera.stitchingDown.neibhborOriginal = -V;

        bottomCamera.stitchingRight.neibhborU        = -V;
        bottomCamera.stitchingRight.neibhborV        = U;
        bottomCamera.stitchingRight.neibhborOriginal = U + V;

        bottomCamera.stitchingLeft.neibhborU        = V;
        bottomCamera.stitchingLeft.neibhborV        = -U;
        bottomCamera.stitchingLeft.neibhborOriginal = Vector2.zero;

        // forward
        forwardCamera.stitchingUp.neibhborU        = U;
        forwardCamera.stitchingUp.neibhborV        = V;
        forwardCamera.stitchingUp.neibhborOriginal = V;

        forwardCamera.stitchingDown.neibhborU        = U;
        forwardCamera.stitchingDown.neibhborV        = V;
        forwardCamera.stitchingDown.neibhborOriginal = -V;

        forwardCamera.stitchingRight.neibhborU        = -U;
        forwardCamera.stitchingRight.neibhborV        = -V;
        forwardCamera.stitchingRight.neibhborOriginal = 2 * U + V;

        forwardCamera.stitchingLeft.neibhborU        = -U;
        forwardCamera.stitchingLeft.neibhborV        = -V;
        forwardCamera.stitchingLeft.neibhborOriginal = V;

        StartCoroutine(doClear());
    }
Esempio n. 11
0
 // Use this for initialization
 void Start()
 {
     maxDisabledBuffer = Random.Range(3.0f, 10.0f);
     sphere            = GameObject.Find("Planet").GetComponent <SphereTerrain>() as SphereTerrain;
     rb = GetComponent <Rigidbody>();
 }