Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void MyProcessWorker(float gather, float buildBase, float buildBarracks)
- {
- float gatherVal = gather;
- float buildBaseVal = buildBase;
- float buildBarracksVal = buildBarracks;
- //makes list and adds the heuristic values to determine choice
- List<float> list = new List<float>();
- list.Add(gatherVal);
- list.Add(buildBaseVal);
- list.Add(buildBarracksVal);
- //sets highest value as the action to do
- float highestOption = list.Max();
- Unit baseUnit = GameManager.Instance.GetUnit(mainBaseNbr);
- Unit mineUnit = GameManager.Instance.GetUnit(mainMineNbr);
- //For each worker
- foreach (int worker in myWorkers)
- {
- //Grab the unit we need for this function
- Unit unit = GameManager.Instance.GetUnit(worker);
- //Make sure this unit actually exists and is idle
- if (unit != null && unit.CurrentAction == UnitAction.IDLE)
- {
- //If buildBaseVal is highest
- if (highestOption == buildBaseVal)
- {
- if(mainMineNbr >= 0)
- {
- if(mineUnit != null)
- {
- //Find the closest build position to the mine and build the base there
- Vector3Int toBuild = FindClosestBuildPosition(mineUnit.GridPosition, UnitType.BASE);
- if (toBuild != Vector3Int.zero)
- {
- Build(unit, toBuild, UnitType.BASE);
- }
- }
- }
- }
- //If buildBarracksVal is highest
- else if (highestOption == buildBarracksVal)
- {
- if(mainBaseNbr >= 0)
- {
- if(baseUnit != null)
- {
- //Find the closest build position to the base and build the barracks there
- Vector3Int toBuild = FindClosestBuildPosition(baseUnit.GridPosition, UnitType.BARRACKS);
- if (toBuild != Vector3Int.zero)
- {
- Build(unit, toBuild, UnitType.BARRACKS);
- }
- }
- }
- }
- //If gatherVal is highest
- else if (highestOption == gatherVal)
- {
- if(mainBaseNbr >= 0 && mainMineNbr >= 0)
- {
- if (baseUnit != null && mineUnit != null)
- {
- Gather(unit, mineUnit, baseUnit);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement