Advertisement
RedDobe

AIUnitData

Sep 9th, 2019
1,640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function array<XComGameState_Player> GetEnemyPlayers( XGPlayer AIPlayer)
  2. {
  3.     local array<XComGameState_Player> EnemyPlayers;
  4.     local XComGameState_Player PlayerStateObject, EnemyStateObject, StateObject;
  5.  
  6.     if (AIPlayer == none)
  7.         return EnemyPlayers;
  8.  
  9.     PlayerStateObject = XComGameState_Player(`XCOMHISTORY.GetGameStateForObjectID(AIPlayer.ObjectID));
  10.  
  11.     foreach `XCOMHISTORY.IterateByClassType(class'XComGameState_Player', StateObject)
  12.     {
  13.         if (StateObject.ObjectID == PlayerStateObject.ObjectID)
  14.             continue;
  15.         //Ignore lost and civilians, this check is for purposes of determining enemies with guns
  16.         if (StateObject.GetTeam() == ETeam_TheLost || StateObject.GetTeam() == ETeam_Neutral)
  17.             continue;
  18.         EnemyStateObject = StateObject;
  19.         if (PlayerStateObject.IsEnemyPlayer(EnemyStateObject))
  20.  
  21.         if (EnemyStateObject != none)
  22.         {
  23.             EnemyPlayers.AddItem(EnemyStateObject);
  24.         }  
  25.     }
  26.     return EnemyPlayers;
  27. }
  28.  
  29. function GetAbsoluteKnowledgeUnitList( out array<StateObjectReference> arrKnownUnits, optional out array<XComGameState_Unit> UnitStateList, bool bSkipUndamageable=true, bool IncludeCiviliansOnTerror=true)
  30. {
  31.     local AlertData kData;
  32.     local StateObjectReference kUnitRef;
  33.     local XComGameState_Unit Unit;
  34.     local XComGameStateHistory History;
  35.     local XComGameState_BattleData Battle;
  36.     local XGAIPlayer AIPlayer, EnemyAIPlayer;
  37.     local XGPlayer EnemyPlayer;
  38.     local XComGameState_Player EnemyPlayerState;
  39.     local array<XComGameState_Player> EnemyPlayers;
  40.     local array<XComGameState_Unit> AllEnemies;
  41.  
  42.     History = `XCOMHISTORY;
  43.     Unit = XComGameState_Unit(History.GetGameStateForObjectID(m_iUnitObjectID));
  44.     AIPlayer = XGAIPlayer(History.GetVisualizer(Unit.ControllingPlayer.ObjectID));
  45.  
  46.     if( AIPlayer != None && AIPlayer.bAIHasKnowledgeOfAllUnconcealedXCom )
  47.     {
  48.         EnemyPlayers = GetEnemyPlayers(AIPlayer);
  49.         foreach EnemyPlayers(EnemyPlayerState)
  50.         {
  51.             if (EnemyPlayerState.GetTeam() == ETeam_XCom)
  52.             {
  53.                 EnemyPlayer = XGPlayer(EnemyPlayerState.GetVisualizer());
  54.            
  55.                 if( bSkipUndamageable )
  56.                 {
  57.                     EnemyPlayer.GetPlayableUnits(AllEnemies);
  58.                 }
  59.                 else
  60.                 {
  61.                     EnemyPlayer.GetUnits(AllEnemies);
  62.                 }
  63.             }
  64.             else
  65.             {
  66.                 EnemyAIPlayer = XGAIPlayer(EnemyPlayerState.GetVisualizer());
  67.        
  68.                 if( bSkipUndamageable )
  69.                 {
  70.                     EnemyAIPlayer.GetPlayableUnits(AllEnemies);
  71.                 }
  72.                 else
  73.                 {
  74.                     EnemyAIPlayer.GetUnits(AllEnemies);
  75.                 }
  76.             }
  77.         }
  78.         UnitStateList.Length = 0;
  79.         arrKnownUnits.Length = 0;
  80.         foreach AllEnemies(Unit)
  81.         {
  82.             if( !Unit.IsConcealed() && !Unit.bRemovedFromPlay )
  83.             {
  84.                 arrKnownUnits.AddItem(Unit.GetReference());
  85.                 UnitStateList.AddItem(Unit);
  86.             }
  87.         }
  88.     }
  89.     //bAIHasKnowledgeOfAllUnconcealedXCom defaults to true and is unused so this section wont ever apply
  90.     else
  91.     {
  92.         arrKnownUnits.Length = 0;
  93.         foreach m_arrAlertData(kData)
  94.         {
  95.             if( IsCauseAbsoluteKnowledge(kData.AlertCause) )
  96.             {
  97.                 Unit = XComGameState_Unit(History.GetGameStateForObjectID(kData.AlertSourceUnitID));
  98.                 if( bSkipUndamageable &&
  99.                    (Unit.bRemovedFromPlay
  100.                    || Unit.IsDead()
  101.                    || Unit.IsIncapacitated()
  102.                    || Unit.bDisabled
  103.                    || Unit.GetMyTemplate().bIsCosmetic)
  104.                    )
  105.                 {
  106.                     continue;
  107.                 }
  108.  
  109.                 kUnitRef = Unit.GetReference();
  110.                 if( arrKnownUnits.Find('ObjectID', kUnitRef.ObjectID) == -1 )
  111.                 {
  112.                     arrKnownUnits.AddItem(kUnitRef);
  113.                     UnitStateList.AddItem(Unit);
  114.                 }
  115.             }
  116.         }
  117.     }
  118.  
  119.     if( IncludeCiviliansOnTerror )
  120.     {
  121.         // Include civilians on terror maps.  These don't have alert data.
  122.         Battle = XComGameState_BattleData(`XCOMHISTORY.GetSingleGameStateObjectForClass(class'XComGameState_BattleData'));
  123.         if( Battle.AreCiviliansAlienTargets() )
  124.         {
  125.             class'X2TacticalVisibilityHelpers'.static.GetAllVisibleUnitsOnTeamForSource(m_iUnitObjectID, eTeam_Neutral, arrKnownUnits);
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement