CDate CSeasonGenerator::getSameWeekDayOneYearLater(const CDate &date) { // To match the same week day one year later // is necesary to look for leap years CDate newDate = date; newDate.setYear(newDate.getYear()+1); if( CDate::isLeap(date.getYear()) ){ CDate Feb29(29, 02, date.getYear(), 23, 59, 59); if( date<=Feb29 ){ newDate.setDay(newDate.getDay()-2); } else{ newDate.setDay(newDate.getDay()-1); } } else{ if( CDate::isLeap(date.getYear()+1) ){ CDate Feb29(29, 02, date.getYear()+1, 23, 59, 59); if( newDate>Feb29 ){ newDate.setDay(newDate.getDay()-2); } else{ newDate.setDay(newDate.getDay()-1); } } else{ newDate.setDay(newDate.getDay()-1); } } return newDate; }
void CTimeManager::endDayEventHandler(const IGameEvent &event) { // Only one "NoMoreEventsToday" event is on the events queue at time, // so we need to add a new event of this type for tomorrow CDate date = event.getDate(); date.setDay(date.getDay()+1); date.setHour(23); date.setMin(59); date.setSec(59); CGameEngine::getInstance()->getEventManager()->addEvent(new CEndDayEvent(date)); }