public void LoadBases(List <SaveManager.BaseData> bases, TimeSpan difference, int totalAgents) { gameManager = GameManager.Instance; Debug.Log("Loading Bases! bases count: " + bases.Count); ResourceSpawner resourceSpawner = GameObject.Find("ResourceSpawner").GetComponent <ResourceSpawner>(); float totalRes = 0.0f; for (int i = 0; i < bases.Count; i++) { SaveManager.BaseData data = bases[i]; GameObject asset = Resources.Load("Base_" + data.baseTypeString) as GameObject; BuildBase(asset, data.position, out Base b); allBases.Add(b); b.LoadSetup(data, difference, resourceSpawner.spawnRate, totalAgents, out float maxResourcesCollected); totalRes += maxResourcesCollected; } //total available spawns float A = (100 / (resourceSpawner.spawnRate / gameManager.resourceSpawner.resourceSpawnRateUpgrade) / (float)totalAgents); float ratioAvailable = A / totalRes; if (ratioAvailable > 1.0f) { ratioAvailable = 1.0f; } else { Debug.Log("Not enough resources available for maximum returns. Upgrade Resource spawn rate!"); } //Load setup 2 needs information gathered from all bases/agents to calculate gains. for (int i = 0; i < allBases.Count; i++) { allBases[i].LoadSetupFinalize(ratioAvailable); } }
public void LoadSetup(SaveManager.BaseData bData, TimeSpan difference, float spawnRate, int totalAgents, out float maxResourceCollect) { //extract information from saved BaseData ID = bData.ID; baseName = bData.baseName; stage = bData.currentStage; baseTypeString = bData.baseTypeString; tapSeconds = bData.boostTime; heldResources = bData.heldResources; int agentsToLoad = bData.numAgents; baseStages[stage].SetActive(true); gameManager = GameManager.Instance; //resource gained should be a function of: // - Time difference, // - Num agents & move speeds, // - Spawn rate of resource, spawn rate is in seconds. // // Resources gained / 100 secs @ 1 move speed. (R) - 1.25 // Available resources per 100 sec: ((100 / spawn rate)/ gameManager.spawnrate) / (number of agents) (A) // Number of 100 sec intervals passed: time diff in seconds / 100(T) // Average resource Value(V) // // gained = T * (R * moveSpeed) * (A * V) float R = 1.4f; float A = (100 / (spawnRate / gameManager.resourceSpawner.resourceSpawnRateUpgrade) / (float)totalAgents); double t = difference.TotalSeconds / 100.0; float T = Mathf.Min((float)t, gameManager.maxPeriodInactive); float V = 5; float gain = 0.0f; maxResourceCollect = 0.0f; GameObject agentPrefab = (GameObject)Resources.Load("Agent_" + baseTypeString, typeof(GameObject)); //agents are spawned in a circle around base when loading. might be better ways to do this in the future. //e.g. spawn en-route to resources or come out of the base one-by-one. float spawnRadius = 4.0f; for (int i = 0; i < agentsToLoad; i++) { float theta = (i * (2 * Mathf.PI) / agentsToLoad); float x = transform.position.x + (spawnRadius * Mathf.Cos(theta)); float z = transform.position.z + (spawnRadius * Mathf.Sin(theta)); Vector3 newAgentPos = new Vector3(x, transform.position.y, z); AddAgent(agentPrefab, newAgentPos, out AgentGameplay a); a.setStage(stage); a.stats.SetStats(bData.agentDatas[i]); float moveSpeed = a.gameObject.GetComponent <AgentPathfinder>().moveSpeed; float agentMaxRes = R * moveSpeed; maxResourceCollect += agentMaxRes; float test = T * agentMaxRes * (/*A * */ V); Debug.Log("This agent earned max " + test + " resources while you were away!"); gain += test; } maxLoadGain = gain; //heldResource += gain; }