Skip to content

Commit

Permalink
[AI] Use setImpulseRequest() to ensure valid request values
Browse files Browse the repository at this point in the history
  • Loading branch information
oznogon committed Mar 19, 2023
1 parent b958d90 commit 5a4d862
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ShipAI::run(float delta)
{
owner->target_rotation = owner->getRotation();
owner->warp_request = 0.0;
owner->impulse_request = 0.0f;
owner->setImpulseRequest(0.0f);

updateWeaponState(delta);
if (update_target_delay > 0.0f)
Expand Down Expand Up @@ -599,13 +599,13 @@ void ShipAI::flyTowards(glm::vec2 target, float keep_distance)
keep_distance = 0.0;

if (distance > keep_distance + owner->impulse_max_speed * 5.0f)
owner->impulse_request = 1.0f;
owner->setImpulseRequest(1.0f);
else
owner->impulse_request = (distance - keep_distance) / owner->impulse_max_speed * 5.0f;
owner->setImpulseRequest((distance - keep_distance) / owner->impulse_max_speed * 5.0f);
if (rotation_diff > 90)
owner->impulse_request = -owner->impulse_request;
owner->setImpulseRequest(-owner->impulse_request);
else if (rotation_diff < 45)
owner->impulse_request *= 1.0f - ((rotation_diff - 45.0f) / 45.0f);
owner->setImpulseRequest(owner->impulse_request * (1.0f - ((rotation_diff - 45.0f) / 45.0f)));
}
}

Expand Down Expand Up @@ -633,19 +633,19 @@ void ShipAI::flyFormation(P<SpaceObject> target, glm::vec2 offset)
{
float angle_diff = angleDifference(owner->target_rotation, owner->getRotation());
if (angle_diff > 10.0f)
owner->impulse_request = 0.0f;
owner->setImpulseRequest(0.0f);
else if (angle_diff > 5.0f)
owner->impulse_request = (10.0f - angle_diff) / 5.0f;
owner->setImpulseRequest((10.0f - angle_diff) / 5.0f);
else
owner->impulse_request = 1.0f;
owner->setImpulseRequest(1.0f);
}else{
if (distance > r / 2.0f)
{
owner->target_rotation += angleDifference(owner->target_rotation, target->getRotation()) * (1.0f - distance / r);
owner->impulse_request = distance / r;
owner->setImpulseRequest(distance / r);
}else{
owner->target_rotation = target->getRotation();
owner->impulse_request = 0.0f;
owner->setImpulseRequest(0.0f);
}
}
}else{
Expand Down
2 changes: 1 addition & 1 deletion src/ai/fighterAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void FighterAI::runAttack(P<SpaceObject> target)
else
{
owner->target_rotation = evade_direction;
owner->impulse_request = 1.0;
owner->setImpulseRequest(1.0f);
}
break;
case recharge:
Expand Down

0 comments on commit 5a4d862

Please sign in to comment.