//! zinc
library RetroFade {
/*
* The current fade-functionality is very primitive at the moment. If you have dynamic fog in your
* map that changes sometimes, I don't recommend this library for you.
*/
constant real
DURATION = 2.00 ,
MAX_DISTANCE = 1000.0 , /* Players whose cameras are out of this range will not see the fog fade */
FLICKER_MAGNITUDE = 300.0 ; /* Factors between Z-End + this & Z-End - this */
constant boolean
FLICKER = true ;
real fog[];
integer units[];
boolean paused = true, want = false, to = true;
constant integer Fz = 18, FZ = 19, Fd = 20, Fr = 21, Fg = 22, Fb = 23;
function onInit() {
integer i; /* Your fog settings Retro's fog settings
Fog type | | Allowed values
¯¯¯¯¯¯¯¯ V V ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
| Z-Start */ fog[0] = 3000.00 ; fog[6] = 1250.0 ; /* 0.00 to ????
---------------------------------------------------------------------------------------
| Z-End */ fog[1] = 5000.00 ; fog[7] = 3250.00 ; /* 0.00 to ????
---------------------------------------------------------------------------------------
| Density */ fog[2] = 0.50 ; fog[8] = 0.1 ; /* 0.00 to 1.00
---------------------------------------------------------------------------------------
| Red */ fog[3] = 1.00 ; fog[9] = 0.35 ; /* 0.00 to 1.00
---------------------------------------------------------------------------------------
| Green */ fog[4] = 1.00 ; fog[10] = 0.35 ; /* 0.00 to 1.00
---------------------------------------------------------------------------------------
| Blue */ fog[5] = 1.00 ; fog[11] = 0.00 ; /* 0.00 to 1.00
---------------------------------------------------------------------------------------
*/
for (i = 0; i < 24; i+= 1) i:units = 0;
for (i = 0; i < 6; i+= 1) {
if (i:fog==fog[i + 6]) {
if (i:fog < 0.999) i:fog+= 0.001;
else i:fog-= 0.001;
}
fog[i + 12] = (i:fog - fog[i + 6])/(DURATION / RETRO_TIMEOUT);
fog[i + 18] = i:fog;
}
}
public struct retrofade [] {
private static method handler()-> boolean {
integer i = 18;
if (!want && paused)
return false;
static if (FLICKER) {
if (GetRandomReal(0.0, 2.0)<=RETRO_TIMEOUT)
SetTerrainFogEx(0, Fz:fog, GetRandomReal(FZ:fog - FLICKER_MAGNITUDE, FZ:fog + FLICKER_MAGNITUDE), Fd:fog, Fr:fog, Fg:fog, Fb:fog);
}
if (paused)
return false;
if (to) while (i < 24) { /* Fade into retro-fog */
if ( i:fog <= fog[i - 12]) {
i:fog = fog[i - 12]; paused = true; break;
} else i:fog -= fog[i - 6]; i+= 1;
}
else while (i < 24) { /* Fade into normal-fog */
if ( i:fog >= fog[i - 18]) {
i:fog = fog[i - 18]; paused = true; break;
} else i:fog += fog[i - 6]; i+= 1;
}
SetTerrainFogEx (0, Fz:fog, FZ:fog, Fd:fog, Fr:fog, Fg:fog, Fb:fog);
return false;
}
module RetroTimerModule;
static method CamCheck (real centerX, real centerY) -> boolean {
real cam_x= GetCameraTargetPositionX(), cam_y= GetCameraTargetPositionY();
return(cam_x >= centerX - MAX_DISTANCE && cam_y >= centerY - MAX_DISTANCE &&
cam_x <= centerX + MAX_DISTANCE && cam_y <= centerY + MAX_DISTANCE );
}
static method yes (player whichPlayer, real x, real y) {
integer id = GetPlayerId(whichPlayer);
if (GetLocalPlayer() != whichPlayer || whichPlayer == null || id > 11)
return;
if (CamCheck(x, y)) {
to = true;
want = true;
if (paused)
paused = false;
}
units[id]+= 1;
}
static method no (player whichPlayer) {
integer id = GetPlayerId(whichPlayer);
if (GetLocalPlayer() != whichPlayer || whichPlayer==null || id > 11)
return;
units[id]-= 1;
if (units[id] <= 0) {
units[id] = 0;
to = false;
want = false;
if (paused)
paused = false;
}
}
}
}
//! endzinc