-
Notifications
You must be signed in to change notification settings - Fork 0
Developer Notes for Penalty Box Timer
These are notes about changes to the CRG Scoreboard server to support a new penalty box timer interface.
The game has a list of eight new penalty box clocks, for a jammer and three blockers on each team, which are set up in the GameImpl constructor, like all the other clocks in the game. Listeners for the various existing clocks are set up in the GameImpl constructor, and new listeners for the box clocks are now also set up in GameImpl constructor to automatically end BoxTrips when the clocks finish. Since the game is where other clocks all live, it seemed to make sense to put the new clocks there as well; they are in a separate BOX_CLOCK list though, rather than CLOCK, which makes them easier to iterate independently from other game clocks, and avoid introducing risk by not messing with the existing clocks. Game snapshots used for undo functionality now also deal with stashing all the new clocks.
The new BoxSeat class deals with controlling a particular box Clock; it starts, stops, resets, and ends a trip, and manages which skater is assigned to the seat. Each Team in the Game has a list of four BoxSeats with ids from the BoxSeat.BoxSeatId enum: JAMMER, BLOCKER1, BLOCKER2, BLOCKER3. Note, there is already a BoxTrip class, but the BoxSeat is a different concept; each Team already has a list of BoxTrips which represent the running list of all the penalties served by the Team. The BoxSeats keep track of how many penalties are currently being served, like usually one or two. Skaters have a new penalty tally, or actually, it's been split into separate tallies for each period for ease of stats-book reporting later. When a box clock ends, the current penalty count from the BoxSeat (which is based on how much time was on the clock) is added to the Skater's penalty tally.
BoxTrips already have a WALLTIME_START and WALLTIME_END which would get set with the scoreboard clock time when the BoxTrip was created and when it ended, which is typically when the Penalty Lineup Tracker taps in and out of the Box button in the PLT interface. That's a rough guess though, since the PLT is busy entering penalty codes and might not see exactly when a person entered or left the box. Now those BoxTrip walltime values get set by the BoxSeat when a box Clock starts and when it reaches zero, so there's no guessing.
BoxSeat - Select Skater
A skater can be selected before or after a clock has started.
When a skater is selected for a seat, the skater's current fielding is looked up. They may not have a current fielding, in which case we assume they're a blocker and go ahead and field them as such.
If the skater selection has changed, delete the existing BoxTrip, and a new BoxTrip is created even if the skater has been selected before starting the clock; its wallclock settings will get syched up with the clock when the clock actually starts.
BoxSeat - Start
When a PBT hits the Start button, the corresponding BoxSeat does some things.
- The associated Clock is either started for the first time or resumed if it had been temporarily stopped. If the Start happens between jams, immediately pause the clock.
- Jammer logic is applied! If the seat is for a jammer, we need to deal some scenarios when a jammer is in the other seat.
- A current BoxTrip is looked up, if the skater has already been selected, and the wallclock time for the BoxTrip is reset to the actual start time.
Jammer Logic
The potential scenarios for jammers reduce to a few conditions.
- One or both jammers have multiple penalties. We cancel penalties as far as possible, taking into account how much time the other jammer has already served, since we can only cancel unserved time. After doing this cancelling, we'll typically proceed with one of the following:
- Simple common case. Arriving jammer serves a penalty reduced to the amount already served by sitting jammer.
- Arriving jammer is turned away due to their penalty having cancelled with the sitting jammer's extra penalty.
- The other jammer's clock has already been reduced, it can't reduce more. So new jammer starts to sit for a full penalty while current jammer keeps sitting.