ZoriaRPG

Day and Night Cycle for Binx

Jun 22nd, 2018
145
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int SUNRISE = 1;
  2.     const int DAY = 0;
  3.     const int SUNSET = 2;
  4.     const int NIGHT = 3;
  5.     const int DAY_PAL = 0;
  6.     const int SUNRISET_PAL = 32;
  7.     const int NIGHT_PAL = 33;
  8.     const int NIGHT_OVERLAY_LAYER = 6;
  9.     const int CLOCK_FRAMES = 0;
  10.     const int CLOCK_SECONDS = 1;
  11.     const int CR_SECONDS = 30;
  12.     const int CLOCK_MINUTES = 2;
  13.     const int CR_MINUTES = 29;
  14.     const int CLOCK_HOURS = 3;
  15.     const int CR_HOURS = 28;
  16.     const int CLOCK_DAYS = 4;
  17.     const int CLOCK_MAX = 5;
  18.     int CYCLE = 0;
  19.     int CURRENTDMAP = -1;
  20.     int CURRENTSCREEN = -1;
  21.  
  22. const int TIME_FRAME     = 0;
  23. const int TIME_SEC   = 1;
  24. const int TIME_MINUTE    = 2;
  25. const int TIME_HOUR  = 3;
  26. const int TIME_DAY   = 4;
  27. const int TIME_MONTH     = 5;
  28. const int TIME_YEAR  = 6;
  29. const int TIME_MAX  = 7;
  30.  
  31. const int DMT_DUNGEON = 2;
  32. const int DMT_INTERIOR = 3;
  33.  
  34. int Time[TIME_MAX]={-1, 0, 0, 0, 1, 1, 1};
  35.  
  36. global script a
  37. {
  38.     void run()
  39.     {
  40.         while(1)
  41.         {
  42.             Do_Time();
  43.             DayNightCycle();
  44.             Waitdraw();
  45.             Waitframe();
  46.         }
  47.     }
  48. }
  49.  
  50. void DayNightCycle()
  51. {
  52.     dmapdata dm = Game->LoadDMapData(Game->GetCurDMap());
  53.     int type = dm->Type;  
  54.    
  55.    
  56.     if ( CURRENTDMAP != Game->GetCurDMap() || CURRENTSCREEN != Game->GetCurScreen() )
  57.     {
  58.    
  59.         TraceNL();
  60.         TraceS("Detected DMap Type: "); Trace(type);
  61.         CURRENTDMAP = Game->GetCurDMap();
  62.         CURRENTSCREEN = Game->GetCurScreen();
  63.     }
  64.    
  65.     if ( type == DMT_INTERIOR )
  66.     {
  67.         TraceS("Interior DMap found by DayNightCycle()"); return;
  68.     }
  69.     if ( type == DMT_DUNGEON )
  70.     {
  71.         TraceNL(); TraceS("Dungeon DMap found by DayNightCycle()"); return;
  72.     }
  73.     else
  74.     {
  75.         if (Time[TIME_HOUR] <= 5)
  76.         {
  77.             if (CYCLE != SUNRISE)
  78.             {
  79.                 CYCLE = SUNRISE;
  80.                 TraceNL(); Game->DMapPalette[CURRENTDMAP] = SUNRISET_PAL;
  81.                 return;
  82.             }
  83.         }
  84.         else if (Time[TIME_HOUR] <= 11)
  85.         {
  86.             if (CYCLE != DAY)
  87.             {
  88.        
  89.                 CYCLE = DAY;
  90.                 Game->DMapPalette[CURRENTDMAP] = DAY_PAL;
  91.                 return;
  92.             }
  93.         }
  94.         else if (Time[TIME_HOUR] <= 17)
  95.         {
  96.             if (CYCLE != SUNSET)
  97.             {
  98.                 CYCLE = SUNSET;
  99.                 Game->DMapPalette[CURRENTDMAP] = SUNRISET_PAL;
  100.                 return;
  101.             }
  102.         }
  103.         else
  104.         {
  105.             if (CYCLE != NIGHT)
  106.             {
  107.                 CYCLE = NIGHT;
  108.                 Game->DMapPalette[CURRENTDMAP] = NIGHT_PAL;
  109.                 return;
  110.             }
  111.         }
  112.         return;    
  113.     }    
  114. }
  115.  
  116.  
  117.  
  118.  
  119. void Do_Time()
  120. {
  121.     int f = ++Time[TIME_FRAME];
  122.     if ( f % 2 )  ++Time[TIME_SEC];
  123.     if ( f >= 60 ) Time[TIME_FRAME] = 0;
  124.     if ( Time[TIME_SEC] > 59 )
  125.     {
  126.         Time[TIME_SEC] = 0;
  127.         ++Time[TIME_MINUTE];
  128.     }
  129.     if ( Time[TIME_MINUTE] > 59 )
  130.     {  
  131.         Time[TIME_MINUTE] = 0;
  132.         ++Time[TIME_HOUR];
  133.     }
  134.     if ( Time[TIME_HOUR] > 23 )
  135.     {
  136.         Time[TIME_HOUR] = 0;
  137.         ++Time[TIME_DAY];
  138.     }
  139.     if ( Time[TIME_DAY] > 30 )
  140.     {
  141.         Time[TIME_DAY] = 1;
  142.         ++Time[TIME_MONTH];
  143.     }
  144.     if ( Time[TIME_MONTH] > 12 )
  145.     {
  146.         Time[TIME_MONTH] = 1;
  147.         ++Time[TIME_YEAR];
  148.     }
  149. }
RAW Paste Data