Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. public void MyProcessWorker(float gather, float buildBase, float buildBarracks)
  2.         {
  3.             float gatherVal = gather;
  4.             float buildBaseVal = buildBase;
  5.             float buildBarracksVal = buildBarracks;
  6.  
  7.             //makes list and adds the heuristic values to determine choice
  8.             List<float> list = new List<float>();
  9.             list.Add(gatherVal);
  10.             list.Add(buildBaseVal);
  11.             list.Add(buildBarracksVal);
  12.  
  13.             //sets highest value as the action to do
  14.             float highestOption = list.Max();
  15.  
  16.             Unit baseUnit = GameManager.Instance.GetUnit(mainBaseNbr);
  17.             Unit mineUnit = GameManager.Instance.GetUnit(mainMineNbr);
  18.  
  19.             //For each worker
  20.             foreach (int worker in myWorkers)
  21.             {
  22.                 //Grab the unit we need for this function
  23.                 Unit unit = GameManager.Instance.GetUnit(worker);
  24.  
  25.                 //Make sure this unit actually exists and is idle
  26.                 if (unit != null && unit.CurrentAction == UnitAction.IDLE)
  27.                 {
  28.                     //If buildBaseVal is highest
  29.                     if (highestOption == buildBaseVal)
  30.                     {
  31.                         if(mainMineNbr >= 0)
  32.                         {
  33.                             if(mineUnit != null)
  34.                             {
  35.                                 //Find the closest build position to the mine and build the base there
  36.                                 Vector3Int toBuild = FindClosestBuildPosition(mineUnit.GridPosition, UnitType.BASE);
  37.                                 if (toBuild != Vector3Int.zero)
  38.                                 {
  39.                                     Build(unit, toBuild, UnitType.BASE);
  40.                                 }
  41.                             }                        
  42.                         }
  43.                     }
  44.                     //If buildBarracksVal is highest
  45.                     else if (highestOption == buildBarracksVal)
  46.                     {
  47.                         if(mainBaseNbr >= 0)
  48.                         {
  49.                             if(baseUnit != null)
  50.                             {
  51.                                 //Find the closest build position to the base and build the barracks there
  52.                                 Vector3Int toBuild = FindClosestBuildPosition(baseUnit.GridPosition, UnitType.BARRACKS);
  53.                                 if (toBuild != Vector3Int.zero)
  54.                                 {
  55.                                     Build(unit, toBuild, UnitType.BARRACKS);
  56.                                 }
  57.                             }                        
  58.                         }                    
  59.                     }
  60.                     //If gatherVal is highest
  61.                     else if (highestOption == gatherVal)
  62.                     {
  63.                         if(mainBaseNbr >= 0 && mainMineNbr >= 0)
  64.                         {
  65.                             if (baseUnit != null && mineUnit != null)
  66.                             {
  67.                                 Gather(unit, mineUnit, baseUnit);
  68.                             }
  69.                         }                    
  70.                     }
  71.                 }
  72.             }
  73.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement