Only charge during the day

This commit is contained in:
Marc Di Luzio 2020-07-07 18:37:59 +01:00
parent 526e9c69eb
commit 1412579c6c

View file

@ -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()