"""Distinguish real ground burial capture from unreleased enemy/boss capture."""


class BuriedPhysical:
    def physical(self,location,timeout=30):
        def released(s):
            bindings=[b for b in s.get('loaded',{}).get('physical',[]) if b['location']==location]
            if not bindings or not any(p['location_id']==location for p in s.get('pellets',[])):return False
            buried=bindings[0]['depth_max']>0
            actors=s.get('loaded',{}).get('actor_audit',{}).get('actors',[])
            return not any(a['location']==location and (a['pool_flags']&0x65
                or (a.get('captured_now',False) and not buried)) for a in actors)
        state=self.game.wait_state(released,timeout,f'actual authored loose/buried pellet {location}')
        actor=next(p for p in state['pellets'] if p['location_id']==location)
        binding=next(b for b in state['loaded']['physical'] if b['location']==location)
        assert binding['collision_model_matches'] and actor['minimum']==binding['min_carriers']
        return state,actor,binding
