#!/bin/bash
[ "$3" == "" ] && exec echo "Usage: $0 <POSTFIX> <MISSION_ID> <MISSION_STATE>"

POSTFIX=$1
MISSION_ID=$2
MISSION_STATE=$3

echo "SELECT DISTINCT player_id FROM final_mission_state${POSTFIX} WHERE ( player_id IN ( SELECT id FROM player_characters WHERE postfix = ${POSTFIX} ) )"

echo ""

echo "( player_id IN ( SELECT player_id FROM final_mission_state${POSTFIX} WHERE index =(${MISSION_ID} - 1) / 10 AND ( state = ( ${MISSION_STATE} <<(${MISSION_ID} - 1) % 10 * 3 ) | ( state & ( ~( 7 << (${MISSION_ID} - 1) % 10 * 3 ) ) ) ) ) )"
