MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / advance

Method advance

src/Savegame/GameTime.cpp:84–137  ·  view source on GitHub ↗

* Advances the ingame time by 5 seconds, automatically correcting * the other components when necessary and sending out a trigger when * a certain time span has elapsed for time-dependent events. * @return Time span trigger. */

Source from the content-addressed store, hash-verified

82 * @return Time span trigger.
83 */
84TimeTrigger GameTime::advance()
85{
86 TimeTrigger trigger = TIME_5SEC;
87 int monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
88 // Leap year
89 if ((_year % 4 == 0) && !(_year % 100 == 0 && _year % 400 != 0))
90 monthDays[1]++;
91
92 _second += 5;
93
94 if (_second >= 60)
95 {
96 _minute++;
97 _second = 0;
98 if (_minute % 10 == 0)
99 {
100 trigger = TIME_10MIN;
101 }
102 if (_minute % 30 == 0)
103 {
104 trigger = TIME_30MIN;
105 }
106 }
107 if (_minute >= 60)
108 {
109 _hour++;
110 _minute = 0;
111 trigger = TIME_1HOUR;
112 }
113 if (_hour >= 24)
114 {
115 _day++;
116 _weekday++;
117 _hour = 0;
118 trigger = TIME_1DAY;
119 }
120 if (_weekday > 7)
121 {
122 _weekday = 1;
123 }
124 if (_day > monthDays[_month - 1])
125 {
126 _day = 1;
127 _month++;
128 trigger = TIME_1MONTH;
129 }
130 if (_month > 12)
131 {
132 _month = 1;
133 _year++;
134 }
135
136 return trigger;
137}
138
139/**
140 * Returns the current ingame second.

Callers 2

timeAdvanceMethod · 0.45
time1HourMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected