1 #include "simulation/ElementCommon.h"
2
3 void Element_SOAP_detach(Simulation * sim, int i);
4 static int update(UPDATE_FUNC_ARGS);
5 static int graphics(GRAPHICS_FUNC_ARGS);
6 static bool ctypeDraw(CTYPEDRAW_FUNC_ARGS);
7
Element_STOR()8 void Element::Element_STOR()
9 {
10 Identifier = "DEFAULT_PT_STOR";
11 Name = "STOR";
12 Colour = PIXPACK(0x50DFDF);
13 MenuVisible = 1;
14 MenuSection = SC_POWERED;
15 Enabled = 1;
16
17 Advection = 0.0f;
18 AirDrag = 0.00f * CFDS;
19 AirLoss = 0.90f;
20 Loss = 0.00f;
21 Collision = 0.0f;
22 Gravity = 0.0f;
23 Diffusion = 0.00f;
24 HotAir = 0.000f * CFDS;
25 Falldown = 0;
26
27 Flammable = 0;
28 Explosive = 0;
29 Meltable = 0;
30 Hardness = 1;
31
32 Weight = 100;
33
34 HeatConduct = 0;
35 Description = "Storage. Captures and stores a single particle. Releases when charged with PSCN, also passes to PIPE.";
36
37 Properties = TYPE_SOLID | PROP_NOCTYPEDRAW;
38
39 LowPressure = IPL;
40 LowPressureTransition = NT;
41 HighPressure = IPH;
42 HighPressureTransition = NT;
43 LowTemperature = ITL;
44 LowTemperatureTransition = NT;
45 HighTemperature = ITH;
46 HighTemperatureTransition = NT;
47
48 Update = &update;
49 Graphics = &graphics;
50 CtypeDraw = &ctypeDraw;
51 }
52
update(UPDATE_FUNC_ARGS)53 static int update(UPDATE_FUNC_ARGS)
54 {
55 int r, rx, ry, np, rx1, ry1;
56 if (!sim->IsValidElement(parts[i].tmp))
57 parts[i].tmp = 0;
58 if(parts[i].life && !parts[i].tmp)
59 parts[i].life--;
60 for (rx=-2; rx<3; rx++)
61 for (ry=-2; ry<3; ry++)
62 if (BOUNDS_CHECK && (rx || ry))
63 {
64 r = pmap[y+ry][x+rx];
65 if ((ID(r))>=NPART || !r)
66 continue;
67 if (!parts[i].tmp && !parts[i].life && TYP(r)!=PT_STOR && !(sim->elements[TYP(r)].Properties&TYPE_SOLID) && (!parts[i].ctype || TYP(r)==parts[i].ctype))
68 {
69 if (TYP(r) == PT_SOAP)
70 Element_SOAP_detach(sim, ID(r));
71 parts[i].tmp = parts[ID(r)].type;
72 parts[i].temp = parts[ID(r)].temp;
73 parts[i].tmp2 = parts[ID(r)].life;
74 parts[i].pavg[0] = parts[ID(r)].tmp;
75 parts[i].pavg[1] = parts[ID(r)].ctype;
76 sim->kill_part(ID(r));
77 }
78 if(parts[i].tmp && TYP(r)==PT_SPRK && parts[ID(r)].ctype==PT_PSCN && parts[ID(r)].life>0 && parts[ID(r)].life<4)
79 {
80 for(ry1 = 1; ry1 >= -1; ry1--){
81 for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){ // Oscillate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1)
82 np = sim->create_part(-1,x+rx1,y+ry1,TYP(parts[i].tmp));
83 if (np!=-1)
84 {
85 parts[np].temp = parts[i].temp;
86 parts[np].life = parts[i].tmp2;
87 parts[np].tmp = parts[i].pavg[0];
88 parts[np].ctype = parts[i].pavg[1];
89 parts[i].tmp = 0;
90 parts[i].life = 10;
91 break;
92 }
93 }
94 }
95 }
96 }
97 return 0;
98 }
99
graphics(GRAPHICS_FUNC_ARGS)100 static int graphics(GRAPHICS_FUNC_ARGS)
101 {
102 if(cpart->tmp){
103 *pixel_mode |= PMODE_GLOW;
104 *colr = 0x50;
105 *colg = 0xDF;
106 *colb = 0xDF;
107 } else {
108 *colr = 0x20;
109 *colg = 0xAF;
110 *colb = 0xAF;
111 }
112 return 0;
113 }
114
ctypeDraw(CTYPEDRAW_FUNC_ARGS)115 static bool ctypeDraw(CTYPEDRAW_FUNC_ARGS)
116 {
117 if (sim->elements[t].Properties & TYPE_SOLID)
118 {
119 return false;
120 }
121 return Element::basicCtypeDraw(CTYPEDRAW_FUNC_SUBCALL_ARGS);
122 }
123