Files
2026-09-06 17:20:24 +02:00

270 lines
7.9 KiB
GDScript

extends Node
#Dialogue variables
var dialog_tree: Dictionary
var marker: Array[int]
var dialogue_resource: Resource
var dialogue_start: String
#Patient attributes
var texture := TextureRect.new()
var image : Texture2D
var original_color: Color
var emotions : Dictionary
var abnormal: bool
var id : String
var type: String
var age: String
var symptoms: Array
#Patient file
var file_text : String
#Patient symptoms ordered from floor to floor
var symptoms_arrays: Array[Array] = [
["SUICIDAL IDEATIONS", "PERSECUTORY DELUSIONS", "UNNATURAL BEHAVIOUR", "INSOMNIA"],
["AUDITORY HALLUCINATIONS"],
["SOMATIC HALLUCINATIONS"],
["SOMATIC DELUSIONS"],
["MYSTICAL DELUSIONS"],
["DYSMORPHOPHOBIA"],
["MEGALOMANIAC DELUSIONS"],
["THOUGHT INSERTION"],
["VISUAL HALLUCINATIONS"],
["EROTOMANIAC DELUSIONS"]
]
#Lists of possible patients sorted by floor
var og_patient_list : Array[Dictionary]
var patient_list: Array[Dictionary]
var patients_seen = []
#Supervisor file path
var supervisor_name = "siveyan"
#Spy
var spy: Node
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#Setting up dialogue marker
marker.resize(100)
marker.fill(0)
#Setting up patient lists
og_patient_list.resize(len(symptoms_arrays))
patient_list.resize(len(symptoms_arrays))
original_color = texture.modulate #Saving original modulation color to reset it after modification
#Adding the spy
spy = Spy.new()
add_child(spy)
func build_dialog_tree(tree_model: Array[int]) -> Dictionary: #Builds the dialog tree for each dialogue
var branch : Dictionary
var tree : Dictionary
for branch_id in tree_model:
branch = {branch_id: "not_asked"}
tree.merge(branch)
return tree
func load_patient(patient_id: String): #Loads new patient
#Storing patient info
id = patient_id
#Loading Subject resources
var config := ConfigFile.new()
config.load("res://Dialogues/Patients/" + id + "_file.cfg") #Loading Subject file
dialogue_resource = load("res://Dialogues/Patients/" + id + ".dialogue") #Loading Dialogue Resource
load_emotions(config, "res://Art/Subjects/Patients/" + id + "/" + id + "_") #Loading Subject emotions
#Setting up Patient File
var patient_name = config.get_value("", "name")
age = config.get_value("", "age")
var profession = config.get_value("", "profession")
var psychiatric_assessment = config.get_value("", "psychiatric_assessment")
file_text = "NAME: " + patient_name + "\nAGE: " + age + "\n\nPROFESSION: " + profession + "\n\nPRE-SCREENING PSYCHIATRIC ASSESSMENT:\n\n" + "[color=orange_red]" + psychiatric_assessment + "[/color]"
var symptom_list = config.get_value("", "psychiatric_assessment").split("\n", false)
symptoms = symptom_list
symptom_list = config.get_value("", "abnormal_symptoms").split("\n", false)
symptoms.append_array(symptom_list)
#Randomizing abnormal status if required
var status = config.get_value("", "status")
match status:
"random":
abnormal = randf() < 0.5 #50/50 abnormal/normal
print("Abnormal value: " + str(abnormal))
"normal":
abnormal = false
"abnormal":
abnormal = true
func load_emotions(config, patient_path):
#Loading Patient Initial Face
var initial_emotion = config.get_value("", "initial_emotion")
var file_path = patient_path + initial_emotion + ".png"
image = load(file_path)
#Loading Face Emotions
var face: Resource
var emotion_branch: Dictionary
var emotion_list = ["neutral", "peaceful", "praying", "puzzled", "suspicious",
"sadsmiling", "crazysmiling", "shockedcrying", "smiling",
"aroused", "excited", "laughing", "happy", "elated", "maniac", "ecstatic",
"embarrassed",
"irritated", "angry", "furious", "pouting",
"threatening", "scary", "terrifying",
"sad", "melancholic", "depressed", "crying", "surprised",
"worried", "scared", "shocked", "panicked", "terrified", "shockedterrified",
"itthatsmiles1", "itthatsmiles2", "itthateats1", "itthateats2",
"abnormal", "abnormal1", "abnormal2", "abnormal3", "special"]
emotions.clear() #Clearing previous patient emotions
for emotion in emotion_list:
file_path = patient_path + emotion + ".png"
face = load(file_path)
if face != null:
emotion_branch = {emotion: face}
emotions.merge(emotion_branch)
#Sorts the patients to determine who can appear on what floor depending on the symptoms unlocked
func sort_patients():
var config := ConfigFile.new()
var file_path : String
var patient_symptoms: Array
var symptom_matched : bool = false
var symptom_list : Array
var patient_type : String
var min_floor : int
for patient_id in Globals.patient_list:
#Loads symptoms for each patient
patient_symptoms.clear()
file_path = "res://Dialogues/Patients/" + patient_id + "_file.cfg"
config.load(file_path)
symptom_list = config.get_value("", "psychiatric_assessment").split("\n", false)
patient_symptoms = symptom_list
symptom_list = config.get_value("", "abnormal_symptoms").split("\n", false)
patient_symptoms.append_array(symptom_list)
print("Patient #" + patient_id + " symptom list: " + str(patient_symptoms))
patient_type = config.get_value("", "type")
#Sets up a minimum floor depending on patient type
match patient_type:
"patient":
min_floor = 0
"its":
min_floor = 2
"ite":
min_floor = 4
print(patient_id + " min_floor : " + str(min_floor))
#Goes through the symptoms_arrays from the last to the first,
#If a symptom matches with the patient symptoms,
#Add that patient to the floors from that floor to the last one
for j in range(len(symptoms_arrays)-1, -1, -1):
for symptom in patient_symptoms:
if symptoms_arrays[j].has(symptom):
symptom_matched = true
print("Symptom matched: " + str(symptoms_arrays[j]) + " and " + str(symptom))
break
if symptom_matched:
print(patient_id + " threshold : " + str(max(j,min_floor)))
for k in range(max(j,min_floor), symptoms_arrays.size()):
og_patient_list[k].merge({patient_id: j+1+min_floor}) # Adds the patient to every floor compatible, with a weighted odd
symptom_matched = false
break
for i in range(len(patient_list)):
patient_list[i] = og_patient_list[i]
print("Floor " + str(i) + " possible patients: " + str(patient_list[i]))
#Weighted random selection from an Array
func weighted_random(patients: Dictionary):
#Calculating total weight
var total_weight : int = 0
for weight in patients.values():
total_weight += weight
print("Total weight: " + str(total_weight))
var r = randf() * total_weight
print("r :" + str(r))
var weight_sum : int = 0
for patient_id in patients:
weight_sum += patients[patient_id]
if weight_sum >= r:
print("Patient selected: " + patient_id + ", Weight: " + str(patients[patient_id]))
return patient_id
return null
func generate_next_id():
var floor_index = -Globals.floor_count -1
var next_id : String
next_id = weighted_random(patient_list[floor_index]) #Picks a random patient depending on floor, with weighted odds
print("Floor Index: " + str(floor_index))
print("Patient selected : " + str(next_id))
return next_id
func next_patient() -> String: #Decides next patient ID
var next_id: String
dialogue_start = "start"
match Globals.floor_count:
-2:
if Globals.patient_count == 0:
next_id = "patient_its_0"
else:
next_id = generate_next_id()
-3:
next_id = generate_next_id()
-4:
if Globals.patient_count == 0:
next_id = "patient_ite_0"
else:
next_id = generate_next_id()
-6:
if Globals.patient_count == 0:
next_id = "patient_spy"
else:
next_id = generate_next_id()
_:
next_id = generate_next_id()
print("NEXT SUBJECT ID: " + next_id)
return next_id
#Erases current subject ID from the corresponding subject list, so it can't be seen twice
func update_list():
patients_seen.append(id)
for i in range(len(patient_list)):
if len(patient_list[i])>1:
patient_list[i].erase(id)
for j in range(len(patient_list)):
print("Updated Floor " + str(j) + " patient list: " + str(patient_list[j]))