@@ -26,11 +26,11 @@ fn get_player_target_list(ecs : &mut World) -> Vec<(f32,Entity)> {
2626 let tile_idx = map. xy_idx ( tile_point. x , tile_point. y ) ;
2727 let distance_to_target = rltk:: DistanceAlg :: Pythagoras . distance2d ( * tile_point, rltk:: Point :: new ( player_pos. x , player_pos. y ) ) ;
2828 if distance_to_target < range as f32 {
29- for possible_target in map . tile_content [ tile_idx ] . iter ( ) {
30- if * possible_target != * player_entity && factions. get ( * possible_target) . is_some ( ) {
31- possible_targets. push ( ( distance_to_target, * possible_target) ) ;
29+ crate :: spatial :: for_each_tile_content ( tile_idx , | possible_target| {
30+ if possible_target != * player_entity && factions. get ( possible_target) . is_some ( ) {
31+ possible_targets. push ( ( distance_to_target, possible_target) ) ;
3232 }
33- }
33+ } ) ;
3434 }
3535 }
3636 }
@@ -133,14 +133,14 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
133133 if pos. x + delta_x < 1 || pos. x + delta_x > map. width -1 || pos. y + delta_y < 1 || pos. y + delta_y > map. height -1 { return RunState :: AwaitingInput ; }
134134 let destination_idx = map. xy_idx ( pos. x + delta_x, pos. y + delta_y) ;
135135
136- for potential_target in map . tile_content [ destination_idx ] . iter ( ) {
137- if let Some ( _vendor) = vendors. get ( * potential_target) {
138- return RunState :: ShowVendor { vendor : * potential_target, mode : VendorMode :: Sell }
136+ crate :: spatial :: for_each_tile_content ( destination_idx , | potential_target| {
137+ if let Some ( _vendor) = vendors. get ( potential_target) {
138+ result = RunState :: ShowVendor { vendor : potential_target, mode : VendorMode :: Sell }
139139 }
140140
141141 let mut hostile = true ;
142- if combat_stats. get ( * potential_target) . is_some ( ) {
143- if let Some ( faction) = factions. get ( * potential_target) {
142+ if combat_stats. get ( potential_target) . is_some ( ) {
143+ if let Some ( faction) = factions. get ( potential_target) {
144144 let reaction = crate :: raws:: faction_reaction (
145145 & faction. name ,
146146 "Player" ,
@@ -151,7 +151,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
151151 }
152152 if !hostile {
153153 // Note that we want to move the bystander
154- swap_entities. push ( ( * potential_target, pos. x , pos. y ) ) ;
154+ swap_entities. push ( ( potential_target, pos. x , pos. y ) ) ;
155155
156156 // Move the player
157157 pos. x = min ( map. width -1 , max ( 0 , pos. x + delta_x) ) ;
@@ -162,26 +162,27 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
162162 let mut ppos = ecs. write_resource :: < Point > ( ) ;
163163 ppos. x = pos. x ;
164164 ppos. y = pos. y ;
165+ result = RunState :: Ticking ;
165166 } else {
166- let target = combat_stats. get ( * potential_target) ;
167+ let target = combat_stats. get ( potential_target) ;
167168 if let Some ( _target) = target {
168- wants_to_melee. insert ( entity, WantsToMelee { target : * potential_target } ) . expect ( "Add target failed" ) ;
169- return RunState :: Ticking ;
169+ wants_to_melee. insert ( entity, WantsToMelee { target : potential_target } ) . expect ( "Add target failed" ) ;
170+ result = RunState :: Ticking ;
170171 }
171172 }
172- let door = doors. get_mut ( * potential_target) ;
173+ let door = doors. get_mut ( potential_target) ;
173174 if let Some ( door) = door {
174175 door. open = true ;
175- blocks_visibility. remove ( * potential_target) ;
176- blocks_movement. remove ( * potential_target) ;
177- let glyph = renderables. get_mut ( * potential_target) . unwrap ( ) ;
176+ blocks_visibility. remove ( potential_target) ;
177+ blocks_movement. remove ( potential_target) ;
178+ let glyph = renderables. get_mut ( potential_target) . unwrap ( ) ;
178179 glyph. glyph = rltk:: to_cp437 ( '/' ) ;
179180 viewshed. dirty = true ;
180181 result = RunState :: Ticking ;
181182 }
182- }
183+ } ) ;
183184
184- if !map . blocked [ destination_idx] {
185+ if !crate :: spatial :: is_blocked ( destination_idx) {
185186 pos. x = min ( map. width -1 , max ( 0 , pos. x + delta_x) ) ;
186187 pos. y = min ( map. height -1 , max ( 0 , pos. y + delta_y) ) ;
187188 entity_moved. insert ( entity, EntityMoved { } ) . expect ( "Unable to insert marker" ) ;
@@ -268,8 +269,8 @@ fn skip_turn(ecs: &mut World) -> RunState {
268269 let viewshed = viewshed_components. get ( * player_entity) . unwrap ( ) ;
269270 for tile in viewshed. visible_tiles . iter ( ) {
270271 let idx = worldmap_resource. xy_idx ( tile. x , tile. y ) ;
271- for entity_id in worldmap_resource . tile_content [ idx ] . iter ( ) {
272- let faction = factions. get ( * entity_id) ;
272+ crate :: spatial :: for_each_tile_content ( idx , | entity_id| {
273+ let faction = factions. get ( entity_id) ;
273274 match faction {
274275 None => { }
275276 Some ( faction) => {
@@ -283,7 +284,7 @@ fn skip_turn(ecs: &mut World) -> RunState {
283284 }
284285 }
285286 }
286- }
287+ } ) ;
287288 }
288289
289290 let hunger_clocks = ecs. read_storage :: < HungerClock > ( ) ;
0 commit comments