1 #include "common/tpt-minmax.h"
2 #include "simulation/ElementCommon.h"
3 
4 static int update(UPDATE_FUNC_ARGS);
5 static int graphics(GRAPHICS_FUNC_ARGS);
6 
Element_GRAV()7 void Element::Element_GRAV()
8 {
9 	Identifier = "DEFAULT_PT_GRAV";
10 	Name = "GRAV";
11 	Colour = PIXPACK(0x202020);
12 	MenuVisible = 1;
13 	MenuSection = SC_POWDERS;
14 	Enabled = 1;
15 
16 	Advection = 0.7f;
17 	AirDrag = 0.00f * CFDS;
18 	AirLoss = 1.00f;
19 	Loss = 1.00f;
20 	Collision = 0.0f;
21 	Gravity = 0.0f;
22 	Diffusion = 0.00f;
23 	HotAir = 0.000f	* CFDS;
24 	Falldown = 1;
25 
26 	Flammable = 10;
27 	Explosive = 0;
28 	Meltable = 0;
29 	Hardness = 30;
30 
31 	Weight = 85;
32 
33 	HeatConduct = 70;
34 	Description = "Very light dust. Changes colour based on velocity.";
35 
36 	Properties = TYPE_PART | PROP_LIFE_DEC;
37 
38 	LowPressure = IPL;
39 	LowPressureTransition = NT;
40 	HighPressure = IPH;
41 	HighPressureTransition = NT;
42 	LowTemperature = ITL;
43 	LowTemperatureTransition = NT;
44 	HighTemperature = ITH;
45 	HighTemperatureTransition = NT;
46 
47 	Update = &update;
48 	Graphics = &graphics;
49 }
50 
update(UPDATE_FUNC_ARGS)51 static int update(UPDATE_FUNC_ARGS)
52 {
53 	if (parts[i].vx*parts[i].vx + parts[i].vy*parts[i].vy >= 0.1f && RNG::Ref().chance(1, 512))
54 	{
55 		if (!parts[i].life)
56 			parts[i].life = 48;
57 	}
58 
59 	return 0;
60 }
61 
graphics(GRAPHICS_FUNC_ARGS)62 static int graphics(GRAPHICS_FUNC_ARGS)
63 {
64 	int GRAV_R, GRAV_B, GRAV_G, GRAV_R2, GRAV_B2, GRAV_G2;
65 
66 	GRAV_R = std::abs((ren->sim->currentTick%120)-60);
67 	GRAV_G = std::abs(((ren->sim->currentTick+60)%120)-60);
68 	GRAV_B = std::abs(((ren->sim->currentTick+120)%120)-60);
69 	GRAV_R2 = std::abs((ren->sim->currentTick%60)-30);
70 	GRAV_G2 = std::abs(((ren->sim->currentTick+30)%60)-30);
71 	GRAV_B2 = std::abs(((ren->sim->currentTick+60)%60)-30);
72 
73 
74 	*colr = 20;
75 	*colg = 20;
76 	*colb = 20;
77 	if (cpart->vx>0)
78 	{
79 		*colr += (cpart->vx)*GRAV_R;
80 		*colg += (cpart->vx)*GRAV_G;
81 		*colb += (cpart->vx)*GRAV_B;
82 	}
83 	if (cpart->vy>0)
84 	{
85 		*colr += (cpart->vy)*GRAV_G;
86 		*colg += (cpart->vy)*GRAV_B;
87 		*colb += (cpart->vy)*GRAV_R;
88 
89 	}
90 	if (cpart->vx<0)
91 	{
92 		*colr -= (cpart->vx)*GRAV_B;
93 		*colg -= (cpart->vx)*GRAV_R;
94 		*colb -= (cpart->vx)*GRAV_G;
95 
96 	}
97 	if (cpart->vy<0)
98 	{
99 		*colr -= (cpart->vy)*GRAV_R2;
100 		*colg -= (cpart->vy)*GRAV_G2;
101 		*colb -= (cpart->vy)*GRAV_B2;
102 	}
103 
104 	if (cpart->life)
105 	{
106 		*pixel_mode = FIRE_ADD | PMODE_ADD | PMODE_GLOW | PMODE_FLARE;
107 		*firer = std::min(*colr * 3, 255);
108 		*fireg = std::min(*colg * 3, 255);
109 		*fireb = std::min(*colb * 3, 255);
110 		*firea = (cpart->life+15)*4;
111 		*cola = (cpart->life+15)*4;
112 	}
113 	else
114 		*pixel_mode = PMODE_ADD;
115 
116 	return 0;
117 }
118