private bool CheckRange() { Vector2d targetDirection = CurrentProject.Body._position - CachedBody._position; long fastMag = targetDirection.FastMagnitude(); return(fastMag <= fastRangeToTarget); }
bool CheckRange() { Vector2d targetDirection = Target.Body._position - cachedBody._position; long fastMag = targetDirection.FastMagnitude(); return(fastMag <= fastRangeToTarget); }
private void ApplyCone(Vector3d center3d, Vector2d forward, long radius, long angle) { Vector2d center = center3d.ToVector2d(); long fastRange = radius * radius; Scan(center, radius); for (int i = 0; i < ScanOutput.Count; i++) { RTSAgent agent = ScanOutput [i]; Vector2d agentPos = agent.Body._position; Vector2d difference = agentPos - center; if (difference.FastMagnitude() > fastRange) { continue; } if (forward.Dot(difference) < 0) { continue; } difference.Normalize(); long cross = forward.Cross(difference).Abs(); if (cross > angle) { continue; } HitAgent(agent); } }
bool CheckRange(LSBody targetBody) { fastRangeToTarget = cachedAttack.Range + (targetBody.IsNotNull() ? targetBody.Radius : 0) + Agent.Body.Radius; fastRangeToTarget *= fastRangeToTarget; Vector2d targetDirection = targetBody._position - CachedBody._position; long fastMag = targetDirection.FastMagnitude(); return(fastMag <= fastRangeToTarget); }
void CheckAutoturn() { if (isColliding) { isColliding = false; //autoturn direction will be culmination of positional changes if (targetReached == true && Agent.IsCasting == false && !(Agent.Body.Immovable || Agent.Body.IsTrigger)) { Vector2d delta = this.Agent.Body._position - this.Agent.Body.LastPosition; if (delta.FastMagnitude() > collisionTurnThreshold) { delta.Normalize(); this.StartTurnDirection(delta); } } } }
void BehaveWithTarget() { if (Target.IsActive == false || Target.SpawnVersion != targetVersion || (this.TargetAllegiance & Agent.GetAllegiance(Target)) == 0) { //Target's lifecycle has ended StopEngage(); BehaveWithNoTarget(); return; } if (!IsWindingUp) { Vector2d targetDirection = Target.Body._position - cachedBody._position; long fastMag = targetDirection.FastMagnitude(); //TODO: Optimize this instead of recalculating magnitude multiple times if (CheckRange()) { if (!inRange) { if (CanMove) { cachedMove.StopMove(); } inRange = true; } Agent.SetState(EngagingAnimState); long mag; targetDirection.Normalize(out mag); bool withinTurn = TrackAttackAngle == false || (fastMag != 0 && cachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 && cachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= AttackAngle); bool needTurn = mag != 0 && !withinTurn; if (needTurn) { if (CanTurn) { cachedTurn.StartTurnDirection(targetDirection); } } else { if (attackCount >= AttackInterval) { StartWindup(); } } } else { if (CanMove) { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); if (cachedMove.IsMoving == false) { cachedMove.StartMove(Target.Body._position); cachedBody.Priority = basePriority; } else { if (inRange) { cachedMove.Destination = Target.Body.Position; } else { if (repathTimer.AdvanceFrame()) { if (Target.Body.PositionChangedBuffer && Target.Body.Position.FastDistance(cachedMove.Destination.x, cachedMove.Destination.y) >= (repathDistance * repathDistance)) { cachedMove.StartMove(Target.Body._position); //So units don't sync up and path on the same frame repathTimer.AdvanceFrames(repathRandom); } } } } } if (IsAttackMoving || isFocused == false) { searchCount -= 1; if (searchCount <= 0) { searchCount = SearchRate; if (ScanAndEngage()) { } else { } } } if (inRange == true) { inRange = false; } } } if (IsWindingUp) { //TODO: Do we need AgentConditional checks here? windupCount += LockstepManager.DeltaTime; if (CanTurn) { Vector2d targetVector = Target.Body._position - cachedBody._position; cachedTurn.StartTurnVector(targetVector); } if (windupCount >= Windup) { windupCount = 0; Fire(); while (this.attackCount >= AttackInterval) { //resetting back down after attack is fired this.attackCount -= (this.AttackInterval); } this.attackCount += Windup; IsWindingUp = false; } } else { windupCount = 0; } if (CanMove && inRange) { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); } }
private void BehaveWithTarget() { if (CurrentProject && (CurrentProject.IsActive == false || !CurrentProject.GetAbility <Structure>().NeedsConstruction)) { //Target's lifecycle has ended StopConstruction(); } else { Vector2d targetDirection = CurrentProject.Body._position - CachedBody._position; long fastMag = targetDirection.FastMagnitude(); if (!IsWindingUp) { if (CheckRange()) { IsBuildMoving = false; if (!inRange) { cachedMove.StopMove(); inRange = true; } Agent.Animator.SetState(ConstructingAnimState); if (!CurrentProject.GetAbility <Structure>().ConstructionStarted) { CurrentProject.GetAbility <Structure>().ConstructionStarted = true; // Restore material ConstructionHandler.RestoreMaterial(CurrentProject.gameObject); } long mag; targetDirection.Normalize(out mag); bool withinTurn = cachedAttack.TrackAttackAngle == false || (fastMag != 0 && CachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 && CachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= cachedAttack.AttackAngle); bool needTurn = mag != 0 && !withinTurn; if (needTurn) { cachedTurn.StartTurnDirection(targetDirection); } else { if (constructCount >= _constructInterval) { StartWindup(); } } } else { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); if (cachedMove.IsMoving == false) { cachedMove.StartMove(CurrentProject.Body._position); CachedBody.Priority = basePriority; } else { if (inRange) { cachedMove.Destination = CurrentProject.Body.Position; } else { if (repathTimer.AdvanceFrame()) { if (CurrentProject.Body.PositionChangedBuffer && CurrentProject.Body.Position.FastDistance(cachedMove.Destination.x, cachedMove.Destination.y) >= (repathDistance * repathDistance)) { cachedMove.StartMove(CurrentProject.Body._position); //So units don't sync up and path on the same frame repathTimer.AdvanceFrames(repathRandom); } } } } if (inRange == true) { inRange = false; } } } if (IsWindingUp) { //TODO: Do we need AgentConditional checks here? windupCount += LockstepManager.DeltaTime; if (windupCount >= Windup) { windupCount = 0; Build(); while (this.constructCount >= _constructInterval) { //resetting back down after attack is fired this.constructCount -= (this._constructInterval); } this.constructCount += Windup; IsWindingUp = false; } } else { windupCount = 0; } if (inRange) { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); } } }
void BehaveWithStorage() { resourceStorage = ClosestResourceStore(); if (!resourceStorage) { // can't find clostest resource store // send command to stop harvesting... StopHarvesting(true); } else { if (!IsWindingUp) { Vector2d targetDirection = resourceStorage.Body._position - CachedBody._position; long fastMag = targetDirection.FastMagnitude(); if (CheckRange(resourceStorage.Body)) { if (!inRange) { cachedMove.StopMove(); inRange = true; } Agent.Animator.SetIdleState(IdlingAnimState); //if (audioElement != null && Time.timeScale > 0) //{ // audioElement.Play(emptyHarvestSound); //} long mag; targetDirection.Normalize(out mag); bool withinTurn = cachedAttack.TrackAttackAngle == false || (fastMag != 0 && CachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 && CachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= cachedAttack.AttackAngle); bool needTurn = mag != 0 && !withinTurn; if (needTurn) { cachedTurn.StartTurnDirection(targetDirection); } else { if (harvestCount >= _harvestInterval) { StartWindup(); } } } else { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); if (cachedMove.IsMoving == false) { cachedMove.StartMove(resourceStorage.Body._position); CachedBody.Priority = basePriority; } else { if (inRange) { cachedMove.Destination = resourceStorage.Body.Position; } else { if (repathTimer.AdvanceFrame()) { if (resourceStorage.Body.PositionChangedBuffer && resourceStorage.Body.Position.FastDistance(cachedMove.Destination.x, cachedMove.Destination.y) >= (repathDistance * repathDistance)) { cachedMove.StartMove(resourceStorage.Body._position); //So units don't sync up and path on the same frame repathTimer.AdvanceFrames(repathRandom); } } } } if (inRange == true) { inRange = false; } } } if (IsWindingUp) { //TODO: Do we need AgentConditional checks here? windupCount += LockstepManager.DeltaTime; if (windupCount >= Windup) { windupCount = 0; Deposit(); while (this.harvestCount >= _harvestInterval) { //resetting back down after attack is fired this.harvestCount -= (this._harvestInterval); } this.harvestCount += Windup; IsWindingUp = false; } } else { windupCount = 0; } if (inRange) { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); } } }
void BehaveWithResource() { if (!resourceTarget || resourceTarget.IsActive == false || resourceTarget.GetAbility <ResourceDeposit>().IsEmpty()) { //Target's lifecycle has ended StopHarvesting(); } else { SetAnimState(); if (!IsWindingUp) { Vector2d targetDirection = resourceTarget.Body._position - CachedBody._position; long fastMag = targetDirection.FastMagnitude(); if (CheckRange(resourceTarget.Body)) { IsHarvestMoving = false; if (!inRange) { cachedMove.StopMove(); inRange = true; } Agent.Animator.SetState(HarvestingAnimState); long mag; targetDirection.Normalize(out mag); bool withinTurn = cachedAttack.TrackAttackAngle == false || (fastMag != 0 && CachedBody.Forward.Dot(targetDirection.x, targetDirection.y) > 0 && CachedBody.Forward.Cross(targetDirection.x, targetDirection.y).Abs() <= cachedAttack.AttackAngle); bool needTurn = mag != 0 && !withinTurn; if (needTurn) { cachedTurn.StartTurnDirection(targetDirection); } else { if (harvestCount >= _harvestInterval) { StartWindup(); } } } else { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); if (cachedMove.IsMoving == false) { cachedMove.StartMove(resourceTarget.Body._position); CachedBody.Priority = basePriority; } else { if (inRange) { cachedMove.Destination = resourceTarget.Body.Position; } else { if (repathTimer.AdvanceFrame()) { if (resourceTarget.Body.PositionChangedBuffer && resourceTarget.Body.Position.FastDistance(cachedMove.Destination.x, cachedMove.Destination.y) >= (repathDistance * repathDistance)) { cachedMove.StartMove(resourceTarget.Body._position); //So units don't sync up and path on the same frame repathTimer.AdvanceFrames(repathRandom); } } } } if (inRange == true) { inRange = false; } } } if (IsWindingUp) { //TODO: Do we need AgentConditional checks here? windupCount += LockstepManager.DeltaTime; if (windupCount >= Windup) { windupCount = 0; // begin collecting resources Collect(); while (this.harvestCount >= _harvestInterval) { //resetting back down after attack is fired this.harvestCount -= (this._harvestInterval); } this.harvestCount += Windup; IsWindingUp = false; } } else { windupCount = 0; } if (inRange) { cachedMove.PauseAutoStop(); cachedMove.PauseCollisionStop(); } } }