Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class X2AbilityMultiTarget_Disc extends X2AbilityMultiTargetStyle;
  2.  
  3. // how many METERS can a spark jump
  4. var float fMaxJumpLength;
  5. // if true, the weapon radius is used, and fMaxJumpLength is a bonus
  6. var bool bUseWeaponRadius;
  7.  
  8. // the maximum of targets permitted
  9. var int iMaxTargets;
  10.  
  11. var bool bIgnoreBlockingCover;
  12.  
  13. // The two functions below would need to stay connected somehow, since the tiles are defined by the targets...
  14.  
  15. // Approach 1 - discarded
  16. // we could just store the target list in a GameStateComponent of XComGameState_Ability
  17. // which then gets read by GetValidTilesForLocation. The Tile Location of the primary target
  18. // should match the Location param
  19. // problem: We actually add a new game state - that outdates the current GameRulesCache_Unit
  20. // this whole update could probably also happen while a gamestate is pending?? Shouldn't but you never know
  21.  
  22.  
  23. // Approach 2 - used for now
  24. // we could get the already calculated targets (GameRulesCache_...), find the PrimaryTarget of that ability, get its location, and compare it to Location
  25. // Multiple targets on the same tile shouldn't be a problem, since the code will take the same path for both
  26. // we then have all the targets in order, which can be used to calculate tiles
  27.  
  28. /**
  29.  * GetMultiTargetOptions
  30.  * @param Targets will have valid PrimaryTarget filled out already
  31.  * @return Targets with AdditionalTargets filled out given the PrimaryTarget in each element
  32.  */
  33. simulated function GetMultiTargetOptions(const XComGameState_Ability Ability, out array<AvailableTarget> Targets)
  34. {
  35.     local X2AbilityTemplate Template;
  36.     local XComGameState_BaseObject PotentialTarget, LastTarget;
  37.     local XComGameState_Unit SourceUnit;
  38.     local XComGameStateHistory History;
  39.     local X2Condition kCondition;
  40.  
  41.     local array<XComGameState_BaseObject> PotentialTargets, OverallTargets;
  42.     local int i, j;
  43.  
  44.     local name AvailableCode;
  45.     local bool bValidTarget;
  46.  
  47.     local XComWorldData WorldData;
  48.  
  49.     local vector ReferenceTargetLocation, CheckLocation;
  50.     local TTile ReferenceTargetTile, CheckTile;
  51.  
  52.     local XComGameState_BaseObject BestTarget;
  53.     local float BestDistance, CheckDistance;
  54.  
  55.     //`log("GetMultiTargetOptions does work",, 'PredatorWeapons');
  56.  
  57.     WorldData = `XWORLD;
  58.  
  59.     History = `XCOMHISTORY;
  60.     SourceUnit = XComGameState_Unit(History.GetGameStateForObjectID(Ability.OwnerStateObject.ObjectID));
  61.  
  62.     Template = Ability.GetMyTemplate();
  63.  
  64.     foreach History.IterateByClassType(class'XComGameState_BaseObject', PotentialTarget)
  65.     {
  66.         // needs to have a location AND be damageable
  67.         if (X2GameRulesetVisibilityInterface(PotentialTarget) == none || Damageable(PotentialTarget) == none)
  68.         {
  69.             continue;
  70.         }
  71.         bValidTarget = true;
  72.         foreach Template.AbilityMultiTargetConditions(kCondition)
  73.         {      
  74.             AvailableCode = kCondition.AbilityMeetsCondition(Ability, PotentialTarget);
  75.             if (AvailableCode != 'AA_Success')
  76.             {
  77.                 bValidTarget = false;
  78.                 break;
  79.             }
  80.             AvailableCode = kCondition.MeetsCondition(PotentialTarget);
  81.             if (AvailableCode != 'AA_Success')
  82.             {
  83.                 bValidTarget = false;
  84.                 break;
  85.             }
  86.    
  87.             AvailableCode = kCondition.MeetsConditionWithSource(PotentialTarget, SourceUnit);
  88.             if (AvailableCode != 'AA_Success')
  89.             {
  90.                 bValidTarget = false;
  91.                 break;
  92.             }
  93.         }
  94.  
  95.         if (bValidTarget && (XComGameState_Destructible(PotentialTarget) == none || XComGameState_Destructible(PotentialTarget).IsTargetable()))
  96.         {
  97.             //`log("Potential Target:" @ PotentialTarget.Class @ PotentialTarget.ObjectID,, 'PredatorWeapons');
  98.             OverallTargets.AddItem(PotentialTarget);
  99.         }
  100.     }
  101.  
  102.     for (i = 0; i < Targets.Length; i++)
  103.     {
  104.         //`log("##############################",, 'PredatorWeapons');
  105.         PotentialTargets = OverallTargets;
  106.         // Targets[i].PrimaryTarget is our primary target
  107.         // We now need to pick Targets[i].AdditionalTargets from PotentialTargets, so that Targets[i].AdditionalTargets.Length = Min(iMaxTargets, PotentialTargets.Length)
  108.         LastTarget = History.GetGameStateForObjectID(Targets[i].PrimaryTarget.ObjectID);
  109.         PotentialTargets.RemoveItem(LastTarget);
  110.         Targets[i].AdditionalTargets.AddItem(LastTarget.GetReference());
  111.         // if we need and have units to jump towards
  112.         while (Targets[i].AdditionalTargets.Length < iMaxTargets && PotentialTargets.Length > 0 && LastTarget != none)
  113.         {
  114.             //`log("We already target" @ Targets[i].AdditionalTargets.Length @ "out of" @ iMaxTargets $ ", and still have" @ PotentialTargets.Length @ "to choose from.",, 'PredatorWeapons');
  115.             // reset best distance
  116.             BestDistance = 10000000000000000.0f;
  117.             BestTarget = none;
  118.  
  119.             ReferenceTargetLocation = GetTargetLocation(LastTarget);
  120.  
  121.             // iterate backwards when removing
  122.             for (j = PotentialTargets.Length - 1; j >= 0; j--)
  123.             {
  124.  
  125.                 CheckLocation = GetTargetLocation(PotentialTargets[j]);
  126.                 CheckDistance = VSize(ReferenceTargetLocation - CheckLocation);
  127.                 if (CheckDistance < BestDistance && (fMaxJumpLength <= 0.0f || CheckDistance < fMaxJumpLength * class'XComWorldData'.const.WORLD_StepSize))
  128.                 {
  129.                     BestDistance = CheckDistance;
  130.                     BestTarget = PotentialTargets[j];
  131.                 }
  132.             }
  133.             if (BestTarget != none)
  134.             {
  135.                 PotentialTargets.RemoveItem(BestTarget);
  136.                 Targets[i].AdditionalTargets.AddItem(BestTarget.GetReference());
  137.             }
  138.             LastTarget = BestTarget;
  139.         }
  140.     }
  141. }
  142.  
  143. /**
  144.  * GetValidTilesForLocation
  145.  * @param Location is the targeted location (location of PRIMARY target)
  146.  * @param ValidTiles are valid tiles, i.e. world effect affected tiles
  147.  */
  148. simulated function GetValidTilesForLocation(const XComGameState_Ability Ability, const vector Location, out array<TTile> ValidTiles)
  149. {
  150.     local GameRulesCache_Unit UnitCache;
  151.     local AvailableAction OurAction;
  152.     local AvailableTarget OurTarget;
  153.     local vector CheckLocation, LastLocation;
  154.     local TTile CheckTile;
  155.  
  156.     local array<StateObjectReference> SortedTargets;
  157.  
  158.     local XComGameStateHistory History;
  159.     local XComWorldData WorldData;
  160.  
  161.     local int i;
  162.  
  163.     local array<TilePosPair> TilePosPairs;
  164.  
  165.     //`log("GetValidTilesForLocation does work",, 'PredatorWeapons');
  166.  
  167.     WorldData = `XWORLD;
  168.     History = `XCOMHISTORY;
  169.  
  170.     `TACTICALRULES.GetGameRulesCache_Unit(Ability.OwnerStateObject, UnitCache);
  171.    
  172.     i = UnitCache.AvailableActions.Find('AbilityObjectRef', Ability.GetReference());
  173.  
  174.     OurAction = UnitCache.AvailableActions[i];
  175.  
  176.     foreach OurAction.AvailableTargets(OurTarget)
  177.     {
  178.         CheckLocation = GetTargetLocation(History.GetGameStateForObjectID(OurTarget.PrimaryTarget.ObjectID));
  179.         if (CheckLocation == Location)
  180.         {
  181.             break;
  182.         }
  183.     }
  184.  
  185.     // OurTarget now has all its targets in AdditionalTargets
  186.     // we need to draw lines from Shooter-FirstTarget-...-LastTarget
  187.     SortedTargets = OurTarget.AdditionalTargets;
  188.     SortedTargets.InsertItem(0, UnitCache.UnitObjectRef);
  189.  
  190.     LastLocation = GetTargetLocation(History.GetGameStateForObjectID(SortedTargets[0].ObjectID));
  191.  
  192.     for (i = 1; i < SortedTargets.Length; i++)
  193.     {
  194.         CheckLocation = GetTargetLocation(History.GetGameStateForObjectID(SortedTargets[i].ObjectID));
  195.         // what are these units?
  196.         WorldData.CollectTilesInCapsule(TilePosPairs, LastLocation, CheckLocation, 0.5f * class'XComWorldData'.const.WORLD_StepSize);
  197.         //`log("Tiles:" @ TilePosPairs.Length,, 'PredatorWeapons');
  198.         LastLocation = CheckLocation;
  199.     }
  200.  
  201.     for (i = 0; i < TilePosPairs.Length; i++)
  202.     {
  203.         ValidTiles.AddItem(TilePosPairs[i].Tile);
  204.     }
  205.  
  206.  
  207. }
  208.  
  209. simulated function vector GetTargetLocation(XComGameState_BaseObject Target)
  210. {
  211.     local TTile Tile;
  212.     X2GameRulesetVisibilityInterface(Target).GetKeystoneVisibilityLocation(Tile);
  213.     return `XWORLD.GetPositionFromTileCoordinates(Tile);
  214.    
  215. }
  216.  
  217. /**
  218.  * GetMultiTargetsForLocation
  219.  * @param Location is the targeted location (location of CURSOR target)
  220.  * @param ValidTiles are valid tiles, i.e. world effect affected tiles
  221.  */
  222. simulated function GetMultiTargetsForLocation(const XComGameState_Ability Ability, const vector Location, out AvailableTarget Target)
  223. {
  224.     //`log("GetMultiTargetsForLocation does work",, 'PredatorWeapons');
  225. }
  226.  
  227. /**
  228. * CheckFilteredMultiTargets
  229. * @param Target will contain a filtered primary target with its filtered multi-targets
  230. * @return Return value should indicate if this primary target is valid, given the list of multi-targets (used to further filter the primary targets).
  231. */
  232. simulated function name CheckFilteredMultiTargets(const XComGameState_Ability Ability, const AvailableTarget Target)
  233. {
  234.     local name nmAACode;
  235.     nmAACode = super.CheckFilteredMultiTargets(Ability, Target);
  236.     /*
  237.         TODO: More conditions? super seems to only check the number of targets
  238.     */
  239.     //`log("CheckFilteredMultiTargets does work",, 'PredatorWeapons');
  240.  
  241.     return nmAACode;
  242. }
  243.  
  244. defaultproperties
  245. {
  246.     iMaxTargets = 3
  247.     fMaxJumpLength = 10.0f
  248.     bAllowSameTarget=true
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement