public override void CheckState() { if (GetLiveSquads() == 0) { SquadState.ToAttack(); } }
public virtual void MoveToTarget(Node destinationNode) { transform.position = targetNode.transform.position + nodePositionOffset; mySquadState = SquadState.Ready; path.Clear(); SetCurrentNode(); targetNode = null; }
// ------------- // INTERNALS // ------------- void moveRequest(Vector3 destination) { // overwrite squadsight foreach (Unit m in members) { m.setSquadSight(new List <Enemy>()); } state = SquadState.RUNNING; Vector3[] dests = new Vector3[members.Count]; dests = buildDestinations(destination); for (int i = 0; i < members.Count; ++i) { members[i].setModeRunning(dests[i]); } }
public override void CheckState() { // Any enemies? if (GetEnemiesInRange().Count > 0) { SquadState.ToAttack(); return; } // Random change to go idle if (UnityEngine.Random.Range(0, 101) < idleProbability) { SquadState.ToIdle(); return; } // Linear, maybe curve instead? idleProbability += 10; }
protected virtual IEnumerator MoveToTargetCoroutine() { mySquadState = Squad.SquadState.Moving; CompositeUnitBehaviour.Weights[0] = movementWeight; myBoxCollider.size = Vector3.zero; for (int nodeIndex = 1; nodeIndex < path.Count; ++nodeIndex) { Vector3 startPosition = transform.position; Vector3 destination = path[nodeIndex].transform.position + nodePositionOffset; float timer = 0f; while (timer < 1f) { timer += Time.deltaTime * MaxSpeed * 0.2f; transform.position = Vector3.Lerp(startPosition, destination, timer); OnAnimateSquadPath?.Invoke(); yield return(null); } if (path.Count > 0) { PreviousNode = path[0]; path.RemoveAt(nodeIndex - 1); --nodeIndex; } else { PreviousNode = null; } } transform.position = targetNode.transform.position + nodePositionOffset; mySquadState = SquadState.PendingUnitsReady; myBoxCollider.size = originalBoxColliderSize; path.Clear(); SetCurrentNode(); targetNode = null; OnAnimateSquadPath?.Invoke(); }
public override void CheckState() { // Any enemies? if (GetEnemiesInRange().Count > 0) { SquadState.ToAttack(); return; } // Random change to start wander if (UnityEngine.Random.Range(0, 101) < idleTimer) { SquadState.ToWander(); return; } // Linear, maybe curve instead? idleTimer += 20; }
public override void CheckState() { // Outnumbered? if (SquadState.Squad.GetUnitCount() == 1 && GetEnemiesInRange().Count > SquadState.Squad.GetUnitCount()) { // TODO: Change if (GetLiveSquads() > 0) { SquadState.ToFlee(); return; } } // All killed if (GetEnemiesInRange().Count == 0) { SquadState.ToIdle(); return; } }
public override void Process() { number = 0; squadTile = null; Vector3 pos = Vector3.zero; squadAvg = SquadState.Squad.GetAveragePosition(); int move = SquadState.Squad.GetSmallestMovement(); // 5 tries int redo = 5; do { pos = squadAvg + move * movementDirection; // Not inside the map if (!TileGenerator.Instance.InMap((int)pos.x, (int)pos.z)) { // Switch movement direction SelectDirection(); --redo; // Couldn't get a new one, go idle if (redo == 0) { SquadState.ToIdle(); return; } } else { redo = 0; } } while (redo > 0); squadTile = TileGenerator.Instance.Tiles[(int)pos.x, (int)pos.z]; }
void ReturnToNormalMovementWeight() { if (mySquadState == SquadState.PendingUnitsReady) { bool areUnitsReady = true; for (int i = 0; i < squadUnits.Count; ++i) { if (squadUnits[i] && squadUnits[i].gameObject.activeInHierarchy) { if (Vector3.SqrMagnitude(transform.position - squadUnits[i].transform.position) > sqrReadyDistance) { areUnitsReady = false; break; } } } if (areUnitsReady) { CompositeUnitBehaviour.Weights[0] = 1f; mySquadState = SquadState.Ready; } } }
public void EngageInMelee() { this.SquadState = SquadState.Melee; for (int i = 0; i < mSquadMembers.Count; ++i) mSquadMembers [i].SwitchToMeleeWeapon (); }
private void AttackEnemySquad(Squad enemySquad) { if (enemySquad.IsDead) return; this.SquadState = SquadState.Engaging; Unit squadUnit = this.SquadLeader; // Surround the enemy! List<Vector3> positions = SurroundingPositions ( enemySquad.SquadCenter, this.SquadCenter, mSquadMembers.Count, kSquadMemberWidth * 2.0f, squadUnit.Range); // TODO add target radius for large targets List<Unit> mEnemies = enemySquad.mSquadMembers; int numEnemies = mEnemies.Count; // engage enemies 1 to 1 for (int i = 0; i < mSquadMembers.Count; ++i) { mSquadMembers [i].Engage (mEnemies [i % numEnemies], positions [i]); } enemySquad.Notify (SquadAction.EnemySighted, this.SquadLeader); }
public void SetDestination(Vector3 location) { if (Vector3.Distance (RallyPoint, location) < 5f) { ForceMove(location); } else { RallyPoint = location; location.z = 0; if (IsEngaged) return; this.SquadState = SquadState.Moving; UpdateSquadCoherency (); } }
private void AttackEnemyTower(Tower tower) { this.SquadState = SquadState.Engaging; Unit squadUnit = this.SquadLeader; // Surround the enemy! List<Vector3> positions = SurroundingPositions ( tower.Position, this.SquadCenter, mSquadMembers.Count, kSquadMemberWidth * 2.0f, squadUnit.Range); // TODO add target radius for large targets // engage in a circle around the tower for (int i = 0; i < mSquadMembers.Count; ++i) { mSquadMembers [i].Engage (tower, positions [i]); } }
public SquadBaseState(SquadState ss) { SquadState = ss; }
public SquadWander(SquadState ss) : base(ss) { SelectDirection(); }
// Use this for initialization void Awake() { this.SquadState = SquadState.Idle; if (IsIndependent) { this.Spawn (this.UnitType, this.transform.position, 1, Allegiance.Rodelle); this.SetDestination (this.transform.position); } }
public SquadAttack(SquadState ss) : base(ss) { }
private void CheckSquadIdle() { if (SquadLeader.IsIdle) this.SquadState = SquadState.Idle; }
// re-enable the search for new enemies private void Disengage() { mTargetSquad = null; mTargetPriority = 0; this.SquadState = SquadState.Moving; for (int i = 0; i < mSquadMembers.Count; ++i) { mSquadMembers [i].Disengage (); } UpdateSquadCoherency (); }
public SquadFlee(SquadState ss) : base(ss) { }
public void ForceMove(Vector3 location) { RallyPoint = location; location.z = 0; Disengage (); this.SquadState = SquadState.ForcedMove; foreach (Unit u in mSquadMembers) u.MoveTo(RallyPoint); }
public SquadIdle(SquadState ss) : base(ss) { }
void Awake() { _state = new SquadState(this); PrepareSquad(); }