Beispiel #1
0
    public void Start()
    {
        //calculate amount of building slots and then set new array of gameobjects with that length, needs to be at Start() to operate correctly
        nBuildingSlots = CalcBuildingSlots(module);
        buildingSlots  = new GameObject[nBuildingSlots];

        //get link to currentresources
        currentRes = GetComponent <CurrentResources>();

        //save resource and treshold multiplier arrays
        SaveResourceTresholds();
        SaveResourceMultipliers();
        currentRes.InitResources(resourceTresholds);

        //save resource storage
        SaveStorageAmounts();
        currentRes.InitStorage(storageAmount);

        //set planet sprite to current type
        GetComponent <SpriteRenderer> ().sprite = sprite;

        //start every planet as scanned and its current resources as active for easy testing, creates lag spikes every ~5s
        currentRes.isActive = true;
        isScanned           = true;
    }
Beispiel #2
0
    //setting the reference to the currentResources that called it
    public Flora(CurrentResources res)
    {
        myParentsResources = res;

        //water consumption, currently very high so testing is easier
        consumption = 0.3f;
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        scanner    = GameObject.Find("Scanner").GetComponent <SpriteRenderer> ();
        scannerCol = GameObject.Find("Scanner").GetComponent <CircleCollider2D> ();

        //audio files
        scannerAudio = GameObject.Find("Scanner").GetComponent <AudioSource> ();
        engineAudio  = GetComponent <AudioSource> ();

        //module slots
        modulePrefab      = (GameObject)Resources.Load("Module Slot");
        modSpriteSize     = modulePrefab.GetComponent <SpriteRenderer> ().size.x *transform.localScale.x;
        modDistanceBuffer = modSpriteSize / 4;
        //print ("modSpriteSize = " + modSpriteSize + ", modDistanceBuffer = " + modDistanceBuffer);
        modules = new GameObject[nModuleSlots];

        //get currentResources
        currentRes = GetComponent <CurrentResources>();

        //get empire ref
        empire = GameObject.Find("Empire").GetComponent <Empire>();

        //add ship to empire's ship list
        empire.ships.Add(this);
    }
Beispiel #4
0
        public override void Tick(float time)
        {
            base.Tick(time);

            elecResource.Add(PowerIncreaseRate * time);

            bool startElecState  = HasPower;
            bool startWaterState = HasWaterSupply;

            #region Water
            float request_water  = WaterDrain * time;
            float recieved_water = 0;

            if (CurrentResources.ContainsKey(typeof(Water)))
            {
                List <ResourceData> water = CurrentResources[typeof(Water)];
                foreach (ResourceData rData in water)
                {
                    recieved_water = rData.resource.Recieve(request_water);
                    if (request_water == recieved_water)
                    {
                        break;
                    }
                }
            }

            if (recieved_water != request_water)
            {
                //Track how long we have not had the water we requested. If its above the acceptable value we dont consider this house to have water.
                ResourceMissingTimes[1] += time;
                if (ResourceMissingTimes[1] > timeoutTime)
                {
                    HasWaterSupply = false;
                }
            }
            else
            {
                //We got the power we requested.
                ResourceMissingTimes[1] = 0;
                HasWaterSupply          = true;
            }

            if (startWaterState != HasWaterSupply)
            {
                Game.CurrentSession.TaskManager.Tasks.Enqueue(waterWarningTask);
            }
            #endregion
        }
        public override void Update(DwarfTime time)
        {
            UpdateTimer.Update(time);
            if (UpdateTimer.HasTriggered)
            {
                List <ResourceAmount> currentResources = Faction.ListResources().Values.ToList();
                bool isDifferent = CurrentResources.Count != currentResources.Count || currentResources.Where((t, i) => t.NumResources != CurrentResources[i].NumResources).Any();


                if (isDifferent)
                {
                    CurrentResources.Clear();
                    CurrentResources.AddRange(currentResources);
                    CreateResourcePanels();
                }
            }
            base.Update(time);
        }
Beispiel #6
0
        protected override void Load()
        {
            using (XmlReader reader = XmlReader.Create(resourceLocation, readerSettings))
            {
                while (reader.Read())
                {
                    if (reader.LocalName.Equals("data", StringComparison.OrdinalIgnoreCase) && reader.HasAttributes)
                    {
                        string name = reader.GetAttribute("name");

                        if (!string.IsNullOrEmpty(name) && reader.ReadToDescendant("value"))
                        {
                            CurrentResources.Add(name, reader.ReadElementContentAsString());
                        }
                    }
                }
            }
        }
Beispiel #7
0
    public void UpdateFloatingInfo()
    {
        currentRes = selectedObject.GetComponent <CurrentResources> ();

        for (int i = 0; i < infoHeaderText.Length; i++)
        {
            print("infoHeaderText[" + i + "] = " + infoHeaderText[i]);
        }

        for (int j = 0; j < infoHeaderImg.Length; j++)
        {
            print("infoHeaderImg[" + j + "] = " + infoHeaderImg[j]);
        }


        infoHeaderText[0].text = currentRes.planet.typeName;

        updateFlavorGUI();
    }
Beispiel #8
0
        protected override void Load()
        {
            ResourceManager rm;
            Type            compiledResource = Type.GetType("Resources." + resourceName + ", App_GlobalResources");

            if (compiledResource != null)
            {
                rm = new ResourceManager(compiledResource);
            }
            else
            {
                rm = new ResourceManager("Kendo.Mvc.Resources." + resourceName, GetType().Assembly);
            }

            using (ResourceSet set = rm.GetResourceSet(culture ?? CultureInfo.CurrentCulture, true, true))
            {
                var iterator = set.GetEnumerator();

                while (iterator.MoveNext())
                {
                    CurrentResources.Add(iterator.Key.ToString(), iterator.Value.ToString());
                }
            }
        }
Beispiel #9
0
    public Fauna(CurrentResources res)
    {
        myParentsResources = res;

        consumption = 0.3f;
    }
Beispiel #10
0
 //setting the reference to the currentResources that called it
 public Water(CurrentResources res)
 {
     myParentsResources = res;
     consumption        = 1;
 }
Beispiel #11
0
 //setting the reference to the currentResources that called it
 public Power(CurrentResources res)
 {
     myParentsResources = res;
 }
Beispiel #12
0
        public override void Tick(float time)
        {
            base.Tick(time);

            //Loop through each job and pay a small amount
            foreach (Job j in Jobs)
            {
                if (j.Taken)
                {
                    Game.CurrentSession.AddFunds((uint)System.Math.Floor(j.Salary.Value * commercialRate.Value));
                }
            }

            bool startElecState  = HasPower;
            bool startWaterState = HasWaterSupply;

            //Request the drain amount of each resource. If the request and recieved amount doesnt match we handle that.
            #region Electricity
            float request_electricity  = ElectricityDrain * time;
            float recieved_electricity = 0;

            if (CurrentResources.ContainsKey(typeof(Electricity)))
            {
                List <ResourceData> electricity = CurrentResources[typeof(Electricity)];
                foreach (ResourceData rData in electricity)
                {
                    recieved_electricity = rData.resource.Recieve(request_electricity);
                    if (request_electricity == recieved_electricity)
                    {
                        break;
                    }
                }
            }

            if (recieved_electricity != request_electricity)
            {
                //Track how long we have not had the power we requested. If its above the acceptable value we dont consider this house to have power.
                ResourceMissingTimes[0] += time;
                if (ResourceMissingTimes[0] > timeoutTime)
                {
                    HasPower = false;
                }
            }
            else
            {
                //We got the power we requested.
                ResourceMissingTimes[0] = 0;
                HasPower = true;
            }

            if (startElecState != HasPower)
            {
                Game.CurrentSession.TaskManager.Tasks.Enqueue(electricityWarningTask);
            }
            #endregion
            #region Water
            float request_water  = WaterDrain * time;
            float recieved_water = 0;

            if (CurrentResources.ContainsKey(typeof(Water)))
            {
                List <ResourceData> water = CurrentResources[typeof(Water)];
                foreach (ResourceData rData in water)
                {
                    recieved_water = rData.resource.Recieve(request_water);
                    if (request_water == recieved_water)
                    {
                        break;
                    }
                }
            }

            if (recieved_water != request_water)
            {
                //Track how long we have not had the water we requested. If its above the acceptable value we dont consider this house to have water.
                ResourceMissingTimes[1] += time;
                if (ResourceMissingTimes[1] > timeoutTime)
                {
                    HasWaterSupply = false;
                }
            }
            else
            {
                //We got the power we requested.
                ResourceMissingTimes[1] = 0;
                HasWaterSupply          = true;
            }

            if (startWaterState != HasWaterSupply)
            {
                Game.CurrentSession.TaskManager.Tasks.Enqueue(waterWarningTask);
            }
            #endregion
        }
Beispiel #13
0
 protected void OnMouseEnter()
 {
     carrierUI.FirstActivate(true, CurrentResources.ToString());
     // WorldUI.Instance.FirstActivate(true);
 }
Beispiel #14
0
        public override void Tick(float time)
        {
            base.Tick(time);

            if (VacantSlots == ResidentCapacity)
            {
                return;
            }

            bool startElecState  = HasPower;
            bool startWaterState = HasWaterSupply;

            //Request the drain amount of each resource. If the request and recieved amount doesnt match we handle that.
            #region Electricity
            float request_electricity  = ElectricityDrain * time;
            float recieved_electricity = 0;

            if (CurrentResources.ContainsKey(typeof(Electricity)))
            {
                List <ResourceData> electricity = CurrentResources[typeof(Electricity)];
                foreach (ResourceData rData in electricity)
                {
                    recieved_electricity = rData.resource.Recieve(request_electricity);
                    if (request_electricity == recieved_electricity)
                    {
                        break;
                    }
                }
            }

            if (recieved_electricity != request_electricity)
            {
                //Track how long we have not had the power we requested. If its above the acceptable value we dont consider this house to have power.
                ResourceMissingTimes[0] += time;
                if (ResourceMissingTimes[0] > timeoutTime)
                {
                    HasPower = false;
                }
            }
            else
            {
                //We got the power we requested.
                ResourceMissingTimes[0] = 0;
                HasPower = true;
            }

            if (startElecState != HasPower)
            {
                Game.CurrentSession.TaskManager.Tasks.Enqueue(electricityWarningTask);
            }
            #endregion
            #region Water
            float request_water  = WaterDrain * time;
            float recieved_water = 0;

            if (CurrentResources.ContainsKey(typeof(Water)))
            {
                List <ResourceData> water = CurrentResources[typeof(Water)];
                foreach (ResourceData rData in water)
                {
                    recieved_water = rData.resource.Recieve(request_water);
                    if (request_water == recieved_water)
                    {
                        break;
                    }
                }
            }

            if (recieved_water != request_water)
            {
                //Track how long we have not had the water we requested. If its above the acceptable value we dont consider this house to have water.
                ResourceMissingTimes[1] += time;
                if (ResourceMissingTimes[1] > timeoutTime)
                {
                    HasWaterSupply = false;
                }
            }
            else
            {
                //We got the power we requested.
                ResourceMissingTimes[1] = 0;
                HasWaterSupply          = true;
            }

            if (startWaterState != HasWaterSupply)
            {
                Game.CurrentSession.TaskManager.Tasks.Enqueue(waterWarningTask);
            }
            #endregion
        }
Beispiel #15
0
 //setting the reference to the currentResources that called it
 public Oxygen(CurrentResources res)
 {
     myParentsResources = res;
     consumption        = 1;
 }
Beispiel #16
0
 //setting the reference to the currentResources that called it
 public Population(CurrentResources res)
 {
     myParentsResources = res;
 }
Beispiel #17
0
    public void AttachModule(GameObject target)
    {
        print(target);
        if (target.tag == "Planet")
        {
            //save Planet component on target
            planet     = target;
            homePlanet = target.GetComponent <Planet>();
            print("homePlanet = " + homePlanet + ", homePlanet.isScanned = " + homePlanet.isScanned + ", homePlanet.nBuildingSlots = " + homePlanet.nBuildingSlots);

            //check if targetplanet has been scanned
            if (homePlanet.isScanned)
            {
                for (int n = 0; n < homePlanet.nBuildingSlots; n++)
                {
                    //if less modules have been attached then there have been iterations of the loop
                    if (homePlanet.nModulesAttached <= n)
                    {
                        //save module on planet
                        homePlanet.buildingSlots [n] = gameObject;

                        //set planet as parent
                        transform.parent = target.transform;

                        //determine new position and place, not exactly working perfectly yet
                        float angle     = n * Mathf.PI * 2f / homePlanet.nBuildingSlots;
                        float newRadius = homePlanet.planetSize * homePlanet.transform.localScale.x * 2 + spriteSize * transform.localScale.x * 2;
                        float x         = newRadius * Mathf.Cos(angle);
                        float y         = newRadius * Mathf.Sin(angle);
                        //gaat niet goed omdat module collider tegen planet botst bij plaatsing, aka berekening klopt niet.. getest door collider trigger te maken
                        transform.localPosition = new Vector2(x, y);
                        print("angle = " + angle + ", newRadius = " + newRadius + ", transform.localPosition = " + transform.localPosition + ", homePlanet.nModulesAttached = " + homePlanet.nModulesAttached);
                        print("homePlanet.planetSize = " + homePlanet.planetSize + ", spriteSize = " + spriteSize);

                        //set rotation relative to parent
                        transform.localRotation = Quaternion.Euler(0f, 0f, angle * Mathf.Rad2Deg);

                        //update module count on planet
                        homePlanet.nModulesAttached++;
                        currentRes = homePlanet.currentRes;

                        //add this module to the currentResources modList
                        homePlanet.currentRes.modList.Add(this);
                        empire.modules.Add(this);
                        empire.planets.Add(homePlanet);
                        empire.empireUIController.UpdateEmpireUI();

                        break;
                    }
                }
                hasLanded = true;
            }
        }
        if (target.tag == "Ship")
        {
            //need to check if slot is available, if not, check next one
            Ship ship   = target.GetComponent <Ship> ();
            int  nSlots = ship.nModuleSlots;
            for (int m = 0; m < nSlots; m++)
            {
                if (ship.modules [m] == null)
                {
                    //print ("!ship.modules [m]" + !ship.modules [m] + ", m = " + m);
                    //save Module on ship
                    ship.modules [m] = gameObject;

                    //set ship as parent, determine position and place
                    transform.parent        = target.transform;
                    transform.localPosition = new Vector2(-spriteSize - sizeBuffer - (m) * (spriteSize + sizeBuffer), 0);
                    transform.rotation      = new Quaternion(0, 0, 0, 0);

                    //update module count on planet, if module was landed before
                    if (hasLanded)
                    {
                        homePlanet.nModulesAttached--;
                    }

                    //set
                    currentRes = ship.currentRes;

                    break;
                }
            }

            hasLanded = false;
            //print ("Succesfully attached to ship, hasLanded = " + hasLanded);
        }
    }