1 #include "simulation/ElementCommon.h"
2 
3 int Element_VIRS_update(UPDATE_FUNC_ARGS);
4 static int graphics(GRAPHICS_FUNC_ARGS);
5 
Element_VIRS()6 void Element::Element_VIRS()
7 {
8 	Identifier = "DEFAULT_PT_VIRS";
9 	Name = "VIRS";
10 	Colour = PIXPACK(0xFE11F6);
11 	MenuVisible = 1;
12 	MenuSection = SC_LIQUID;
13 	Enabled = 1;
14 
15 	Advection = 0.6f;
16 	AirDrag = 0.01f * CFDS;
17 	AirLoss = 0.98f;
18 	Loss = 0.95f;
19 	Collision = 0.0f;
20 	Gravity = 0.1f;
21 	Diffusion = 0.00f;
22 	HotAir = 0.000f	* CFDS;
23 	Falldown = 2;
24 
25 	Flammable = 0;
26 	Explosive = 0;
27 	Meltable = 0;
28 	Hardness = 20;
29 
30 	Weight = 31;
31 
32 	DefaultProperties.temp = 72.0f + 273.15f;
33 	HeatConduct = 251;
34 	Description = "Virus. Turns everything it touches into virus.";
35 
36 	Properties = TYPE_LIQUID|PROP_DEADLY;
37 
38 	LowPressure = IPL;
39 	LowPressureTransition = NT;
40 	HighPressure = IPH;
41 	HighPressureTransition = NT;
42 	LowTemperature = 305.0f;
43 	LowTemperatureTransition = PT_VRSS;
44 	HighTemperature = 673.0f;
45 	HighTemperatureTransition = PT_VRSG;
46 
47 	DefaultProperties.pavg[1] = 250;
48 
49 	Update = &Element_VIRS_update;
50 	Graphics = &graphics;
51 }
52 
Element_VIRS_update(UPDATE_FUNC_ARGS)53 int Element_VIRS_update(UPDATE_FUNC_ARGS)
54 {
55 	//pavg[0] measures how many frames until it is cured (0 if still actively spreading and not being cured)
56 	//pavg[1] measures how many frames until it dies
57 	int r, rx, ry, rndstore = RNG::Ref().gen();
58 	if (parts[i].pavg[0])
59 	{
60 		parts[i].pavg[0] -= (rndstore & 0x1) ? 0:1;
61 		//has been cured, so change back into the original element
62 		if (!parts[i].pavg[0])
63 		{
64 			sim->part_change_type(i,x,y,parts[i].tmp2);
65 			parts[i].tmp2 = 0;
66 			parts[i].pavg[0] = 0;
67 			parts[i].pavg[1] = 0;
68 		}
69 		return 0;
70 		//cured virus is never in below code
71 	}
72 	//decrease pavg[1] so it slowly dies
73 	if (parts[i].pavg[1])
74 	{
75 		if (!(rndstore & 0x7) && --parts[i].pavg[1] <= 0)
76 		{
77 			sim->kill_part(i);
78 			return 1;
79 		}
80 		rndstore >>= 3;
81 	}
82 
83 	for (rx=-1; rx<2; rx++)
84 		for (ry=-1; ry<2; ry++)
85 		{
86 			if (BOUNDS_CHECK && (rx || ry))
87 			{
88 				r = pmap[y+ry][x+rx];
89 				if (!r)
90 					continue;
91 
92 				//spread "being cured" state
93 				if (parts[ID(r)].pavg[0] && (TYP(r) == PT_VIRS || TYP(r) == PT_VRSS || TYP(r) == PT_VRSG))
94 				{
95 					parts[i].pavg[0] = parts[ID(r)].pavg[0] + ((rndstore & 0x3) ? 2:1);
96 					return 0;
97 				}
98 				//soap cures virus
99 				else if (TYP(r) == PT_SOAP)
100 				{
101 					parts[i].pavg[0] += 10;
102 					if (!(rndstore & 0x3))
103 						sim->kill_part(ID(r));
104 					return 0;
105 				}
106 				else if (TYP(r) == PT_PLSM)
107 				{
108 					if (surround_space && RNG::Ref().chance(10 + sim->pv[(y+ry)/CELL][(x+rx)/CELL], 100))
109 					{
110 						sim->create_part(i, x, y, PT_PLSM);
111 						return 1;
112 					}
113 				}
114 				//transforms things into virus here
115 				else if (TYP(r) != PT_VIRS && TYP(r) != PT_VRSS && TYP(r) != PT_VRSG && TYP(r) != PT_DMND)
116 				{
117 					if (!(rndstore & 0x7))
118 					{
119 						parts[ID(r)].tmp2 = TYP(r);
120 						parts[ID(r)].pavg[0] = 0;
121 						if (parts[i].pavg[1])
122 							parts[ID(r)].pavg[1] = parts[i].pavg[1] + 1;
123 						else
124 							parts[ID(r)].pavg[1] = 0;
125 						if (parts[ID(r)].temp < 305.0f)
126 							sim->part_change_type(ID(r), x+rx, y+ry, PT_VRSS);
127 						else if (parts[ID(r)].temp > 673.0f)
128 							sim->part_change_type(ID(r), x+rx, y+ry, PT_VRSG);
129 						else
130 							sim->part_change_type(ID(r), x+rx, y+ry, PT_VIRS);
131 					}
132 					rndstore >>= 3;
133 				}
134 				//protons make VIRS last forever
135 				else if (TYP(sim->photons[y+ry][x+rx]) == PT_PROT)
136 				{
137 					parts[i].pavg[1] = 0;
138 				}
139 			}
140 			//reset rndstore only once, halfway through
141 			else if (!rx && !ry)
142 				rndstore = RNG::Ref().gen();
143 		}
144 	return 0;
145 }
146 
graphics(GRAPHICS_FUNC_ARGS)147 static int graphics(GRAPHICS_FUNC_ARGS)
148 {
149 	*pixel_mode |= PMODE_BLUR;
150 	*pixel_mode |= NO_DECO;
151 	return 1;
152 }
153