2014-06-28 04:22:53 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include "test_globals.hpp"
|
|
|
|
#include <objects/CharacterObject.hpp>
|
|
|
|
#include <data/WeaponData.hpp>
|
2014-07-14 02:29:05 +02:00
|
|
|
#include <objects/ProjectileObject.hpp>
|
2014-06-28 04:22:53 +02:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(WeaponTests)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(TestWeaponScan)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Test RADIUS scan
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
BOOST_REQUIRE( character->model != nullptr);
|
|
|
|
BOOST_REQUIRE( character->physObject != nullptr);
|
|
|
|
|
|
|
|
WeaponScan scan( 10.f, {0.f, 0.f, 10.f}, {0.f,0.f, -10.f} );
|
|
|
|
|
|
|
|
Global::get().e->doWeaponScan( scan );
|
|
|
|
|
|
|
|
BOOST_CHECK( character->mHealth < 100.f );
|
2014-06-28 18:20:49 +02:00
|
|
|
|
|
|
|
Global::get().e->destroyObject(character);
|
2014-06-28 04:22:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-14 02:29:05 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(TestProjectile)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
|
|
|
|
auto projectile = new ProjectileObject(Global::get().e, {25.f, 0.f, 10.f},
|
|
|
|
{
|
|
|
|
ProjectileObject::Grenade,
|
|
|
|
{0.f, 0.f, -1.f},
|
|
|
|
2.0f,
|
|
|
|
0.5f
|
|
|
|
});
|
|
|
|
|
|
|
|
Global::get().e->objects.insert( projectile );
|
|
|
|
|
|
|
|
BOOST_CHECK( character->mHealth == 100.f );
|
|
|
|
|
|
|
|
for(float t = 0.f; t <= 1.f; t += 0.016f) {
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
|
|
|
projectile->tick(0.016f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK( projectile->getPosition().z < 10.f );
|
|
|
|
|
|
|
|
// Grenade should have dentonated by this point
|
|
|
|
BOOST_CHECK( character->mHealth < 100.f );
|
|
|
|
|
|
|
|
Global::get().e->destroyObject(projectile);
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
|
2014-07-16 05:36:15 +02:00
|
|
|
auto projectile = new ProjectileObject(Global::get().e, {26.f, 1.f, 10.f},
|
2014-07-14 02:29:05 +02:00
|
|
|
{
|
|
|
|
ProjectileObject::Molotov,
|
|
|
|
{0.f, 0.f, -1.f},
|
|
|
|
2.0f,
|
2014-07-16 05:36:15 +02:00
|
|
|
10.f
|
2014-07-14 02:29:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
Global::get().e->objects.insert( projectile );
|
|
|
|
|
|
|
|
BOOST_CHECK( character->mHealth == 100.f );
|
|
|
|
|
2014-07-16 05:36:15 +02:00
|
|
|
for(float t = 0.f; t <= 9.0f; t += 0.016f) {
|
2014-07-14 02:29:05 +02:00
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
|
|
|
projectile->tick(0.016f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK( projectile->getPosition().z < 10.f );
|
2014-07-16 05:36:15 +02:00
|
|
|
BOOST_CHECK( projectile->getPosition().z > 0.f );
|
2014-07-14 02:29:05 +02:00
|
|
|
|
|
|
|
BOOST_CHECK( character->mHealth < 100.f );
|
|
|
|
|
|
|
|
Global::get().e->destroyObject(projectile);
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE( character != nullptr );
|
|
|
|
|
2014-07-16 05:36:15 +02:00
|
|
|
auto projectile = new ProjectileObject(Global::get().e, {26.f, 1.f, 10.f},
|
2014-07-14 02:29:05 +02:00
|
|
|
{
|
|
|
|
ProjectileObject::RPG,
|
|
|
|
{0.f, 0.f, -1.f},
|
|
|
|
2.0f,
|
2014-07-16 05:36:15 +02:00
|
|
|
10.f
|
2014-07-14 02:29:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
Global::get().e->objects.insert( projectile );
|
|
|
|
|
|
|
|
BOOST_CHECK( character->mHealth == 100.f );
|
|
|
|
|
2014-07-16 05:36:15 +02:00
|
|
|
for(float t = 0.f; t <= 9.f; t += 0.016f) {
|
2014-07-14 02:29:05 +02:00
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
|
|
|
projectile->tick(0.016f);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK( projectile->getPosition().z < 10.f );
|
|
|
|
|
|
|
|
BOOST_CHECK( character->mHealth < 100.f );
|
|
|
|
|
|
|
|
Global::get().e->destroyObject(projectile);
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 04:22:53 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|