From e44668ad6fb34b62a12059d3b13b314d26a69903 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Sun, 7 Feb 2016 09:11:13 -0500 Subject: [PATCH] Added penalty distance sort. --- lib/race.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/race.php b/lib/race.php index 4970609..b1abdb6 100644 --- a/lib/race.php +++ b/lib/race.php @@ -79,15 +79,16 @@ 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 "\n"; echo "\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 "\n"; @@ -101,6 +102,7 @@ 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]"; @@ -217,7 +219,7 @@ 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 : ''; @@ -237,6 +239,7 @@ $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) : ''; @@ -456,6 +459,7 @@ $methods = array( 'distance' => 'StandardSort', + 'penalty_distance' => 'StandardSort', 'best_speed' => 'ByBestSpeed', 'average_speed' => 'ByAverageSpeed', 'fastest_lap' => 'ByFastestLap', @@ -497,6 +501,7 @@ $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; } @@ -527,6 +532,7 @@ if ($method == $sort) $uri = " $Method"; else { $uri = preg_replace('/&args=[^&]+/', '', $_SERVER['REQUEST_URI']); + /* XXX build_http_str */ $uri = " $Method"; @@ -616,6 +622,7 @@ /* 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. */ -- 2.7.4
$field