Skip to content

Commit

Permalink
Mark agents as static if they spawn near goal (#125)
Browse files Browse the repository at this point in the history
* Init static agents

* Fix the compile error

* Formatting
  • Loading branch information
aaravpandya authored May 21, 2024
1 parent 3dd1e5e commit 02fff3b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/level_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ static inline Entity createAgent(Engine &ctx, const MapObject &agentInit) {
ctx.get<EntityType>(agent) = agentInit.type;

ctx.get<Goal>(agent)= Goal{.position = Vector2{.x = agentInit.goalPosition.x - ctx.data().mean.x, .y = agentInit.goalPosition.y - ctx.data().mean.y}};
if(ctx.data().numControlledVehicles < ctx.data().params.maxNumControlledVehicles && agentInit.type == EntityType::Vehicle && agentInit.valid[0])
{
ctx.get<ControlledState>(agent) = ControlledState{.controlledState = ControlMode::BICYCLE};
ctx.data().numControlledVehicles++;
}
else
{
ctx.get<ControlledState>(agent) = ControlledState{.controlledState = ControlMode::EXPERT};
}

// Since position, heading, and speed may vary within an episode, their
// values are retained so that on an episode reset they can be restored to
Expand All @@ -83,6 +74,21 @@ static inline Entity createAgent(Engine &ctx, const MapObject &agentInit) {
trajectory.valids[i] = agentInit.valid[i];
}

if((ctx.get<Goal>(agent).position - trajectory.positions[0]).length() < 0.5f)
{
ctx.get<ResponseType>(agent) = ResponseType::Static;
}

if(ctx.data().numControlledVehicles < ctx.data().params.maxNumControlledVehicles && agentInit.type == EntityType::Vehicle && agentInit.valid[0] && ctx.get<ResponseType>(agent) == ResponseType::Dynamic)
{
ctx.get<ControlledState>(agent) = ControlledState{.controlledState = ControlMode::BICYCLE};
ctx.data().numControlledVehicles++;
}
else
{
ctx.get<ControlledState>(agent) = ControlledState{.controlledState = ControlMode::EXPERT};
}

// This is not stricly necessary since , but is kept here for consistency
resetAgent(ctx, agent);

Expand Down

0 comments on commit 02fff3b

Please sign in to comment.