-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathOtto.cs
74 lines (64 loc) · 2.31 KB
/
Otto.cs
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
using System;
using Unity.AI.Planner;
using Unity.AI.Planner.DomainLanguage.TraitBased;
using Unity.Collections;
using Unity.Entities;
using UnityEngine.AI.Planner.DomainLanguage.TraitBased;
#if PLANNER_DOMAIN_GENERATED
using AI.Planner.Actions.WorkaholicAgent;
using AI.Planner.Domains;
#endif
namespace Workaholic
{
#if PLANNER_DOMAIN_GENERATED
[Serializable]
public class Otto : BaseAgent<Otto, DomainObject, StateEntityKey, StateData, StateDataContext, ActionScheduler, NeedHeuristic, TerminationEvaluator, StateManager, ActionKey>
{
public bool Dead { get; set; }
public static ComponentType[] NeedFilter;
public static ComponentType[] InventoryFilter;
void Awake()
{
NeedFilter = new ComponentType[] { typeof(Need) };
InventoryFilter = new ComponentType[] { typeof(Inventory) };
}
protected override void Update()
{
if (!Dead)
base.Update();
}
}
public struct NeedHeuristic : IHeuristic<StateData>
{
public float Evaluate(StateData stateData)
{
var totalNeedsUrgency = 0L;
// Resources
var domainObjects = new NativeList<(DomainObject, int)>(4, Allocator.Temp);
foreach (var (_, domainObjectIndex) in stateData.GetDomainObjects(domainObjects, Otto.NeedFilter))
{
var needTrait = stateData.GetTraitOnObjectAtIndex<Need>(domainObjectIndex);
totalNeedsUrgency += needTrait.Urgency;
}
float value = 50;
// Score based on total urgency over all needs (0 -> 300).
if (totalNeedsUrgency > 50)
value = 0;
if (totalNeedsUrgency > 100)
value = -30;
if (totalNeedsUrgency > 150)
value = -50;
if (totalNeedsUrgency > 200)
value = -150;
domainObjects.Clear();
foreach (var (_, domainObjectIndex) in stateData.GetDomainObjects(domainObjects, Otto.InventoryFilter))
{
var inventoryTrait = stateData.GetTraitOnObjectAtIndex<Inventory>(domainObjectIndex);
value += inventoryTrait.Amount * 10;
}
domainObjects.Dispose();
return value;
}
}
#endif
}