Only charge during the day
This commit is contained in:
parent
526e9c69eb
commit
1412579c6c
1 changed files with 12 additions and 0 deletions
|
@ -152,6 +152,11 @@ func (w *World) RoverRecharge(rover string) (int, error) {
|
|||
return 0, fmt.Errorf("Failed to find rover with name: %s", rover)
|
||||
}
|
||||
|
||||
// We can only recharge during the day
|
||||
if !w.Daytime() {
|
||||
return i.Charge, nil
|
||||
}
|
||||
|
||||
// Add one charge
|
||||
if i.Charge < i.MaximumCharge {
|
||||
i.Charge++
|
||||
|
@ -489,6 +494,13 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Daytime returns if it's currently daytime
|
||||
// for simplicity this uses the 1st half of the day as daytime, the 2nd half as nighttime
|
||||
func (w *World) Daytime() bool {
|
||||
tickInDay := w.CurrentTicks % w.TicksPerDay
|
||||
return tickInDay < w.TicksPerDay/2
|
||||
}
|
||||
|
||||
// RLock read locks the world
|
||||
func (w *World) RLock() {
|
||||
w.worldMutex.RLock()
|
||||
|
|
Loading…
Add table
Reference in a new issue