Spaces:
Runtime error
Runtime error
File size: 4,776 Bytes
ce81a16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
using Photon.Deterministic;
using System;
using Quantum.Prototypes;
namespace Quantum
{
[Serializable]
public struct ResponseCurvePack
{
public FP MultiplyFactor;
public AssetRefAIFunctionFP ResponseCurveRef;
[NonSerialized] public ResponseCurve ResponseCurve;
}
public unsafe partial class Consideration
{
public string Label;
public AssetRefAIFunctionInt RankRef;
public AssetRefAIFunctionBool CommitmentRef;
public AssetRefConsideration[] NextConsiderationsRefs;
public AssetRefAIAction[] OnEnterActionsRefs;
public AssetRefAIAction[] OnUpdateActionsRefs;
public AssetRefAIAction[] OnExitActionsRefs;
[NonSerialized] public AIFunctionInt Rank;
[NonSerialized] public AIFunctionBool Commitment;
[NonSerialized] public Consideration[] NextConsiderations;
[NonSerialized] public AIAction[] OnEnterActions;
[NonSerialized] public AIAction[] OnUpdateActions;
[NonSerialized] public AIAction[] OnExitActions;
public ResponseCurvePack[] ResponseCurvePacks;
public FP BaseScore;
public UTMomentumData MomentumData;
public FP Cooldown;
public byte Depth;
public int GetRank(Frame frame, EntityRef entity = default)
{
if (Rank == null)
return 0;
return Rank.Execute(frame, entity);
}
public FP Score(Frame frame, EntityRef entity = default)
{
if (ResponseCurvePacks.Length == 0)
return 0;
FP score = 1;
for (int i = 0; i < ResponseCurvePacks.Length; i++)
{
score *= ResponseCurvePacks[i].ResponseCurve.Execute(frame, entity) * ResponseCurvePacks[i].MultiplyFactor;
// If we find a negative veto, the final score would be zero anyways, so we stop here
if (score == 0)
{
break;
}
}
score += BaseScore;
FP modificationFactor = 1 - (1 / ResponseCurvePacks.Length);
FP makeUpValue = (1 - score) * modificationFactor;
FP finalScore = score + (makeUpValue * score);
return finalScore;
}
public void OnEnter(Frame frame, UtilityReasoner* reasoner, EntityRef entity = default)
{
for (int i = 0; i < OnEnterActions.Length; i++)
{
OnEnterActions[i].Update(frame, entity);
}
}
public void OnExit(Frame frame, UtilityReasoner* reasoner, EntityRef entity = default)
{
for (int i = 0; i < OnExitActions.Length; i++)
{
OnExitActions[i].Update(frame, entity);
}
}
public void OnUpdate(Frame frame, UtilityReasoner* reasoner, EntityRef entity = default)
{
for (int i = 0; i < OnUpdateActions.Length; i++)
{
OnUpdateActions[i].Update(frame, entity);
}
if (NextConsiderationsRefs != null && NextConsiderationsRefs.Length > 0)
{
Consideration chosenConsideration = reasoner->SelectBestConsideration(frame, NextConsiderations, (byte)(Depth + 1), reasoner, entity);
if (chosenConsideration != default)
{
chosenConsideration.OnUpdate(frame, reasoner, entity);
UTManager.ConsiderationChosen?.Invoke(entity, chosenConsideration.Identifier.Guid.Value);
}
}
}
public override void Loaded(IResourceManager resourceManager, Native.Allocator allocator)
{
base.Loaded(resourceManager, allocator);
Rank = (AIFunctionInt)resourceManager.GetAsset(RankRef.Id);
if (ResponseCurvePacks != null)
{
for (Int32 i = 0; i < ResponseCurvePacks.Length; i++)
{
ResponseCurvePacks[i].ResponseCurve = (ResponseCurve)resourceManager.GetAsset(ResponseCurvePacks[i].ResponseCurveRef.Id);
ResponseCurvePacks[i].MultiplyFactor = 1;
}
}
OnEnterActions = new AIAction[OnEnterActionsRefs == null ? 0 : OnEnterActionsRefs.Length];
if (OnEnterActionsRefs != null)
{
for (Int32 i = 0; i < OnEnterActionsRefs.Length; i++)
{
OnEnterActions[i] = (AIAction)resourceManager.GetAsset(OnEnterActionsRefs[i].Id);
}
}
OnUpdateActions = new AIAction[OnUpdateActionsRefs == null ? 0 : OnUpdateActionsRefs.Length];
if (OnEnterActionsRefs != null)
{
for (Int32 i = 0; i < OnUpdateActionsRefs.Length; i++)
{
OnUpdateActions[i] = (AIAction)resourceManager.GetAsset(OnUpdateActionsRefs[i].Id);
}
}
OnExitActions = new AIAction[OnExitActionsRefs == null ? 0 : OnExitActionsRefs.Length];
if (OnEnterActionsRefs != null)
{
for (Int32 i = 0; i < OnExitActionsRefs.Length; i++)
{
OnExitActions[i] = (AIAction)resourceManager.GetAsset(OnExitActionsRefs[i].Id);
}
}
Commitment = (AIFunctionBool)resourceManager.GetAsset(CommitmentRef.Id);
NextConsiderations = new Consideration[NextConsiderationsRefs == null ? 0 : NextConsiderationsRefs.Length];
if (NextConsiderationsRefs != null)
{
for (Int32 i = 0; i < NextConsiderationsRefs.Length; i++)
{
NextConsiderations[i] = (Consideration)resourceManager.GetAsset(NextConsiderationsRefs[i].Id);
}
}
}
}
}
|