Exemple #1
0
        }//end SetChange

        float Exchange(int currencyID, Mnfctr cMan)
        {//go through nm and see if exchange is ok, if is then add to total, if not, return

            float needing = 0;//the cost of all of the items needed
            float making = 0;//the profit from all of the items sold

            for (int nm = 0; nm < cMan.needing.Count; nm++)
            {//go through all needing, getting min cost
                NeedMake currentNM = cMan.needing[nm];

                Goods currentGood = controller.goods[currentNM.groupID].goods[currentNM.itemID];

                float thisNeeding = currentGood.minPrice * currentNM.number * controller.GetExchangeRate(currentGood.currencyID, currencyID);

                if (thisNeeding != 0)//if is a value
                    needing += thisNeeding;//then add to the needing
                else
                    return 0;//else return 0 as currency is invalid
            }//end for needing
            for (int nm = 0; nm < cMan.making.Count; nm++)
            {//go through all making, getting max price
                NeedMake currentNM = cMan.making[nm];

                Goods currentGood = controller.goods[currentNM.groupID].goods[currentNM.itemID];

                float thisMaking = currentGood.maxPrice * currentNM.number * controller.GetExchangeRate(currentGood.currencyID, currencyID);

                if (thisMaking != 0)//if is a value
                    making += thisMaking;//then add to the making
                else
                    return 0;//else return 0 as currency is invalid
            }//end for needing

            return ((making / needing) - 1) * 100;//return the percent profit
        }//end CurrencyExchange
Exemple #2
0
        }//end Create

        void AddRemove(List<NeedMake> items, bool needing)
        {//go through all the items in the list, adding or removing them
            for (int i = 0; i < items.Count; i++)
            {//go through all items
                NeedMake cNM = items[i];
                int number = 0;
                number = cNM.number * (needing ? -1 : 1);//the number of items multiply by -1 if needing so they are removed
                stock[cNM.groupID].stock[cNM.itemID].number += number;//add or remove from post stock
                controller.UpdateAverage(cNM.groupID, cNM.itemID, number, 0);//need to update the average number of this item
            }//end for items
        }//end AddRemove
Exemple #3
0
        }//end Manfuacture Check

        bool ResourceCheck(int groupID, int processID)
        {//check that the manufacturing process has enough resources to work, and numbers are not above or below min values if option selected
            Mnfctr cMan = controller.manufacture[groupID].manufacture[processID];

            for (int n = 0; n < cMan.needing.Count; n++)
            {//go through all needing
                NeedMake cCheck = cMan.needing[n];
                int quant = items[cCheck.groupID].items[cCheck.itemID].number;

                if (quant < cCheck.number)//if not enough
                    return false;//then return false as it cannot be made
            }//end for needing

            if ((spaceRemaining + cMan.needingMass - cMan.makingMass) < 0)//check that has enough space to be able to manufacture
                return false;

            //if has managed to pass all of the checks
            return true;//return true as the process can be done
        }//end ResourceCheck
Exemple #4
0
        }//end ManfuactureCheck

        bool ResourceCheck(int groupID, int processID)
        {//check that the manufacturing process has enough resources to work, and numbers are not above or below min values if option selected
            Mnfctr cProcess = controller.manufacture[groupID].manufacture[processID];
            List<NeedMake> check = cProcess.needing;//check the needing list
            for (int n = 0; n < check.Count; n++)
            {//go through all needing
                NeedMake cCheck = check[n];
                Stock cStock = stock[cCheck.groupID].stock[cCheck.itemID];
                if (cStock.number < cCheck.number || (cStock.minMax && stopProcesses && cStock.number <= cStock.min))//if not enough, or has below minimum with stop processes enabled
                    return false;//then return false as it cannot be made
            }//end for needing

            check = cProcess.making;//check the making list
            for (int m = 0; m < check.Count; m++)
            {//go through all making
                NeedMake cCheck = check[m];
                Stock cStock = stock[cCheck.groupID].stock[cCheck.itemID];
                if (cStock.minMax && stopProcesses && cStock.number >= cStock.max)//if already has too many items, and has stop processes enabled
                    return false;//then return false as it cannot be made
            }//end for making
             //if has managed to pass all of the checks
            return true;//return true as the process can be done
        }//end ResourceCheck
Exemple #5
0
				}//end Spawn
				
				void Create (NeedMake chosen, GameObject crate, int number)
				{//create the spawned items
								
						GameObject spawned = (GameObject)GameObject.Instantiate (crate);
						
						switch (shapeOption) {//start a switch with the different spawn area options
						case 0://sphere
								spawned.transform.position = Random.insideUnitSphere * maxDist;
								break;
						case 1://circle
								spawned.transform.position = Random.insideUnitCircle * maxDist;
								break;
						case 2://cube
								spawned.transform.position = new Vector3 (RandomLength (maxDist), RandomLength (maxDist), RandomLength (maxDist));
								break;
						case 3://square
								spawned.transform.position = new Vector3 (RandomLength (maxDist), RandomLength (maxDist), 0);
								break;
						}//end switch
						
						spawned.transform.position = transform.position + transform.rotation * Vector3.Scale(spawned.transform.position, transform.lossyScale);
						//sort out position relating to spawner position and rotation
				
						spawned.transform.parent = transform;//set the spawned item to be under the spawner
						spawned.name = controller.goods [chosen.groupID].goods [chosen.itemID].name + "\u00D7" + number.ToString ();
			
						Item spawnedScript = spawned.GetComponent<Item> ();//get the item script
			
						//need to set the group and item IDs as some items may share a crate
						spawnedScript.groupID = chosen.groupID;//set the groupID
						spawnedScript.itemID = chosen.itemID;//set the itemID	
						spawnedScript.number = number;//set the number of this item
						spawnedScript.traderCollect = traderCollect;//set the trader collect to the one set in the editor
						spawnedScript.spawned = true;//let the item know that it was spawned
						
						ChangeCount(number, true);
				}//end Create
Exemple #6
0
				}//end Awake
	
				IEnumerator Spawn ()
				{//spawn an item
						yield return new WaitForSeconds (Random.Range (minTime, maxTime));//pause for a time before spawning
						if (count < maxSpawn || maxSpawn == 0) {//check can spawn a new item
								
								int cG = Random.Range (0, canSpawn.Count);//the chosen group
								NeedMake chosen = canSpawn [cG] [Random.Range (0, canSpawn [cG].Count)];
								
								GameObject crate = controller.goods [chosen.groupID].goods [chosen.itemID].itemCrate;
								
								if (crate == null)//check that there is a crate
										Debug.LogError (controller.goods [chosen.groupID].goods [chosen.itemID].name + " does not have a crate and no default crate has been specified!");
								else {//only create if crate exists
										int toSpawn = Random.Range (min, max + 1);//spawn a number of items
								
										if (diffItems) {
												for (int s = 0; s<toSpawn; s++)
														Create (chosen, crate, 1);//spawn each item individually
										} else //else all in one
												Create (chosen, crate, toSpawn);//else can increase the number
								}//end creating item								
						}//end number check
						StartCoroutine (Spawn ());//spawn a new item
				}//end Spawn