MaximilianPs

Faction System

Jul 15th, 2021 (edited)
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. private void initFactions()
  2.     {
  3.         ///<summary>
  4.         /// ==== DEEP EXPLAINATION ================================================================
  5.         ///
  6.         ///  I'VE USED A DATATABLE !
  7.         ///
  8.         /// To avoid redundant datas, we will avoid to have
  9.         /// TownA - TownB 30
  10.         /// TownB - TownA 40
  11.         /// do to so, indeed we need that the value from A and B still the same,
  12.         /// At each cycle we will move the pointer forward so:
  13.         /// Pesaro, will check Fano and Gabicce.
  14.         /// next cycle, Fano will check just Gabicce, 'cause Pesaro already have a relation with Fano.
  15.         /// On the next Gabicce, will check nothing 'cause Gabicce already have a relation with Pesaro and Fano!
  16.         /// </summary>
  17.         int counter = Towns.Count;
  18.         int x = 0;
  19.         foreach (var faction in FactionsNames)
  20.         {
  21.             if (faction == Towns[counter-1].name)
  22.                 break;
  23.  
  24.             for (int t = x; t < counter; t++)
  25.             {
  26.                 // We didn't set the last town because all relationship are alreayd set.
  27.                 if (faction == Towns[t].GetComponent<TownAI>().TownName)
  28.                     continue;
  29.  
  30.                 FactionRow fr;
  31.                 fr.IdFactionA = FactionsNames.IndexOf(faction);
  32.                 fr.IdFactionB = t;
  33.                 fr.RelationValue = Random.Range(0, 100);
  34.  
  35.                 FactionTable.Add(fr);
  36.  
  37.                // Debug.Log(faction + "("+ fr.IdFactionA + ") : " + Towns[t].GetComponent<TownAI>().TownName +"("+ fr.IdFactionB + ") = " + fr.RelationValue);
  38.             }
  39.  
  40.             x++; // increasing the cursor so next step we will skip the check of the early town!
  41.         }
  42.  
  43.         for (int i = 0; i < FactionTable.Count; i++)
  44.         {
  45.             TownAI townAAi = Towns[FactionTable[i].IdFactionA].GetComponent<TownAI>();
  46.             TownAI townBAi = Towns[FactionTable[i].IdFactionB].GetComponent<TownAI>();
  47.  
  48.             townAAi.AddEnemyOrAllied(townBAi.gameObject, FactionTable[i].RelationValue);
  49.             townBAi.AddEnemyOrAllied(townAAi.gameObject, FactionTable[i].RelationValue);
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment