Пример #1
0
void GamePair::addBotClientAndSetTeam(const string &name, S32 teamIndex)
{
   ServerGame *server = GameManager::getServerGame();

   server->addBot(Vector<string>(), ClientInfo::ClassRobotAddedByAutoleveler);
   // Get most recently added clientInfo
   ClientInfo *clientInfo = server->getClientInfo(server->getClientInfos()->size() - 1);
   ASSERT_TRUE(clientInfo->isRobot()) << "This is supposed to be a robot!";

   // Normally, in a game, a ship or bot would be destroyed and would respawn when their team changes, and upon
   // respawning the BfObject representing that ship would be on the correct team.  Not so here (where we are
   // taking lots of shortcuts); here we need to manually assign a new team to the robot object in addition to
   // it's more "official" setting on the ClientInfo.
   clientInfo->setTeamIndex(teamIndex);
   clientInfo->getShip()->setTeam(teamIndex);
}
Пример #2
0
TEST(ObjectScopeTest, TestItemPropagation)
{
   for(S32 i = 0; i < testInfos.size(); i++)
   {
      // Create a GamePair using our text item code, with 2 clients; one will be red, the other blue.
      // The test will confirm which players get the red text item, the blue line, and the zone object.
      string levelCode = getLevelCodeForItemPropagationTests(testInfos[i].itemToTest);

      GamePair gamePair(levelCode, 2);

      // First, ensure we have two players, one red, one blue
      ServerGame *serverGame = gamePair.server;

      ASSERT_EQ(2, serverGame->getPlayerCount());
      ASSERT_EQ(Colors::blue.toHexString(), serverGame->getTeamColor(0).toHexString());
      ASSERT_EQ(Colors::red.toHexString(), serverGame->getTeamColor(1).toHexString());

      // Do the following rigamarole to break dependency on assumption client0 is blue and client1 is red
      ClientGame *client0 = gamePair.getClient(0);
      ClientGame *client1 = gamePair.getClient(1);

      ClientGame *blue = (serverGame->getTeamColor(client0->getLocalRemoteClientInfo()->getTeamIndex()).toHexString() ==
         Colors::blue.toHexString()) ? client0 : client1;

      ClientGame *red = (serverGame->getTeamColor(client0->getLocalRemoteClientInfo()->getTeamIndex()).toHexString() ==
         Colors::red.toHexString()) ? client0 : client1;

      ASSERT_EQ(Colors::blue.toHexString(), serverGame->getTeamColor(blue->getLocalRemoteClientInfo()->getTeamIndex()).toHexString());
      ASSERT_EQ(Colors::red.toHexString(), serverGame->getTeamColor(red->getLocalRemoteClientInfo()->getTeamIndex()).toHexString());

      ASSERT_FALSE(serverGame->getClientInfos()->get(0)->getConnection()->mInCommanderMap);
      ASSERT_FALSE(serverGame->getClientInfos()->get(1)->getConnection()->mInCommanderMap);

      // Now that we know which client is which, we can check to see which objects are available where
      {
         SCOPED_TRACE("Not in CommandersMap // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].startingCondition);
      }

      // Turn on cmdrs map... should not affect results
      red->setUsingCommandersMap(true);
      blue->setUsingCommandersMap(true);

      gamePair.idle(10, 5);     // Let things settle

      ASSERT_TRUE(serverGame->getClientInfos()->get(0)->getConnection()->mInCommanderMap);
      ASSERT_TRUE(serverGame->getClientInfos()->get(1)->getConnection()->mInCommanderMap);
      {
         SCOPED_TRACE("In CommandersMap // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].startingCondition);
      }

      Vector<DatabaseObject *> fillVector;

      // Change the textitem from red to blue
      serverGame->getLevel()->findObjects(testInfos[i].objectTypeNumber, fillVector);
      ASSERT_EQ(1, fillVector.size());
      BfObject *obj = static_cast<BfObject *>(fillVector[0]);
      obj->setTeam(0);     // Blue team

      gamePair.idle(10, 5);     // Let things settle
      {
         SCOPED_TRACE("Item Moved To Blue // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].itemMovedToBlue);
      }
      obj->setTeam(1);          // Back to red

      gamePair.idle(10, 5);     // Let things settle
      {
         SCOPED_TRACE("Item Moved To Red // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].itemMovedToRed);
      }

      // Now change the player's team from blue to red
      blue->changeOwnTeam(1);
      EXPECT_EQ(0, blue->getLocalRemoteClientInfo()->getTeamIndex()) << "Expect this client to be on team 0 (change hasn't propagated yet)";
      gamePair.idle(10, 5);     // Let things settle
      EXPECT_EQ(1, blue->getLocalRemoteClientInfo()->getTeamIndex()) << "Expect this client to be on team 1 (change should have propagated)";

      EXPECT_EQ(1, serverGame->getClientInfos()->get(0)->getTeamIndex());
      EXPECT_EQ(1, serverGame->getClientInfos()->get(1)->getTeamIndex());
      {
         SCOPED_TRACE("Blue Player Moved To Red, Items On Red // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].playersMovedToRed);
      }

      // And put both players on blue
      blue->changeOwnTeam(0);
      red->changeOwnTeam(0);

      EXPECT_EQ(1, blue->getLocalRemoteClientInfo()->getTeamIndex()) << "Expect this client to be on team 1 (change hasn't propagated yet)";
      EXPECT_EQ(1, red->getLocalRemoteClientInfo()->getTeamIndex()) << "Expect this client to be on team 1 (change hasn't propagated yet)";
      gamePair.idle(10, 5);     // Let things settle
      EXPECT_EQ(0, blue->getLocalRemoteClientInfo()->getTeamIndex()) << "Expect this client to be on team 0 (change should have propagated)";
      EXPECT_EQ(0, blue->getLocalRemoteClientInfo()->getTeamIndex()) << "Expect this client to be on team 0 (change should have propagated)";

      EXPECT_EQ(0, serverGame->getClientInfos()->get(0)->getTeamIndex());
      EXPECT_EQ(0, serverGame->getClientInfos()->get(1)->getTeamIndex());
      {
         SCOPED_TRACE("Both Players Moved To Blue, Items On Red // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].playersMovedToBlue);
      }

      // Make items neutral and see if they propagate properly
      fillVector.clear();
      serverGame->getLevel()->findObjects(testInfos[i].objectTypeNumber, fillVector);
      ASSERT_EQ(1, fillVector.size());
      for(S32 j = 0; j < fillVector.size(); j++)
         static_cast<BfObject *>(fillVector[j])->setTeam(TEAM_NEUTRAL);
      gamePair.idle(10, 5);     // Let things settle
      {
         SCOPED_TRACE("Items On Neutral // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].itemMovedToNeutral);
      }

      for(S32 j = 0; j < fillVector.size(); j++)
         static_cast<BfObject *>(fillVector[j])->setTeam(TEAM_HOSTILE);
      gamePair.idle(10, 5);     // Let things settle
      {
         SCOPED_TRACE("Items On Hostile // " + testInfos[i].itemToTest);
         testScope(serverGame, blue, red, testInfos[i], testInfos[i].itemsMovedToHostile);
      }
   }
}