Advertisement
Moolah60

officially_wut

Sep 19th, 2022
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.92 KB | None | 0 0
  1. static evdate_u decode_date(evdate_u* enc_date) {
  2.   evdate_u date;
  3.   date.d.month = enc_date->d.month;
  4.  
  5.   /* Check for event that happens month */
  6.   if (date.d.month == EV_SPDATE_EVERYMONTH) {
  7.     date.d.month = ZCommonGet(time.rtcTime.month);
  8.   }
  9.   date.d.day = enc_date->d.day;
  10.  
  11.   /* Check for last day of month event */
  12.   if (date.d.day == EV_SPDATE_LASTDAY) {
  13.     date.d.day = last_day_of_month(date.d.month);
  14.   }
  15.  
  16.   /* Check if the event's date is a "cached" day in the game save */
  17.   if (date.d.month > EV_SPDATE_LASTDAY) {
  18.     date.v = SaveGet(
  19.         event.xday[date.d.month - 100]); /* Save data is month-day pairing */
  20.   }
  21.  
  22.   date.d.flag = enc_date->d.flag;
  23.   date.d.hour = enc_date->d.hour;
  24.  
  25.   /* Check if the event's hour is a "cached" time in the game save */
  26.   if ((date.d.hour & 0x20) != 0) {
  27.     date.d.hour =
  28.         (char)SaveGet(event.xday[date.d.hour & 0x1F]) | (date.d.hour & 0xC0);
  29.   }
  30.  
  31.   /* Check if date is Japanese Lunar Calendar format */
  32.   if (date.d.month >= 80) {
  33.     date.d.month -= 80;
  34.  
  35.     if (date.d.month < lbRk_KYUU_LEAP_MONTH) {
  36.       date.v = kyu2sei(&date); /* Standard Lunar conversion */
  37.     } else {
  38.       /* Calculate Lunar New Year */
  39.       evdate_u lunar_newyear;
  40.       lunar_newyear.d.month = lbRk_KYUU_MONTH_START;
  41.       lunar_newyear.d.day = DAY_01;
  42.       lunar_newyear.d.flag = 0;
  43.       lunar_newyear.d.flag = TIME_00;
  44.  
  45.       /* Lunar New Year date conversion */
  46.       lunar_newyear.v = kyu2sei(&lunar_newyear);
  47.       if (date.d.day == DAY_30) {
  48.         if (lunar_newyear.v != to_ev_month_day(FEBRUARY, DAY_01)) {
  49.           date.d.month = lunar_newyear.d.month;
  50.           date.d.day = lunar_newyear.d.day - 1;
  51.         } else {
  52.           date.d.day = DAY_31;
  53.           date.d.month = JANUARY;
  54.         }
  55.       } else if (date.d.day == 29) {
  56.         if (lunar_newyear.v == to_ev_month_day(FEBRUARY, DAY_02)) {
  57.           date.d.day = DAY_31;
  58.           date.d.month = JANUARY;
  59.         } else if (lunar_newyear.v == to_ev_month_day(FEBRUARY, DAY_01)) {
  60.           date.d.day = DAY_30;
  61.           date.d.month = JANUARY;
  62.         } else {
  63.           date.d.month = lunar_newyear.d.month;
  64.           date.d.day = lunar_newyear.d.day - 2;
  65.         }
  66.       } else if (date.d.day == DAY_25) {
  67.         if (lunar_newyear.v == to_ev_month_day(FEBRUARY, DAY_05)) {
  68.           date.d.day = DAY_31;
  69.           date.d.month = JANUARY;
  70.         } else if (lunar_newyear.v == to_ev_month_day(FEBRUARY, DAY_04)) {
  71.           date.d.day = DAY_30;
  72.           date.d.month = JANUARY;
  73.         } else if (lunar_newyear.v == to_ev_month_day(FEBRUARY, DAY_03)) {
  74.           date.d.day = DAY_29;
  75.           date.d.month = JANUARY;
  76.         } else if (lunar_newyear.v == to_ev_month_day(FEBRUARY, DAY_02)) {
  77.           date.d.day = DAY_28;
  78.           date.d.month = JANUARY;
  79.         } else if (lunar_newyear.v == to_ev_month_day(FEBRUARY, DAY_01)) {
  80.           date.d.day = DAY_27;
  81.           date.d.month = JANUARY;
  82.         } else if (lunar_newyear.v == to_ev_month_day(JANUARY, DAY_05)) {
  83.           date.d.day = DAY_31;
  84.           date.d.month = DECEMBER;
  85.         } else if (lunar_newyear.v == to_ev_month_day(JANUARY, DAY_04)) {
  86.           date.d.day = DAY_30;
  87.           date.d.month = DECEMBER;
  88.         } else if (lunar_newyear.v == to_ev_month_day(JANUARY, DAY_03)) {
  89.           date.d.day = DAY_29;
  90.           date.d.month = DECEMBER;
  91.         } else if (lunar_newyear.v == to_ev_month_day(JANUARY, DAY_02)) {
  92.           date.d.day = DAY_28;
  93.           date.d.month = DECEMBER;
  94.         } else if (lunar_newyear.v == to_ev_month_day(JANUARY, DAY_01)) {
  95.           date.d.day = DAY_27;
  96.           date.d.month = DECEMBER;
  97.         } else {
  98.           date.d.day = lunar_newyear.d.day - 5;
  99.           date.d.month = lunar_newyear.d.month;
  100.         }
  101.       }
  102.     }
  103.   }
  104.  
  105.   /* Check for day of week event */
  106.   if ((date.d.day & 0x80) != 0) {
  107.     date.d.day = m_weekday2day(date.d.month, date.d.day);
  108.   }
  109.  
  110.   return date;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement