case 'row1': return array('#d9d9d9', '#d4d4d4');
case 'row2': return array('#ebebeb', '#e6e6e6');
case 'winner': return array('#00ad19', '#009416'); // Green 129,100,80 129,100,68
- case 'runnerup': return array('#66cc75', '#57ad63'); // Green 128,50,80 128,50,68
- case 'BySpeed': return array('#cc4300', '#ad3900'); // Orange 20,100,80 20,100,68
- case 'ByAverageSpeed': return array('#cb5e29', '#ad5023'); // Orange 20,80,80 20,80,68
- case 'ByFastestLap': return array('#3d8bcc', '#3476ad'); // Blue 207,70,80 207,70,68
- case 'ByAverageLap': return array('#669dcc', '#5786ad'); // Blue 207,50,80 207,50,68
+ case 'runner_up': return array('#66cc75', '#57ad63'); // Green 128,50,80 128,50,68
+ case 'best_speed': return array('#cc4300', '#ad3900'); // Orange 20,100,80 20,100,68
+ case 'average_speed': return array('#cb5e29', '#ad5023'); // Orange 20,80,80 20,80,68
+ case 'fastest_lap': return array('#3d8bcc', '#3476ad'); // Blue 207,70,80 207,70,68
+ case 'average_lap': return array('#669dcc', '#5786ad'); // Blue 207,50,80 207,50,68
}
return null;
}
- function entry_bgcolor($row, $column, $prize_entry = null) {
+ function entry_bgcolor($row, $column, $prize_name = null) {
$blue = colour('blue');
$white = colour('white');
$orange = colour('orange');
$colours = array(
/* Header. */
- array_merge($blue, $blue, $blue, $blue, $blue, $white, $white, $white, $orange, $orange),
+ array_merge($blue, $blue, $blue, $blue, $blue, $white, $white, $white, $orange, $orange, $orange),
/* Rows. */
colour('row1'),
colour('row2'),
- /* Winners. */
- colour('winner'),
- colour('runnerup'),
- colour('BySpeed'),
- colour('ByAverageSpeed'),
- colour('ByFastestLap'),
- colour('ByAverageLap')
);
- if (! is_null($prize_entry)) $row_index = $prize_entry + 3;
+ $row_index = $row % 2;
+ if (! is_null($prize_name)) $colours = array(colour($prize_name), colour($prize_name));
else if (! $row) $row_index = 0;
- else $row_index = 1 + ($row % 2);
+ else $row_index++;
$column_index = $column % count($colours[$row_index]);
return $colours[$row_index][$column_index];
}
- function entry_fgcolor($row, $column, $prize_entry = null) {
+ function entry_fgcolor($row, $column, $prize_name = null) {
$white = array('#ffffff');
$blue = array_splice(colour('blue'), 1);
$orange = array_splice(colour('orange'), 0, 1);
$colours = array(
/* Header. */
- array_merge($white, $white, $white, $white, $white, $white, $white, $white, $white, $white, $blue, $blue, $blue,$blue, $blue, $blue, $white, $white, $white),
+ array_merge($white, $white, $white, $white, $white, $white, $white, $white, $white, $white, $blue, $blue, $blue,$blue, $blue, $blue, $white, $white, $white, $white),
/* Rows. */
$blue,
$orange,
/* Winners. */
$white,
array('#ebebeb'),
- $white,
- array('#ebebeb'),
- $white,
- array('#ebebeb'),
);
- if (! is_null($prize_entry)) $row_index = $prize_entry + 3;
+ if (! is_null($prize_name)) $row_index = 3 + ($row % 2);
else if (! $row) $row_index = 0;
else $row_index = 1 + ($row % 2);
$column_index = $column % count($colours[$row_index]);
}
function entry_header($type) {
- $fields = array('P', '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');
+ $fields = array('P', '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');
$small_fields = array('Distance', 'Penalty', 'Lap distance', 'Fastest lap', 'Average lap', 'Average speed');
if ($type == 'html') {
echo "<table class=\"entries\">\n";
}
}
- function entry_footer($type) {
- $keys = array(
- 'winner' => 'Race winner',
- 'runnerup' => 'Runner-up',
- 'BySpeed' => 'Best single lap speed',
- 'ByAverageSpeed' => 'Best average speed',
- 'ByFastestLap' => 'Fastest single lap',
- 'ByAverageLap' => 'Fastest average lap',
- );
+ function entry_footer($race, $type) {
+ $keys = array();
+ foreach ($race->getPrizeKeys() as $p) {
+ $keys[$p] = ucfirst($race->PrizeDescription($p));
+ }
$rows = array(
'orange' => "Competitor's best non-prizewinning entry",
'blue' => "Competitor's other entries"
$fields[] = format_speed($entry->getAverageSpeed());
$fields[] = format_time($entry->getFastestLap());
$fields[] = format_time($entry->getAverageLap());
-
- $prize_entry = null;
- $n = 0;
- foreach ($prizewinners as $ignored => $id) {
- if ($entry->getId() == $id) {
- $prize_entry = $n;
- break;
- }
- $n++;
+ $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();
if ($entry->usedDockingComputer()) $formatting[] = 'i';
echo "<tr>\n";
$column = 0;
foreach ($fields as $field) {
- $bgcolor = entry_bgcolor($row, $column, $prize_entry);
- $fgcolor = entry_fgcolor($foreground, $column, $prize_entry);
+ $bgcolor = entry_bgcolor($row, $column, $prize_name);
+ $fgcolor = entry_fgcolor($foreground, $column, $prize_name);
if (is_array($field)) $display = $field[1];
else $display = $field;
$text = entry_formatting($display, $formatting, $type);
echo "[tr]\n";
$column = 0;
foreach ($fields as $field) {
- $bgcolor = entry_bgcolor($row, $column, $prize_entry);
- $fgcolor = entry_fgcolor($foreground, $column, $prize_entry);
+ $bgcolor = entry_bgcolor($row, $column, $prize_name);
+ $fgcolor = entry_fgcolor($foreground, $column, $prize_name);
$display = (is_array($field)) ? $field[0] : $field;
$text = entry_formatting($display, $formatting, $type);
echo "[td=\"bgcolor: $bgcolor\"][color=$fgcolor]";
$race = new Race;
$race->setName($name);
if ($allotted_time) $race->setAllottedTime($allotted_time);
+ $prizes = 0;
+ foreach ($posted as $k => $v) {
+ if (! preg_match('/^prize_(.+)$/', $k, $m)) continue;
+ $p = $m[1];
+ $prizes |= $race->PrizeValue($p);
+ }
+ if ($race->hasRunnerUp()) $prizes |= $race->PrizeValue('winner');
+ $race->setPrizes($prizes);
$race->save();
foreach ($posted as $k => $v) {
if (do_race($name, $allotted_time, $posted)) return true;
}
- echo "<div id=\"waypoints\">\n";
form();
+ echo "<div id=\"waypoints\">\n";
+ echo "<h3>Prizes</h3>\n";
+ echo "<p>";
+ foreach (Race::PrizeKeys() as $p) {
+ $description = ucfirst(Race::PrizeDescription($p));
+ $name = "prize_$p";
+ echo "<label><input type=\"checkbox\" name=\"$name\"";
+ if ($_POST[$name]) echo " checked=\"checked\"";
+ echo "> $description</label>\n";
+ }
+ echo "</p>\n";
+
+ echo "<h3>Waypoints</h3>\n";
echo "<table>\n";
foreach ($stations as $station) {
$system = $station->getSystem();
return false;
}
- function find_prizewinners($entries, $allotted_time) {
- $sorted = array(
- 'ByBestSpeed' => null,
- 'ByAverageSpeed' => null,
- 'ByFastestLap' => null,
- 'ByAverageLap' => null
- );
- $ret = array_merge(
- array('leader' => null, 'runnerup' => null),
- $sorted
- );
-
+ function find_prizewinners($race, $entries) {
+ $ret = array();
$competitors = array();
-
- uasort($entries, "Entry::StandardSort");
-
- /* Leader and runner-up. */
- foreach ($entries as $entry) {
- if ($entry->isExcluded()) continue;
- $entry_id = $entry->getId();
- if (in_array($entry_id, array_values($ret))) continue;
- $competitor_id = $entry->getShip()->getCompetitorId();
- if (in_array($competitor_id, $competitors)) continue;
- if (is_null($ret['leader'])) {
- $ret['leader'] = $entry_id;
- $competitors[] = $competitor_id;
- }
- else if (is_null($ret['runnerup'])) {
- $ret['runnerup'] = $entry_id;
- $competitors[] = $competitor_id;
- break;
- }
- }
-
- /* Standard races only have standard classification. */
- if (! $allotted_time) return $ret;
-
- /* Other prizes. */
- foreach (array_keys($sorted) as $key) {
- uasort($entries, "Entry::$key");
+ $last_sort_method = null;
+ foreach ($race->getPrizeKeys() as $p) {
+ $sort_method = $race->PrizeSortMethod($p);
+ if ($sort_method != $last_sort_method) uasort($entries, "Entry::$sort_method");
+ $last_sort_method = $sort_method;
foreach ($entries as $entry) {
if ($entry->isExcluded()) continue;
$entry_id = $entry->getId();
if (in_array($entry_id, array_values($ret))) continue;
$competitor_id = $entry->getShip()->getCompetitorId();
if (in_array($competitor_id, $competitors)) continue;
- $ret[$key] = $entry_id;
+ $ret[$p] = $entry_id;
$competitors[] = $competitor_id;
break;
}
}
-
return $ret;
}
if (count($entry_objects)) {
$entries = array();
foreach ($entry_objects as $entry) $entries[] = $entry;
- $prizewinners = find_prizewinners($entries, $allotted_time);
+ $prizewinners = find_prizewinners($race, $entries);
$plots = array(
"cmdr" => array(
"values" => array(),
}
echo "<h3>$name</h3>\n";
+ if ($race->getPrizes()) {
+ $prizes = array();
+ foreach ($race->getPrizeKeys() as $p) $prizes[] = $race->PrizeDescription($p);
+ echo "<p>Prizes for " . implode(", ", $prizes) . ".</p>\n";
+ }
echo "<div id=\"plot_distribution\"></div>\n";
echo "<div id=\"plot_legs\"></div>\n";
echo "<div id=\"plot_speeds\"></div>\n";
}
show_entry($entry, $allotted_time, $p, $r, $s, $n++, $type, $prizewinners);
}
- entry_footer($type);
+ entry_footer($race, $type);
echo "</div>\n";
}
echo "</div>\n";