Skip to content

Commit 5e55f2d

Browse files
committed
Fixed issues with DomainBuilder
1 parent 71c9304 commit 5e55f2d

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

extension/src/Agents/AgentDomainBuilder.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class AgentDomainBuilder final : public BaseDomainBuilder
3333
}
3434
AgentDomainBuilder(StringType n) : BaseDomainBuilder(n) {}
3535

36-
// TODO Implement Extra HasState, SetState
37-
3836
//======================================================//
37+
//
3938
// Encapsulated HTN Tasks
39+
//
4040
//======================================================//
4141
// TODO Implement Encapsulated HTN Tasks
4242

@@ -51,9 +51,10 @@ class AgentDomainBuilder final : public BaseDomainBuilder
5151
{
5252
if (agentNode->has_method("moveTo"))
5353
{
54+
// Call the
5455
Variant result = agentNode->call("moveTo");
55-
// Variant result = agent->call("moveTo");
56-
// UtilityFunctions::print(result);
56+
57+
//? Can print output using: UtilityFunctions::print(result);
5758
if (result)
5859
{
5960
return TaskStatus::Success;
@@ -65,18 +66,24 @@ class AgentDomainBuilder final : public BaseDomainBuilder
6566
}
6667
else
6768
{
68-
// UtilityFunctions::print("AgentDomainBuilder : No Function moveTo");
69+
//? Can print output using:UtilityFunctions::print("AgentDomainBuilder : No Function moveTo");
6970
return TaskStatus::Failure;
7071
}
7172
}
7273
}
7374

7475
void MoveTo()
7576
{
77+
AddCondition("AgentNewPos", [=](IContext &ctx)
78+
{ return static_cast<AgentContext &>(ctx).HasState(WsAgent::wsAgentMovement, (int)(AgentMovement::NewPosition)); });
7679
AddAction("MoveTo");
7780

7881
AddOperator(std::bind(&AgentDomainBuilder::MoveToOperator, this, std::placeholders::_1));
7982

80-
// UtilityFunctions::print("Added MoveTo Operator");
83+
AddEffect("ArrivedAtNewPos", FluidEffectType::Permanent, [=](IContext &ctx, FluidEffectType effectType)
84+
{ return static_cast<AgentContext &>(ctx).SetState(
85+
WsAgent::wsAgentMovement, (int)(AgentMovement::Arrived), true, effectType); });
86+
87+
End();
8188
}
8289
};

extension/src/Agents/Domains/AgentXDomainDefinition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class AgentXDomainDefinition
3737
/*
3838
Tasks are encapsulated and defined in AgentDomainBuilder.h
3939
*/
40+
// TODO : Add all your needed encapsulated HTN tasks here
4041

4142
builder.AddSelector("MoveTo");
4243
builder.MoveTo();
43-
builder.End(); // End the MoveTO
4444
builder.End(); // End the Selector
4545

4646
return *builder.Build();

extension/src/Agents/Knowledge/AgentWorldState.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using namespace std;
66
enum class WsAgent
77
{
88
wsEnemyRange,
9+
wsAgentMovement,
910
wsHealth,
1011
};
1112

@@ -15,19 +16,27 @@ enum class EnemyRange
1516
OutOfRange,
1617
};
1718

19+
enum class AgentMovement
20+
{
21+
NewPosition,
22+
Arrived,
23+
};
24+
1825
typedef uint8_t EnemyRangeTy;
26+
typedef uint8_t MovementTy;
1927

2028
class AgentWorldState : public IWorldState<WsAgent, uint8_t, AgentWorldState>
2129
{
22-
uint8_t CurrentWorldState[2];
30+
uint8_t CurrentWorldState[3];
2331
EnemyRange currentRange;
2432

2533
public:
2634
AgentWorldState()
2735
{
28-
// TODO This initial setup could be incorrect in the end
36+
// TODO : Initial States for the Agent are setup here
2937
currentRange = static_cast<EnemyRange>(CurrentWorldState[static_cast<int>(WsAgent::wsEnemyRange)]);
3038
CurrentWorldState[(int)(WsAgent::wsEnemyRange)] = (int)(EnemyRange::InViewRange);
39+
CurrentWorldState[(int)(WsAgent::wsEnemyRange)] = (int)(AgentMovement::Arrived);
3140
}
3241

3342
bool HasState(WsAgent state, uint8_t value)
@@ -39,6 +48,6 @@ class AgentWorldState : public IWorldState<WsAgent, uint8_t, AgentWorldState>
3948

4049
void SetState(WsAgent state, uint8_t value) { CurrentWorldState[(int)state] = value; }
4150

42-
//! Size must match the Enums length
43-
int GetMaxPropertyCount() { return 2; }
51+
//! Size must match the CurrentWorldState length
52+
int GetMaxPropertyCount() { return 3; }
4453
};

extension/src/ai_blue_agent.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ void AIBlueAgent::planner_tick()
6161
* Note : Sensors go here
6262
*/
6363

64-
// TODO You will need to Bind Sensors so that they can be called in Godot
65-
void AIBlueAgent::vision_sensor()
64+
// TODO Update this to meet your Knowledge Definitions
65+
void AIBlueAgent::vision_sensor(int state, int value)
6666
{
67-
// Vision Sensor Code
67+
// Get Agent Movement State in the Agents Knowledge
68+
WsAgent wsAgentState = static_cast<WsAgent>(state);
69+
// Get the value to assign to that agents Knowledge State
70+
AgentMovement movementValue = static_cast<AgentMovement>(value);
71+
72+
_context.SetStateAgent(wsAgentState, MovementTy(movementValue), true, FluidEffectType::PlanAndExecute);
6873
}
6974

7075
/**
@@ -73,9 +78,10 @@ void AIBlueAgent::vision_sensor()
7378
* Note : All class Functions to be exposed to GDScript need to be setup here
7479
*/
7580

81+
// TODO : You will need to Bind Sensors so that they can be called in Godot
7682
void AIBlueAgent::_bind_methods()
7783
{
7884
ClassDB::bind_method(D_METHOD("agent_setup", "node"), &AIBlueAgent::agent_setup);
7985
ClassDB::bind_method(D_METHOD("planner_tick"), &AIBlueAgent::planner_tick);
80-
ClassDB::bind_method(D_METHOD("vision_sensor"), &AIBlueAgent::vision_sensor);
86+
ClassDB::bind_method(D_METHOD("vision_sensor", "state", "value"), &AIBlueAgent::vision_sensor);
8187
}

extension/src/ai_blue_agent.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ class AIBlueAgent : public Node3D
3838

3939
void _physics_process(double delta) override;
4040

41-
/**
41+
/*
4242
* Sensors
43-
*
4443
*/
45-
void vision_sensor();
44+
45+
// TODO : Add all your sensors to the top level class here
46+
47+
void vision_sensor(int state, int value);
4648
};
4749

4850
#endif // AIBlueAgent_CLASS_H

0 commit comments

Comments
 (0)