11use specs:: prelude:: * ;
2- use super :: { Map , Position , BlocksTile , Pools , spatial} ;
2+ use super :: { Map , Position , BlocksTile , Pools , spatial, TileSize } ;
33
44pub struct MapIndexingSystem { }
55
66impl < ' a > System < ' a > for MapIndexingSystem {
7+ #[ allow( clippy:: type_complexity) ]
78 type SystemData = ( ReadExpect < ' a , Map > ,
89 ReadStorage < ' a , Position > ,
910 ReadStorage < ' a , BlocksTile > ,
1011 ReadStorage < ' a , Pools > ,
12+ ReadStorage < ' a , TileSize > ,
1113 Entities < ' a > , ) ;
1214
1315 fn run ( & mut self , data : Self :: SystemData ) {
14- let ( map, position, blockers, pools, entities) = data;
16+ let ( map, position, blockers, pools, sizes , entities) = data;
1517
1618 spatial:: clear ( ) ;
1719 spatial:: populate_blocked_from_map ( & * map) ;
@@ -23,8 +25,21 @@ impl<'a> System<'a> for MapIndexingSystem {
2325 }
2426 }
2527 if alive {
26- let idx = map. xy_idx ( position. x , position. y ) ;
27- spatial:: index_entity ( entity, idx, blockers. get ( entity) . is_some ( ) ) ;
28+ if let Some ( size) = sizes. get ( entity) {
29+ // Multi-tile
30+ for y in position. y .. position. y + size. y {
31+ for x in position. x .. position. x + size. x {
32+ if x > 0 && x < map. width -1 && y > 0 && y < map. height -1 {
33+ let idx = map. xy_idx ( x, y) ;
34+ spatial:: index_entity ( entity, idx, blockers. get ( entity) . is_some ( ) ) ;
35+ }
36+ }
37+ }
38+ } else {
39+ // Single tile
40+ let idx = map. xy_idx ( position. x , position. y ) ;
41+ spatial:: index_entity ( entity, idx, blockers. get ( entity) . is_some ( ) ) ;
42+ }
2843 }
2944 }
3045 }
0 commit comments