@@ -9,6 +9,7 @@ use super::map_point;
9
9
#[ derive( Copy , Clone ) ]
10
10
pub enum VisionStatus {
11
11
NotSeen ,
12
+ NotSeenButDetected ,
12
13
Seen ,
13
14
Detected ,
14
15
}
@@ -55,10 +56,11 @@ impl VisionMap {
55
56
56
57
pub fn add_unit ( & mut self , unit : VisionUnit ) { self . units . push ( unit) ; }
57
58
58
- pub fn vision_status ( & self , position : ( f32 , f32 ) ) -> usize {
59
+ pub fn vision_status ( & self , position : ( f32 , f32 ) ) -> usize {
59
60
let int_point = round_point2 ( position) ;
60
61
match self . points [ int_point. 0 ] [ int_point. 1 ] {
61
62
VisionStatus :: NotSeen => 0 ,
63
+ VisionStatus :: NotSeenButDetected => 0 ,
62
64
VisionStatus :: Seen => 1 ,
63
65
VisionStatus :: Detected => 2 ,
64
66
}
@@ -103,6 +105,7 @@ impl VisionMap {
103
105
for y in 0 ..self . height {
104
106
match self . points [ x] [ y] {
105
107
VisionStatus :: NotSeen => vision_map[ x] [ y] = 0 ,
108
+ VisionStatus :: NotSeenButDetected => vision_map[ x] [ y] = 0 ,
106
109
VisionStatus :: Seen => vision_map[ x] [ y] = 1 ,
107
110
VisionStatus :: Detected => vision_map[ x] [ y] = 2 ,
108
111
}
@@ -144,8 +147,12 @@ fn set_vision(points: &mut Vec<Vec<VisionStatus>>, position: &(f32, f32), sight_
144
147
for y in rect. y ..rect. y_end {
145
148
let d = octile_distance_f32 ( u_position, ( x, y) ) ;
146
149
147
- if d <= sight_range && matches ! ( points[ x] [ y] , VisionStatus :: NotSeen ) {
148
- points[ x] [ y] = VisionStatus :: Seen ;
150
+ if d <= sight_range {
151
+ if matches ! ( points[ x] [ y] , VisionStatus :: NotSeen ) {
152
+ points[ x] [ y] = VisionStatus :: Seen ;
153
+ } else if matches ! ( points[ x] [ y] , VisionStatus :: NotSeenButDetected ) {
154
+ points[ x] [ y] = VisionStatus :: Detected ;
155
+ }
149
156
}
150
157
}
151
158
}
@@ -155,6 +162,27 @@ fn calc_ground_detection(points: &mut Vec<Vec<VisionStatus>>,
155
162
map_points : & Vec < Vec < map_point:: MapPoint > > ,
156
163
position : & ( f32 , f32 ) ,
157
164
sight_range : f32 ) {
165
+ let u_position = round_point2 ( * position) ;
166
+ let size = ( ( sight_range * 2f32 ) as usize , ( sight_range * 2f32 ) as usize ) ;
167
+ let width = points. len ( ) ;
168
+ let height = points[ 0 ] . len ( ) ;
169
+
170
+ let rect = rectangle:: Rectangle :: init_from_center2 ( u_position, size, width, height) ;
171
+
172
+ for x in rect. x ..rect. x_end {
173
+ for y in rect. y ..rect. y_end {
174
+ let d = octile_distance_f32 ( u_position, ( x, y) ) ;
175
+
176
+ if d <= sight_range {
177
+ if matches ! ( points[ x] [ y] , VisionStatus :: NotSeen ) || matches ! ( points[ x] [ y] , VisionStatus :: NotSeenButDetected ) {
178
+ points[ x] [ y] = VisionStatus :: NotSeenButDetected ;
179
+ } else {
180
+ points[ x] [ y] = VisionStatus :: Detected ;
181
+ }
182
+ }
183
+ }
184
+ }
185
+
158
186
let circumference = 2f32 * sight_range * std:: f32:: consts:: PI ;
159
187
let rays = circumference as usize ;
160
188
let step_mult = 1.3f32 ;
@@ -217,22 +245,28 @@ fn calc_ground_vision(points: &mut Vec<Vec<VisionStatus>>,
217
245
for step in 0 ..steps {
218
246
// Rays are only drawn until non-walkable is found and thus the cannot go out of bounds
219
247
let step_f32 = step as f32 / step_mult;
220
- let new_pos =
221
- ( ( position. 0 + v_x * step_f32) as usize , ( position. 1 + v_y * step_f32) as usize ) ;
248
+ let new_pos = ( ( position. 0 + v_x * step_f32) as usize , ( position. 1 + v_y * step_f32) as usize ) ;
222
249
223
-
224
250
// TODO: Same for height difference
225
251
if map_points[ new_pos. 0 ] [ new_pos. 1 ] . height > max_height_seen {
226
252
// Ray can't reach further
227
- println ! ( "Ray {} stopped at ({}, {}), angle was {} and vector was ({}, {}) with step {}" , index, new_pos. 0 , new_pos. 1 , angle, v_x, v_y, step_f32) ;
253
+ println ! ( "Ray {} stopped at ({}, {}), angle was {} and vector was ({}, {}) with step {}" ,
254
+ index, new_pos. 0 , new_pos. 1 , angle, v_x, v_y, step_f32) ;
228
255
break ;
229
256
}
230
257
231
258
if matches ! ( points[ new_pos. 0 ] [ new_pos. 1 ] , VisionStatus :: NotSeen ) {
232
259
// if new_pos.0 == 25 && new_pos.1 == 8 {
233
- println ! ( "Ray {} set vision to ({}, {}), angle was {} and vector was ({}, {}) with step {}" , index, new_pos. 0 , new_pos. 1 , angle, v_x, v_y, step_f32) ;
260
+ println ! ( "Ray {} set vision to ({}, {}), angle was {} and vector was ({}, {}) with step {}" ,
261
+ index, new_pos. 0 , new_pos. 1 , angle, v_x, v_y, step_f32) ;
234
262
// }
235
263
points[ new_pos. 0 ] [ new_pos. 1 ] = VisionStatus :: Seen ;
264
+ } else if matches ! ( points[ new_pos. 0 ] [ new_pos. 1 ] , VisionStatus :: NotSeenButDetected ) {
265
+ // if new_pos.0 == 25 && new_pos.1 == 8 {
266
+ println ! ( "Ray {} set vision to ({}, {}), angle was {} and vector was ({}, {}) with step {}" ,
267
+ index, new_pos. 0 , new_pos. 1 , angle, v_x, v_y, step_f32) ;
268
+ // }
269
+ points[ new_pos. 0 ] [ new_pos. 1 ] = VisionStatus :: Detected ;
236
270
}
237
271
}
238
272
}
0 commit comments