impl.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //task DoPulse1
  2. static stock
  3. YSI_g_sTimer[32] = "y_zonepulse_";
  4. forward __GangZonePulse(playerid, zone, from, to, time, stage, delay, time2, delay2, r0, g0, b0, a0, r1, g1, b1, a1);
  5. public __GangZonePulse(playerid, zone, from, to, time, stage, delay, time2, delay2, r0, g0, b0, a0, r1, g1, b1, a1)
  6. {
  7. if (!IsPlayerConnected(playerid))
  8. {
  9. return;
  10. }
  11. valstr(YSI_g_sTimer[12], zone);
  12. //format(YSI_g_sTimer, sizeof (YSI_g_sTimer), "y_zonepulse_%d", zone);
  13. stage = (stage + 1) % (time + time2);
  14. if (stage == time)
  15. {
  16. GangZoneShowForPlayer(playerid, zone, to);
  17. SetPVarInt(playerid, YSI_g_sTimer, SetTimerEx("__GangZonePulse", delay, 0, "iiiiiiiiiiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2, r0, g0, b0, a0, r1, g1, b1, a1));
  18. return;
  19. }
  20. else if (stage == 0)
  21. {
  22. GangZoneShowForPlayer(playerid, zone, from);
  23. SetPVarInt(playerid, YSI_g_sTimer, SetTimerEx("__GangZonePulse", delay2, 0, "iiiiiiiiiiiiiiiii", playerid, zone, from, to, time, 0, delay, time2, delay2, r0, g0, b0, a0, r1, g1, b1, a1));
  24. return;
  25. }
  26. if (stage > time)
  27. {
  28. // Fade back
  29. new
  30. multiplier = 2 * time2 - stage;
  31. // r = r1 * multiplier / time2 + r0,
  32. // g = g1 * multiplier / time2 + g0,
  33. // b = b1 * multiplier / time2 + b0,
  34. // a = a1 * multiplier / time2 + a0;
  35. //P:7("__GangZonePulse: %d %d %x %x %x %x", playerid, zone, r & 0xFF, g & 0xFF, b & 0xFF, a & 0xFF);
  36. GangZoneShowForPlayer(playerid, zone, ((r1 * multiplier / time2 + r0) << 24) | (((g1 * multiplier / time2 + g0) & 0xFF) << 16) | (((b1 * multiplier / time2 + b0) & 0xFF) << 8) | ((a1 * multiplier / time2 + a0) & 0xFF));
  37. //GangZoneShowForPlayer(playerid, zone, (r << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF));
  38. SetPVarInt(playerid, YSI_g_sTimer, SetTimerEx("__GangZonePulse", ZONE_PULSE_STAGE_TIME, 0, "iiiiiiiiiiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2, r0, g0, b0, a0, r1, g1, b1, a1));
  39. }
  40. else
  41. {
  42. // Fade there.
  43. //new
  44. // r = r1 * stage / time + r0,
  45. // g = g1 * stage / time + g0,
  46. // b = b1 * stage / time + b0,
  47. // a = a1 * stage / time + a0;
  48. //P:7("__GangZonePulse: %d %d %x %x %x %x", playerid, zone, r & 0xFF, g & 0xFF, b & 0xFF, a & 0xFF);
  49. GangZoneShowForPlayer(playerid, zone, ((r1 * stage / time + r0) << 24) | (((g1 * stage / time + g0) & 0xFF) << 16) | (((b1 * stage / time + b0) & 0xFF) << 8) | ((a1 * stage / time + a0) & 0xFF));
  50. SetPVarInt(playerid, YSI_g_sTimer, SetTimerEx("__GangZonePulse", ZONE_PULSE_STAGE_TIME, 0, "iiiiiiiiiiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2, r0, g0, b0, a0, r1, g1, b1, a1));
  51. }
  52. return;
  53. }
  54. stock _GangZonePulse(@PlayerSet:ps, zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME, time2 = -1, delay2 = -1)
  55. {
  56. //static
  57. // YSI_g_sTimer[32];
  58. //format(YSI_g_sTimer, sizeof (YSI_g_sTimer), "y_zonepulse_%d", zone);
  59. valstr(YSI_g_sTimer[12], zone);
  60. if (time2 == -1)
  61. {
  62. time2 = time;
  63. }
  64. if (delay2 == -1)
  65. {
  66. delay2 = delay;
  67. }
  68. time /= ZONE_PULSE_STAGE_TIME;
  69. time2 /= ZONE_PULSE_STAGE_TIME;
  70. // Do a load of maths in advance.
  71. new
  72. r0 = (from >>> 24),
  73. g0 = (from >>> 16 & 0xFF),
  74. b0 = (from >>> 8 & 0xFF),
  75. a0 = (from & 0xFF),
  76. r1 = ((to >>> 24) - r0),
  77. g1 = ((to >>> 16 & 0xFF) - g0),
  78. b1 = ((to >>> 8 & 0xFF) - b0),
  79. a1 = ((to & 0xFF) - a0);
  80. // This method would have simpler maths in the main timer, but with less
  81. // accurate results (possibly MUCH less accurate). For reference, this way
  82. // would result in:
  83. //
  84. // cur = from + fromAdd - fromSub;
  85. //
  86. /*new
  87. thereAdd,
  88. thereSub,
  89. backAdd,
  90. backSub;
  91. if (to >>> 24 > from >>> 24) thereAdd |= ((to >>> 24) - (from >>> 24)) / time << 24, backSub |= ((to >>> 24) - (from >>> 24)) / time2 << 24;
  92. else thereSub |= ((from >>> 24) - (to >>> 24)) / time << 24, backAdd |= ((from >>> 24) - (to >>> 24)) / time2 << 24;
  93. if (to >>> 16 & 0xFF > from >>> 16 & 0xFF) thereAdd |= ((to >>> 16 & 0xFF) - (from >>> 16 & 0xFF)) / time << 16, backSub |= ((to >>> 16 & 0xFF) - (from >>> 16 & 0xFF)) / time2 << 16;
  94. else thereSub |= ((from >>> 16 & 0xFF) - (to >>> 16 & 0xFF)) / time << 16, backAdd |= ((from >>> 16 & 0xFF) - (to >>> 16 & 0xFF)) / time2 << 16;
  95. if (to >>> 8 & 0xFF > from >>> 8 & 0xFF) thereAdd |= ((to >>> 8 & 0xFF) - (from >>> 8 & 0xFF)) / time << 8, backSub |= ((to >>> 8 & 0xFF) - (from >>> 8 & 0xFF)) / time2 << 8;
  96. else thereSub |= ((from >>> 8 & 0xFF) - (to >>> 8 & 0xFF)) / time << 8, backAdd |= ((from >>> 8 & 0xFF) - (to >>> 8 & 0xFF)) / time2 << 8;
  97. if (to & 0xFF > from & 0xFF) thereAdd |= ((to & 0xFF) - (from & 0xFF)) / time, backSub |= ((to & 0xFF) - (from & 0xFF)) / time2;
  98. else thereSub |= ((from & 0xFF) - (to & 0xFF)) / time, backAdd |= ((from & 0xFF) - (to & 0xFF)) / time2;*/
  99. foreach (new p : PS(ps))
  100. {
  101. KillTimer(GetPVarInt(p, YSI_g_sTimer));
  102. GangZoneShowForPlayer(p, zone, from);
  103. // Don't delay at the start (because that's just silly, it already is
  104. // that colour).
  105. SetPVarInt(p, YSI_g_sTimer, SetTimerEx("__GangZonePulse", ZONE_PULSE_STAGE_TIME, 0, "iiiiiiiiiiiiiiiii", p, zone, from, to, time, 0, delay, time2, delay2, r0, g0, b0, a0, r1, g1, b1, a1));
  106. }
  107. }
  108. #define GangZonePulse(%0) PSF:_GangZonePulse(%0)
  109. #define GangZonePulseForPlayer(%0) PSF:_GangZonePulse(%0)
  110. #define GangZonePulseForAll(%0) PSF:_GangZonePulse(ALL_PLAYERS,%0)
  111. stock _GangZoneStopPulse(@PlayerSet:ps, zone)
  112. {
  113. //static
  114. // YSI_g_sTimer[32];
  115. //format(YSI_g_sTimer, sizeof (YSI_g_sTimer), "y_zonepulse_%d", zone);
  116. valstr(YSI_g_sTimer[12], zone);
  117. foreach (new p : PS(ps))
  118. {
  119. KillTimer(GetPVarInt(p, YSI_g_sTimer));
  120. }
  121. }
  122. #define GangZoneStopPulse(%0) PSF:_GangZoneStopPulse(%0)
  123. #define GangZoneStopPulseForPlayer(%0) PSF:_GangZoneStopPulse(%0)
  124. #define GangZoneStopPulseForAll(%0) PSF:_GangZoneStopPulse(ALL_PLAYERS,%0)