2014-06-28 04:22:53 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <data/WeaponData.hpp>
|
2019-01-01 13:12:37 +01:00
|
|
|
#include <items/Weapon.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <objects/CharacterObject.hpp>
|
2014-07-14 02:29:05 +02:00
|
|
|
#include <objects/ProjectileObject.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2014-06-28 04:22:53 +02:00
|
|
|
|
2019-01-05 03:02:28 +01:00
|
|
|
auto& operator<<(std::ostream& s, const ScanType& type) {
|
|
|
|
return s << static_cast<int>(type);
|
|
|
|
}
|
|
|
|
|
2014-06-28 04:22:53 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE(WeaponTests)
|
|
|
|
|
2019-01-01 13:12:37 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(radius_ctor_creates_radius_scan) {
|
|
|
|
WeaponScan scan{10.f, {1.f, 1.f, 1.f}, 5.f};
|
2019-01-05 03:02:28 +01:00
|
|
|
BOOST_CHECK_EQUAL(scan.type, ScanType::Radius);
|
2019-01-01 13:12:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(hitscan_ctor_creates_radius_scan) {
|
|
|
|
WeaponScan scan{10.f, {1.f, 1.f, 1.f}, {0.f, 0.f, 0.f}};
|
2019-01-05 03:02:28 +01:00
|
|
|
BOOST_CHECK_EQUAL(scan.type, ScanType::HitScan);
|
2019-01-01 13:12:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct WeaponScanFixture {
|
|
|
|
GameObject* source = reinterpret_cast<GameObject*>(0x0000BEEF);
|
|
|
|
WeaponScan scan{10.f, {1.f, 1.f, 1.f}, {0.f, 0.f, 0.f}, nullptr, source};
|
|
|
|
};
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_CASE(weapon_scan_doesnt_injur_source, WeaponScanFixture) {
|
|
|
|
BOOST_CHECK(!scan.doesDamage(reinterpret_cast<GameObject*>(0x0000BEEF)));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_CASE(weapon_scan_does_injur_others, WeaponScanFixture) {
|
|
|
|
BOOST_CHECK(scan.doesDamage(reinterpret_cast<GameObject*>(0xDEADBEEF)));
|
|
|
|
}
|
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(TestDoWeaponScan, DATA_TEST_PREDICATE) {
|
2016-09-09 22:13:22 +02:00
|
|
|
{
|
|
|
|
// Test RADIUS scan
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2019-05-11 21:33:23 +02:00
|
|
|
BOOST_REQUIRE(character->getClump() != nullptr);
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_REQUIRE(character->physObject != nullptr);
|
2014-06-28 04:22:53 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
WeaponScan scan(10.f, {0.f, 0.f, 10.f}, {0.f, 0.f, -10.f});
|
2014-06-28 04:22:53 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->doWeaponScan(scan);
|
2014-06-28 04:22:53 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
2014-06-28 18:20:49 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
2014-06-28 04:22:53 +02:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:29:59 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(TestProjectile, DATA_TEST_PREDICATE) {
|
2016-09-09 22:13:22 +02:00
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2018-11-08 00:26:38 +01:00
|
|
|
auto wepdata = &Global::get().e->data->weaponData.at(5);
|
2014-07-20 22:21:51 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
auto projectile = new ProjectileObject(
|
|
|
|
Global::get().e, {26.f, 1.f, 10.f},
|
|
|
|
{ProjectileObject::Grenade, {0.f, 0.f, -1.f}, 2.0f, 5.0f, wepdata});
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->allObjects.push_back(projectile);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(character->getCurrentState().health == 100.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t <= 5.f; t += 0.016f) {
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
|
|
|
projectile->tick(0.016f);
|
|
|
|
}
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK_LT(
|
|
|
|
glm::distance(character->getPosition(), projectile->getPosition()),
|
|
|
|
10.f);
|
|
|
|
BOOST_CHECK_LT(
|
|
|
|
glm::distance(character->getPosition(), projectile->getPosition()),
|
|
|
|
5.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Grenade should have dentonated by this point
|
|
|
|
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObjectQueued(character);
|
|
|
|
Global::get().e->destroyQueuedObjects();
|
|
|
|
}
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2018-11-08 00:26:38 +01:00
|
|
|
auto wepdata = &Global::get().e->data->weaponData.at(6);
|
2014-07-20 22:21:51 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
auto projectile = new ProjectileObject(
|
|
|
|
Global::get().e, {26.f, 1.f, 10.f},
|
|
|
|
{ProjectileObject::Molotov, {0.f, 0.f, -1.f}, 2.0f, 10.f, wepdata});
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->allObjects.push_back(projectile);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(character->getCurrentState().health == 100.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t <= 9.0f; t += 0.016f) {
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
|
|
|
projectile->tick(0.016f);
|
|
|
|
}
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(projectile->getPosition().z < 10.f);
|
|
|
|
BOOST_CHECK(projectile->getPosition().z > 0.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObjectQueued(character);
|
|
|
|
Global::get().e->destroyQueuedObjects();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2018-11-08 00:26:38 +01:00
|
|
|
auto wepdata = &Global::get().e->data->weaponData.at(7);
|
2014-07-20 22:21:51 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
auto projectile = new ProjectileObject(
|
|
|
|
Global::get().e, {26.f, 1.f, 10.f},
|
|
|
|
{ProjectileObject::RPG, {0.f, 0.f, -1.f}, 2.0f, 10.f, wepdata});
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->allObjects.push_back(projectile);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(character->getCurrentState().health == 100.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
for (float t = 0.f; t <= 9.f; t += 0.016f) {
|
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
|
|
|
projectile->tick(0.016f);
|
|
|
|
}
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(projectile->getPosition().z < 10.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
2014-07-14 02:29:05 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObjectQueued(character);
|
|
|
|
Global::get().e->destroyQueuedObjects();
|
|
|
|
}
|
2014-07-14 02:29:05 +02:00
|
|
|
}
|
|
|
|
|
2014-06-28 04:22:53 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|