Skip to content

Commit

Permalink
tweak(manifest_prediction) Predicts a crew manifest based on declares…
Browse files Browse the repository at this point in the history
… in lobby

ChaoticOnyx#10587
  • Loading branch information
Moscowchief authored Oct 22, 2023
1 parent f613783 commit f1372f2
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@
if(JOB_PRIORITY_HIGH)
pref.job_high = null
if(JOB_PRIORITY_MIDDLE)
pref.job_medium |= pref.job_high
pref.job_high = switched_job.title
pref.job_medium -= switched_job.title
if(JOB_PRIORITY_LOW)
Expand Down
14 changes: 14 additions & 0 deletions code/modules/mob/new_player/new_player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
output += "<p><a href='byond://?src=\ref[src];show_settings=1'>Settings</a></p>"

if(GAME_STATE <= RUNLEVEL_LOBBY)
output += "<a href='byond://?src=\ref[src];predict_manifest=1'>View Crew Manifest Prediction</A><br><br>"
if(ready)
output += "<p>\[ <span class='linkOn'><b>Ready</b></span> | <a href='byond://?src=\ref[src];ready=0'>Not Ready</a> \]</p>"
else
Expand Down Expand Up @@ -200,6 +201,9 @@
if(href_list["manifest"])
ViewManifest()

if(href_list["predict_manifest"])
ViewManifestPrediction()

if(href_list["SelectedJob"])
var/datum/job/job = job_master.GetJob(href_list["SelectedJob"])

Expand Down Expand Up @@ -580,6 +584,16 @@
popup.set_content(dat)
popup.open()

/mob/new_player/proc/ViewManifestPrediction()
if(SSatoms.init_state < INITIALIZATION_INNEW_REGULAR)
to_chat(src, SPAN("notice", "Please, wait for the game to initialize!"))
return
var/dat = "<div align='center'>"
dat += manifest_prediction()
var/datum/browser/popup = new(src, "Crew Manifest Prediction", "Crew Manifest Prediction", 370, 420, src)
popup.set_content(dat)
popup.open()

/mob/new_player/Move()
return 0

Expand Down
187 changes: 160 additions & 27 deletions code/modules/modular_computers/file_system/manifest.dm
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
// Generates a simple HTML crew manifest for use in various places
/proc/html_crew_manifest(monochrome, OOC)
var/list/dept_data = list(
list("names" = list(), "header" = "Heads of Staff", "flag" = COM),
list("names" = list(), "header" = "Command Support", "flag" = SPT),
list("names" = list(), "header" = "Research", "flag" = SCI),
list("names" = list(), "header" = "Security", "flag" = SEC),
list("names" = list(), "header" = "Medical", "flag" = MED),
list("names" = list(), "header" = "Engineering", "flag" = ENG),
list("names" = list(), "header" = "Supply", "flag" = SUP),
list("names" = list(), "header" = "Exploration", "flag" = EXP),
list("names" = list(), "header" = "Service", "flag" = SRV),
list("names" = list(), "header" = "Civilian", "flag" = CIV),
list("names" = list(), "header" = "Miscellaneous", "flag" = MSC),
list("names" = list(), "header" = "Silicon")
GLOBAL_LIST_EMPTY(dept_data)

/proc/manifest_data_initialization(monochrome = FALSE, OOC = FALSE, prediction = FALSE)
var/key = prediction ? "all_jobs_in_dept" : "names"

GLOB.dept_data = list(
list("[key]" = list(), "header" = "Heads of Staff", "flag" = COM),
list("[key]" = list(), "header" = "Command Support", "flag" = SPT),
list("[key]" = list(), "header" = "Research", "flag" = SCI),
list("[key]" = list(), "header" = "Security", "flag" = SEC),
list("[key]" = list(), "header" = "Medical", "flag" = MED),
list("[key]" = list(), "header" = "Engineering", "flag" = ENG),
list("[key]" = list(), "header" = "Supply", "flag" = SUP),
list("[key]" = list(), "header" = "Exploration", "flag" = EXP),
list("[key]" = list(), "header" = "Service", "flag" = SRV),
list("[key]" = list(), "header" = "Civilian", "flag" = CIV),
list("[key]" = list(), "header" = "Miscellaneous", "flag" = MSC),
list("[key]" = list(), "header" = "Silicon")
)
var/list/misc //Special departments for easier access
var/list/bot
for(var/list/department in dept_data)
if(department["flag"] == MSC)
misc = department["names"]
if(isnull(department["flag"]))
bot = department["names"]

var/list/isactive = new()
var/dat = {"
<head><style>
.manifest {border-collapse:collapse;}
Expand All @@ -33,8 +28,25 @@
.manifest tr.alt td {[monochrome?"border-top-width: 2px":"background-color: [OOC?"#373737; color:white":"#DEF"]"]}
</style></head>
<table class="manifest" width='350px'>
<tr class='head'><th>Name</th><th>Position</th><th>Activity</th></tr>
<tr class='head'><th>Name</th><th>Position</th><th>[prediction?"Chances":"Activity"]</th></tr>
"}

return dat

// Generates a simple HTML crew manifest for use in various places
/proc/html_crew_manifest(monochrome, OOC)
var/dat = manifest_data_initialization(monochrome, OOC)
var/list/misc //Special departments for easier access
var/list/bot

for(var/list/department in GLOB.dept_data)
if(department["flag"] == MSC)
misc = department["names"]
if(isnull(department["flag"]))
bot = department["names"]

var/list/isactive = list()

// sort mobs
for(var/datum/computer_file/crew_record/CR in GLOB.all_crew_records)
var/name = CR.get_name()
Expand All @@ -51,7 +63,7 @@
isactive[name] = CR.get_status_physical()

var/found_place = FALSE
for(var/list/department in dept_data)
for(var/list/department in GLOB.dept_data)
var/list/names = department["names"]
//if(CR.get_department() && (GLOB.text_to_department_flags[CR.get_department()] & department["flag"]))
if(department["flag"] in CR.assigned_deparment_flags)
Expand All @@ -71,9 +83,9 @@

bot[robot.name] = "[robot.modtype] [robot.braintype]"

for(var/list/department in dept_data)
for(var/list/department in GLOB.dept_data)
var/list/names = department["names"]
if(names.len > 0)
if(length(names))
dat += "<tr><th colspan=3>[department["header"]]</th></tr>"
for(var/name in names)
dat += "<tr class='candystripe'><td>[name]</td><td>[names[name]]</td><td>[isactive[name]]</td></tr>"
Expand All @@ -83,6 +95,127 @@
dat = replacetext(dat, "\t", "")
return dat

/proc/manifest_prediction()
var/dat = manifest_data_initialization(monochrome = FALSE, OOC = TRUE, prediction = TRUE)
var/list/empty_command_positions = GLOB.command_positions.Copy()
var/list/command_positions_with_candidates = list()
var/list/command_candidates = list()

//searching for heads positions
for(var/mob/new_player/player in GLOB.player_list)
if(!player.ready || ("Assistant" in player.client.prefs.job_low))
continue

var/datum/preferences/player_prefs = player.client.prefs
var/player_name = player_prefs.real_name
for(var/command_position in GLOB.command_positions)
var/datum/job/job = job_master.GetJob(command_position)
for(var/priority = JOB_PRIORITY_HIGH to JOB_PRIORITY_LOW)
if(player_prefs.IsJobPriority(job, priority))
if(!command_positions_with_candidates[command_position])
command_positions_with_candidates[command_position] = list(
JOB_PRIORITY_HIGH = list(),
JOB_PRIORITY_MIDDLE = list(),
JOB_PRIORITY_LOW = list()
)
command_positions_with_candidates[command_position][priority] += list("[player_name]" = player.client.ckey)

//sorting head positions
var/list/command_positions_by_ckey = list()
for(var/CP in command_positions_with_candidates)
var/command_position = CP
var/list/candidates = command_positions_with_candidates[command_position]
for(var/priority = JOB_PRIORITY_HIGH to JOB_PRIORITY_LOW)
if(!(command_position in empty_command_positions))
break
for(var/candidate in candidates[priority])
empty_command_positions -= command_position
var/ckey = candidates[priority][candidate]
if(!command_positions_by_ckey[ckey])
command_positions_by_ckey[ckey] = list(
"positions" = list(
JOB_PRIORITY_HIGH = list(),
JOB_PRIORITY_MIDDLE = list(),
JOB_PRIORITY_LOW = list()
),
"player_name" = "[candidate]"
)
command_positions_by_ckey[ckey]["positions"][priority] += command_position
command_candidates |= ckey

//inserting choosen heads in GLOB.dept_data
for(var/ckey in command_positions_by_ckey)
var/command_position
for(var/priority = JOB_PRIORITY_HIGH to JOB_PRIORITY_LOW)
if(length(command_positions_by_ckey[ckey]["positions"][priority]))
command_position = pick(command_positions_by_ckey[ckey]["positions"][priority])
break
var/player_name = command_positions_by_ckey[ckey]["player_name"]
for(var/list/department in GLOB.dept_data)
var/flag = job_master.occupations_by_title[command_position].department_flag
if(department["flag"]&flag)
department["all_jobs_in_dept"][command_position] += list("[player_name]" = command_position)
break

//searching for rest non-heads positions
for(var/mob/new_player/player in GLOB.player_list)
if(!player.ready || (player.client.ckey in command_candidates))
continue

var/datum/preferences/player_prefs = player.client.prefs
var/player_name = player_prefs.real_name
var/silicon = FALSE

var/list/preferenced_jobs
if("Assistant" in player_prefs.job_low)
preferenced_jobs = list(
list("Assistant")
)
else
preferenced_jobs = list(
player_prefs.job_high ? list(player_prefs.job_high) : list(),
player_prefs.job_medium,
player_prefs.job_low
)

//inserting non-head positions in GLOB.dept_data
for(var/list/J in preferenced_jobs)
var/list/jobs = J - GLOB.command_positions
if(!length(jobs))
continue

var/job = pick(jobs)

if(job in list("AI", "Cyborg"))
silicon = TRUE

for(var/list/department in GLOB.dept_data)
var/flag = job_master.occupations_by_title[job].department_flag

if(!silicon ? department["flag"]&flag : department["header"] == "Silicon")
department["all_jobs_in_dept"][job] += list(!silicon ? "[player_name]" : "\[Unknown\]" = player_prefs.player_alt_titles[job] ? player_prefs.player_alt_titles[job] : job)
break
break

//building manifest page
for(var/list/department in GLOB.dept_data)
var/list/all_jobs = department["all_jobs_in_dept"]
if(!length(all_jobs))
continue

dat += "<tr><th colspan=3>[department["header"]]</th></tr>"
for(var/J in all_jobs)
var/list/job = all_jobs[J]
for(var/name in job)
var/job_slots = job_master.occupations_by_title[job[name]].spawn_positions
var/chance = job_slots == -1 ? 100 : clamp(job_slots/length(job)*100, 0, 100)
dat += "<tr class='candystripe'><td>[name]</td><td>[job[name]]</td><td>[chance]%</td></tr>"

dat += "</table>"
dat = replacetext(dat, "\n", "") // so it can be placed on paper correctly
dat = replacetext(dat, "\t", "")
return dat

/proc/silicon_nano_crew_manifest(list/filter)
var/list/filtered_entries = list()

Expand Down

0 comments on commit f1372f2

Please sign in to comment.