@@ -26,11 +26,18 @@ public class AIController : MonoBehaviour
2626
2727 private bool _firstCommandsPassed = false ;
2828
29+ /// <summary>
30+ /// Starts a Coroutine, that will handle the first few seconds of the game.
31+ /// </summary>
2932 private void Start ( )
3033 {
3134 StartCoroutine ( FirstCommands ( ) ) ;
3235 }
3336
37+ /// <summary>
38+ /// This method handles the first few seconds of the game and will make the AI send its first three units to the near resource points. Then the normal decision making will take over.
39+ /// </summary>
40+ /// <returns>IEnumerator</returns>
3441 private IEnumerator FirstCommands ( )
3542 {
3643 yield return new WaitForSeconds ( 1 ) ;
@@ -48,17 +55,9 @@ private IEnumerator FirstCommands()
4855 _firstCommandsPassed = true ;
4956 }
5057
51- private bool AreNearPointsCaptured ( )
52- {
53- bool result = true ;
54- foreach ( var point in nearResourcePoints )
55- {
56- if ( point . ownerTeam != 2 ) result = false ;
57- }
58-
59- return result ;
60- }
61-
58+ /// <summary>
59+ /// Calls the methods for decision making and unit building.
60+ /// </summary>
6261 private void Update ( )
6362 {
6463 if ( _firstCommandsPassed )
@@ -68,6 +67,10 @@ private void Update()
6867 UnitBuilding ( ) ;
6968 }
7069
70+ /// <summary>
71+ /// The heart of this AIController. Here all decisions throughout the game are made.
72+ /// </summary>
73+ /// <remarks>The AI has a list of priorities. They are marked in the code with comments as well as properly explained in an wiki article in the Github repository.</remarks>
7174 private void DecisionMaking ( )
7275 {
7376 Unit closestUnit = GetClosestEnemyUnit ( ) ;
@@ -130,7 +133,11 @@ private void DecisionMaking()
130133 SendTroopsAgainst ( enemyBase ) ;
131134 }
132135 }
133-
136+
137+ /// <summary>
138+ /// This method gets called the get the closest enemy/player unit.
139+ /// </summary>
140+ /// <returns>The enemy/player unit which is closest to the AIs base.</returns>
134141 private Unit GetClosestEnemyUnit ( )
135142 {
136143 Unit closestUnit = null ;
@@ -151,6 +158,10 @@ private Unit GetClosestEnemyUnit()
151158 return closestUnit ;
152159 }
153160
161+ /// <summary>
162+ /// Sends all currently inactive AI troops to a point on the map.
163+ /// </summary>
164+ /// <param name="destination">The point on the map the units should head towards.</param>
154165 private void SendTroopsToPosition ( Vector3 destination )
155166 {
156167 List < Unit > inactiveUnits = GetAllCurrentlyInactiveUnits ( ) ;
@@ -165,6 +176,10 @@ private void SendTroopsToPosition(Vector3 destination)
165176 }
166177 }
167178
179+ /// <summary>
180+ /// Sends all currently inactive AI troops against a specific enemy.
181+ /// </summary>
182+ /// <param name="enemy">Reference to the enemy that should be attacked.</param>
168183 private void SendTroopsAgainst ( HealthEntity enemy )
169184 {
170185 List < Unit > inactiveUnits = GetAllCurrentlyInactiveUnits ( ) ;
@@ -175,6 +190,11 @@ private void SendTroopsAgainst(HealthEntity enemy)
175190 }
176191 }
177192
193+ /// <summary>
194+ /// Determines a list of all currently inactive units.
195+ /// </summary>
196+ /// <remarks>Inactive means, that the unit is currently not moving and not in combat.</remarks>
197+ /// <returns>List of the currently inactive units.</returns>
178198 private List < Unit > GetAllCurrentlyInactiveUnits ( )
179199 {
180200 List < Unit > inactiveUnits = new List < Unit > ( ) ;
@@ -189,26 +209,47 @@ private List<Unit> GetAllCurrentlyInactiveUnits()
189209 return inactiveUnits ;
190210 }
191211
212+ /// <summary>
213+ /// Helper function that adds a unit to the AIs list of own units.
214+ /// </summary>
215+ /// <param name="unit">The unit that should be added to the list.</param>
192216 public void AddOwnUnit ( Unit unit )
193217 {
194218 ownUnits . Add ( unit ) ;
195219 }
196220
221+ /// <summary>
222+ /// Helper function that removes a unit to the AIs list of own units.
223+ /// </summary>
224+ /// <param name="unit">The unit that should be removed from the list.</param>
197225 public void RemoveOwnUnit ( Unit unit )
198226 {
199227 ownUnits . Remove ( unit ) ;
200228 }
201229
230+ /// <summary>
231+ /// Helper function that adds a unit to the AIs list of enemy units.
232+ /// </summary>
233+ /// <param name="unit">The unit that should be added to the list.</param>
202234 public void AddEnemyUnit ( Unit unit )
203235 {
204236 enemyUnits . Add ( unit ) ;
205237 }
206238
239+ /// <summary>
240+ /// Helper function that removes a unit to the AIs list of enemy units.
241+ /// </summary>
242+ /// <param name="unit">The unit that should be removed from the list.</param>
207243 public void RemoveEnemyUnit ( Unit unit )
208244 {
209245 enemyUnits . Remove ( unit ) ;
210246 }
211247
248+ /// <summary>
249+ /// Checks for a not captured resource point near the AI base.
250+ /// </summary>
251+ /// <remarks>The near resource points are the ones behind the AI base and the one in the middle. </remarks>
252+ /// <returns>The resource point that should be captured next.</returns>
212253 private ResourcePoint GetNextNearResourcePoint ( )
213254 {
214255 foreach ( ResourcePoint rPoint in nearResourcePoints )
@@ -218,6 +259,12 @@ private ResourcePoint GetNextNearResourcePoint()
218259
219260 return null ;
220261 }
262+
263+ /// <summary>
264+ /// Checks for a not captured resource point near the player base.
265+ /// </summary>
266+ /// <remarks>The near resource points are the ones behind the player base. </remarks>
267+ /// <returns>The resource point that should be captured next.</returns>
221268 private ResourcePoint GetNextFarResourcePoint ( )
222269 {
223270 foreach ( ResourcePoint rPoint in farResourcePoints )
@@ -228,6 +275,12 @@ private ResourcePoint GetNextFarResourcePoint()
228275 return null ;
229276 }
230277
278+ /// <summary>
279+ /// Checks if there are enemies on a resource point.
280+ /// </summary>
281+ /// <remarks>If there are indeed enemies on a point, those enemies should be killed first.</remarks>
282+ /// <param name="resourcePoint"></param>
283+ /// <returns>The first enemy unit on the resource point.</returns>
231284 private Unit CheckForEnemiesOnResourcePoint ( ResourcePoint resourcePoint )
232285 {
233286 foreach ( var enemyUnit in enemyUnits )
@@ -241,6 +294,10 @@ private Unit CheckForEnemiesOnResourcePoint(ResourcePoint resourcePoint)
241294 return null ;
242295 }
243296
297+ /// <summary>
298+ /// Builds the unit that is next in line to be build.
299+ /// </summary>
300+ /// <remarks>The logic that determines which unit should be build next is AIController.FindNExtUnitToBuild()</remarks>
244301 private void UnitBuilding ( )
245302 {
246303 switch ( nextUnitToBuild )
0 commit comments