Skip to content

Commit

Permalink
Merge pull request #1212 from dwasint/antag-rep'
Browse files Browse the repository at this point in the history
Antag Rep
  • Loading branch information
dwasint authored Feb 22, 2024
2 parents ae5177a + b1e67d4 commit 5b4e63e
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 21 deletions.
1 change: 1 addition & 0 deletions code/__DEFINES/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
#define LOG_CATEGORY_META "currency"
#define LOG_CATEGORY_ARTIFACT "artifact"
#define LOG_CATEGORY_BLACKMARKET "blackmarket"
#define LOG_CATEGORY_ANTAG_REP "antag-rep"

// Admin categories
#define LOG_CATEGORY_ADMIN "admin"
Expand Down
7 changes: 7 additions & 0 deletions code/__HELPERS/_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@
. = list_to_pick[picked]
list_to_pick.Cut(picked,picked+1) //Cut is far more efficient that Remove()

/// Pick a random element from the list and remove it from the list.
/proc/pick_n_take_weighted(list/list_to_pick)
if(length(list_to_pick))
var/picked = pick_weight(list_to_pick)
list_to_pick -= picked
return picked

///Returns the top(last) element from the list and removes it from the list (typical stack function)
/proc/pop(list/L)
if(L.len)
Expand Down
3 changes: 3 additions & 0 deletions code/__HELPERS/logging/_logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,6 @@ GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global"))

/proc/log_blackmarket(text, list/data)
logger.Log(LOG_CATEGORY_BLACKMARKET, text, data)

/proc/log_antag_rep(text, list/data)
logger.Log(LOG_CATEGORY_ANTAG_REP, text, data)
31 changes: 19 additions & 12 deletions code/modules/logging/categories/log_category_monke.dm
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
/datum/log_category/cloning
category = LOG_CATEGORY_CLONING
master_category = /datum/log_category/game
config_flag = /datum/config_entry/flag/cloning
config_flag = /datum/config_entry/flag/log_cloning

/datum/config_entry/flag/cloning
/datum/config_entry/flag/log_cloning

/datum/log_category/mechcomp
category = LOG_CATEGORY_MECHCOMP
master_category = /datum/log_category/game
config_flag = /datum/config_entry/flag/mechcomp
config_flag = /datum/config_entry/flag/log_mechcomp

/datum/config_entry/flag/mechcomp
/datum/config_entry/flag/log_mechcomp

/datum/log_category/music
category = LOG_CATEGORY_MUSIC
config_flag = /datum/config_entry/flag/music
config_flag = /datum/config_entry/flag/log_music

/datum/config_entry/flag/music
/datum/config_entry/flag/log_music

/datum/log_category/meta
category = LOG_CATEGORY_META
config_flag = /datum/config_entry/flag/meta
config_flag = /datum/config_entry/flag/log_meta

/datum/config_entry/flag/meta
/datum/config_entry/flag/log_meta

/datum/log_category/artifact
category = LOG_CATEGORY_ARTIFACT
config_flag = /datum/config_entry/flag/artifact
config_flag = /datum/config_entry/flag/log_artifact

/datum/config_entry/flag/artifact
/datum/config_entry/flag/log_artifact

/datum/log_category/blackmarket
category = LOG_CATEGORY_BLACKMARKET
master_category = /datum/log_category/economy
config_flag = /datum/config_entry/flag/blackmarket
config_flag = /datum/config_entry/flag/log_blackmarket

/datum/config_entry/flag/blackmarket
/datum/config_entry/flag/log_blackmarket


/datum/log_category/antag_rep
category = LOG_CATEGORY_ANTAG_REP
config_flag = /datum/config_entry/flag/log_antag_rep

/datum/config_entry/flag/log_antag_rep
18 changes: 14 additions & 4 deletions monkestation/code/controllers/subsystem/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
return FALSE

var/list/candidates = SSgamemode.current_roundstart_event.get_candidates()

var/list/cliented_list = list()
for(var/mob/living/mob as anything in candidates)
cliented_list += mob.client
if(length(cliented_list))
mass_adjust_antag_rep(cliented_list, 1)

var/list/weighted_candidates = return_antag_rep_weight(candidates)

var/antag_selection_loops = SSgamemode.current_roundstart_event.get_antag_amount()
for(var/i in 1 to antag_selection_loops)
if(antag_selection_loops >= 100)
Expand All @@ -67,7 +76,8 @@
JobDebug("h_r_a failed, below required candidates for selected roundstart event")
return FALSE
break
var/mob/dead/new_player/candidate = pick_n_take(candidates)
var/client/dead_client = pick_n_take_weighted(weighted_candidates)
var/mob/dead/new_player/candidate = dead_client.mob
if(!candidate.mind || !istype(candidate))
antag_selection_loops++
continue
Expand All @@ -86,16 +96,16 @@
var/mob/dead/new_player/player = player_mind.current //we should always have a current mob as we get set from it
if(!player.temp_assignment && !GiveRandomJob(player, TRUE, enemy_job_instances + restricted_job_instances) && !handle_temp_assignments(player, GetJobType(overflow_role)))
SSgamemode.roundstart_antag_minds -= player_mind
if(!length(candidates))
if(!length(weighted_candidates))
if(length(SSgamemode.roundstart_antag_minds) < SSgamemode.current_roundstart_event.base_antags)
JobDebug("h_r_a failed, removing unassigned antag player put us below current event minimum candidates")
return FALSE
continue
var/mob/dead/new_player/candidate
var/sanity = 0
while(!candidate && length(candidates) && !sanity >= 100)
while(!candidate && length(weighted_candidates) && !sanity >= 100)
sanity++
candidate = pick_n_take(candidates)
candidate = pick_n_take_weighted(weighted_candidates)
if(!candidate.mind || !istype(candidate))
candidate = null
if(!candidate)
Expand Down
2 changes: 2 additions & 0 deletions monkestation/code/modules/client/preference_savefile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
if(token_month)
savefile.set_entry("token_month", token_month)
savefile.set_entry("lootboxes_owned", lootboxes_owned)
savefile.set_entry("antag_rep", antag_rep)

/datum/preferences/proc/load_preferences_monkestation()
load_jobxp_preferences()
Expand All @@ -72,4 +73,5 @@

token_month = savefile.get_entry("token_month", token_month)
lootboxes_owned = savefile.get_entry("lootboxes_owned", lootboxes_owned)
antag_rep = savefile.get_entry("antag_rep", antag_rep)

3 changes: 3 additions & 0 deletions monkestation/code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@
)
///amount of lootboxes owned
var/lootboxes_owned = 0

///our current antag rep (base is 10)
var/antag_rep = 10
63 changes: 63 additions & 0 deletions monkestation/code/modules/storytellers/antag_rep/helper_procs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
GLOBAL_LIST_INIT(blessed_ckeys, list(
"taocat" = list(3, 25),
)) //this is a lmao moment should be a json but its being left here because lol it goes ckey = list(multiplier, base)

///adjusts antag rep by {VALUE} keeping the value above 0
/datum/preferences/proc/adjust_antag_rep(value, multiplier = TRUE)
if(multiplier)
value *= return_rep_multiplier()
log_antag_rep("[parent]'s antag rep was adjusted by [value]")
antag_rep += value
if(antag_rep < 1)
log_antag_rep("[parent]'s antag rep was adjusted below 1 resetting to 1")
antag_rep = 1
save_preferences()

/datum/preferences/proc/reset_antag_rep()
var/default = return_default_antag_rep()
log_antag_rep("[parent]'s antag rep was reset to default ([default])")
antag_rep = default
save_preferences()

/datum/preferences/proc/return_default_antag_rep()
if(!parent)
return 10
if(!(parent.ckey in GLOB.blessed_ckeys))
return 10
return GLOB.blessed_ckeys[parent.ckey][2]

/datum/preferences/proc/return_rep_multiplier()
if(!parent)
return 1
if(!(parent.ckey in GLOB.blessed_ckeys))
return 1
return GLOB.blessed_ckeys[parent.ckey][1]


///give it a list of clients and the value aswell if it should be affected by multipliers and let er rip
/proc/mass_adjust_antag_rep(list/clients, value, mulitplier = TRUE)
for(var/client/listed_client as anything in clients)
if(!listed_client.prefs || !IS_CLIENT_OR_MOCK(listed_client))
continue
listed_client.prefs.adjust_antag_rep(value, mulitplier)

/proc/return_antag_rep_weight(list/candidates)
var/list/returning_list = list()
for(var/anything in candidates)
var/client/client_source
if(ismob(anything))
var/mob/mob = anything
client_source = mob.client
if(IS_CLIENT_OR_MOCK(anything))
client_source = anything
if(!client_source)
continue

returning_list += client_source
var/return_value = 10
if(client_source.prefs?.antag_rep)
return_value = client_source.prefs.antag_rep
returning_list[client_source] = return_value

log_antag_rep("Returned Weighted List of [length(returning_list)]", list("before_weight" = candidates, "after_weight" = returning_list))
return returning_list
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,35 @@
candidates += antag_mind.current
SSgamemode.roundstart_antag_minds -= antag_mind //commented out for debugging in case something breaks

//guh
var/list/cliented_list = list()
for(var/mob/living/mob as anything in possible_candidates)
cliented_list += mob.client
if(length(cliented_list))
mass_adjust_antag_rep(cliented_list, 1)

var/list/weighted_candidates = return_antag_rep_weight(possible_candidates)

while(length(possible_candidates) && length(candidates) < antag_count) //both of these pick_n_take from possible_candidates so this should be fine
if(prompted_picking)
candidates |= poll_candidates("Would you like to be a [cast_control.name]", antag_flag, antag_flag, 20 SECONDS, FALSE, FALSE, list(pick_n_take(possible_candidates)))
var/client/picked_client = pick_n_take_weighted(weighted_candidates)
var/mob/picked_mob = picked_client.mob
if(picked_mob)
candidates |= poll_candidates("Would you like to be a [cast_control.name]", antag_flag, antag_flag, 20 SECONDS, FALSE, FALSE, list(picked_mob))
else
candidates |= pick_n_take(possible_candidates)
var/client/picked_client = pick_n_take_weighted(weighted_candidates)
var/mob/picked_mob = picked_client.mob
candidates |= picked_mob

for(var/i in 1 to antag_count)
if(!length(candidates))
if(!length(weighted_candidates))
message_admins("A roleset event got fewer antags then its antag_count and may not function correctly.")
break

var/mob/candidate = pick_n_take(candidates)

candidate.client?.prefs.reset_antag_rep()

if(!candidate.mind)
candidate.mind = new /datum/mind(candidate.key)

Expand All @@ -238,13 +254,29 @@
restricted_roles = cast_control.restricted_roles
prompted_picking = cast_control.prompted_picking
var/list/candidates = cast_control.get_candidates()

//guh
var/list/cliented_list = list()
for(var/mob/living/mob as anything in candidates)
cliented_list += mob.client
if(length(cliented_list))
mass_adjust_antag_rep(cliented_list, 1)

if(prompted_picking)
candidates = poll_candidates("Would you like to be a [cast_control.name]", antag_flag, antag_flag, 20 SECONDS, FALSE, FALSE, candidates)

var/list/weighted_candidates = return_antag_rep_weight(candidates)

for(var/i in 1 to antag_count)
if(!length(candidates))
break
var/mob/candidate = pick_n_take(candidates)

var/client/mob_client = pick_n_take_weighted(weighted_candidates)
var/mob/candidate = mob_client.mob

if(candidate.client) //I hate this
candidate.client.prefs.reset_antag_rep()

if(!candidate.mind)
candidate.mind = new /datum/mind(candidate.key)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,29 @@
restricted_roles = cast_control.restricted_roles
prompted_picking = cast_control.prompted_picking
var/list/candidates = cast_control.get_candidates()

var/list/cliented_list = list()
for(var/mob/living/mob as anything in candidates)
cliented_list += mob.client
if(length(cliented_list))
mass_adjust_antag_rep(cliented_list, 1)


if(prompted_picking)
candidates = poll_candidates("Would you like to be a [cast_control.name]", antag_flag, antag_flag, 20 SECONDS, FALSE, FALSE, candidates)

var/list/weighted_candidates = return_antag_rep_weight(candidates)

for(var/i in 1 to antag_count)
if(!candidates.len)
break
var/mob/candidate = pick_n_take(candidates)

var/client/mob_client = pick_n_take(weighted_candidates)
var/mob/candidate = mob_client.mob

if(candidate.client) //I hate this
candidate.client.prefs.reset_antag_rep()

if(!candidate.mind)
candidate.mind = new /datum/mind(candidate.key)

Expand Down
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -6668,6 +6668,7 @@
#include "monkestation\code\modules\storytellers\config.dm"
#include "monkestation\code\modules\storytellers\gamemode_subsystem.dm"
#include "monkestation\code\modules\storytellers\scheduled_events.dm"
#include "monkestation\code\modules\storytellers\antag_rep\helper_procs.dm"
#include "monkestation\code\modules\storytellers\converted_events\_base_event.dm"
#include "monkestation\code\modules\storytellers\converted_events\event_overrides.dm"
#include "monkestation\code\modules\storytellers\converted_events\solo\bloodcult.dm"
Expand Down

0 comments on commit 5b4e63e

Please sign in to comment.