Show number of laps contributing to the joker bonus.
authorCMDR furrycat <elite@furrycat.net>
Thu, 28 Jan 2016 15:03:59 +0000 (10:03 -0500)
committerCMDR furrycat <elite@furrycat.net>
Thu, 28 Jan 2016 15:03:59 +0000 (10:03 -0500)
entry.js

index 8e624dc..a4b4c8f 100644 (file)
--- a/entry.js
+++ b/entry.js
@@ -260,12 +260,13 @@ function display_when(condition, value) {
 
 /* Calculate bonus time. */
 function calculate_bonus(laps, start_time, allotted_time, table) {
-  if (! joker()) return [0, false];
+  if (! joker()) return [0, false, 0];
   var time = 0;
   var hull_start = 0;
   var hull_end = 0;
   var last_hull = 100;
   var race_ineligible = false;
+  var joker_laps = 0;
   for (var lap = 1; lap <= laps; lap++) {
     var lap_ineligible = false;
     /* Lap must be complete within the allotted time. */
@@ -290,10 +291,11 @@ function calculate_bonus(laps, start_time, allotted_time, table) {
       if (hull_end > hull_start) lap_ineligible = race_ineligible = true;
       if (! lap_ineligible) time += Math.floor(hull_end / 2);
     }
-    else race_ineligible = true;
+    else lap_ineligible = race_ineligible = true;
+    if (! lap_ineligible) joker_laps++;
   }
   /* Double bonus if no repairs at all. */
-  return [time, ! race_ineligible];
+  return [time, ! race_ineligible, joker_laps];
 }
 
 /* Calculate penalty time. */
@@ -467,6 +469,7 @@ function do_stats(table) {
   var bonus_details = calculate_bonus(complete_laps, start_time, allotted_time, table);
   var earned_bonus_time = bonus_details[0];
   var bonus_time = earned_bonus_time * (bonus_details[1] ? 2 : 1);
+  var bonus_laps = bonus_details[2];
   if (allotted_time && raced_time > allotted_time + bonus_time) {
     /* Get stations past the deadline. */
     var extras = [];
@@ -527,6 +530,7 @@ function do_stats(table) {
   do_stat('allotted_time', available_time, display_when(time_limited(), format_time(available_time)));
   var bonus_string = format_time(bonus_time);
   if (bonus_details[1]) bonus_string += ' (' + format_time(earned_bonus_time) + ')';
+  if (bonus_laps) bonus_string += ' from ' + String(bonus_laps) + ' lap' + ((bonus_laps == 1) ? '' : 's');
   do_stat('bonus_time', bonus_time, display_when(joker(), bonus_string));
   do_stat('penalty_time', penalty_time, display_when(time_limited(), format_time(penalty_time)));
   do_stat('raced_time', finish_time - start_time, display_when(time_limited() || joker(), format_difference(finish_time, start_time)));