2014-07-04 22:06:56 +02:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <data/WeaponData.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <items/InventoryItem.hpp>
|
2014-07-04 22:06:56 +02:00
|
|
|
#include <objects/CharacterObject.hpp>
|
2016-09-09 22:13:22 +02:00
|
|
|
#include <objects/ItemPickup.hpp>
|
|
|
|
#include <objects/PickupObject.hpp>
|
2014-07-04 22:06:56 +02:00
|
|
|
#include "test_globals.hpp"
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
class TestPickup : public PickupObject {
|
2014-07-04 22:06:56 +02:00
|
|
|
public:
|
2016-09-09 22:13:22 +02:00
|
|
|
bool picked_up = false;
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
TestPickup(GameWorld* engine, const glm::vec3& position)
|
|
|
|
: PickupObject(engine, position, 0, OnStreet) {
|
|
|
|
}
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
bool onCharacterTouch(CharacterObject* character) {
|
|
|
|
picked_up = true;
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-04 22:06:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(PickupTests)
|
|
|
|
|
2016-06-16 22:11:55 +02:00
|
|
|
#if RW_TEST_WITH_DATA
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_pickup_interaction) {
|
|
|
|
{
|
|
|
|
auto character =
|
|
|
|
Global::get().e->createPedestrian(1, {30.1f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
TestPickup* p = new TestPickup(Global::get().e, {30.f, 0.f, 0.f});
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Global::get().e->insertObject(p);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(!p->picked_up);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
|
|
|
p->tick(0.f);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(p->picked_up);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
p->picked_up = false;
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(!p->picked_up);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
|
|
|
p->tick(0.f);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(!p->picked_up);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
|
|
|
p->tick(60.5f);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_CHECK(p->picked_up);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(p);
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
2014-07-04 22:06:56 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_item_pickup) {
|
|
|
|
{
|
|
|
|
auto character =
|
|
|
|
Global::get().e->createPedestrian(1, {30.1f, 0.f, 0.f});
|
|
|
|
BOOST_REQUIRE(character != nullptr);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
auto item = Global::get().e->getInventoryItem(3);
|
|
|
|
BOOST_REQUIRE(item != nullptr);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
ItemPickup* p = new ItemPickup(Global::get().e, {30.f, 0.f, 0.f},
|
2016-09-11 03:58:00 +02:00
|
|
|
nullptr, PickupObject::OnStreet, item);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->allObjects.push_back(p);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
// Check the characters inventory is empty.
|
|
|
|
for (int i = 0; i < maxInventorySlots; ++i) {
|
|
|
|
BOOST_CHECK(character->getCurrentState().weapons[i].weaponId == 0);
|
|
|
|
}
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
|
|
|
p->tick(0.f);
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
auto& inventory = character->getCurrentState().weapons;
|
|
|
|
BOOST_CHECK(std::any_of(std::begin(inventory), std::end(inventory),
|
|
|
|
[&](const CharacterWeaponSlot& i) {
|
|
|
|
return i.weaponId ==
|
|
|
|
item->getInventorySlot();
|
|
|
|
}));
|
2014-07-04 22:06:56 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
Global::get().e->destroyObject(p);
|
|
|
|
Global::get().e->destroyObject(character);
|
|
|
|
}
|
2014-07-04 22:06:56 +02:00
|
|
|
}
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
2014-07-04 22:06:56 +02:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|