-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on JP surveys, add Move Towards command + processor
Still a bit buggy, move towards command tanks the frame rate
- Loading branch information
1 parent
a1314b9
commit 7f61506
Showing
13 changed files
with
495 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Pulsar4X.Datablobs; | ||
|
||
public class MoveTowardsTargetDB : BaseDataBlob | ||
{ | ||
[JsonProperty] | ||
public int TargetId { get; set; } | ||
|
||
[JsonProperty] | ||
public double DistanceOffset { get; set; } = 100; // 100 meters is probably close enough for a default | ||
|
||
[JsonProperty] | ||
public double Speed { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
Pulsar4X/GameEngine/Engine/Orders/Actions/JPSurveyOrder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using Pulsar4X.Datablobs; | ||
using Pulsar4X.Extensions; | ||
|
||
namespace Pulsar4X.Engine.Orders; | ||
|
||
public class JPSurveyOrder : EntityCommand | ||
{ | ||
public override ActionLaneTypes ActionLanes => ActionLaneTypes.Movement | ActionLaneTypes.InteractWithExternalEntity; | ||
|
||
public override bool IsBlocking => true; | ||
|
||
public override string Name => $"Jump Point Survey {Target.GetOwnersName()} ({GetProgressPercent()}%)"; | ||
|
||
public override string Details => ""; | ||
|
||
public Entity Target { get; private set; } | ||
public JPSurveyableDB? TargetSurveyDB { get; private set; } = null; | ||
public DateTime? PreviousUpdate { get; private set; } = null; | ||
public JPSurveyProcessor? Processor { get; private set; } = null; | ||
|
||
private Entity _entityCommanding; | ||
internal override Entity EntityCommanding | ||
{ | ||
get { return _entityCommanding; } | ||
} | ||
|
||
public JPSurveyOrder() { } | ||
public JPSurveyOrder(Entity commandingEntity, Entity target) | ||
{ | ||
_entityCommanding = commandingEntity; | ||
Target = target; | ||
if(Target.TryGetDatablob<JPSurveyableDB>(out var jpSurveyableDB)) | ||
{ | ||
TargetSurveyDB = jpSurveyableDB; | ||
} | ||
} | ||
|
||
public override EntityCommand Clone() | ||
{ | ||
var command = new JPSurveyOrder(EntityCommanding, Target) | ||
{ | ||
UseActionLanes = this.UseActionLanes, | ||
RequestingFactionGuid = this.RequestingFactionGuid, | ||
EntityCommandingGuid = this.EntityCommandingGuid, | ||
CreatedDate = this.CreatedDate, | ||
ActionOnDate = this.ActionOnDate, | ||
ActionedOnDate = this.ActionedOnDate, | ||
IsRunning = this.IsRunning | ||
}; | ||
|
||
return command; | ||
} | ||
|
||
public override bool IsFinished() | ||
{ | ||
return TargetSurveyDB == null ? true : TargetSurveyDB.IsSurveyComplete(EntityCommanding.FactionOwnerID); | ||
} | ||
|
||
internal override void Execute(DateTime atDateTime) | ||
{ | ||
if(!IsRunning) | ||
{ | ||
IsRunning = true; | ||
PreviousUpdate = atDateTime; | ||
Processor = new JPSurveyProcessor(EntityCommanding, Target); | ||
} | ||
else | ||
{ | ||
if(PreviousUpdate != null && atDateTime - PreviousUpdate >= TimeSpan.FromDays(1)) | ||
{ | ||
Processor?.ProcessEntity(EntityCommanding, atDateTime); | ||
PreviousUpdate = atDateTime; | ||
} | ||
} | ||
} | ||
|
||
internal override bool IsValidCommand(Game game) | ||
{ | ||
return TargetSurveyDB != null; | ||
} | ||
|
||
public static JPSurveyOrder CreateCommand(int requestingFactionId, Entity fleet, Entity target) | ||
{ | ||
var command = new JPSurveyOrder(fleet, target) | ||
{ | ||
RequestingFactionGuid = requestingFactionId | ||
}; | ||
|
||
return command; | ||
} | ||
|
||
private float GetProgressPercent() | ||
{ | ||
if(TargetSurveyDB == null) return 0f; | ||
if(!TargetSurveyDB.HasSurveyStarted(RequestingFactionGuid)) return 0f; | ||
|
||
uint pointsRequired = TargetSurveyDB.PointsRequired; | ||
uint currentValue = TargetSurveyDB.SurveyPointsRemaining[RequestingFactionGuid]; | ||
|
||
return (1f - ((float)currentValue / (float)pointsRequired)) * 100f; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
Pulsar4X/GameEngine/Engine/Orders/Actions/MoveFleetTowardsTargetOrder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Pulsar4X.Datablobs; | ||
|
||
namespace Pulsar4X.Engine.Orders; | ||
|
||
public class MoveFleetTowardsTargetOrder : EntityCommand | ||
{ | ||
public override ActionLaneTypes ActionLanes => ActionLaneTypes.Movement; | ||
|
||
public override bool IsBlocking => true; | ||
|
||
public override string Name => "Move Fleet Towards Target"; | ||
|
||
public override string Details => ""; | ||
|
||
private Entity _entityCommanding; | ||
|
||
internal override Entity EntityCommanding => _entityCommanding; | ||
|
||
public Entity Target { get; set; } | ||
|
||
List<EntityCommand> _shipCommands = new List<EntityCommand>(); | ||
|
||
public override EntityCommand Clone() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override bool IsFinished() | ||
{ | ||
if(!IsRunning) return false; | ||
|
||
foreach(var command in _shipCommands) | ||
{ | ||
if(!command.IsFinished()) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
internal override void Execute(DateTime atDateTime) | ||
{ | ||
if(IsRunning) return; | ||
if(!_entityCommanding.TryGetDatablob<FleetDB>(out var fleetDB)) return; | ||
// Get all the ships we need to add the movement command to | ||
var ships = fleetDB.Children.Where(c => c.HasDataBlob<ShipInfoDB>()); | ||
|
||
foreach(var ship in ships) | ||
{ | ||
var shipCommand = MoveTowardsTargetOrder.CreateCommand(ship, Target); | ||
ship.Manager.Game.OrderHandler.HandleOrder(shipCommand); | ||
_shipCommands.Add(shipCommand); | ||
} | ||
IsRunning = true; | ||
} | ||
|
||
public static MoveFleetTowardsTargetOrder CreateCommand(Entity entity, Entity target) | ||
{ | ||
var order = new MoveFleetTowardsTargetOrder() | ||
{ | ||
RequestingFactionGuid = entity.FactionOwnerID, | ||
EntityCommandingGuid = entity.Id, | ||
_entityCommanding = entity, | ||
Target = target, | ||
}; | ||
|
||
return order; | ||
} | ||
|
||
internal override bool IsValidCommand(Game game) | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.