Fixing bugs with pathfinding, bump version
This commit is contained in:
1 parent
8e2b019c92
commit
f1cc28ab31
22 files changed
+1119
-759
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#include "LocationGameState.h"
|
||||
#include "game_server/InternalGameServer.h"
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
@@ -12,6 +13,19 @@ int fail(const char* message)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
FRG::Vec3fp point(float x, float y, float z)
|
||||
{
|
||||
return {
|
||||
static_cast<FRG::fp>(x),
|
||||
static_cast<FRG::fp>(y),
|
||||
static_cast<FRG::fp>(z)};
|
||||
}
|
||||
|
||||
bool samePoint(const FRG::Vec3fp& left, const FRG::Vec3fp& right)
|
||||
{
|
||||
return left.x == right.x && left.y == right.y && left.z == right.z;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
@@ -74,17 +88,34 @@ int main()
|
||||
!singlePlayerBattleZone || !multiplayerBattleZoneConfig) {
|
||||
return fail("Expected three campaigns including both Battle Zone modes");
|
||||
}
|
||||
if (singlePlayerBattleZone->startStatePath !=
|
||||
multiplayerBattleZoneConfig->startStatePath) {
|
||||
return fail("Battle Zone modes do not share their initial state");
|
||||
if (singlePlayerBattleZone->startStatePath.empty() ||
|
||||
multiplayerBattleZoneConfig->startStatePath.empty()) {
|
||||
return fail("Battle Zone modes are missing initial state paths");
|
||||
}
|
||||
if (multiplayerBattleZoneConfig->networkPlayerSlots.size() != 2 ||
|
||||
if (multiplayerBattleZoneConfig->networkPlayerSlots.size() != 4 ||
|
||||
multiplayerBattleZoneConfig->networkPlayerSlots[0] != "player1" ||
|
||||
multiplayerBattleZoneConfig->networkPlayerSlots[1] !=
|
||||
"player2" ||
|
||||
multiplayerBattleZoneConfig->networkPlayerSlots[2] != "player3" ||
|
||||
multiplayerBattleZoneConfig->networkPlayerSlots[3] != "player4" ||
|
||||
multiplayerBattleZoneConfig->networkCompatibility.empty()) {
|
||||
return fail("Multiplayer player slots were not loaded");
|
||||
}
|
||||
const std::string compatibilityFingerprint =
|
||||
FRG::makeNetworkCompatibilityFingerprint(
|
||||
*multiplayerBattleZoneConfig);
|
||||
FRG::CampaignConfig reorderedContent = *multiplayerBattleZoneConfig;
|
||||
if (reorderedContent.locations.empty() ||
|
||||
reorderedContent.locations.front().navigationJsonPaths.size() < 2) {
|
||||
return fail("Expected multiple navigation maps for fingerprint test");
|
||||
}
|
||||
std::reverse(
|
||||
reorderedContent.locations.front().navigationJsonPaths.begin(),
|
||||
reorderedContent.locations.front().navigationJsonPaths.end());
|
||||
if (compatibilityFingerprint ==
|
||||
FRG::makeNetworkCompatibilityFingerprint(reorderedContent)) {
|
||||
return fail("Compatibility fingerprint ignored navigation-map order");
|
||||
}
|
||||
|
||||
FRG::LocationDefinition definition;
|
||||
definition.config.id = "test_location";
|
||||
@@ -152,18 +183,18 @@ int main()
|
||||
hostileNpc.enabled = true;
|
||||
hostileNpc.canAttack = true;
|
||||
hostileNpc.hp = hostileNpc.initialHp = 75.f;
|
||||
hostileNpc.position = Eigen::Vector3f::Zero();
|
||||
hostileNpc.homePosition = {5.f, 0.f, 0.f};
|
||||
hostileNpc.position = point(0.f, 0.f, 0.f);
|
||||
hostileNpc.homePosition = point(5.f, 0.f, 0.f);
|
||||
hostileNpc.stopInPlace();
|
||||
|
||||
auto playerOne = std::make_shared<FRG::CharacterState>();
|
||||
playerOne->configureAsPlayer();
|
||||
playerOne->enabled = true;
|
||||
playerOne->position = {3.f, 0.f, 0.f};
|
||||
playerOne->position = point(3.f, 0.f, 0.f);
|
||||
auto playerTwo = std::make_shared<FRG::CharacterState>();
|
||||
playerTwo->configureAsPlayer();
|
||||
playerTwo->enabled = true;
|
||||
playerTwo->position = {2.f, 0.f, 0.f};
|
||||
playerTwo->position = point(2.f, 0.f, 0.f);
|
||||
FRG::PlayerStateMap combatPlayers{
|
||||
{"player1", playerOne}, {"player2", playerTwo}};
|
||||
|
||||
@@ -172,8 +203,8 @@ int main()
|
||||
return fail("Hostile NPC did not select the nearest player");
|
||||
}
|
||||
|
||||
playerOne->position = {1.f, 0.f, 0.f};
|
||||
playerTwo->position = {4.f, 0.f, 0.f};
|
||||
playerOne->position = point(1.f, 0.f, 0.f);
|
||||
playerTwo->position = point(4.f, 0.f, 0.f);
|
||||
state.update(100, combatPlayers, false);
|
||||
if (hostileNpc.attackTargetId != "player2") {
|
||||
return fail("Hostile NPC did not retain its living target lock");
|
||||
@@ -189,64 +220,12 @@ int main()
|
||||
state.update(100, combatPlayers, false);
|
||||
if (!hostileNpc.attackTargetId.empty() ||
|
||||
hostileNpc.battle_state != 0 ||
|
||||
(hostileNpc.requestedWalkTarget - hostileNpc.homePosition).norm() >
|
||||
FRG::CharacterState::kWalkThreshold) {
|
||||
(hostileNpc.requestedWalkTarget -
|
||||
hostileNpc.homePosition).normSquared() >
|
||||
FRG::CharacterState::kWalkThreshold_SQUARED()) {
|
||||
return fail("Hostile NPC did not return home after losing its target");
|
||||
}
|
||||
|
||||
auto blocker = std::make_shared<FRG::CharacterState>();
|
||||
blocker->enabled = true;
|
||||
blocker->hp = 50.f;
|
||||
blocker->position = {0.8f, 0.f, 0.f};
|
||||
state.npcs["blocker"] = blocker;
|
||||
hostileNpc.position = Eigen::Vector3f::Zero();
|
||||
hostileNpc.homePosition = {5.f, 0.f, 0.f};
|
||||
hostileNpc.attackTargetId = "player1";
|
||||
hostileNpc.requestedWalkTarget = playerOne->position;
|
||||
hostileNpc.walkTarget = playerOne->position;
|
||||
hostileNpc.pathWaypoints = {playerOne->position};
|
||||
hostileNpc.currentWaypointIndex = 0;
|
||||
hostileNpc.movementBlockedTicks = 0;
|
||||
playerOne->enabled = true;
|
||||
playerOne->hp = 75.f;
|
||||
playerOne->position = {4.f, 0.f, 0.f};
|
||||
playerTwo->enabled = true;
|
||||
playerTwo->hp = 75.f;
|
||||
playerTwo->position = {2.f, 0.f, 0.f};
|
||||
|
||||
bool blockedRetryRequested = false;
|
||||
for (int tick = 0; tick < 10 && !blockedRetryRequested; ++tick) {
|
||||
const FRG::LocationSimulationEvents events =
|
||||
state.update(100, combatPlayers, false);
|
||||
for (const auto& event : events.characters) {
|
||||
if (event.characterId == "npc" &&
|
||||
event.events.forceNavigationReplan) {
|
||||
blockedRetryRequested = true;
|
||||
if (!state.replanCharacter(
|
||||
"npc", combatPlayers,
|
||||
event.events.blockingCharacterId)) {
|
||||
return fail("Blocked NPC replan was rejected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!blockedRetryRequested ||
|
||||
hostileNpc.attackTargetId != "player2" ||
|
||||
(hostileNpc.requestedWalkTarget - playerTwo->position).norm() >
|
||||
FRG::CharacterState::kWalkThreshold) {
|
||||
return fail("Blocked NPC did not switch to the nearest player");
|
||||
}
|
||||
|
||||
playerOne->enabled = false;
|
||||
playerTwo->enabled = false;
|
||||
if (!state.replanCharacter("npc", combatPlayers, "blocker") ||
|
||||
!hostileNpc.attackTargetId.empty() ||
|
||||
hostileNpc.battle_state != 0 ||
|
||||
(hostileNpc.requestedWalkTarget - hostileNpc.homePosition).norm() >
|
||||
FRG::CharacterState::kWalkThreshold) {
|
||||
return fail("Blocked NPC did not return home without an eligible target");
|
||||
}
|
||||
|
||||
FRG::CampaignConfig battleZone;
|
||||
battleZone.id = "battle_zone";
|
||||
battleZone.questsPath = "resources/config/quests_battle_zone.json";
|
||||
@@ -295,8 +274,9 @@ int main()
|
||||
return fail(
|
||||
"Loaded multiplayer slot did not restore animation metadata");
|
||||
}
|
||||
if (!loadedNetworkBot->second.state.position.isApprox(
|
||||
Eigen::Vector3f(4.f, 0.f, 5.f))) {
|
||||
if (!samePoint(
|
||||
loadedNetworkBot->second.state.position,
|
||||
point(4.f, 0.f, 5.f))) {
|
||||
return fail("Loaded multiplayer slot position was overwritten");
|
||||
}
|
||||
if (loadedNetworkBot->second.state.enabled)
|
||||
@@ -304,19 +284,19 @@ int main()
|
||||
|
||||
const std::string locationId = loadedNetworkSnapshot->currentLocationId;
|
||||
networkServer.submit(FRG::SetCharacterPositionCommand{
|
||||
locationId, "player2", Eigen::Vector3f(7.f, 0.f, 8.f), true});
|
||||
locationId, "player2", point(7.f, 0.f, 8.f), true});
|
||||
networkServer.submit(FRG::SetCharacterFacingAngleCommand{
|
||||
locationId, "player2", 1.5f, true});
|
||||
locationId, "player2", FRG::fp(1.5f), true});
|
||||
networkServer.submit(FRG::SetCharacterFaceTargetCommand{
|
||||
locationId, "player2", "player1"});
|
||||
networkServer.submit(FRG::SetCharacterEnabledCommand{
|
||||
locationId, "player2", false});
|
||||
const auto commandSnapshot = networkServer.snapshot();
|
||||
const auto commandCharacter = commandSnapshot->players.at("player2").state;
|
||||
if (!commandCharacter.position.isApprox(Eigen::Vector3f(7.f, 0.f, 8.f)) ||
|
||||
!commandCharacter.homePosition.isApprox(Eigen::Vector3f(7.f, 0.f, 8.f)) ||
|
||||
commandCharacter.facingAngle != 1.5f ||
|
||||
commandCharacter.targetFacingAngle != 1.5f ||
|
||||
if (!samePoint(commandCharacter.position, point(7.f, 0.f, 8.f)) ||
|
||||
!samePoint(commandCharacter.homePosition, point(7.f, 0.f, 8.f)) ||
|
||||
commandCharacter.facingAngle != FRG::fp(1.5f) ||
|
||||
commandCharacter.targetFacingAngle != FRG::fp(1.5f) ||
|
||||
!commandCharacter.faceTargetId.empty() ||
|
||||
commandCharacter.enabled) {
|
||||
return fail("Semantic character commands were not applied");
|
||||
@@ -330,61 +310,20 @@ int main()
|
||||
}
|
||||
|
||||
FRG::CharacterState guardedMover;
|
||||
guardedMover.configureAsPlayer();
|
||||
guardedMover.enabled = true;
|
||||
guardedMover.position = Eigen::Vector3f::Zero();
|
||||
guardedMover.walkTarget = Eigen::Vector3f(2.f, 0.f, 0.f);
|
||||
guardedMover.requestedWalkTarget = guardedMover.walkTarget;
|
||||
guardedMover.pathWaypoints = {guardedMover.walkTarget};
|
||||
const std::vector<FRG::CharacterMovementObstacle> movementObstacles{
|
||||
{"mover", Eigen::Vector3f::Zero(), 0.45f},
|
||||
{"blocker", Eigen::Vector3f(0.8f, 0.f, 0.f), 0.45f}};
|
||||
FRG::CharacterUpdateContext guardedContext;
|
||||
guardedContext.characterId = "mover";
|
||||
guardedContext.movementObstacles = &movementObstacles;
|
||||
FRG::CharacterUpdateEvents blockedEvents;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
blockedEvents = guardedMover.update(100, guardedContext);
|
||||
if (!guardedMover.position.isZero() ||
|
||||
blockedEvents.forceNavigationReplan ||
|
||||
!guardedMover.pathWaypoints.empty()) {
|
||||
return fail("Movement guard did not cancel the blocked player action");
|
||||
}
|
||||
nlohmann::json guardedJson;
|
||||
guardedMover.velocity = {
|
||||
FRG::fp::from_raw_value(12345),
|
||||
FRG::fp::from_raw_value(-6789)};
|
||||
guardedMover.save(guardedJson);
|
||||
FRG::CharacterState restoredGuardedMover;
|
||||
restoredGuardedMover.load(guardedJson);
|
||||
if (restoredGuardedMover.movementBlockedTicks !=
|
||||
guardedMover.movementBlockedTicks ||
|
||||
restoredGuardedMover.navigationRetryTicks !=
|
||||
guardedMover.navigationRetryTicks) {
|
||||
return fail("Movement blockage state did not round trip");
|
||||
}
|
||||
|
||||
FRG::LocationGameState occupancyState;
|
||||
auto stationary = std::make_shared<FRG::CharacterState>();
|
||||
stationary->enabled = true;
|
||||
stationary->hp = 10.f;
|
||||
stationary->position = Eigen::Vector3f(4.f, 0.f, 0.f);
|
||||
auto moving = std::make_shared<FRG::CharacterState>();
|
||||
moving->enabled = true;
|
||||
moving->hp = 10.f;
|
||||
moving->pathWaypoints = {Eigen::Vector3f(8.f, 0.f, 0.f)};
|
||||
moving->movedLastTick = true;
|
||||
moving->attackTargetId = "stationary";
|
||||
FRG::PlayerStateMap occupancyPlayers{
|
||||
{"stationary", stationary}, {"moving", moving}};
|
||||
if (occupancyState.collectPathObstacles(
|
||||
"requester", occupancyPlayers).size() != 1 ||
|
||||
occupancyState.collectPathObstacles(
|
||||
"requester", occupancyPlayers, "moving").size() != 2 ||
|
||||
!occupancyState.collectPathObstacles(
|
||||
"stationary", occupancyPlayers).empty() ||
|
||||
!occupancyState.collectPathObstacles(
|
||||
"moving", occupancyPlayers).empty() ||
|
||||
occupancyState.collectPathObstacles(
|
||||
"moving", occupancyPlayers, "stationary").size() != 1) {
|
||||
return fail("Stationary obstacle collection policy is incorrect");
|
||||
guardedMover.navigationRetryTicks ||
|
||||
restoredGuardedMover.velocity.x.raw_value() != 12345 ||
|
||||
restoredGuardedMover.velocity.y.raw_value() != -6789) {
|
||||
return fail("Character velocity did not round trip");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in new issue
Block a user