From: CMDR furrycat Date: Wed, 3 Feb 2016 22:04:00 +0000 (-0500) Subject: If a competitor won prize then only rank his prizewinning entry. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=b52fb77284bdf42105aa53a0cd17a03fc82b0eb9;p=furrycat%2Frace-o-matic.git If a competitor won prize then only rank his prizewinning entry. --- diff --git a/lib/race.php b/lib/race.php index 056859c..50b1c3f 100644 --- a/lib/race.php +++ b/lib/race.php @@ -212,7 +212,7 @@ } } - 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 : ''; @@ -241,12 +241,6 @@ $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(); @@ -375,8 +369,8 @@ } 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); @@ -385,15 +379,18 @@ 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) { @@ -634,15 +631,20 @@ $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(); @@ -656,7 +658,7 @@ $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 "\n";