/* Méthode qui permet de créer les connexions entre les différents objets */
void HomeCreator3D::createConnection()
{
    QObject::connect(&window, SIGNAL(itemSelected(QString)), this, SLOT(itemSelected(QString)));
    QObject::connect(window.getUi()->widget, SIGNAL(constructionOK()), this, SLOT(enable3D()));
    QObject::connect(window.getUi()->widget, SIGNAL(objectChangePosition(double, double, double)), this, SLOT(objectMove(double, double, double)));
    QObject::connect(window.getUi()->widget, SIGNAL(objectChangeRotation()), this, SLOT(objectRotate()));
    QObject::connect(window.getUi()->widget, SIGNAL(selection(int)), this, SLOT(selection(int)));
    QObject::connect(window.getUi()->widget, SIGNAL(deleteObject()), this, SLOT(deleteObject()));

    QObject::connect(&window, SIGNAL(newHouse()), this, SLOT(reInit()));
    QObject::connect(&window, SIGNAL(loadHouse(QString)), this, SLOT(loadMaison(QString)));
    QObject::connect(&window, SIGNAL(saveHouse(QString)), this, SLOT(saveMaison(QString)));
}
TEST_F(SimulatorTest, fire) {
	House newHouse(Point(0, 1), 2);
	Street verticalLeft("VerticalLeft", Point(2, 2), Point(2, 1));
	Street horizontal("Horizontal", Point(2, 2), Point(4, 2));
	Street verticalRight("VerticalRight", Point(4, 3), Point(4, 2));
	ASSERT_TRUE(ptrCity->add(newHouse));
	ASSERT_TRUE(ptrCity->add(horizontal));
	ASSERT_TRUE(ptrCity->add(verticalLeft));
	ASSERT_TRUE(ptrCity->add(verticalRight));

	Simulator sim(ptrCity, ptrOutput);
	House* ptrHouse = ptrCity->getHouses()[0];
	ASSERT_TRUE(ptrHouse != NULL);

	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_EQ(2, ptrHouse->getHealth());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_EQ(1, ptrHouse->getHealth());

	EXPECT_FALSE(sim.sendFireTrucks());	// oh, there isn't even a firedepot

	// now build a firedepot
	FireDepot newDepot(Point(4, 7), Point(4, 3), "Firedepot", 1);
	ASSERT_TRUE(ptrCity->add(newDepot));
	FireDepot* ptrDepot = ptrCity->findFireDepot("Firedepot");
	ASSERT_TRUE(ptrDepot != NULL);

	EXPECT_FALSE(sim.sendFireTrucks());	// oh, there isn't even a firetruck

	// add a firetruck
	FireTruck newTruck("Truck", ptrDepot);
	ASSERT_TRUE(ptrCity->add(newTruck));
	FireTruck* ptrTruck = ptrCity->getFireTrucks()[0];
	ASSERT_TRUE(ptrTruck != NULL);

	EXPECT_TRUE(sim.sendFireTrucks());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrHouse->isFireTruckAssigned());
	EXPECT_EQ(Point(2, 1), ptrTruck->getDestination());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 1), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(ptrDepot->getEntrance(), ptrTruck->getDestination());
	EXPECT_FALSE(ptrHouse->isBurning());
	EXPECT_FALSE(ptrHouse->isFireTruckAssigned());

	EXPECT_NO_FATAL_FAILURE(sim.repairBuildings());
	EXPECT_EQ(1.5, ptrHouse->getHealth());

	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut());
	EXPECT_TRUE(ptrHouse->isBurning());
	EXPECT_TRUE(ptrDepot->isBurning());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(2, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(3, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 2), ptrTruck->getPosition());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_EQ(Point(4, 3), ptrTruck->getPosition());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());
	EXPECT_TRUE(ptrTruck->isArrived());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_EQ(0.5, ptrHouse->getHealth());
	EXPECT_EQ(-1, ptrDepot->getHealth());
	EXPECT_TRUE(ptrDepot->isDead());
	EXPECT_FALSE(ptrDepot->isBurning());

	EXPECT_NO_FATAL_FAILURE(sim.drive());
	EXPECT_TRUE(ptrTruck->isAtEntranceDepot());

	EXPECT_NO_FATAL_FAILURE(sim.burningDown());
	EXPECT_EQ(-0.5, ptrHouse->getHealth());
	EXPECT_EQ(-1, ptrDepot->getHealth());

	EXPECT_TRUE(sim.endSimulation());
}