|
89 | 89 | indices = null |
90 | 90 | ..() |
91 | 91 |
|
| 92 | + proc/forensic_search(var/search_input) |
| 93 | + var/list/datum/db_record/record_matches = forensic_search_subjects(search_input) |
| 94 | + var/result = "" |
| 95 | + if(length(record_matches) > 0) |
| 96 | + result = SPAN_SUCCESS("<li>Records matching \"[search_input]\"</li>") |
| 97 | + var/match_num = "" |
| 98 | + if(length(record_matches) > 1) |
| 99 | + match_num = " (1/[length(record_matches)])" |
| 100 | + var/match_count = 1 |
| 101 | + for(var/datum/db_record/R in record_matches) |
| 102 | + result += "<li>[SPAN_NOTICE("Match[match_num]:<b> [R["name"]]</b>")]" + " ([R["rank"]])</li>" |
| 103 | + var/fprint_right = R["fingerprint_right"] |
| 104 | + var/fprint_left = R["fingerprint_left"] |
| 105 | + if(fprint_right == fprint_left) |
| 106 | + result += "<li style='margin-left:15px;list-style-type:none'><i>Fingerprints:</i> [fprint_right]</li>" |
| 107 | + else |
| 108 | + result += "<li style='margin-left:15px;list-style-type:none'><i>Fingerprint (R):</i> [fprint_right]</li>\ |
| 109 | + <li style='margin-left:15px;list-style-type:none'><i>Fingerprint (L):</i> [fprint_left]</li>" |
| 110 | + result += "<li style='margin-left:15px;list-style-type:none'><i>Blood DNA:</i> [R["dna"]]</li>" |
| 111 | + match_count++ |
| 112 | + match_num = " ([match_count]/[length(record_matches)])" |
| 113 | + return result |
| 114 | + |
| 115 | + // Search for partial fingerprints |
| 116 | + record_matches = forensic_search_fingerprint_partial(search_input) |
| 117 | + if(length(record_matches) > 0) |
| 118 | + result = SPAN_SUCCESS("<li>Potential matches for \"[search_input]\"</li>") |
| 119 | + for(var/datum/db_record/R in record_matches) |
| 120 | + var/fprint_right = R["fingerprint_right"] |
| 121 | + var/fprint_left = R["fingerprint_left"] |
| 122 | + var/match_result = SPAN_NOTICE("<li style='margin-left:15px;list-style-type:none'>["<b>[R["name"]]</b>"]") |
| 123 | + if(fprint_right == fprint_left) |
| 124 | + match_result += ": [fprint_right]</li>" |
| 125 | + else |
| 126 | + match_result += ": [fprint_right] | [fprint_left]</li>" |
| 127 | + result += match_result |
| 128 | + return result |
| 129 | + return SPAN_ALERT("No match found in security records for \"[search_input]\".") |
| 130 | + |
| 131 | + /// Search for records based on name, dna, or fingerprints |
| 132 | + proc/forensic_search_subjects(var/search_input) |
| 133 | + var/search_low = lowertext(search_input) |
| 134 | + var/list/datum/db_record/subject_records = list() |
| 135 | + for(var/datum/db_record/R as anything in data_core.general.records) |
| 136 | + var/is_subj = (search_low == lowertext(R["dna"])) |
| 137 | + is_subj = is_subj || (search_low == lowertext(R["name"])) |
| 138 | + is_subj = is_subj || (search_low == lowertext(R["fingerprint_right"])) |
| 139 | + is_subj = is_subj || (search_low == lowertext(R["fingerprint_left"])) |
| 140 | + if(is_subj) |
| 141 | + subject_records += R |
| 142 | + return subject_records |
| 143 | + |
| 144 | + proc/forensic_search_fingerprint_partial(var/search_input) |
| 145 | + RETURN_TYPE(/list/datum/db_record) |
| 146 | + if(!search_input) |
| 147 | + return null |
| 148 | + var/list/record_prints = list() |
| 149 | + var/list/datum/db_record/record_refs = list() |
| 150 | + |
| 151 | + // Collect the fingerprint data and their associated records that we need to go through |
| 152 | + for(var/list/datum/db_record/record in data_core.general.records) |
| 153 | + var/fprint_right = record["fingerprint_right"] |
| 154 | + var/fprint_left = record["fingerprint_left"] |
| 155 | + if(fprint_right == fprint_left) |
| 156 | + if(!fprint_right) |
| 157 | + continue |
| 158 | + record_prints.Add(fprint_right) |
| 159 | + record_refs.Add(record) |
| 160 | + else |
| 161 | + if(fprint_right) |
| 162 | + record_prints.Add(fprint_right) |
| 163 | + record_refs.Add(record) |
| 164 | + if(fprint_left) |
| 165 | + record_prints.Add(fprint_left) |
| 166 | + record_refs.Add(record) |
| 167 | + if(!record_prints || !record_refs) |
| 168 | + return null |
| 169 | + |
| 170 | + // Get the input into a more usable format |
| 171 | + // Print: (..3..-4567-...?...-CDEF) => Bunches: list("_3_","4567","_?_","CDEF") |
| 172 | + search_input = limit_chars(search_input, list("?",".","-"), TRUE, TRUE) |
| 173 | + var/list/input_bunches = splittext(search_input, "-") |
| 174 | + for(var/i in length(input_bunches) to 1 step -1) |
| 175 | + if(input_bunches[i] == "") |
| 176 | + input_bunches.Cut(i, i+1) |
| 177 | + if(length(input_bunches) == 0) |
| 178 | + return null |
| 179 | + var/list/input_empty = list() |
| 180 | + for(var/i in 1 to length(input_bunches)) |
| 181 | + input_bunches[i] = text_replace_repeat(input_bunches[i], ".", "_") |
| 182 | + var/is_empty = !contains_chars(input_bunches[i], null, TRUE, TRUE) |
| 183 | + input_empty += is_empty |
| 184 | + |
| 185 | + var/trim_start = 0 |
| 186 | + var/trim_end = 0 |
| 187 | + for(var/i in 1 to length(input_empty)) |
| 188 | + if(!input_empty[i]) |
| 189 | + break |
| 190 | + trim_start++ |
| 191 | + for(var/i in length(input_empty) to 1 step -1) |
| 192 | + if(!input_empty[i]) |
| 193 | + break |
| 194 | + trim_end++ |
| 195 | + trim_list(input_bunches, trim_start, trim_end) |
| 196 | + if(length(input_bunches) == 0) |
| 197 | + return null |
| 198 | + |
| 199 | + // Find and collect all records containing a matching print |
| 200 | + var/list/datum/db_record/match_records = list() // All records with a matching print |
| 201 | + for(var/i in 1 to length(record_prints)) |
| 202 | + var/list/rec_bunches = splittext(record_prints[i], "-") |
| 203 | + trim_list(rec_bunches, trim_start, trim_end) |
| 204 | + if(length(rec_bunches) == 0) |
| 205 | + continue |
| 206 | + var/input_index = 1 |
| 207 | + for(var/k in 1 to length(rec_bunches)) |
| 208 | + var/bunch_match = FALSE |
| 209 | + if(findtext(input_bunches[input_index], "_")) // (-...A...-) or (...A...B...) |
| 210 | + // Not efficient to split the input bunch every time, but should be fine |
| 211 | + var/list/input_bunch_split = splittext(input_bunches[input_index], "_") |
| 212 | + input_bunch_split.RemoveAll("") |
| 213 | + if(length(input_empty) == 1) |
| 214 | + // Check the whole fingerprint rather than individual bunches |
| 215 | + if(findtextEx_ordered(record_prints[i], input_bunch_split)) |
| 216 | + bunch_match = TRUE |
| 217 | + else if(findtextEx_ordered(rec_bunches[k], input_bunch_split)) |
| 218 | + bunch_match = TRUE |
| 219 | + else if(findtextEx(input_bunches[input_index], "?")) |
| 220 | + if(text_replace_repeat(input_bunches[input_index], "?", "?") == "?") // Bunch only contains question marks |
| 221 | + input_index++ |
| 222 | + else if(text_equals_partial(rec_bunches[k], input_bunches[input_index], "?")) // (-??A?-) |
| 223 | + bunch_match = TRUE |
| 224 | + if(bunch_match) |
| 225 | + input_index++ |
| 226 | + else |
| 227 | + input_index = 1 |
| 228 | + if(input_index == length(input_bunches) + 1) // Found a match! |
| 229 | + match_records += record_refs[i] |
| 230 | + break |
| 231 | + return match_records |
| 232 | + |
92 | 233 | /datum/db_record |
93 | 234 | VAR_PRIVATE/datum/record_database/db |
94 | 235 | VAR_PRIVATE/list/fields |
|
0 commit comments