Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/reone/game/object/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Creature : public Object, public scene::IAnimationEventListener {
// END Equipment

// Pathfinding
bool navigateToObject(const Object &object, bool run, float distance, float dt);
bool navigateTo(const glm::vec3 &dest, bool run, float distance, float dt);
void clearPath();
void advanceOnPath(const glm::vec3 &dest, const glm::vec3 &dir, bool run, float distance, float dt);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/game/action/closedoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace game {
void CloseDoorAction::execute(std::shared_ptr<Action> self, Object &actor, float dt) {
auto creatureActor = _game.getObjectById<Creature>(actor.id());

bool reached = !creatureActor || creatureActor->navigateTo(_door->position(), true, kDefaultMaxObjectDistance, dt);
bool reached = !creatureActor || creatureActor->navigateToObject(*_door, true, kDefaultMaxObjectDistance, dt);
if (reached) {
_door->close();
complete();
Expand Down
4 changes: 2 additions & 2 deletions src/libs/game/action/commonactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void tryUnlockDoorWithKey(Door &door, Object &actor, Party &party) {
bool unlockDoor(Door &door, Object &actor, float distance, float dt) {
if (actor.type() == ObjectType::Creature) {
auto &creature = static_cast<Creature &>(actor);
bool reached = creature.navigateTo(door.position(), true, distance, dt);
bool reached = creature.navigateToObject(door, true, distance, dt);
if (!reached) {
return false;
}
Expand All @@ -80,7 +80,7 @@ bool unlockDoor(Door &door, Object &actor, float distance, float dt) {

bool unlockPlaceable(Placeable &placeable, Object &actor, float distance, float dt) {
if (auto *creature = dyn_cast<Creature>(&actor)) {
bool reached = creature->navigateTo(placeable.position(), true, distance, dt);
bool reached = creature->navigateToObject(placeable, true, distance, dt);
if (!reached) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/game/action/follow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void FollowAction::execute(std::shared_ptr<Action> self, Object &actor, float dt
float distance2 = creatureActor->getSquareDistanceTo(glm::vec2(dest));
bool run = distance2 > kDistanceWalk * kDistanceWalk;

if (creatureActor->navigateTo(dest, run, _followDistance, dt)) {
if (creatureActor->navigateToObject(*_follow, run, _followDistance, dt)) {
complete();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/game/action/followleader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void FollowLeaderAction::execute(std::shared_ptr<Action> self, Object &actor, fl
float distance2 = creatureActor->getSquareDistanceTo(glm::vec2(destination));
bool run = distance2 > kDistanceWalk;

if (creatureActor->navigateTo(destination, run, kDefaultFollowDistance, dt)) {
if (creatureActor->navigateToObject(*leader, run, kDefaultFollowDistance, dt)) {
complete();
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/libs/game/action/movetoobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ void MoveToObjectAction::execute(std::shared_ptr<Action> self, Object &actor, fl
}
}

bool reached = creatureActor->navigateTo(dest, _run, _range, dt);
bool reached = false;
if (_moveTo) {
reached = creatureActor->navigateToObject(*_moveTo, _run, _range, dt);
} else {
reached = creatureActor->navigateTo(dest, _run, _range, dt);
}

if (reached) {
complete();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/game/action/opencontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void OpenContainerAction::execute(std::shared_ptr<Action> self, Object &actor, f
}

auto &creatureActor = cast<Creature>(actor);
bool reached = creatureActor.navigateTo(_object->position(), true, kDefaultMaxObjectDistance, dt);
bool reached = creatureActor.navigateToObject(*_object, true, kDefaultMaxObjectDistance, dt);
if (reached) {
_game.openContainer(_object);
complete();
Expand Down
2 changes: 1 addition & 1 deletion src/libs/game/action/opendoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace game {
void OpenDoorAction::execute(std::shared_ptr<Action> self, Object &actor, float dt) {
if (actor.type() == ObjectType::Creature) {
auto &creature = static_cast<Creature &>(actor);
bool reached = creature.navigateTo(_door->position(), true, kDefaultMaxObjectDistance, dt);
bool reached = creature.navigateToObject(*_door, true, kDefaultMaxObjectDistance, dt);
if (!reached) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/game/action/startconversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void StartConversationAction::execute(std::shared_ptr<Action> self, Object &acto
}
bool reached =
_ignoreStartRange ||
creatureActor->navigateTo(_objectToConverse->position(), true, kMaxConversationDistance, dt);
creatureActor->navigateToObject(*_objectToConverse, true, kMaxConversationDistance, dt);

if (!reached) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/game/attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ bool navigateToAttackTarget(Creature &attacker, Object &target, float dt, bool &
return true;
}

if (!attacker.navigateTo(target.position(), true, attacker.getAttackRange(), dt)) {
if (!attacker.navigateToObject(target, true, attacker.getAttackRange(), dt)) {
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions src/libs/game/object/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,16 @@ glm::vec3 Creature::computeSteeringForce(const Uniwalk &uni, const glm::vec3 &ne
return combinedForce;
}

bool Creature::navigateToObject(const Object &object, bool run, float distance, float dt) {
float epsilon = 0.2f;
float minDistance = creaturePersonalSpace() + epsilon;
if (auto creature = dyn_cast<Creature>(&object)) {
minDistance += creature->creaturePersonalSpace();
}
glm::vec3 dest = object.position();
return navigateTo(dest, run, std::max(minDistance, distance), dt);
}

bool Creature::navigateTo(const glm::vec3 &dest, bool run, float distance, float dt) {
if (_movementRestricted)
return false;
Expand Down
Loading