If a competitor won prize then only rank his prizewinning entry.
authorCMDR furrycat <elite@furrycat.net>
Wed, 3 Feb 2016 22:04:00 +0000 (17:04 -0500)
committerCMDR furrycat <elite@furrycat.net>
Wed, 3 Feb 2016 22:04:00 +0000 (17:04 -0500)
lib/race.php

index 056859c..50b1c3f 100644 (file)
     }
   }
 
-  function show_entry($entry, $allotted_time, $position, $rank, $ship_rank, $row, $type, $prizewinners) {
+  function show_entry($entry, $allotted_time, $position, $rank, $ship_rank, $row, $type, $prize_name) {
     $fields = array();
     $fields[] = $position;
     $fields[] = $position ? $rank : '';
     $fields[] = format_speed($entry->getAverageSpeed());
     $fields[] = format_time($entry->getFastestLap());
     $fields[] = format_time($entry->getAverageLap());
-    $prize_name = null;
-    foreach ($prizewinners as $name => $id) {
-      if ($entry->getId() != $id) continue;
-      $prize_name = $name;
-      break;
-    }
     $fields[] = (is_null($prize_name)) ? '' : ucfirst(Race::PrizeDescription($prize_name));
 
     $formatting = array();
   }
 
   function find_prizewinners($race, $entries) {
-    $ret = array();
     $competitors = array();
+    $prizes = array();
     $last_sort_method = null;
     foreach ($race->getPrizeKeys() as $p) {
       $sort_method = $race->PrizeSortMethod($p);
       foreach ($entries as $entry) {
         if ($entry->isExcluded()) continue;
         $entry_id = $entry->getId();
-        if (in_array($entry_id, array_values($ret))) continue;
+        if (array_key_exists($entry_id, $prizes)) continue;
         $competitor_id = $entry->getShip()->getCompetitorId();
-        if (in_array($competitor_id, $competitors)) continue;
-        $ret[$p] = $entry_id;
-        $competitors[] = $competitor_id;
+        if (array_key_exists($competitor_id, $competitors)) continue;
+        $prizes[$entry_id] = $p;
+        $competitors[$competitor_id] = $entry_id;
         break;
       }
     }
-    return $ret;
+    return array(
+      "competitors" => $competitors,
+      "entries" => $prizes
+    );
   }
 
   function pull($values) {
         $competitor_entries = array();
         $excluded_competitors = array();
         foreach ($entries as $entry) {
+          $entry_id = $entry->getId();
           $p = $r = $s = '';
+          $prize_name = null;
           $competitor = $entry->getShip()->getCompetitor();
           $name = $competitor->getForumName();
           if (! $name) $name = $competitor->getCmdrName();
           if (! $entry->isExcluded()) {
-            if (array_key_exists($name, $competitor_entries)) $competitor_entries[$name]++;
-            else {
-              $competitor_entries[$name] = 1;
-              $r = count($competitor_entries);
+            if (array_key_exists($entry_id, $prizewinners["entries"])) $prize_name = $prizewinners["entries"][$entry_id];
+            if ($prize_name || ! array_key_exists($competitor->getId(), $prizewinners["competitors"])) {
+              if (array_key_exists($name, $competitor_entries)) $competitor_entries[$name]++;
+              else {
+                $competitor_entries[$name] = 1;
+                $r = count($competitor_entries);
+              }
             }
 
             $hull_id = $entry->getShip()->getHull()->getId();
             $r = (array_key_exists($name, $excluded_competitors)) ? 2 : 1;
             $excluded_competitors[$name] = 1;
           }
-          show_entry($entry, $allotted_time, $p, $r, $s, $n++, $type, $prizewinners);
+          show_entry($entry, $allotted_time, $p, $r, $s, $n++, $type, $prize_name);
         }
         entry_footer($race, $type);
         echo "</div>\n";