Beispiel #1
0
void TeamManager::addRound(QList<int> barcode)
{
    if (! timebar->isRunning())
        return;
    int passed_rounds_ms = 0;
    bool found = false;
    for(int i = 0; i < teams.size(); i++) {
        if (teams.at(i)->getBarcode() == barcode) {
            QList<int> team_rounds = teams.at(i)->getRounds();
            for (int j = 0; j < team_rounds.count(); j++) {
                passed_rounds_ms += team_rounds.at(j);
            }
            teams.at(i)->addRound(timebar->getTotalTime() - passed_rounds_ms - timebar->getCurrentTime());
            rounds.append(QPair<Team *, int>(teams.at(i), timebar->getTotalTime() - passed_rounds_ms - timebar->getCurrentTime()));
            found = true;
            break;
        }
    }
    if (!found)
        return;
    QPair<QString, int> best_round = getBestRound();
    QPair<QString, int> last_round = getLastRound();
    int rounds_count = MainWindow::getInstance()->getTeamManager()->getTeamByBarcode(barcode)->getTotalRounds();
    MainWindow::getInstance()->getBestRoundBar()->updateBar(best_round.first, best_round.second);
    MainWindow::getInstance()->getLastRoundBar()->updateBar(last_round.first, last_round.second, rounds_count);
    printRoundsByTeam();
}
// Fills the trail array with the location ids of the last 6 turns
void giveMeTheTrail(DracView currentView, PlayerID player,
                     LocationID trail[TRAIL_SIZE]) {

   // can't use getHistory for this.
   // go through past plays and populate trail with actual locations

   DracView dv;
   int i;
   int round;
   int location;
   // int pastPlaysLength;
   // int index;

   dv = currentView;
   i = 0;
   round = getLastRound(dv, player);

   // printf("giveTrail: round is: %d, currRound: %d\n", round, getRound(dv->gv));

   location = UNKNOWN_LOCATION;
   // pastPlaysLength = dv->pastPlaysLength;
   // index = dv->pastPlaysIndex[player];


   // Make all trail array UNKNOWN_LOCATION (-1)
   for (i = 0; i < TRAIL_SIZE; i++) {
      trail[i] = UNKNOWN_LOCATION;
   }

   i = 0;

   // Get valid locations from pastPlays and insert them into the trail
   while (i < TRAIL_SIZE && round >= 0) {

      location = getRoundLocation(dv, round, player);
      trail[i] = location;
      i += 1;

      // printf("round: %d, location: %s (%d), pastPlaysLength: %d\n", round, locationStr, location, pastPlaysLength);

      /*
      if (validPlace(location) == TRUE || location == TELEPORT) {
         // location id is valid, add it to the trail

         if (location == TELEPORT) {
            location = CASTLE_DRACULA;
         }

         trail[i] = location;
         // printf("inserting %d into trail[%d]\n", location, i);
         i += 1;

      } 
      */

      // if location isn't valid then decrement round and continue
      round -= 1;
   }
}
// Find out what minions are placed at the specified location
void whatsThere(DracView currentView, LocationID where,
                   int *numTraps, int *numVamps) {
   
   DracView dv;
   int count;
   LocationID trail[TRAIL_SIZE] = { -1 };
   LocationID whereType;
   int index;
   int round;
   int trapSetRound;

   dv = currentView;
   count = 0;
   whereType = idToType(where);
   *numTraps = 0;
   *numVamps = 0;
   index = dv->pastPlaysIndex[PLAYER_DRACULA];
   round = getLastRound(dv, PLAYER_DRACULA);
   trapSetRound = -1;

   // printf("whatsThere: round is: %d, currRound: %d\n", round, getRound(dv->gv));

   /* 
    * 1. Get minions placed by Drac
    *       1a. Get Drac's trail
    *       1b. if city is in the trail: increment for any traps/vamps
    *
    * 2. If traps found: 
    *       2a. get each hunter's trail
    *       2b. check if city is in hunter's trail, AND if traps/vamps
    *             have been encountered
    *       2c. if traps/vamps have been encountered, decrement them
    */ 


   // 1. Get minions placed by Drac

   // 'where' restrictions:
   //    - not in the sea,
   //    - is a valid city number,
   //    - not the hospital

   if (whereType != SEA && validPlace(where) && 
                  where != ST_JOSEPH_AND_ST_MARYS) {

      // 1a.
      getHistory(dv->gv, PLAYER_DRACULA, trail);

      
      // 1b. Store the traps set by Drac within that city, if applicable

      // if 'where' is within the trail
      while (count < TRAIL_SIZE) {
         // Starting at the latest round, check if the city the user 
         // wants to check is in drac's trail. 
         // If so, increment if any traps or vamps are there and note
         // which round in which they were set by Drac

         if (trail[count] == where) {

            // index+3 and index+4: the indices where
            //             dracula's encounters will be stored

            if (dv->past[((round - count) * ROUND_LENGTH) + (index + MINION_ONE)] == 'T') {
               *numTraps += 1;
               //printf("yep0: loc[%c%c], round: %d, count: %d\n",dv->past[((round-count) * ROUND_LENGTH) + index+1], dv->past[((round-count) * ROUND_LENGTH) + index+2], round, count);
            } else if (dv->past[((round - count) * ROUND_LENGTH) + (index + MINION_ONE)] == 'V') {
               *numVamps += 1;
            }

            if (dv->past[((round - count) * ROUND_LENGTH) + (index + MINION_TWO)] == 'T') {
               *numTraps += 1;
            } else if (dv->past[((round - count) * ROUND_LENGTH) + (index + MINION_TWO)] == 'V') {
               *numVamps += 1;
            }

            // break out of the loop since 'where' can only be 
            // in the trail once
            trapSetRound = round - count;
            count = TRAIL_SIZE;
         }

         count += 1;
      }
   }

   //printf("found drac's: at %s, traps: %d, vamps: %d\n", idToName(where), *numTraps, *numVamps);


   // 2. If traps found

   // Traps have been found at the given city.
   // Check to see if any hunters have visited that city since,
   // hence encountering and disabling that trap/vamp
   if (trapSetRound != -1 && *numTraps > 0 && *numVamps > 0) {
      int hunter;
      int index;

      hunter = 0;

      // go through all hunter's (NUM_PLAYERS-1) trails**
      // if a hunter has visited the 'where' city, and has
      // encountered a trap/vamp, then decrement trap/vamp
      //
      // **since drac's and hunter's giveMeTheTrails are out of sync,
      // go through the pastPlays string
      // Will need to do that anyway because we need to check the string
      // for T&V encounters
      while (hunter < NUM_PLAYERS-1) {
         index = dv->pastPlaysIndex[hunter];
         round = getLastRound(dv, hunter);
         

         for (count = 0; count < TRAIL_SIZE; count++) {
            if (getRoundLocation(dv, round, hunter) == where) {
               if (dv->past[(round * ROUND_LENGTH) + (index + MINION_ONE)] == 'T') {
                  *numTraps -= 1;
               } else if (dv->past[(round * ROUND_LENGTH) + (index + MINION_ONE)] == 'V') {
                  *numTraps -= 1;
               }

               if (dv->past[(round * ROUND_LENGTH) + (index + MINION_TWO)] == 'T') {
                  *numTraps -= 1;
               } else if (dv->past[(round * ROUND_LENGTH) + (index + MINION_TWO)] == 'V') {
                  *numTraps -= 1;
               }
            }

            round -= 1;
         }
         
         hunter += 1;
      }
   }

   // printf("where: %s (%d), numTraps: %d, numVamps: %d\n", idToName(where), where, *numTraps, *numVamps);
}