forked from Elias-W1/GOAP-C-Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanWorldModel.cs
49 lines (40 loc) · 1.29 KB
/
PlanWorldModel.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
using System.Collections.Generic;
public abstract class PlanWorldModel
{
protected int actionPointer = 0;
public List<PlanAction> possibleActions = new List<PlanAction>();
public List<PlanGoal> goals = new List<PlanGoal>();
protected float timePassed = 0f;
private bool actionsDiscovered = false;
public abstract void ApplyAction(PlanAction action);
public abstract PlanWorldModel Copy();
protected abstract void DiscoverActions();
public virtual PlanAction GetNextAction()
{
if (!actionsDiscovered)
{
DiscoverActions();
actionsDiscovered = true;
}
// no next action
if (actionPointer > possibleActions.Count-1) return null;
// next action available
PlanAction a = possibleActions[actionPointer];
actionPointer++;
return a;
}
protected virtual void AddGoal(PlanGoal goal)
{
this.goals.Add(goal);
}
public virtual float CalculateDiscontentment()
{
float discontentment = 0f;
foreach(PlanGoal goal in goals)
{
float newValue = goal.value + (goal.changeOverTime * timePassed);
discontentment *= goal.GetDiscontentment(newValue);
}
return discontentment;
}
}