adeon has entered the game!
Joined: 22 Feb 2009
|
Posted: Tue Mar 10, 2009 3:25 am Post subject: My old daylight system on ACS |
|
|
Hello everyone.
I've been studying ACS programming and made a daylight system some time ago.
Actually, I'm not using zdaemon since I'd rather OpenGL ports because of the color depth.
I'm currently trying to develop a daylight system using real values of latitude, day of year and so on. The problem is that ACS doens't like maths so much, but anyways... I am posting my old daylight system. Consider the arrays having each value of color, each one representing Red, Green or Blue. Using a 16 bit colors port you can see the lighting somehow yellow in "the morning" of the cycle. Unfortunely, it's impossible to be noticed running on a 256 colors port, but still there's the lighting cycle effect.
If you're interested, I'm posting the code right here:
Code: | #include "zcommon.acs"
int debug;
//DAYLIGHT SYSTEM 0.1
int daycycleminutes = 1; //How long the day is in minutes - multiply for 2100 to get the value in ticks
int daylightsector = 300; //What sectors are going to be affected by daylight?
int daylightambient = 32; //Set ambient light from 0 to 255 (0 = full darkness)
/* These arrays express the RGB value at every moment using physically accurate
colors of sun and sky lighting from Latitude 64.1, 17/07/1886 */
//List of colours
str DR[255] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,1,2,5,7,10,12,15,17,20,24,27,31,36,40,45,50,55,60,
66,71,76,80,85,90,95,100,105,109,114,118,123,127,132,135,140,
143,147,150,155,158,161,165,168,171,174,178,180,182,185,189,
191,194,197,198,201,204,205,208,209,212,214,216,217,220,221,
223,224,226,228,229,230,232,233,234,235,237,237,239,240,241,
241,243,244,244,245,245,246,247,248,249,249,249,250,250,250,
250,251,251,251,251,252,252,252,252,252,251,251,251,251,251,
250,249,249,249,248,248,247,247,247,245,245,244,243,242,241,
240,239,239,237,237,235,234,233,231,230,229,228,226,224,223,
221,220,219,216,214,212,210,207,205,202,200,198,195,193,191,
187,185,183,179,176,173,170,167,164,161,157,153,150,146,142,
139,134,130,126,122,117,113,108,103,99,94,89,84,79,74,69,64,
58,53,49,43,34,30,26,22,19,16,13,11,9,6,3,2,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0};
str DG[255] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,1,2,5,7,11,13,16,18,20,24,27,31,36,39,44,48,53,58,
64,69,74,79,83,88,94,98,104,108,113,117,122,127,131,135,140,
144,147,151,155,159,163,166,169,173,176,179,182,185,188,191,
194,196,199,201,205,207,209,211,213,216,217,220,221,223,225,
227,228,230,232,234,235,236,238,238,240,242,242,243,245,246,
246,248,249,249,251,250,251,252,252,253,253,253,253,254,254,
254,254,254,254,254,255,255,254,254,254,254,254,254,254,254,
253,253,253,252,252,252,252,252,252,251,250,249,248,247,246,
245,244,244,242,242,239,239,238,236,234,233,233,231,229,227,
225,224,223,220,218,216,214,211,209,205,203,201,198,196,193,
190,188,185,181,178,175,172,168,165,162,157,154,151,146,142,
139,134,129,125,121,116,112,107,102,97,92,87,82,77,72,67,62,
56,51,47,42,34,29,26,22,19,16,14,12,9,7,3,2,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0};
str DB[255] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,1,2,5,7,11,13,15,17,19,22,25,28,30,34,38,42,45,49,
54,59,63,67,72,76,81,86,91,95,100,104,109,113,118,122,126,
130,134,138,142,146,150,153,156,160,164,167,170,172,176,179,
182,184,188,189,193,195,197,200,202,204,206,208,210,213,215,
216,217,219,222,223,224,226,227,228,229,231,232,233,234,236,
236,237,238,239,240,240,241,242,243,244,243,244,244,245,245,
245,246,246,246,246,247,247,247,247,247,246,246,246,246,246,
245,244,244,243,243,243,242,242,241,240,240,239,238,237,236,
235,234,233,232,231,229,229,227,225,224,222,223,221,219,218,
215,214,214,210,208,206,203,201,197,194,191,189,186,184,181,
178,176,172,169,166,162,159,155,152,149,144,141,137,133,129,
125,121,116,112,108,103,99,94,89,85,80,75,71,66,61,57,53,48,
44,40,36,30,26,24,21,18,16,13,11,9,6,3,2,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0};
Script 255 OPEN
{
int dsample;
while (true)
{
//Print for debug purposes
if(debug==true){print(d:dsample,s:"\n",d:DR[dsample],s:",",d:DG[dsample],s:",",d:DB[dsample]);}
if(dsample<255)
{
if((DR[dsample]+DG[dsample]+DB[dsample])/3 < daylightambient)
{
Sector_SetColor(daylightsector,daylightambient,daylightambient,daylightambient);
dsample++;
delay(daycycleminutes*2100/255);
}
else
{
Sector_SetColor(daylightsector,DR[dsample],DG[dsample],DB[dsample]);
dsample++;
delay(daycycleminutes*2100/255);
}
}
else
{
dsample=0;
Sector_SetColor(daylightsector,daylightambient,daylightambient,daylightambient);
dsample++;
delay(daycycleminutes*2100/255);
}
}
} |
daycycleminutes: As you can imagine, just put the value in minutes corresponding to day lenght in the game.
By the way, I used physically accurate algorithms to get these RGB values for every single sample. If you put the value 1440 (which means 24 hours), there's going to be a morning and an evening pretty realistic in terms of countries in the very north of the globe.
daylightsector: That's the Sector Number which is going to be considered to affect the respective sectors in the map. If you want special sectors to be affected, just add'em in the code. It's quite simple.
daylightambient: Ambient color for minimal lighting to avoid full darkness.
That's it. I hope you like
See you. |
|