-
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.
Showing
6 changed files
with
176 additions
and
7 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
103 changes: 103 additions & 0 deletions
103
Pulsar4X/GameEngine/Engine/Orders/Actions/GeoSurveyOrder.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 GeoSurveyOrder : EntityCommand | ||
{ | ||
public override ActionLaneTypes ActionLanes => ActionLaneTypes.Movement | ActionLaneTypes.InteractWithExternalEntity; | ||
|
||
public override bool IsBlocking => true; | ||
|
||
public override string Name => $"Geo Survey {Target.GetOwnersName()} ({GetProgressPercent()}%)"; | ||
|
||
public override string Details => ""; | ||
|
||
public Entity Target { get; private set; } | ||
public GeoSurveyableDB? TargetGeoSurveyDB { get; private set; } = null; | ||
public DateTime? PreviousUpdate { get; private set; } = null; | ||
public GeoSurveyProcessor? Processor { get; private set; } = null; | ||
|
||
private Entity _entityCommanding; | ||
internal override Entity EntityCommanding | ||
{ | ||
get { return _entityCommanding; } | ||
} | ||
|
||
public GeoSurveyOrder() { } | ||
public GeoSurveyOrder(Entity commandingEntity, Entity target) | ||
{ | ||
_entityCommanding = commandingEntity; | ||
Target = target; | ||
if(Target.TryGetDatablob<GeoSurveyableDB>(out var geoSurveyableDB)) | ||
{ | ||
TargetGeoSurveyDB = geoSurveyableDB; | ||
} | ||
} | ||
|
||
public override EntityCommand Clone() | ||
{ | ||
var command = new GeoSurveyOrder(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 TargetGeoSurveyDB == null ? true : TargetGeoSurveyDB.IsSurveyComplete(EntityCommanding.FactionOwnerID); | ||
} | ||
|
||
internal override void Execute(DateTime atDateTime) | ||
{ | ||
if(!IsRunning) | ||
{ | ||
IsRunning = true; | ||
PreviousUpdate = atDateTime; | ||
Processor = new GeoSurveyProcessor(EntityCommanding, Target); | ||
} | ||
else | ||
{ | ||
if(PreviousUpdate != null && atDateTime - PreviousUpdate >= TimeSpan.FromDays(1)) | ||
{ | ||
Processor?.ProcessEntity(EntityCommanding, atDateTime); | ||
PreviousUpdate = atDateTime; | ||
} | ||
} | ||
} | ||
|
||
internal override bool IsValidCommand(Game game) | ||
{ | ||
return TargetGeoSurveyDB != null; | ||
} | ||
|
||
public static GeoSurveyOrder CreateCommand(int requestingFactionId, Entity fleet, Entity target) | ||
{ | ||
var command = new GeoSurveyOrder(fleet, target) | ||
{ | ||
RequestingFactionGuid = requestingFactionId | ||
}; | ||
|
||
return command; | ||
} | ||
|
||
private float GetProgressPercent() | ||
{ | ||
if(TargetGeoSurveyDB == null) return 0f; | ||
if(!TargetGeoSurveyDB.HasSurveyStarted(RequestingFactionGuid)) return 0f; | ||
|
||
uint pointsRequired = TargetGeoSurveyDB.PointsRequired; | ||
uint currentValue = TargetGeoSurveyDB.GeoSurveyStatus[RequestingFactionGuid]; | ||
|
||
return (1f - ((float)currentValue / (float)pointsRequired)) * 100f; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
Pulsar4X/GameEngine/Engine/Processors/GeoSurveyProcessor.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,60 @@ | ||
using System; | ||
using Pulsar4X.Datablobs; | ||
using Pulsar4X.Interfaces; | ||
|
||
namespace Pulsar4X.Engine; | ||
|
||
public class GeoSurveyProcessor : IInstanceProcessor | ||
{ | ||
public Entity Fleet { get; internal set; } | ||
public Entity Target { get; internal set; } | ||
|
||
public GeoSurveyProcessor() {} | ||
|
||
public GeoSurveyProcessor(Entity fleet, Entity target) | ||
{ | ||
Fleet = fleet; | ||
Target = target; | ||
} | ||
|
||
internal override void ProcessEntity(Entity entity, DateTime atDateTime) | ||
{ | ||
// TODO: need to only get the survey points from ships that are at the survey location | ||
uint totalSurveyPoints = GetSurveyPoints(Fleet); | ||
|
||
if(Target.TryGetDatablob<GeoSurveyableDB>(out var geoSurveyableDB)) | ||
{ | ||
if(!geoSurveyableDB.GeoSurveyStatus.ContainsKey(Fleet.FactionOwnerID)) | ||
geoSurveyableDB.GeoSurveyStatus[Fleet.FactionOwnerID] = geoSurveyableDB.PointsRequired; | ||
|
||
if(totalSurveyPoints > geoSurveyableDB.GeoSurveyStatus[Fleet.FactionOwnerID]) | ||
{ | ||
geoSurveyableDB.GeoSurveyStatus[Fleet.FactionOwnerID] = 0; | ||
} | ||
else | ||
{ | ||
geoSurveyableDB.GeoSurveyStatus[Fleet.FactionOwnerID] -= totalSurveyPoints; | ||
} | ||
} | ||
} | ||
|
||
private uint GetSurveyPoints(Entity entity) | ||
{ | ||
uint totalSurveyPoints = 0; | ||
|
||
if(entity.TryGetDatablob<GeoSurveyAbilityDB>(out var geoSurveyAbilityDB)) | ||
{ | ||
totalSurveyPoints += geoSurveyAbilityDB.Speed; | ||
} | ||
|
||
if(entity.TryGetDatablob<FleetDB>(out var fleetDB)) | ||
{ | ||
foreach(var child in fleetDB.Children) | ||
{ | ||
totalSurveyPoints += GetSurveyPoints(child); | ||
} | ||
} | ||
|
||
return totalSurveyPoints; | ||
} | ||
} |
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