MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / timeInRange

Method timeInRange

src/logic/NpcScriptState.h:247–269  ·  view source on GitHub ↗

* @return Whether the given hours/minutes match to this state */

Source from the content-addressed store, hash-verified

245 * @return Whether the given hours/minutes match to this state
246 */
247 bool timeInRange(int hours, int minutes)
248 {
249 auto tbigger = [&](int h1, int m1, int h2, int m2) {
250 return h1 > h2 || (h1 == h2 && m1 > m2);
251 };
252
253 auto tsmaller = [&](int h1, int m1, int h2, int m2) {
254 return h1 < h2 || (h1 == h2 && m1 < m2);
255 };
256
257 auto trange = [&](int h1, int m1, int h, int m, int h2, int m2) {
258 return tbigger(h, m, h1, m1) && tsmaller(h, m, h2, m2);
259 };
260
261 bool crossesZero = hoursEnd < hoursStart;
262
263 if (!crossesZero)
264 return trange(hoursStart, minutesStart, hours, minutes, hoursEnd, minutesEnd);
265 else
266 {
267 return trange(hoursStart, minutesStart, hours, minutes, 24, 0) && trange(0, 0, hours, minutes, hoursEnd, minutesEnd);
268 }
269 }
270
271 int hoursStart;
272 int minutesStart;

Callers 1

doAIStateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected