2014-05-29 10:10:08 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2014-06-06 16:22:26 +02:00
|
|
|
#include <objects/CharacterObject.hpp>
|
|
|
|
#include <objects/VehicleObject.hpp>
|
2014-06-06 18:04:00 +02:00
|
|
|
#include <ai/DefaultAIController.hpp>
|
2014-05-29 10:10:08 +02:00
|
|
|
#include "test_globals.hpp"
|
2016-04-17 05:54:19 +02:00
|
|
|
#include <engine/Animator.hpp>
|
2014-05-29 10:10:08 +02:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(CharacterTests)
|
|
|
|
|
2016-06-16 22:11:55 +02:00
|
|
|
#if RW_TEST_WITH_DATA
|
2014-05-29 10:10:08 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_create)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
|
|
|
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
auto controller = new DefaultAIController(character);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
|
2014-05-29 10:10:08 +02:00
|
|
|
// Check the initial activity is Idle.
|
2014-05-29 12:12:40 +02:00
|
|
|
BOOST_CHECK_EQUAL( controller->getCurrentActivity(), nullptr );
|
2014-05-29 10:10:08 +02:00
|
|
|
|
|
|
|
// Check that Idle activities are instantly displaced.
|
2014-05-29 12:12:40 +02:00
|
|
|
controller->setNextActivity( new Activities::GoTo( glm::vec3{ 1000.f, 0.f, 0.f } ) );
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( controller->getCurrentActivity()->name(), "GoTo" );
|
|
|
|
BOOST_CHECK_EQUAL( controller->getNextActivity(), nullptr );
|
2014-05-29 10:10:08 +02:00
|
|
|
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_activities)
|
|
|
|
{
|
|
|
|
{
|
2016-05-02 18:38:04 +02:00
|
|
|
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 225.6f});
|
2014-05-29 10:10:08 +02:00
|
|
|
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
auto controller = new DefaultAIController(character);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-31 09:18:50 +02:00
|
|
|
controller->setNextActivity( new Activities::GoTo( glm::vec3{ 10.f, 10.f, 0.f } ) );
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-29 12:12:40 +02:00
|
|
|
BOOST_CHECK_EQUAL( controller->getCurrentActivity()->name(), "GoTo" );
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2014-05-31 09:18:50 +02:00
|
|
|
for(float t = 0.f; t < 11.5f; t+=(1.f/60.f)) {
|
2014-05-29 10:10:08 +02:00
|
|
|
controller->update(1.f/60.f);
|
|
|
|
character->tick(1.f/60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
|
|
|
}
|
|
|
|
|
2016-05-28 02:06:13 +02:00
|
|
|
BOOST_CHECK_LT( glm::distance(character->getPosition(), {10.f, 10.f, 0.f}), 0.1f);
|
2014-05-29 10:10:08 +02:00
|
|
|
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
delete controller;
|
|
|
|
}
|
2014-05-29 12:12:40 +02:00
|
|
|
{
|
2014-06-06 16:22:26 +02:00
|
|
|
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
2014-05-29 12:12:40 +02:00
|
|
|
BOOST_REQUIRE(vehicle != nullptr);
|
2014-06-06 13:18:32 +02:00
|
|
|
BOOST_REQUIRE(vehicle->model != nullptr);
|
2014-05-29 12:12:40 +02:00
|
|
|
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
|
|
|
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
|
2014-06-06 18:04:00 +02:00
|
|
|
auto controller = new DefaultAIController(character);
|
2014-05-29 12:12:40 +02:00
|
|
|
|
|
|
|
controller->setNextActivity( new Activities::EnterVehicle( vehicle, 0 ) );
|
|
|
|
|
2014-05-31 09:18:50 +02:00
|
|
|
for(float t = 0.f; t < 0.5f; t+=(1.f/60.f)) {
|
2014-05-29 12:12:40 +02:00
|
|
|
character->tick(1.f/60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
|
|
|
|
2014-05-31 13:15:20 +02:00
|
|
|
for(float t = 0.f; t < 9.0f; t+=(1.f/60.f)) {
|
2014-05-29 12:12:40 +02:00
|
|
|
character->tick(1.f/60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( vehicle, character->getCurrentVehicle() );
|
2014-05-31 09:18:50 +02:00
|
|
|
|
2016-05-25 00:49:01 +02:00
|
|
|
controller->setNextActivity( new Activities::ExitVehicle( ) );
|
|
|
|
|
|
|
|
for(float t = 0.f; t < 9.0f; t+=(1.f/60.f)) {
|
|
|
|
character->tick(1.f/60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
|
|
|
|
|
|
|
character->setPosition(glm::vec3(5.f, 0.f, 0.f));
|
|
|
|
controller->setNextActivity( new Activities::EnterVehicle( vehicle, 0 ) );
|
|
|
|
|
|
|
|
for(float t = 0.f; t < 0.5f; t+=(1.f/60.f)) {
|
|
|
|
character->tick(1.f/60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
|
|
|
controller->skipActivity();
|
|
|
|
|
|
|
|
for(float t = 0.f; t < 5.0f; t+=(1.f/60.f)) {
|
|
|
|
character->tick(1.f/60.f);
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
|
|
|
|
2014-05-31 09:18:50 +02:00
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
delete controller;
|
2014-05-29 12:12:40 +02:00
|
|
|
}
|
2014-05-29 10:10:08 +02:00
|
|
|
}
|
|
|
|
|
2016-04-17 05:54:19 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_death)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
auto controller = new DefaultAIController(character);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( character->getCurrentState().health, 100.f );
|
|
|
|
BOOST_CHECK( character->isAlive() );
|
|
|
|
|
|
|
|
GameObject::DamageInfo dmg;
|
|
|
|
dmg.type = GameObject::DamageInfo::Bullet;
|
|
|
|
dmg.hitpoints = character->getCurrentState().health + 1.f;
|
|
|
|
|
|
|
|
// Do some damage
|
|
|
|
BOOST_CHECK(character->takeDamage(dmg));
|
|
|
|
|
|
|
|
BOOST_CHECK( ! character->isAlive() );
|
|
|
|
|
|
|
|
character->tick(0.16f);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(
|
|
|
|
character->animator->getAnimation(0),
|
|
|
|
character->animations.ko_shot_front);
|
|
|
|
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
delete controller;
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
2016-04-17 05:54:19 +02:00
|
|
|
|
2014-05-29 10:10:08 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
|