|
Re: Wind
[Re: bart_the_13th]
#311649
02/21/10 10:37
02/21/10 10:37
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
Long time ago I found this in User Resources. Don't really remember who made it. Any way great thanks for creator. Will it help in creating Wind effect? Not fog, as it was already made. Wind, with particles that can detect entities and level blocks.
////////////WIND VARIABLES//////////////////////
var w_acceleration; // wind acceleration indicator flag
var w_speed_max = 1; // maximum highest wind speed...range: 0-1
var w_speed_min = 0.3; // maximum lowest wind speed based on random(w_speed_min)...range: 0-1
var w_speed_goal;
var w_speed_current;
var w_speed_change;
var w_speed_factor = 1; // multiplies w_speed_max when hurricane is used...higher = faster speed....dependent on w_speed_max....range: 1-infinity
var w_speed_change_min = 0.02; // lower value = slower rate of decrease....range: 0-1
var w_speed_change_max = 0.04; // higher value = faster rate of increase...range: 0-1
var w_still_factor = 0; // higher value = longer lasting periods of stillness(no wind)....range: 0-infinity
// dependent on w_still_flag being set to 1.....based on random(w_still_factor)
var w_still_flag = 0; // 0 = no periods of stillness , 1 = stillness of a random duration which is dependent on w_still_factor
var w_active = 0; // 0 = simulation paused, 1 = simulation active
var w_volatility; // wind volatility based on random number...determines likelihood of a strong gust
var w_power_factor = 2; /* DETERMINES WIND BEHAVIOR
1 = always strong gusts..no normal ones
2 = more frequent random strong gusts
3 = less frequent random strong gusts
4 = no strong gusts..always normal ones
5 = constant strong gust/hurricane..no calming
6 = no wind */
////////////
////////////DIRECTION VARIABLES///////////////////
var d_direction_min[3] = -1,0,0; // currently set to SW
var d_direction_max[3] = -1,0,0; // currently set to SE
/* DIRECTIONS ARE INTO THE CARDINAL DIRECTION(i.e. north wind is blowing towards north)
0, 1, 0 north
0,-1, 0 south
-1, 0, 0 west
1, 0, 0 east */
var d_direction_current[3];
var d_direction_goal[3];
var d_direction_change_pct;
var d_direction_increment = 0.1; // higher value = faster direction change
var d_degrees; // degrees
font standard_font = <ackfont.pcx>, 6, 9; // panel font
/////////////
/////////////CARDINAL DIRECTION STRINGS///////////////
string north =" N"; string northeast ="NE";
string northwest = "NW"; string east =" E";
string west =" W"; string south = " S";
string southeast ="SE"; string southwest = "SW";
string error = "ER"; string blank = " ";
string coor; //cardinal direction indicator
////////////
////////////WIND STATUS STRINGS//////////////////////
string calm = " Calm"; string gust = " Gust";
string b_gust =" Strong"; string still = " Still";
string hurri = "Hurricane"; string paused =" Paused";
string windstatus; //wind status indicator
////////////
////////////WIND PANEL STRINGS//////////////////////
string wacceleration = " Wind Acceleration:"; string speed = " Current Speed:";
string goal = " Speed Goal:"; string vola = " Volatility:\n";
string curdir = " Current Direction_XY:\n"; string dirgoal = " Direction Goal_XY:\n";
string dirpercent = "Direction Change Percent:\n"; string deg = " Degrees:";
string direction = " Cardinal Direction:"; string status = " Wind Status:";
////////////
////////////SIMULATION SCRIPT//////////////////////
function error_check() //do not change any of this unless you know what you are doing and what it affects
{
while(w_active == 0) { if(w_active == 1) { break; } wait(1); } //script is paused
if(w_active > 1 || w_active < 0) { w_active = 1; } //if not set to 0 or 1, defaults to 1(active)
if(w_acceleration != 0 && w_acceleration != 1 && w_acceleration != -1) { w_acceleration = 0; } // keeps values valid
if(w_speed_change_max < w_speed_change_min ) { w_speed_change_max = w_speed_change_min + 0.01; } //max should be >= min
if(w_speed_max < w_speed_min) { w_speed_max = w_speed_min + 0.1; } //max should be >= min
if(w_speed_factor < 1) { w_speed_factor = 1; } //should never be < 1
if(w_power_factor < 1 || w_power_factor > 6) { w_power_factor = 3; } // keeps values valid and defaults it to "less strong gusts" if invalid
if(d_direction_increment == 0) { d_direction_increment = 0.1; } // keeps values valid and defaults it to...uh...default
if(d_direction_min[0] < -1 || d_direction_min[0] > 1) { d_direction_min[0] = -1; } // defaults min X to West if intially invalid
if(d_direction_max[0] < -1 || d_direction_max[0] > 1) { d_direction_max[0] = 1; } // defaults max X to East is intially invalid
if(d_direction_min[1] < -1 || d_direction_min[1] > 1) { d_direction_min[1] = 1; } // defaults min Y to North if intially invalid
if(d_direction_max[1] < -1 || d_direction_max[1] > 1) { d_direction_max[1] = 1; } // defaults max Y to North is intially invalid
if(d_direction_min[2] != 0) { d_direction_min[2] = 0; } // defaults min Z to 0 if intially nonzero
if(d_direction_max[2] != 0) { d_direction_max[2] = 0; } // defaults max Z to 0 if intially nonzero
if(w_still_flag < 0 || w_still_flag > 1) { w_still_flag = 1; } // keeps values valid and defaults to on
if(w_still_factor < 0) { w_still_factor = 3; } // keeps values valid and sets to default
}
function get_rand(a,b) //returns random number
{
return (random(1) * (b - a) + a);
}
function get_wind_direction() //get wind direction goal
{
d_direction_goal.x = get_rand(d_direction_min.x, d_direction_max.x);
d_direction_goal.y = get_rand(d_direction_min.y, d_direction_max.y);
d_direction_change_pct = 0.001;
}
function wind_sim() //main wind function
{
while(1)
{
//error_check(); //error and pause check once per frame
if(w_active == 1)
{
if(w_acceleration == 1) //gusting towards a goal
{
if(w_speed_current >= w_speed_goal && w_power_factor != 5)
{
w_speed_goal = random(w_speed_min); // we're at our goal...set new goal between 0 and w_speed_min
w_acceleration = -1; // direction flag to calm
w_speed_change = get_rand(w_speed_change_min, w_speed_change_max); // how fast to calm
}
else
{
if(w_power_factor == 5)
{
w_speed_goal = w_speed_max * w_speed_factor; //use maximum speed - multiply by a w_speed_factor for stronger wind
w_speed_change = w_speed_change_max; // use maximum increment
}
if(w_power_factor == 6) //no wind started while gusting(during gameplay) so set goal, etc
{
w_speed_goal = 0; //use maximum speed - multiply by a w_speedfactor for stronger wind
w_speed_change = w_speed_change_min ; // use maximum increment
}
if(w_speed_current < w_speed_goal)
{
w_speed_current += (w_speed_change * time_step); //not at goal...so increment wind speed
w_speed_current = min(w_speed_current, w_speed_goal); //restrain it if >= than goal
}
}
}
else
{
if(w_acceleration == -1) //calming towards a goal
{
if(w_speed_current <= w_speed_goal)
{
w_acceleration = 0; // we're at our goal....set no goal
}
else
{
if(w_power_factor == 5) //hurricane started while calming(during gameplay) so set goal, etc
{
w_speed_goal = w_speed_max * w_speed_factor; //use maximum speed - multiply by a w_speed_factor for stronger wind
w_speed_change = w_speed_change_max; // use maximum increment
if(w_speed_current < w_speed_goal)
{
w_acceleration = 1;
}
}
w_speed_current -= (w_speed_change * time_step); //not at goal...so decrement wind speed
w_speed_current = max(w_speed_current, w_speed_goal); //restrain it if <= than goal
if(w_speed_current <= w_speed_goal && w_still_flag == 1) //random stillness if w_still_flag set to 1...also zeros out values for panel's display
{
w_acceleration = 0;
w_speed_current = 0;
w_speed_goal = 0;
w_volatility = 0;
d_degrees = 0;
vec_set(d_direction_current,nullvector);
vec_set(d_direction_goal,nullvector);
str_cpy(windstatus,still);
str_cpy(coor,blank);
wait(random(-w_still_factor)); // still wind period based on w_still_factor value
}
}
}
else //no wind so check for direction change/gust power/special winds
{
if(w_power_factor != 6)
{
get_wind_direction(); //get wind direction goal
}
if(w_power_factor == 5) //prepare constant gust/hurricane
{
if(w_speed_current <= w_speed_goal)
{
w_acceleration = 1;
}
}
if(w_power_factor == 6) //prepare stillness..zero variables out for panel display
{
w_speed_goal = 0;
w_speed_change = w_speed_change_min; //uses minimum calming speed
w_volatility = 0;
vec_set(d_direction_current,nullvector);
vec_set(d_direction_goal,nullvector);
if(w_speed_current > w_speed_goal)
{
w_acceleration = -1;
}
else
{
w_acceleration = 0;
}
}
if(w_power_factor != 5 && w_power_factor != 6)
{
w_volatility = random(w_active);
if(w_volatility <= w_active/w_power_factor && w_power_factor != 4) //prepare strong gust
{
w_speed_goal = get_rand(w_speed_min, w_speed_max); //Get a speed goal based on randomness
w_speed_change = w_speed_change_max; // use maximum increment
w_acceleration = 1;
}
else
{
if(w_volatility > w_active/w_power_factor || w_power_factor == 4) //prepare normal gust
{
w_speed_goal = get_rand(w_speed_min, w_speed_max); //Get a speed goal based on randomness
w_speed_change = get_rand(w_speed_change_min, w_speed_change_max); // How fast we will get there
w_acceleration = 1;
}
}
}
}
}
if(d_direction_change_pct != 0) //change wind direction
{
d_direction_change_pct += (d_direction_increment * time_step );
vec_lerp(d_direction_current, d_direction_current, d_direction_goal, d_direction_change_pct); //get to direction goal
if(d_direction_change_pct >= 1)
{
vec_set(d_direction_current,d_direction_goal); // we've reached our goal...stop shifting direction.
d_direction_change_pct = 0;
}
}
d_degrees = fatan(d_direction_current.x,d_direction_current.y); //get the degrees
if(d_direction_current.y > 0) //shift degrees in cartesian quadrant i,ii...NE,NW,N
{
d_degrees %= 360;
/*if(d_degrees < 0)
{
d_degrees += 360;
}
else
{
if(d_degrees >= 360)
{
d_degrees -= 360;
}
}*/
}
else
{
if(d_direction_current.y < 0) //shift degrees in cartesian quadrant iii,iv...SW,SE,S
{
d_degrees += 180;
}
else
{
if(d_direction_current.x > 0 && d_direction_current.y == 0) //shift degrees for E
{
d_degrees += 90;
}
else
{
if(d_direction_current.x < 0 && d_direction_current.y == 0) //shift degrees for W
{
d_degrees += 270;
}
}
}
}
wind_degrees(d_degrees); //call to the cardinal direction indicator
wind_status(w_acceleration); //call to the wind status indicator
}
wait(1);
}
}
function wind_status(d) //set wind status indicator
{
if(w_active == 0) //paused
{
str_cpy(windstatus,paused);
}
else
{
if(w_power_factor == 5) //hurricane
{
str_cpy(windstatus,hurri);
}
else
{
if(w_power_factor == 6) //still
{
str_cpy(windstatus,still);
}
else
{
if(d == -1) //calm
{
str_cpy(windstatus,calm);
}
else
{
if(d == 1 && w_speed_change != w_speed_change_max) //gust
{
str_cpy(windstatus,gust);
}
else
{
if(d == 1 && w_speed_change == w_speed_change_max) //strong gust
{
str_cpy(windstatus,b_gust);
}
}
}
}
}
}
}
function wind_degrees(c) //set cardinal direction indicator
{
if(w_power_factor == 6) //no wind
{
str_cpy(coor,blank);
}
else
{
if(c < 45)
{
str_cpy(coor,north);
}
else
{
if(c < 90)
{
str_cpy(coor,northeast);
}
else
{
if(c < 135)
{
str_cpy(coor,east);
}
else
{
if(c < 180)
{
str_cpy(coor,southeast);
}
else
{
if(c < 225)
{
str_cpy(coor,south);
}
else
{
if(c < 270)
{
str_cpy(coor,southwest);
}
else
{
if(c < 315)
{
str_cpy(coor,west);
}
else
{
if(c < 360)
{
str_cpy(coor,northwest);
}
}
}
}
}
}
}
}
}
}
text wind_direction //cardinal direction indicator
{
layer = 1;
pos_x = 195;
font = standard_font;
strings = 1;
string = coor;
}
text wind_status_panel //wind status indicator
{
layer = 1;
pos_x = 153;
font = standard_font;
strings = 1;
string = windstatus; }
text wind_panel_header //descriptions for panel
{
layer = 1;
pos_x = 0;
font = standard_font;
strings = 10;
string = wacceleration,speed,goal,vola,curdir,dirgoal,dirpercent,deg,direction,status;
}
panel wind_panel //statistics panel
{
layer = 1; pos_x = 0; flags = refresh;
DIGITS = 165, 0, 7, standard_font, 1, w_acceleration; DIGITS = 165, 9, 7.2, standard_font, 1, w_speed_current;
DIGITS = 165, 18, 7.2, standard_font, 1, w_speed_goal; DIGITS = 165, 27, 7.1, standard_font, 1, w_volatility;
DIGITS = 165, 45, 7.2, standard_font, 1, d_direction_current.x; DIGITS = 210, 45, 7.2, standard_font, 1, d_direction_current.y;
DIGITS = 165, 63, 7.2, standard_font, 1, d_direction_goal.x; DIGITS = 210, 63, 7.2, standard_font, 1, d_direction_goal.y;
DIGITS = 165, 81, 7.2, standard_font, 1, d_direction_change_pct; DIGITS = 165, 99, 7, standard_font, 1, d_degrees;
}
function panel_on //switches panels on/off
{
if(wind_panel.visible == off) //switch on panels halfway down screen
{
wind_panel.pos_y = screen_size.y/2;
wind_panel_header.pos_y = screen_size.y/2;
wind_direction.pos_y = screen_size.y/2 + 108;
wind_status_panel.pos_y = screen_size.y/2 + 117;
wind_panel.visible = on;
wind_panel_header.visible = on;
wind_direction.visible = on;
wind_status_panel.visible = on;
}
else //switch off
{
wind_panel.visible = off;
wind_panel_header.visible = off;
wind_direction.visible = off;
wind_status_panel.visible = off;
}
}
on_f9 = panel_on; //activate statistics panels
|
|
|
|