private float healthLoss; //amount of health to lose per second // Use this for initialization void Start() { // initialize resource array to correct length resources = new float[SimManager.instance.numberOfGroups]; totalResources = 0; inTrade = false; // create new resource table myValueTable = new ResourceValueTable(); // Reset wander time currentTime = timePerSearchDir; //Register this agent with the SimManager SimManager.instance.RegisterAgent(gameObject, id); // Setup the enumeration timer and health lookws = new WaitForSeconds(Random.Range(0.4f, 0.6f)); healthLoss = Random.Range(0.9f, 1.1f); // Start look around StartCoroutine(LookAround()); // Create a personal resource monitor GameObject rm = Instantiate(resourceMonitor); rm.GetComponent <ResourceMonitor>().myAgent = this; }
// Use this for initialization void Start() { // Set static variable so everything can access this instance = this; globalTableSnapshots = new List <float[, ]>(); globalTable = new ResourceValueTable(); // Ensure at least 1 group and 1 agent are in the simulation if (numberOfGroups <= 0) { numberOfGroups = 1; } if (numberOfAgentsPerGroup <= 0) { numberOfAgentsPerGroup = 1; } // Generate a new seed if one is not specified System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); if (seed == 0) { seed = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds; } // Initialize the seed and print it to the console Random.InitState(seed); print("Seed: " + seed); // Setup the appriopriate array colors = new Color[numberOfGroups]; populations = new int[numberOfGroups]; for (int j = 0; j < colors.Length; j++) // Generate colors for each group. Ensure that each colour is somewhat different. { bool validColor = false; int iter = 0; while (!validColor && iter < 100) { iter++; colors[j] = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); validColor = true; for (int k = 0; k < colors.Length; k++) { if (j == k || colors[k] == null) { continue; } else if (Vector3.Distance(new Vector3(colors[j].r, colors[j].g, colors[j].b), new Vector3(colors[k].r, colors[k].g, colors[k].b)) < 0.5f) // Treat the colours as Vector3s in order to computer difference { validColor = false; break; } } } } // Setup the rest of the simulation SpawnResources(); SpawnAgents(); }