Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 60 additions & 68 deletions Core/Game/Abilities/Essential/Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ protected override void OnInitialize()

protected override void OnSimulate()
{

attackCount -= FixedMath.One / LockstepManager.FrameRate;
if (attackCount > 0) {
attackCount -= LockstepManager.DeltaTime;
}
if (HasTarget)
{
BehaveWithTarget();
Expand Down Expand Up @@ -251,88 +252,58 @@ void BehaveWithTarget()
if (Target.IsActive == false || Target.SpawnVersion != targetVersion ||
(this.TargetAllegiance & Agent.GetAllegiance(Target)) == 0)
{
//Target no longer exists
StopEngage();
BehaveWithNoTarget();
return;
}
if (IsWindingUp)
{
windupCount -= FixedMath.One / LockstepManager.FrameRate;
if (windupCount < 0)
{
if (this.AgentConditional(Target))
{
Fire();
while (this.attackCount < 0)
this.attackCount += (this.AttackInterval);
this.attackCount -= Windup;
}
else {
StopEngage();
this.ScanAndEngage();
}
IsWindingUp = false;

}
}
else {
if (!IsWindingUp) {
Vector2d targetDirection = Target.Body._position - cachedBody._position;
long fastMag = targetDirection.FastMagnitude();
long fastMag = targetDirection.FastMagnitude ();

if (fastMag <= fastRangeToTarget)
{
if (!inRange)
{
if (fastMag <= fastRangeToTarget) {
if (!inRange) {
if (CanMove)
cachedMove.StopMove();
cachedMove.StopMove ();

}
Agent.SetState(EngagingAnimState);
Agent.SetState (EngagingAnimState);

long mag;
targetDirection.Normalize(out 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);
(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 (needTurn) {
if (CanTurn) {
cachedTurn.StartTurnDirection (targetDirection);
} else {

}
}
else {
if (attackCount <= 0)
{
StartWindup();
} else {
if (attackCount <= 0) {
StartWindup ();
}
}

if (inRange == false)
{
if (inRange == false) {
inRange = true;
}
}
else {
if (CanMove)
{
if (cachedMove.IsMoving == false)
{
cachedMove.StartMove(Target.Body._position);
} else {
if (CanMove) {
if (cachedMove.IsMoving == false) {
cachedMove.StartMove (Target.Body._position);
cachedBody.Priority = basePriority;
}
else {
} 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)) {
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);
Expand All @@ -342,26 +313,47 @@ void BehaveWithTarget()
}
}

if (isAttackMoving || isFocused == false)
{
if (isAttackMoving || isFocused == false) {
searchCount -= 1;
if (searchCount <= 0)
{
if (searchCount <= 0) {
searchCount = SearchRate;
if (ScanAndEngage())
{
}
else {
if (ScanAndEngage ()) {
} else {
}
}
}
if (inRange == true)
{
if (inRange == true) {
inRange = false;
}

}
}

if (IsWindingUp)
{
windupCount -= LockstepManager.DeltaTime;
if (windupCount < 0)
{
if (this.AgentConditional(Target))
{
Fire();
int counter = 0;
while (this.attackCount <= 0) {
this.attackCount += (this.AttackInterval);
counter++;
if (counter > 1)
Debug.Log ("asdf" + this.attackCount.ToDouble());
}
this.attackCount -= Windup;
}
else {
StopEngage();
this.ScanAndEngage();
}
IsWindingUp = false;

}
}
}

void BehaveWithNoTarget()
Expand Down Expand Up @@ -743,7 +735,7 @@ public bool ScanWithinRangeAndEngage()
#if UNITY_EDITOR
void OnDrawGizmos()
{
if (Agent.IsActive == false) return;
if (Agent == null || Agent.IsActive == false) return;
if (Agent.Body == null)
Debug.Log (Agent.gameObject);
Gizmos.DrawWireSphere(Application.isPlaying ? Agent.Body._visualPosition : this.transform.position, this.Range.ToFloat());
Expand Down
16 changes: 15 additions & 1 deletion Core/Game/Agents/AgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,15 @@ public AgentCommander Commander {
}
}
}

public static AgentController GetInstanceManager (int index) {
if (index >= AgentController.InstanceManagers.Count) {
Debug.LogError ("Controller with index " + index + " not created. You can automatically create controllers by configuring AgentControllerCreator.");
return null;
} else if (index < 0) {
Debug.LogError ("Controller cannot have negative index.");
}
return AgentController.InstanceManagers [index];
}
public static AgentController Create ()
{
return new AgentController ();
Expand Down Expand Up @@ -542,6 +550,12 @@ public LSAgent CreateAgent (string agentCode, Vector2d position, Vector2d rotati
InitializeAgent (agent, position, rotation);
return agent;
}

/// <summary>
/// Creates and initializes an agent without activating LSBody, LSInfluencer, etc..
/// </summary>
/// <returns>The bare agent.</returns>
/// <param name="agentCode">Agent code.</param>
public LSAgent CreateBareAgent (string agentCode) {
var agent = CreateRawAgent (agentCode);
AddAgent (agent);
Expand Down
12 changes: 8 additions & 4 deletions Core/Game/Effects/EffectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ public static bool IsValid(string effectCode)
{
return !string.IsNullOrEmpty (effectCode) && effectCode != "None" && CodeDataMap.ContainsKey (effectCode);
}

public static LSEffect LazyCreateEffect(string effectCode, Vector3 position)
public static LSEffect CreateCollisionEffect (string effectCode, LSProjectile projectile, LSBody hitBody) {
Vector3 collisionDirection = -(projectile.Forward.ToVector3());
Vector3 collisionPosition = collisionDirection * hitBody.Radius.ToFloat () + hitBody.PositionalTransform.position;
return CreateEffect (effectCode, collisionPosition, projectile.transform.rotation);
}
public static LSEffect CreateEffect(string effectCode, Vector3 position)
{
if (!IsValid(effectCode))
return null;
Expand All @@ -69,7 +73,7 @@ public static LSEffect LazyCreateEffect(string effectCode, Vector3 position)
return effect;
}

public static LSEffect LazyCreateEffect(string effectCode, Vector3 position, Quaternion rotation)
public static LSEffect CreateEffect(string effectCode, Vector3 position, Quaternion rotation)
{
if (!IsValid(effectCode))
return null;
Expand All @@ -81,7 +85,7 @@ public static LSEffect LazyCreateEffect(string effectCode, Vector3 position, Qua

}

public static LSEffect LazyCreateEffect(string effectCode, Transform spawnParent)
public static LSEffect CreateEffect(string effectCode, Transform spawnParent)
{
if (!IsValid(effectCode))
return null;
Expand Down
9 changes: 7 additions & 2 deletions Core/Game/Managers/LockstepManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ public static class LockstepManager
{
public const int FrameRate = 32;
public const int InfluenceResolution = 2;
public const float BaseDeltaTime = (float)(1d / FrameRate);
public const long DeltaTime = FixedMath.One / FrameRate;
public const float DeltaTimeF = DeltaTime / FixedMath.OneF;

private static int InfluenceCount;

public static int InfluenceFrameCount { get; private set; }

/// <summary>
/// Number of frames that have passed. FrameCount/FrameRate = duration of game session in seconds.
/// </summary>
/// <value>The frame count.</value>
public static int FrameCount { get; private set; }

public static bool GameStarted { get; private set; }
Expand Down Expand Up @@ -95,7 +100,7 @@ internal static void Setup ()
PhysicsManager.Setup ();
ClientManager.Setup ();

Time.fixedDeltaTime = BaseDeltaTime;
Time.fixedDeltaTime = DeltaTimeF;
Time.maximumDeltaTime = Time.fixedDeltaTime * 2;
InputCodeManager.Setup ();

Expand Down
2 changes: 1 addition & 1 deletion Core/Game/Managers/ServerSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static IEnumerator Tick ()
receivedBytes.FastClear ();
Send (bufferBytes.ToArray ());
}
yield return LSUtility.WaitRealTime (LockstepManager.BaseDeltaTime * LockstepManager.InfluenceResolution);
yield return LSUtility.WaitRealTime (LockstepManager.DeltaTimeF * LockstepManager.InfluenceResolution);
}
}
}
Expand Down
Loading