Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class X2AbilityMultiTarget_Disc extends X2AbilityMultiTargetStyle;
- // how many METERS can a spark jump
- var float fMaxJumpLength;
- // if true, the weapon radius is used, and fMaxJumpLength is a bonus
- var bool bUseWeaponRadius;
- // the maximum of targets permitted
- var int iMaxTargets;
- var bool bIgnoreBlockingCover;
- // The two functions below would need to stay connected somehow, since the tiles are defined by the targets...
- // Approach 1 - discarded
- // we could just store the target list in a GameStateComponent of XComGameState_Ability
- // which then gets read by GetValidTilesForLocation. The Tile Location of the primary target
- // should match the Location param
- // problem: We actually add a new game state - that outdates the current GameRulesCache_Unit
- // this whole update could probably also happen while a gamestate is pending?? Shouldn't but you never know
- // Approach 2 - used for now
- // we could get the already calculated targets (GameRulesCache_...), find the PrimaryTarget of that ability, get its location, and compare it to Location
- // Multiple targets on the same tile shouldn't be a problem, since the code will take the same path for both
- // we then have all the targets in order, which can be used to calculate tiles
- /**
- * GetMultiTargetOptions
- * @param Targets will have valid PrimaryTarget filled out already
- * @return Targets with AdditionalTargets filled out given the PrimaryTarget in each element
- */
- simulated function GetMultiTargetOptions(const XComGameState_Ability Ability, out array<AvailableTarget> Targets)
- {
- local X2AbilityTemplate Template;
- local XComGameState_BaseObject PotentialTarget, LastTarget;
- local XComGameState_Unit SourceUnit;
- local XComGameStateHistory History;
- local X2Condition kCondition;
- local array<XComGameState_BaseObject> PotentialTargets, OverallTargets;
- local int i, j;
- local name AvailableCode;
- local bool bValidTarget;
- local XComWorldData WorldData;
- local vector ReferenceTargetLocation, CheckLocation;
- local TTile ReferenceTargetTile, CheckTile;
- local XComGameState_BaseObject BestTarget;
- local float BestDistance, CheckDistance;
- //`log("GetMultiTargetOptions does work",, 'PredatorWeapons');
- WorldData = `XWORLD;
- History = `XCOMHISTORY;
- SourceUnit = XComGameState_Unit(History.GetGameStateForObjectID(Ability.OwnerStateObject.ObjectID));
- Template = Ability.GetMyTemplate();
- foreach History.IterateByClassType(class'XComGameState_BaseObject', PotentialTarget)
- {
- // needs to have a location AND be damageable
- if (X2GameRulesetVisibilityInterface(PotentialTarget) == none || Damageable(PotentialTarget) == none)
- {
- continue;
- }
- bValidTarget = true;
- foreach Template.AbilityMultiTargetConditions(kCondition)
- {
- AvailableCode = kCondition.AbilityMeetsCondition(Ability, PotentialTarget);
- if (AvailableCode != 'AA_Success')
- {
- bValidTarget = false;
- break;
- }
- AvailableCode = kCondition.MeetsCondition(PotentialTarget);
- if (AvailableCode != 'AA_Success')
- {
- bValidTarget = false;
- break;
- }
- AvailableCode = kCondition.MeetsConditionWithSource(PotentialTarget, SourceUnit);
- if (AvailableCode != 'AA_Success')
- {
- bValidTarget = false;
- break;
- }
- }
- if (bValidTarget && (XComGameState_Destructible(PotentialTarget) == none || XComGameState_Destructible(PotentialTarget).IsTargetable()))
- {
- //`log("Potential Target:" @ PotentialTarget.Class @ PotentialTarget.ObjectID,, 'PredatorWeapons');
- OverallTargets.AddItem(PotentialTarget);
- }
- }
- for (i = 0; i < Targets.Length; i++)
- {
- //`log("##############################",, 'PredatorWeapons');
- PotentialTargets = OverallTargets;
- // Targets[i].PrimaryTarget is our primary target
- // We now need to pick Targets[i].AdditionalTargets from PotentialTargets, so that Targets[i].AdditionalTargets.Length = Min(iMaxTargets, PotentialTargets.Length)
- LastTarget = History.GetGameStateForObjectID(Targets[i].PrimaryTarget.ObjectID);
- PotentialTargets.RemoveItem(LastTarget);
- Targets[i].AdditionalTargets.AddItem(LastTarget.GetReference());
- // if we need and have units to jump towards
- while (Targets[i].AdditionalTargets.Length < iMaxTargets && PotentialTargets.Length > 0 && LastTarget != none)
- {
- //`log("We already target" @ Targets[i].AdditionalTargets.Length @ "out of" @ iMaxTargets $ ", and still have" @ PotentialTargets.Length @ "to choose from.",, 'PredatorWeapons');
- // reset best distance
- BestDistance = 10000000000000000.0f;
- BestTarget = none;
- ReferenceTargetLocation = GetTargetLocation(LastTarget);
- // iterate backwards when removing
- for (j = PotentialTargets.Length - 1; j >= 0; j--)
- {
- CheckLocation = GetTargetLocation(PotentialTargets[j]);
- CheckDistance = VSize(ReferenceTargetLocation - CheckLocation);
- if (CheckDistance < BestDistance && (fMaxJumpLength <= 0.0f || CheckDistance < fMaxJumpLength * class'XComWorldData'.const.WORLD_StepSize))
- {
- BestDistance = CheckDistance;
- BestTarget = PotentialTargets[j];
- }
- }
- if (BestTarget != none)
- {
- PotentialTargets.RemoveItem(BestTarget);
- Targets[i].AdditionalTargets.AddItem(BestTarget.GetReference());
- }
- LastTarget = BestTarget;
- }
- }
- }
- /**
- * GetValidTilesForLocation
- * @param Location is the targeted location (location of PRIMARY target)
- * @param ValidTiles are valid tiles, i.e. world effect affected tiles
- */
- simulated function GetValidTilesForLocation(const XComGameState_Ability Ability, const vector Location, out array<TTile> ValidTiles)
- {
- local GameRulesCache_Unit UnitCache;
- local AvailableAction OurAction;
- local AvailableTarget OurTarget;
- local vector CheckLocation, LastLocation;
- local TTile CheckTile;
- local array<StateObjectReference> SortedTargets;
- local XComGameStateHistory History;
- local XComWorldData WorldData;
- local int i;
- local array<TilePosPair> TilePosPairs;
- //`log("GetValidTilesForLocation does work",, 'PredatorWeapons');
- WorldData = `XWORLD;
- History = `XCOMHISTORY;
- `TACTICALRULES.GetGameRulesCache_Unit(Ability.OwnerStateObject, UnitCache);
- i = UnitCache.AvailableActions.Find('AbilityObjectRef', Ability.GetReference());
- OurAction = UnitCache.AvailableActions[i];
- foreach OurAction.AvailableTargets(OurTarget)
- {
- CheckLocation = GetTargetLocation(History.GetGameStateForObjectID(OurTarget.PrimaryTarget.ObjectID));
- if (CheckLocation == Location)
- {
- break;
- }
- }
- // OurTarget now has all its targets in AdditionalTargets
- // we need to draw lines from Shooter-FirstTarget-...-LastTarget
- SortedTargets = OurTarget.AdditionalTargets;
- SortedTargets.InsertItem(0, UnitCache.UnitObjectRef);
- LastLocation = GetTargetLocation(History.GetGameStateForObjectID(SortedTargets[0].ObjectID));
- for (i = 1; i < SortedTargets.Length; i++)
- {
- CheckLocation = GetTargetLocation(History.GetGameStateForObjectID(SortedTargets[i].ObjectID));
- // what are these units?
- WorldData.CollectTilesInCapsule(TilePosPairs, LastLocation, CheckLocation, 0.5f * class'XComWorldData'.const.WORLD_StepSize);
- //`log("Tiles:" @ TilePosPairs.Length,, 'PredatorWeapons');
- LastLocation = CheckLocation;
- }
- for (i = 0; i < TilePosPairs.Length; i++)
- {
- ValidTiles.AddItem(TilePosPairs[i].Tile);
- }
- }
- simulated function vector GetTargetLocation(XComGameState_BaseObject Target)
- {
- local TTile Tile;
- X2GameRulesetVisibilityInterface(Target).GetKeystoneVisibilityLocation(Tile);
- return `XWORLD.GetPositionFromTileCoordinates(Tile);
- }
- /**
- * GetMultiTargetsForLocation
- * @param Location is the targeted location (location of CURSOR target)
- * @param ValidTiles are valid tiles, i.e. world effect affected tiles
- */
- simulated function GetMultiTargetsForLocation(const XComGameState_Ability Ability, const vector Location, out AvailableTarget Target)
- {
- //`log("GetMultiTargetsForLocation does work",, 'PredatorWeapons');
- }
- /**
- * CheckFilteredMultiTargets
- * @param Target will contain a filtered primary target with its filtered multi-targets
- * @return Return value should indicate if this primary target is valid, given the list of multi-targets (used to further filter the primary targets).
- */
- simulated function name CheckFilteredMultiTargets(const XComGameState_Ability Ability, const AvailableTarget Target)
- {
- local name nmAACode;
- nmAACode = super.CheckFilteredMultiTargets(Ability, Target);
- /*
- TODO: More conditions? super seems to only check the number of targets
- */
- //`log("CheckFilteredMultiTargets does work",, 'PredatorWeapons');
- return nmAACode;
- }
- defaultproperties
- {
- iMaxTargets = 3
- fMaxJumpLength = 10.0f
- bAllowSameTarget=true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement