extends Node #Dialogue variables var dialog_tree: Dictionary var marker: Array[int] var dialogue_resource: Resource #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 #Patient file var file_text : String #Patient symptoms ordered from floor to floor var symptoms_arrays: Array[Array] = [ ["SUICIDAL IDEATIONS", "PERSECUTORY DELUSIONS", "UNNATURAL BEHAVIOUR", "AUDITORY HALLUCINATIONS"], ["SOMATIC HALLUCINATIONS", "MEGALOMANIAC DELUSIONS"], ["MYSTICAL DELUSIONS", "MANIA"], ["CHEMOSENSORY HALLUCINATIONS", "SELF-MUTILATION"], ["VISUAL HALLUCINATIONS", "HETERO-AGRESSIVE BEHAVIOUR"] ] #Lists of possible patients sorted by floor var og_patient_list : Array[Dictionary] var patient_list: Array[Dictionary] var og_its_list = ["its_01"] var its_list = [] var og_entities_list = ["entity_01"] var entities_list = [] var entities_current_floor = [] var patients_seen = [] var its_seen = [] var entities_seen = [] #Supervisor file path var supervisor_name = "loeveth" # 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)) its_list = og_its_list entities_list = og_entities_list original_color = texture.modulate #Saving original modulation color to reset it after modification 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_info: Dictionary): #Loads new patient #Storing patient info id = patient_info["id"] type = patient_info["type"] #Loading Subject resources var file_path: String var config := ConfigFile.new() match type: #Setting right file path depending on subject type "patient": file_path = "Patients/" "its": file_path = "ITS/" "entity": file_path = "Entities/" "supervisor": file_path = "Supervisors/" config.load("res://Dialogues/" + file_path + id + "_file.cfg") #Loading Subject file dialogue_resource = load("res://Dialogues/" + file_path + id + ".dialogue") #Loading Dialogue Resource load_emotions(config, "res://Art/Subjects/" + file_path + id + "/" + id + "_") #Loading Subject emotions #Setting up Patient File var patient_name = config.get_value("", "name") var 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]" #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", "laughing", "happy", "elated", "maniac", "ecstatic", "irritated", "angry", "furious", "sad", "depressed", "crying", "surprised", "worried", "scared", "shocked", "panicked", "terrified", "itthatsmiles1", "itthatsmiles2", "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 var symptom_list: Array 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)) #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: for k in range(j, symptoms_arrays.size()): og_patient_list[k].merge({patient_id: j+1}) # Adds the patient to every floor compatible 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(patient_type: String): var floor_index = -Globals.floor_count -1 print("Floor Index: " + str(floor_index)) var next_id : String = "" match patient_type: "patient": next_id = weighted_random(patient_list[floor_index]) #Picks a random patient depending on floor, with weighted odds print("Patient selected : " + str(next_id)) "its": next_id = its_list.pick_random() print("ITS selected: " + str(next_id)) "entity": next_id = entities_current_floor.pick_random() print("Entity selected: " + str(next_id)) return next_id func next_patient() -> Dictionary: #Decides next patient ID var next_id: String var next_type: String match Globals.floor_count: -2: if Globals.patient_count == 0: next_id = "its_00" next_type = "its" else: next_type = next_patient_type() next_id = generate_next_id(next_type) _: next_type = next_patient_type() next_id = generate_next_id(next_patient_type()) return {"id": next_id, "type": next_type} #Randomizes next patient type (human, it, its) func next_patient_type(): var type_list = [] match Globals.floor_count: -1: return "patient" -2: return "patient" -3: type_list.append("its") for i in range(Globals.diagnoses_quota - 1): type_list.append("patient") return type_list.pick_random() _: for i in range(int(floor(Globals.diagnoses_quota/4))): type_list.append("its") if len(entities_current_floor) > 0: type_list.append("entity") for i in range(int(floor(Globals.diagnoses_quota/2))): type_list.append("patient") return type_list.pick_random() #Erases current patient ID from the corresponding patient list, so it can't be seen twice func update_list(): print("Patient type: " + str(Patient.type)) match type: "patient": 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])) "its": its_seen.append(id) if len(its_list)>1: its_list.erase(id) print("Updated ITS list: " + str(its_list)) "entity": entities_seen.append(id) if len(entities_list)>1: entities_list.erase(id) print("Updated Entities list: " + str(entities_list)) #Randomly picks which entities will be present on the current floor func pick_floor_entities(): var entity for i in range(int(floor(Globals.diagnoses_quota/4))): if len(entities_list) > 0: entity = entities_list.pick_random() entities_current_floor.append(entity)