summaryrefslogtreecommitdiff
path: root/src/elements/pipe.c
blob: 7d709aa587b19c2124e3cedd2b812cec134974c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <element.h>

int update_PIPE(UPDATE_FUNC_ARGS) {
	int r, rx, ry, np, trade, q, ctype;
	if (!parts[i].ctype && parts[i].life<=10)
	{
		if (parts[i].temp<272.15)
		{
			if (parts[i].temp>173.25&&parts[i].temp<273.15)
			{
				parts[i].ctype = 2;
				parts[i].life = 0;
			}
			if (parts[i].temp>73.25&&parts[i].temp<=173.15)
			{
				parts[i].ctype = 3;
				parts[i].life = 0;
			}
			if (parts[i].temp>=0&&parts[i].temp<=73.15)
			{
				parts[i].ctype = 4;
				parts[i].life = 0;
			}
		}
		else
		{
			for (rx=-2; rx<3; rx++)
				for (ry=-2; ry<3; ry++)
					if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
					{
						r = pmap[y+ry][x+rx];
						if ((r>>8)>=NPART )
							continue;
						if (!r)
							create_part(-1,x+rx,y+ry,PT_BRCK);
					}
			if (parts[i].life==1)
				parts[i].ctype = 1;
		}
	}
	if (parts[i].ctype==1)
	{
		for (rx=-1; rx<2; rx++)
			for (ry=-1; ry<2; ry++)
				if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
				{
					r = pmap[y+ry][x+rx];
					if ((r>>8)>=NPART)
						continue;
					if (!r&&!parts[i].life)
						parts[i].life=50;
				}
		if (parts[i].life==2)
		{
			parts[i].ctype = 2;
			parts[i].life = 6;
		}
	}
	if (parts[i].ctype>1)
		for ( q = 0; q<3; q++)
			for ( ctype = 2; ctype<5; ctype++)
			{
				if (parts[i].ctype==ctype)
				{
					if (parts[i].life==3)
					{
						for (rx=-1; rx<2; rx++)
							for (ry=-1; ry<2; ry++)
								if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
								{
									r = pmap[y+ry][x+rx];
									if ((r>>8)>=NPART || !r)
										continue;
									if ((r&0xFF)==PT_PIPE&&parts[r>>8].ctype==1)
									{
										parts[r>>8].ctype = (((ctype)%3)+2);//reverse
										parts[r>>8].life = 6;
									}
								}
					}
					else
					{
						rx = rand()%3-1;
						ry = rand()%3-1;
						if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
						{
							r = pmap[y+ry][x+rx];
							if ((r>>8)>=NPART)
								continue;
							else if (!r&&parts[i].tmp!=0)
							{
								np = create_part(-1,x+rx,y+ry,parts[i].tmp);
								if (np!=-1)
								{
									parts[np].temp = parts[i].temp;//pipe saves temp and life now
									parts[np].life = parts[i].flags;
								}
								parts[i].tmp = 0;
								continue;
							}
							else if (!r)
								continue;
							else if (parts[i].tmp == 0 && (ptypes[r&0xFF].falldown!= 0 || ptypes[r&0xFF].state == ST_GAS))
							{
								parts[i].tmp = parts[r>>8].type;
								parts[i].temp = parts[r>>8].temp;
								parts[i].flags = parts[r>>8].life;
								kill_part(r>>8);
							}
							else if ((r&0xFF)==PT_PIPE && parts[r>>8].ctype!=(((ctype)%3)+2) && parts[r>>8].tmp==0&&parts[i].tmp>0)
							{
								parts[r>>8].tmp = parts[i].tmp;
								parts[r>>8].temp = parts[i].temp;
								parts[r>>8].flags = parts[i].flags;
								parts[i].tmp = 0;
							}
						}
					}
				}
			}
	return 0;
}