@@ -46,10 +46,14 @@ Element_LDTC::Element_LDTC()
46
46
Update = &Element_LDTC::update;
47
47
}
48
48
49
- const int mask_invert_filter = 0x1 ;
50
- const int mask_ignore_energy = 0x2 ;
51
- const int mask_no_copy_color = 0x4 ;
52
- const int mask_keep_searching = 0x8 ;
49
+ // #TPT-Directive ElementHeader Element_LDTC static const int FLAG_INVERT_FILTER
50
+ // #TPT-Directive ElementHeader Element_LDTC static const int FLAG_IGNORE_ENERGY
51
+ // #TPT-Directive ElementHeader Element_LDTC static const int FLAG_NO_COPY_COLOR
52
+ // #TPT-Directive ElementHeader Element_LDTC static const int FLAG_KEEP_SEARCHING
53
+ const int Element_LDTC::FLAG_INVERT_FILTER = 0x1 ;
54
+ const int Element_LDTC::FLAG_IGNORE_ENERGY = 0x2 ;
55
+ const int Element_LDTC::FLAG_NO_COPY_COLOR = 0x4 ;
56
+ const int Element_LDTC::FLAG_KEEP_SEARCHING = 0x8 ;
53
57
54
58
// NOTES:
55
59
// ctype is used to store the target element, if any. (NONE is treated as a wildcard)
@@ -62,31 +66,37 @@ const int mask_keep_searching = 0x8;
62
66
// 0x08: Keep searching even after finding a particle
63
67
64
68
69
+ // #TPT-Directive ElementHeader Element_LDTC static bool phot_data_type(int rt);
65
70
/* Returns true for particles that activate the special FILT color copying mode */
66
- bool phot_data_type (int rt)
71
+ bool Element_LDTC:: phot_data_type (int rt)
67
72
{
68
- if (rt == PT_FILT || rt == PT_PHOT || rt == PT_BRAY)
69
- return true ;
70
- return false ;
73
+ return rt == PT_FILT || rt == PT_PHOT || rt == PT_BRAY;
71
74
}
72
75
76
+ // #TPT-Directive ElementHeader Element_LDTC static bool accepted_conductor(Simulation *sim, int rt);
73
77
/* Returns true for particles that start a ray search ("dtec" mode)
74
78
*/
75
- bool accepted_type (Simulation* sim, int r)
79
+ bool Element_LDTC::accepted_conductor (Simulation* sim, int r)
76
80
{
77
81
int rt = TYP (r);
78
- if ((sim->elements [rt].Properties & PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR))
79
- {
80
- if (sim->parts [ID (r)].life == 0 )
81
- return true ;
82
- }
83
- return false ;
82
+ return (sim->elements [rt].Properties & PROP_CONDUCTS) &&
83
+ !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT ||
84
+ rt == PT_PTCT || rt == PT_INWR) &&
85
+ sim->parts [ID (r)].life == 0 ;
84
86
}
85
87
86
88
// #TPT-Directive ElementHeader Element_LDTC static int update(UPDATE_FUNC_ARGS)
87
89
int Element_LDTC::update (UPDATE_FUNC_ARGS)
88
90
{
89
- int max = parts[i].tmp + parts[i].life ;
91
+ int ctype = TYP (parts[i].ctype ), ctypeExtra = ID (parts[i].ctype ), detectLength = parts[i].tmp , detectSpaces = parts[i].tmp2 ;
92
+ bool copyColor = !(parts[i].tmp2 & Element_LDTC::FLAG_NO_COPY_COLOR);
93
+ bool ignoreEnergy = parts[i].tmp2 & Element_LDTC::FLAG_IGNORE_ENERGY;
94
+ bool invertFilter = parts[i].tmp2 & Element_LDTC::FLAG_INVERT_FILTER;
95
+ bool keepSearching = parts[i].tmp2 & Element_LDTC::FLAG_KEEP_SEARCHING;
96
+ if (detectSpaces < 0 )
97
+ detectSpaces = parts[i].tmp2 = 0 ;
98
+ if (detectLength < 0 )
99
+ detectLength = parts[i].tmp = 0 ;
90
100
for (int rx = -1 ; rx <= 1 ; rx++)
91
101
{
92
102
for (int ry = -1 ; ry <= 1 ; ry++)
@@ -96,70 +106,68 @@ int Element_LDTC::update(UPDATE_FUNC_ARGS)
96
106
int r = pmap[y+ry][x+rx];
97
107
if (!r)
98
108
continue ;
99
-
100
- if (!accepted_type (sim, r) && ((parts[i].tmp2 & mask_no_copy_color) || !phot_data_type (TYP (r))))
109
+ bool boolMode = Element_LDTC::accepted_conductor (sim, r);
110
+ bool filtMode = copyColor && TYP (r) == PT_FILT;
111
+ if (!boolMode && !filtMode)
101
112
continue ;
102
113
103
- // Stolen from DRAY, does the ray searching
114
+ int maxRange = parts[i]. life + parts[i]. tmp ;
104
115
int xStep = rx * -1 , yStep = ry * -1 ;
105
116
int xCurrent = x + (xStep * (parts[i].life + 1 )), yCurrent = y + (yStep * (parts[i].life + 1 ));
106
- for (;(parts[i].tmp == 0 ) || !(xCurrent - x >= max) || (yCurrent-y >= max); xCurrent += xStep, yCurrent += yStep)
117
+ for (; !parts[i].tmp ||
118
+ (xStep * (xCurrent - x) <= maxRange &&
119
+ yStep * (yCurrent - y) <= maxRange);
120
+ xCurrent += xStep, yCurrent += yStep)
107
121
{
108
- int rr = pmap[yCurrent][xCurrent];
109
122
if (!(xCurrent>=0 && yCurrent>=0 && xCurrent<XRES && yCurrent<YRES))
110
- {
111
123
break ; // We're out of bounds! Oops!
112
- }
113
- if (!rr)
114
- {
124
+ int rr = pmap[yCurrent][xCurrent];
125
+ if (!rr && !ignoreEnergy)
115
126
rr = sim->photons [yCurrent][xCurrent];
116
- if (!(rr && !(parts[i].tmp2 & mask_ignore_energy)))
117
- {
118
- continue ;
119
- }
120
- }
121
127
if (!rr)
122
128
continue ;
123
129
124
- // Usual DTEC-like mode
125
- if (!phot_data_type (TYP (r)))
130
+ // If ctype isn't set (no type restriction), or ctype matches what we found
131
+ // Can use .tmp2 flag to invert this
132
+ bool matchesCtype = parts[i].ctype == TYP (rr) && (ctype != PT_LIFE || parts[ID (rr)].ctype == ctypeExtra);
133
+ bool matchesFilter = !ctype || (invertFilter ^ (int )matchesCtype);
134
+ if (!matchesFilter)
126
135
{
127
- // If ctype isn't set (no type restriction), or ctype matches what we found
128
- // Can use .tmp2 flag to invert this
129
- if (parts[i].ctype == 0 || (parts[i].ctype == TYP (rr)) ^ (parts[i].tmp2 & mask_invert_filter))
130
- {
131
- parts[ID (r)].life = 4 ;
132
- parts[ID (r)].ctype = TYP (r);
133
- sim->part_change_type (ID (r), x + rx, y + ry, PT_SPRK);
136
+ if (keepSearching)
137
+ continue ;
138
+ else
134
139
break ;
135
- }
136
- // room for more conditions here.
137
140
}
138
- // FILT color copying mode
139
- else
141
+ // room for more conditions here.
142
+
143
+ if (boolMode)
144
+ {
145
+ parts[ID (r)].life = 4 ;
146
+ parts[ID (r)].ctype = TYP (r);
147
+ sim->part_change_type (ID (r), x + rx, y + ry, PT_SPRK);
148
+ break ;
149
+ }
150
+
151
+ if (filtMode)
140
152
{
141
- // If ctype isn't set (no type restriction), or ctype matches what we found
142
- // Can use .tmp2 flag to invert this
143
- if (parts[i].ctype == 0 || (parts[i].ctype == TYP (rr)) ^ (parts[i].tmp2 & mask_invert_filter))
153
+ if (!Element_LDTC::phot_data_type (TYP (rr)))
154
+ continue ;
155
+
156
+ int nx = x + rx, ny = y + ry;
157
+ int photonWl = TYP (rr) == PT_FILT ?
158
+ Element_FILT::getWavelengths (&parts[ID (rr)]) :
159
+ parts[ID (rr)].ctype ;
160
+ while (TYP (r) == PT_FILT)
144
161
{
145
- if (phot_data_type (TYP (rr)))
146
- {
147
- int nx = x + rx, ny = y + ry;
148
- while (TYP (r) == PT_FILT)
149
- {
150
- parts[ID (r)].ctype = Element_FILT::getWavelengths (&parts[ID (rr)]);
151
- nx += rx;
152
- ny += ry;
153
- if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)
154
- break ;
155
- r = pmap[ny][nx];
156
- }
162
+ parts[ID (r)].ctype = photonWl;
163
+ nx += rx;
164
+ ny += ry;
165
+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)
157
166
break ;
158
- }
167
+ r = pmap[ny][nx];
159
168
}
160
- }
161
- if (!(parts[i].tmp2 & mask_keep_searching))
162
169
break ;
170
+ }
163
171
}
164
172
}
165
173
}
0 commit comments