Esempio n. 1
0
        void OnEnable()
        {
            controllerNormal = GameObject.FindGameObjectWithTag(Tags.C).GetComponent<Controller>();
            controllerSO = new SerializedObject(controllerNormal);

            postSO = new SerializedObject(targets);
            postNormal = (TradePost)target;
            postNormal.tag = Tags.TP;

            sel = controllerNormal.selected.P;
            showLinks = controllerSO.FindProperty("showLinks");
            smallScroll = controllerSO.FindProperty("smallScroll");

            scrollPos = controllerNormal.scrollPos;

            stock = postSO.FindProperty("stock");
            controllerGoods = controllerSO.FindProperty("goods");
            currencies = postSO.FindProperty("currencies");
            exchanges = postSO.FindProperty("exchanges");
            manufacturing = postSO.FindProperty("manufacture");
            controllerMan = controllerSO.FindProperty("manufacture");
            customPricing = postSO.FindProperty("customPricing");

            stopProcesses = postSO.FindProperty("stopProcesses");
            allowTrades = postSO.FindProperty("allowTrades");
            allowMan = postSO.FindProperty("allowManufacture");

            GUITools.GetNames(controllerNormal);
            GUITools.ManufactureInfo(controllerNormal);

            expendable = controllerNormal.expTraders.enabled;

            if (!Application.isPlaying)//only do this if it isnt playing
                controllerNormal.SortAll();
        }//end OnEnable
Esempio n. 2
0
		Controller controller;//the controller
	
		// Use this for initialization
		void Start () {
			controller = GameObject.FindGameObjectWithTag (Tags.C).GetComponent<Controller> ();
			Random.InitState(seed);//set the seed
			#region posts
			for (int n = 0; n<numberOfPosts; n++) {//add new posts, setting them up   
				TradePost newPost = GameObject.CreatePrimitive (PrimitiveType.Sphere).AddComponent<TradePost> ();//create the sphere
				newPost.transform.position = Random.insideUnitSphere * sphereRadius;//set the position
				newPost.transform.parent = GameObject.Find ("Posts").transform;//set the parent, so doesnt fill hierarchy
				newPost.name = "Trade Post " + (n + 1);//set the name so is easier to find any later
				controller.SortTradePost(newPost);//sort the new post information

                for (int c = 0; c < controller.currencies.Count; c++)//go through each currency and give a random ammount
                    newPost.currencies[c] = Random.Range(minCurrency, maxCurrency);
			
				for (int g = 0; g<controller.goods.Count; g++) {//go through all groups
					for (int s = 0; s<controller.goods[g].goods.Count; s++)//go through all goods
						newPost.stock [g].stock [s].number = Random.Range (minItems, maxItems);//set the number of items. dont need to add because is sorted in the trade post script
				}//end for groups
			
				for (int m = 0; m<controller.manufacture.Count; m++) {//go through all manufacture groups
					for (int p = 0; p<controller.manufacture[m].manufacture.Count; p++) {//go through all processes
						int random = Random.Range (-50, 20);//create a random number which can be negative so may not be enabled
						if (random > 0) {//if greater than 0, enable this manufacture process
							newPost.manufacture [m].manufacture [p].enabled = true;
							newPost.manufacture [m].manufacture [p].create = random;//set the create time to the random time just generated
							newPost.manufacture [m].manufacture [p].cooldown = Random.Range (0, 30);//generate another random time for cooldown
						}//end if > 0
					}//end for processes
				}//end for manufacture groups
				
				SortTags(newPost.gameObject, true);//sort factions
				SortTags(newPost.gameObject, false);//sort groups
			}//end for new posts
			#endregion
			controller.GetPostScripts ();
			#region traders
			for (int n = 0; n<numberOfTraders; n++) {//add new traders, setting them up
				Trader newTrader = GameObject.CreatePrimitive (PrimitiveType.Cube).AddComponent<Trader> ();//create the cube
				newTrader.gameObject.AddComponent<TSTraderAI>();//add the trader AI
				int random = Random.Range (0, controller.tradePosts.Length);//select the starting trade post from all of the trade posts
				GameObject targetPost = controller.tradePosts [random];//set the start post
				newTrader.transform.position = targetPost.transform.position;//set the position to the start trade post
				newTrader.target = targetPost;//set the target of the trader to the starting trade post
				newTrader.transform.parent = GameObject.Find ("Traders").transform;//set the parent, so doesnt fill hierarchy
				newTrader.name = "Trader " + (n + 1);//set the name so is easier to find any later
			
				newTrader.closeDistance = 0.3f;//set the close distance
				newTrader.transform.localScale = new Vector3 (0.25f, 0.25f, 0.25f);//scale the cubes so they are smaller than the trade post spheres

                for (int c = 0; c < controller.currencies.Count; c++)//go through each currency and give a random ammount
                    newTrader.currencies[c] = Random.Range(minCurrency, maxCurrency);

                SortTags(newTrader.gameObject, true);
			}//end for new traders
			#endregion

			controller.GenerateDistances ();//added all the posts and traders, now needs to get distances
			//without the line above, TradeSys will not do anything!
			
		}//end Start
Esempio n. 3
0
    }//end Update

    bool CheckPos()
    {//Check if there are any trade posts within close distance
        Collider[] nearbyObjects = Physics.OverlapSphere(this.transform.position, closeDistance);

        for (int n = 0; n < nearbyObjects.Length; n++)
        {//go through nearby objects and see if they have the trade post tag
            if (nearbyObjects[n].tag == CallumP.TradeSys.Tags.TP)
            {//check has the trade post tag
                nearPost = nearbyObjects[n].GetComponent<CallumP.TradeSys.TradePost>();//set the near post to the trade post script
                return true;//return true so doesnt go through the rest of the nearby objects
            }
            else if (nearbyObjects[n].tag == CallumP.TradeSys.Tags.I && controller.pickUp)
            {//if item tag and allowed to collect
                nearItem = nearbyObjects[n].GetComponent<CallumP.TradeSys.Item>();//set the near item to this
                return false;//needs to return false so is not seen to be at a trade post
            }//end if item
        }//end for all nearby objects
        return false;//return false as has not found anything
    }//end CheckPos
Esempio n. 4
0
        }//end ChangeTradeHome

        public void ChangeTraderHome(TradePost post)
        {//used to change which trade post appears as the home post. Only useful for depots
            homeID = controller.GetPostID(post.gameObject);
        }//end ChangeTradeHome