set_npc_attraction.qsrc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # set_npc_attraction
  2. !! set_npc_attraction function.
  3. !!
  4. !! Modify the attraction (analogous to appearance) and relative hotcat (analogous to hotcat) using the various preferences (set in npc_set_preference, standard preferences set in npcstatic stored in npc_standard_preferences)
  5. !! How to use:
  6. !! gs 'set_npc_attraction', $npc_code, max_hotcat_change
  7. !! $npc_code: the code of the npc for which we calculate. Examles: 'A12', 'B3', 'C13'
  8. !! max_hotcat_change: the maximum difference between npc_rel_hotcat and normal hotcat.
  9. !! Defaults to 2. When set negative, it is unbounded instead.
  10. !!
  11. !! Sets the npc_attraction[$npc_code] and npc_rel_hotcat[$npc_code] variables
  12. !! We start with the player''s appearance and add modifiers based on the npc''s preferences.
  13. npc_attraction[$ARGS[0]] = pcs_apprnc
  14. !! Create the $npc_pref_traits and npc_trait_values arrays
  15. dynamic $npc_preferences[$ARGS[0]]
  16. dynamic $npc_pref_values[$ARGS[0]]
  17. if arrsize('$npc_pref_traits') > 0:
  18. set_attraction_loop_index = 0
  19. :preferences_loop_start
  20. !!Per preference, we see if the preference applies (the func() part) if so we add the attraction value.
  21. !!If the value is positive, then the npc likes that quality. If it is negative they dislike it.
  22. npc_attraction[$ARGS[0]] += npc_trait_values[$npc_pref_traits[set_attraction_loop_index]] * func( 'pcs_has_attr', $npc_pref_traits[set_attraction_loop_index] )
  23. set_attraction_loop_index +=1
  24. if set_attraction_loop_index < arrsize('$npc_pref_traits'): jump 'preferences_loop_start'
  25. killvar 'set_attraction_loop_index'
  26. end
  27. killvar '$npc_pref_traits'
  28. killvar 'npc_trait_values'
  29. killvar 'preferences_loop_start'
  30. if npc_attraction[$ARGS[0]] <= 40:
  31. npc_rel_hotcat[$ARGS[0]] = 1
  32. elseif npc_attraction[$ARGS[0]] <= 60:
  33. npc_rel_hotcat[$ARGS[0]] = 2
  34. elseif npc_attraction[$ARGS[0]] <= 80:
  35. npc_rel_hotcat[$ARGS[0]] = 3
  36. elseif npc_attraction[$ARGS[0]] <= 100:
  37. npc_rel_hotcat[$ARGS[0]] = 4
  38. elseif npc_attraction[$ARGS[0]] <= 125:
  39. npc_rel_hotcat[$ARGS[0]] = 5
  40. elseif npc_attraction[$ARGS[0]] <= 150:
  41. npc_rel_hotcat[$ARGS[0]] = 6
  42. elseif npc_attraction[$ARGS[0]] <= 165:
  43. npc_rel_hotcat[$ARGS[0]] = 7
  44. elseif npc_attraction[$ARGS[0]] <= 180:
  45. npc_rel_hotcat[$ARGS[0]] = 8
  46. elseif npc_attraction[$ARGS[0]] <= 199:
  47. npc_rel_hotcat[$ARGS[0]] = 9
  48. else
  49. npc_rel_hotcat[$ARGS[0]] = 10
  50. end
  51. if ARGS[1] = 0: ARGS[1] = 2
  52. if ARGS[1] > 0:
  53. if npc_rel_hotcat[$ARGS[0]] - hotcat > ARGS[1]:
  54. npc_rel_hotcat[$ARGS[0]] = hotcat + ARGS[1]
  55. elseif hotcat - npc_rel_hotcat > ARGS[1]:
  56. npc_rel_hotcat[$ARGS[0]] = hotcat - ARGS[1]
  57. end
  58. end
  59. --- set_npc_attraction ---------------------------------