rustyscreeps/screeps-game-api

`Source::ticks_to_regeneration` panics if source is full

Closed this issue · 1 comments

If a source has not been harvested since its last regeneration, Source.ticksToRegeneration is null. This is not documented in the official API, but is consistent. As a result, calling Source::ticks_to_regeneration on a full source panics, as we are expecting a number.

As with #418, in this scenario we can reasonably change to an Option for this function, return 0, or possibly return ENERGY_REGEN_TIME.

Good catch, thanks! Definitely had encountered this panic on very rare occasion before too 😅 Option<u32> seems like the way to go in both this case and the case of Mineral, which has the same issue - helps the user understand the possibility for the alternate case, then they can just .unwrap_or(ENERGY_REGEN_TIME) or whatever if they want to make it a representative number