Added penalty distance sort.
authorCMDR furrycat <elite@furrycat.net>
Sun, 7 Feb 2016 14:11:13 +0000 (09:11 -0500)
committerCMDR furrycat <elite@furrycat.net>
Sun, 7 Feb 2016 14:11:13 +0000 (09:11 -0500)
lib/race.php

index 4970609..b1abdb6 100644 (file)
     return sprintf("%s%s%s", open_tags($formatting, $tags), $text, close_tags($formatting, $tags));
   }
 
-  function entry_header($format, $type) {
-    $fields = array('R', 'S', 'E', 'CMDR name', 'Forum name', 'Ship name', 'Ship type', 'Distance', 'Penalty', 'Lap distance', 'Laps', 'Allotted', 'Bonus', 'Raced', 'Total', 'Best speed', 'Average speed', 'Fastest lap', 'Average lap', 'Award');
+  function entry_header($sort, $format, $type) {
+    $fields = array('R', 'S', 'E', 'CMDR name', 'Forum name', 'Ship name', 'Ship type', 'Distance', 'Penalty', 'Lap distance', 'Laps', 'Total distance', 'Allotted', 'Bonus', 'Raced', 'Total', 'Best speed', 'Average speed', 'Fastest lap', 'Average lap', 'Award');
     if ($format == "full") array_unshift($fields, 'P');
-    $small_fields = array('Distance', 'Penalty', 'Lap distance', 'Fastest lap', 'Average lap', 'Average speed');
+    $small_fields = array('Distance', 'Penalty', 'Lap distance', 'Total distance', 'Fastest lap', 'Average lap', 'Average speed');
     if ($type == 'html') {
       echo "<table class=\"entries\">\n";
       echo "<tr>\n";
       $column = 0;
       foreach ($fields as $field) {
+        if ($field == 'Total distance' && $sort != 'penalty_distance') continue;
         $bgcolor = entry_bgcolor(0, $column);
         $fgcolor = entry_fgcolor(0, $column);
         echo "<th style=\"background-color: $bgcolor; color: $fgcolor\">$field</th>\n";
       echo "[tr]\n";
       $column = 0;
       foreach ($fields as $field) {
+        if ($field == 'Total distance' && $sort != 'penalty_distance') continue;
         $bgcolor = entry_bgcolor(0, $column);
         $fgcolor = entry_fgcolor(0, $column);
         echo "[td=\"bgcolor: $bgcolor\"][color=$fgcolor]";
     return (array_key_exists($condition, $formats) && $formats[$condition][0] >= $formats[$format][0]);
   }
 
-  function show_entry($format, $entry, $allotted_time, $position, $rank, $ship_rank, $row, $type, $prize_name) {
+  function show_entry($sort, $format, $entry, $allotted_time, $position, $rank, $ship_rank, $row, $type, $prize_name) {
     $fields = array();
     if ($format == "full") $fields[] = $position;
     $fields[] = $position ? $rank : '';
     $fields[] = format_time($entry->getPenaltyTime());
     $fields[] = format_distance($entry->getLapDistance());
     $fields[] = $entry->getCompleteLaps();
+    if ($sort == 'penalty_distance') $fields[] = format_distance($entry->getTotalDistance() + (float) $entry->getPenaltyTime() / 2);
     $bonus_time = $entry->getBonusTime();
     $fields[] = ($allotted_time > 0) ? format_time($allotted_time + $bonus_time) : '';
     $fields[] = ($bonus_time > 0) ? format_time($bonus_time) : '';
 
     $methods = array(
       'distance' => 'StandardSort',
+      'penalty_distance' => 'StandardSort',
       'best_speed' => 'ByBestSpeed',
       'average_speed' => 'ByAverageSpeed',
       'fastest_lap' => 'ByFastestLap',
         $entries = array();
         $entries_by_id = array();
         foreach ($entry_objects as $entry) {
+          if ($sort == 'penalty_distance') $entry->setTotalDistance($entry->getTotalDistance() - (float) $entry->getPenaltyTime() / 2);
           $entries[] = $entry;
           $entries_by_id[$entry->getId()] = $entry;
         }
         if ($method == $sort) $uri = " $Method";
         else {
           $uri = preg_replace('/&args=[^&]+/', '', $_SERVER['REQUEST_URI']);
+          /* XXX build_http_str */
           $uri = " <a href=\"$uri&args=sort:$method";
           if ($format) $uri .= "+format:$format";
           $uri .= "\">$Method</a>";
               /* One entry per racer per ship. */
               if (filtered("ships", $format, $formats) && $competitor_hull_entries[$name][$hull_id]++) continue;
               /* One entry per racer. */
+              /* XXX what if in both excluded_competitors */
               if ((array_key_exists($name, $excluded_competitors) || array_key_exists($name, $competitor_entries)) && filtered("competitors", $format, $formats)) continue;
             }
             /* Ranked only. */