# gschool_randperson

!! arguments: <gender> <excluded_first_name> <grupTipeEnabled>...
!! gender : 0 for male, 1 for female
!! excluded_first_name : can be '' or you can provide result of previous invocation, so you can compose non-repeating pairs of people
!! <grupTipeEnabled>... : 1 if you include grupTipe, 0 otherwise, look at examples below
!!
!! example:
!! $rand_girl = func('gschool_randperson', 1, '', 1, 1, 0, 1, 0, 0)
!! $rand_girl1 = func('gschool_randperson', 1, $rand_girl, 1, 1, 0, 1)
!!
!! Having grupTipes (social groups)
!! 1 - cool kids
!! 2 - jocks
!! 3 - nerds
!! 4 - Gopnik
!! 5 - outcasts
!! 6 - teachers
!! examples above instruct to choose random person from: cool kids, jocks and gopniks
!! NOTE that in $rand_girl1 zero values for outcasts and teachers are not defined - undefined values will be zero by language
!! Thanks to that you can include new social group and you don''t need to make changes in all places

rand_person_ind = 0
rand_filtered_ind = 0

:filter_loop
  rand_person_ind = rand_person_ind + 1
  if rand_person_ind >= ARRSIZE('grupTipe') : jump 'outside_filter_loop'
  genderMatches = ARGS[0] = npcPol[rand_person_ind]
  nameIsNotRepeated = ARGS[1] <> $npc_firstname[$school_static_num[rand_person_ind]]
  grupTipeIsLegal = grupTipe[rand_person_ind] > 0
  grupTipeMatches = ARGS[grupTipe[rand_person_ind] + 1] = 1
  if genderMatches and nameIsNotRepeated and grupTipeIsLegal and grupTipeMatches :
    rand_filtered[rand_filtered_ind] = rand_person_ind
    rand_filtered_ind = rand_filtered_ind + 1
  end
  jump 'filter_loop'
:outside_filter_loop

if ARRSIZE('rand_filtered') > 0 :
  random_person = rand_filtered[rand(0,ARRSIZE('rand_filtered'))]
  $RESULT = $npc_firstname[$school_static_num[random_person]]
else
  $rand_gender = IIF (ARGS[0] = 0, 'boy', 'girl')
  $RESULT =  '<<$rand_gender>> you don''t know'
end

KILLVAR 'rand_person_ind'
KILLVAR 'rand_filtered_ind'
KILLVAR 'rand_filtered'
KILLVAR '$rand_gender'
KILLVAR 'random_person'
KILLVAR 'genderMatches'
KILLVAR 'nameIsNotRepeated'
KILLVAR 'grupTipeIsLegal'
KILLVAR 'grupTipeMatches'

--- gschool_randperson ---------------------------------
