Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve player vehicle enter behaviour #725

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
27 changes: 23 additions & 4 deletions rwengine/src/ai/CharacterController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,28 @@
bool Activities::EnterVehicle::canSkip(CharacterObject *character,
CharacterController *) const {
// If we're already inside the vehicle, it can't helped.
return character->getCurrentVehicle() == nullptr;
if (character->getCurrentVehicle() != nullptr) {
return false;

Check warning on line 377 in rwengine/src/ai/CharacterController.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/ai/CharacterController.cpp#L377

Added line #L377 was not covered by tests
}

switch (character->getCurrentCycle())
{
case AnimCycle::CarOpenLHS:

Check warning on line 382 in rwengine/src/ai/CharacterController.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/ai/CharacterController.cpp#L382

Added line #L382 was not covered by tests
case AnimCycle::CarGetInLHS:
case AnimCycle::CarPullOutLHS:
case AnimCycle::CarOpenRHS:
case AnimCycle::CarGetInRHS:
case AnimCycle::CarPullOutRHS:
return false;
default:
return true;

Check warning on line 390 in rwengine/src/ai/CharacterController.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/ai/CharacterController.cpp#L388-L390

Added lines #L388 - L390 were not covered by tests
}
}

bool Activities::EnterVehicle::update(CharacterObject *character,
CharacterController *controller) {
constexpr float kSprintToEnterDistance = 5.f;
constexpr float kGiveUpDistance = 100.f;
constexpr float kGiveUpDistance = 50.f;

Check warning on line 397 in rwengine/src/ai/CharacterController.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/ai/CharacterController.cpp#L397

Added line #L397 was not covered by tests

RW_UNUSED(controller);

Expand Down Expand Up @@ -424,6 +439,7 @@
bool tryToEnter = false;

if (entering) {
character->setPosition(entryPos);
if (character->getCurrentCycle() == cycle_open) {
if (character->animator->isCompleted(AnimIndexAction)) {
tryToEnter = true;
Expand All @@ -432,7 +448,6 @@
0.5f) {
vehicle->setPartTarget(entryDoor, true, entryDoor->openAngle);
} else {
// character->setPosition(vehicle->getSeatEntryPosition(seat));
character->rotation = vehicle->getRotation();
}
} else if (character->getCurrentCycle() == cycle_pullout) {
Expand All @@ -443,6 +458,7 @@
if (character->animator->isCompleted(AnimIndexAction)) {
/// @todo move to a more suitable place
vehicle->grantOccupantRewards(character);
vehicle->setImmobilised(false);

// VehicleGetIn is over, finish activity
return true;
Expand All @@ -455,6 +471,7 @@
float targetDistance = glm::length(targetDirection);

if (targetDistance <= 0.4f) {
character->setPosition(entryPos);
entering = true;
// Warp character to vehicle orientation
character->controller->setMoveDirection({0.f, 0.f, 0.f});
Expand Down Expand Up @@ -495,6 +512,8 @@

currentOccupant->controller->setNextActivity(
std::make_unique<Activities::ExitVehicle>(true));

vehicle->setImmobilised(true);
} else {
character->playCycle(cycle_enter);
character->enterVehicle(vehicle, seat);
Expand Down Expand Up @@ -528,7 +547,7 @@

character->rotation = vehicle->getRotation();

// Exit the vehicle immediatley
// Exit the vehicle immediately
character->enterVehicle(nullptr, seat);
character->setPosition(exitPos);

Expand Down
14 changes: 6 additions & 8 deletions rwengine/src/objects/CharacterObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,12 @@
// enterAction(VehicleSit);
return true;
}
} else {
if (currentVehicle) {
currentVehicle->setOccupant(seat, nullptr);
// Disabled due to crashing.
// setPosition(currentVehicle->getPosition());
setCurrentVehicle(nullptr, 0);
return true;
}
} else if (currentVehicle) {
currentVehicle->setOccupant(seat, nullptr);

Check warning on line 496 in rwengine/src/objects/CharacterObject.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/objects/CharacterObject.cpp#L496

Added line #L496 was not covered by tests
// Disabled due to crashing.
// setPosition(currentVehicle->getPosition());
setCurrentVehicle(nullptr, 0);
return true;

Check warning on line 500 in rwengine/src/objects/CharacterObject.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/objects/CharacterObject.cpp#L499-L500

Added lines #L499 - L500 were not covered by tests
}
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions rwengine/src/objects/VehicleObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@
}
}

if (immobilised) {
// An immobilised car should not be able to move on it's own.
engineForce = 0.f;
brakeF = 5.f;
}

Check warning on line 413 in rwengine/src/objects/VehicleObject.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/objects/VehicleObject.cpp#L411-L413

Added lines #L411 - L413 were not covered by tests

for (int w = 0; w < physVehicle->getNumWheels(); ++w) {
btWheelInfo& wi = physVehicle->getWheelInfo(w);

Expand Down Expand Up @@ -694,6 +700,14 @@
return handbrake;
}

void VehicleObject::setImmobilised(bool immobile) {
immobilised = immobile;
}

Check warning on line 705 in rwengine/src/objects/VehicleObject.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/objects/VehicleObject.cpp#L703-L705

Added lines #L703 - L705 were not covered by tests

bool VehicleObject::getImmobilised() const {
return immobilised;

Check warning on line 708 in rwengine/src/objects/VehicleObject.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/objects/VehicleObject.cpp#L707-L708

Added lines #L707 - L708 were not covered by tests
}

void VehicleObject::ejectAll() {
for (std::map<size_t, GameObject*>::iterator it = seatOccupants.begin();
it != seatOccupants.end();) {
Expand Down
5 changes: 5 additions & 0 deletions rwengine/src/objects/VehicleObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class VehicleObject final : public GameObject {
float throttle{0.f};
float brake{0.f};
bool handbrake = true;
bool immobilised = false;
std::vector<btScalar> wheelsRotation;

Atomic* chassishigh_ = nullptr;
Expand Down Expand Up @@ -147,6 +148,10 @@ class VehicleObject final : public GameObject {

bool getHandbraking() const;

void setImmobilised(bool);

bool getImmobilised() const;

void tick(float dt) override;

void tickPhysics(float dt);
Expand Down
2 changes: 1 addition & 1 deletion rwengine/src/script/ScriptMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void ScriptMachine::executeThread(SCMThread& t, int msPassed) {
if (a.type == SCMType::TString) {
printf(" %1x:'%s'", a.type, a.string);
} else if (a.type == SCMType::TFloat16) {
printf(" %1x:%f", a.type, a.realValue());
printf(" %1x:%f", a.type, static_cast<float>(a.realValue()));
} else {
printf(" %1x:%d", a.type, a.integerValue());
}
Expand Down