@@ -270,6 +270,22 @@ public long? GameTime
270270 }
271271 }
272272
273+ /// <summary>
274+ /// The duration of the last tick
275+ /// </summary>
276+ /// <remarks>
277+ /// Should be update externally.
278+ /// </remarks>
279+ public long LastTickDuration => this . _lastTickDuraion ;
280+
281+ /// <summary>
282+ /// The time of the last tick
283+ /// </summary>
284+ /// <remarks>
285+ /// Should be update externally.
286+ /// </remarks>
287+ public long LastTickTime => this . _lastTickTime ;
288+
273289 /// <summary>
274290 /// A list of the generated orders.
275291 /// </summary>
@@ -325,6 +341,8 @@ public long? RemainingTime
325341 // inner court.
326342 private bool ? _hasMovedIntoInnerCourt = null ;
327343
344+ private long _lastTickDuraion = 1000 ; // Just a magic default value.
345+
328346 // Minus one to prevent division by zero.
329347 private long _lastTickTime = Utility . SystemTime - 1 ;
330348
@@ -343,14 +361,6 @@ public long? RemainingTime
343361
344362 private long ? _startTime = null ;
345363
346- private long _lastTickDuration
347- {
348- get
349- {
350- return Utility . SystemTime - this . _lastTickTime ;
351- }
352- }
353-
354364 private Dictionary < CampType , Vehicle > _vehicle = null ;
355365
356366 #endregion
@@ -417,6 +427,9 @@ public Game()
417427 /// </summary>
418428 public void Refresh ( )
419429 {
430+ this . _lastTickDuraion = Utility . SystemTime - this . _lastTickTime ;
431+ this . _lastTickTime = Utility . SystemTime ;
432+
420433 // The game should only refresh when running.
421434 if (
422435 this . _gameState != GameStatusType . Running
@@ -457,8 +470,9 @@ public void Refresh()
457470
458471 this . AutoCharge ( ) ;
459472
460- // Update the time of the last tick.
461- this . _lastTickTime = Utility . SystemTime ;
473+ // Must generate orders after refreshing the game to avoid interacting with
474+ // orders not processed by the slave.
475+ this . GenerateOrder ( ) ;
462476 }
463477
464478 /// <summary>
@@ -602,7 +616,7 @@ public void SetChargingPile()
602616 ++ chargingPileNumber ;
603617 }
604618 }
605- if ( chargingPileNumber > Game . ChargingPileMaxNumber )
619+ if ( chargingPileNumber >= Game . ChargingPileMaxNumber )
606620 {
607621 return ;
608622 }
@@ -651,7 +665,7 @@ private void AutoCharge()
651665 /// <summary>
652666 /// Attempt to generate an order.
653667 /// </summary>
654- public void GenerateOrder ( )
668+ private void GenerateOrder ( )
655669 {
656670 var newOrder = this . _orderGenerator . Generate ( ( long ) this . GameTime ) ;
657671 if ( newOrder != null )
@@ -758,7 +772,7 @@ void ScoreHittingWall()
758772 if ( this . IsInWall ( vehiclePosition ) )
759773 {
760774 this . _score [ ( CampType ) this . _camp ] +=
761- Game . ScoreHittingWallRate * this . _lastTickDuration ;
775+ Game . ScoreHittingWallRate * this . LastTickDuration ;
762776 }
763777 }
764778
@@ -798,11 +812,11 @@ void ScoreMoving()
798812 // Score parking penalty.
799813 if (
800814 vehicle . ParkingDuration != null &&
801- ( long ) vehicle . ParkingDuration >= 5000 + this . _lastTickDuration
815+ ( long ) vehicle . ParkingDuration >= 5000 + this . LastTickDuration
802816 )
803817 {
804818 this . _score [ ( CampType ) this . _camp ] +=
805- Game . ScoreOvertimeParkingRate * this . _lastTickDuration ;
819+ Game . ScoreOvertimeParkingRate * this . LastTickDuration ;
806820 }
807821 }
808822
@@ -823,7 +837,7 @@ void TackleBarriers()
823837 if ( this . IsInBarrier ( vehiclePosition ) )
824838 {
825839 vehicle . IncreaseMaxDistance (
826- ( int ) Math . Round ( Game . BarrierDischargingRate * this . _lastTickDuration )
840+ ( int ) Math . Round ( Game . BarrierDischargingRate * this . LastTickDuration )
827841 ) ;
828842 }
829843 }
@@ -848,7 +862,7 @@ void TackleChargingPiles()
848862 ) )
849863 {
850864 vehicle . IncreaseMaxDistance (
851- ( int ) Math . Round ( Game . ChargingPileChargingRate * this . _lastTickDuration )
865+ ( int ) Math . Round ( Game . ChargingPileChargingRate * this . LastTickDuration )
852866 ) ;
853867 }
854868
@@ -859,7 +873,7 @@ void TackleChargingPiles()
859873 ) )
860874 {
861875 vehicle . IncreaseMaxDistance (
862- ( int ) Math . Round ( Game . ChargingPileDischargingRate * this . _lastTickDuration )
876+ ( int ) Math . Round ( Game . ChargingPileDischargingRate * this . LastTickDuration )
863877 ) ;
864878 }
865879 }
0 commit comments