Beispiel #1
0
 void DestroyTurbine()
 {
     //float price = GetComponent<PriceController>().price;
     //GameResources.removeWealth(-(price - (1 - (float)turbine.health) * price/2));
     TurbineManager.GetInstance().RemoveTurbine(turbine.gameObject);
     CloseMenu();
 }
Beispiel #2
0
    // Resource calculators
    static void updateResources(float gameDeltaTime)
    {
        TurbineManager turbManager = TurbineManager.GetInstance();

        turbManager.Update(gameDeltaTime);
        // **Update production
        production = turbManager.GetTotalProduction();

        // **Update wealth
        wealth += production * costOfElectricity * gameDeltaTime;         // Add 'sold' electricity to our wealth
        //wealth -= turbManager.GetTotalMaintenanceCosts() * gameDeltaTime; // Deduct the price of turbine maintenance

        // **Update public acceptance
        // The public gets more negative with more turbines built
        float buildingNuisance = turbManager.GetTurbineCount() * nuisanceModifier;

        publicAcceptance  = production - buildingNuisance; // Public acceptance increases with power produced
        publicAcceptance /= 100;                           // Scaling factor
        publicAcceptance  = 1.0f / (1.0f + (float)Math.Exp(-(publicAcceptance - 5.0f)));
        publicAcceptance *= 100;                           // Convert to %

        // Update time
        date = date.AddHours(gameDeltaTime);

        // wealth += 0.8f * production;
    }
Beispiel #3
0
 // Create the singletone for the TurbineManager. Also checks if there is another present and logs and error.
 void CreateSingleton()
 {
     if (instance != null)
     {
         Debug.LogError("TurbineManager already exists while it should be instantiated only once.");
         Destroy(gameObject);
         return;
     }
     instance = this;
 }
Beispiel #4
0
    float CalculateScore()
    {
        float value = 0;

        for (int i = 0; i < TurbineManager.GetInstance().GetTurbineCount(); i++)
        {
            //value += TurbineManager.GetInstance().transform.GetChild(i).GetComponent<TurbineController>().price;
        }

        double days = (GameResources.getDate() - initialDate).TotalDays;

        return(coeffWealth * GameResources.getWealth() + coeffProduction * GameResources.getProduction() + coeffValue * value + coeffTime * Convert.ToSingle(days));
    }
 void LoadTurbines()
 {
     for (int i = 0; i < TurbineManager.GetInstance().turbinePrefabs.Length; i++) // turbines array is filled through the prefab, wouldn't it be better if built through a config file?
     {
         //For each turbine, load a button for the user to select one.
         int    index   = i;
         Button turbBut = Instantiate(turbineButton); // Creates the button
         turbBut.transform.SetParent(overviewPanel.transform);
         turbBut.gameObject.GetComponentInChildren <Text>().text = TurbineManager.GetInstance().turbinePrefabs[i].name;
         turbBut.transform.localScale = Vector3.one;
         turbBut.onClick.AddListener(delegate { LoadTurbineButton(index); }); // Subscribes a method to the button for when a turbine is selected
         menuButtons.Add(turbBut);
     }
 }
    // The start method gets called first
    void Start()
    {
        // Subscribe methods buttons
        cancelButton.onClick.AddListener(Cancel);
        buildButton.onClick.AddListener(BuildButton);

        turbines    = TurbineManager.GetInstance().turbinePrefabs;
        turbineText = TurbineManager.GetInstance().turbineText;
        LoadTurbines();
        LoadOthers();
        canCancel = true;

        GetComponent <Canvas>().renderMode  = RenderMode.ScreenSpaceCamera;
        GetComponent <Canvas>().worldCamera = Camera.main.transform.GetChild(0).GetComponent <Camera>();
    }
Beispiel #7
0
    // Builder function, some class wants the world to add an object
    public void AddTurbine(GameObject t, Vector3 pos, Quaternion rotation, float scale, GridTileOccupant.OccupantType type, Transform parent)
    {
        float diameter = t.GetComponent <SizeController>().diameter;

        pos.y = BuildingHeight(pos, diameter * scale);
        t.transform.position = pos;
        t.transform.rotation = rotation;
        t.transform.SetParent(parent);
        AddToGridTiles(t, pos, diameter * scale, type);
        EqualTerrain(pos, (diameter * scale), false);
        TurbineManager turbManager = TurbineManager.GetInstance();

        turbManager.AddTurbine(t);

        if (TileInfomationMenu.instance != null && TileInfomationMenu.instance.toggle.isOn)
        {
            WindVisualizer.instance.UpdateChunks();
        }
    }
Beispiel #8
0
 void checkFirstObjectives()
 {
     if (!firstObjectivesCompleted[0])
     {
         foreach (Transform child in TurbineManager.GetInstance().transform)
         {
             firstObjectivesCompleted[0] = true;
         }
     }
     else
     {
         foreach (Transform child in TurbineManager.GetInstance().transform)
         {
             if (child.gameObject.GetComponent <TurbineController>().efficiency > 0.5)
             {
                 firstObjectivesCompleted[1] = true;
             }
         }
     }
 }
Beispiel #9
0
    float calculateFinalScore()
    {
        float result;

        result = (float)(obj2Date.Subtract(GameResources.getDate()).TotalHours) / 1000;
        //print("Score for time: " + (float)(obj2Date.Subtract(GameResources.getDate()).TotalHours) / 1000);

        foreach (Transform child in TurbineManager.GetInstance().transform)
        {
            result += child.gameObject.GetComponent <TurbineController>().efficiency * 50;
            //print("Score for turbine: " + child.gameObject.GetComponent<TurbineController>().efficiency * 50);
        }

        //print("Score for Public Acceptance: " + GameResources.getPublicAcceptance());
        result += GameResources.getPublicAcceptance();

        //print("Score for money: " + GameResources.getWealth() / 100);
        result += GameResources.getWealth() / 100;

        return(result);
    }
    void BuildNow(GridTile plantGrid, Vector3 plantPos)
    {
        if (isTurbine) // If we want to build a turbine...
        {
            curInstantiated.GetComponent <TurbineController>().enabled = true;
            world.AddTurbine(curInstantiated, plantPos, curInstantiated.transform.rotation, curInstantiated.GetComponent <SizeController>().desiredScale, GridTileOccupant.OccupantType.Turbine, TurbineManager.GetInstance().transform); // Let the world controller know we want to build this thing
            Renderer[] rens       = curInstantiated.GetComponentsInChildren <Renderer>();
            Renderer[] rensPrefab = curSelected.GetComponentsInChildren <Renderer>();
            int        count      = 0;
            foreach (Renderer ren in curInstantiated.GetComponentsInChildren <Renderer>())
            {
                foreach (Material mat in ren.materials)
                {
                    mat.shader = Shader.Find("Standard");
                    mat.color  = originalMaterial[count];
                    count++;
                }
            }
        }
        else
        {
            world.AddOther(curSelected, plantPos, curInstantiated.transform.rotation, curInstantiated.GetComponent <SizeController>().desiredScale, GridTileOccupant.OccupantType.Other, TerrainController.thisTerrainController.transform);
            Destroy(curInstantiated);
            WindVaneController windVaneController = curInstantiated.GetComponent <WindVaneController>();

            if (windVaneController != null)
            {
                windVaneController.enabled = true;
            }
        }
        GameResources.Buy(curInstantiated.GetComponent <PriceController>().price);
        curInstantiated = null;

        GameObject newObject = new GameObject();

        newObject.transform.parent = Camera.main.transform;
        AudioSource doefAudioSource = newObject.AddComponent <AudioSource>();

        doefAudioSource.clip = doef;
        doefAudioSource.Play();
        inBuildMode = false;
    }