Skip to content

Commit

Permalink
Admin panel for campaign (#16178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lumipharon authored Jun 29, 2024
1 parent 61ebe95 commit ad5ecbd
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 6 deletions.
5 changes: 4 additions & 1 deletion code/datums/gamemodes/campaign/campaign_mission.dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
)
/// Timer used to calculate how long till mission ends
var/game_timer
/// Timer for when the mission starts
var/start_timer
///The length of time until mission ends, if timed
var/max_game_time = 0
///Whether the max game time has been reached
Expand Down Expand Up @@ -181,7 +183,7 @@
play_selection_intro()
load_map()
addtimer(CALLBACK(src, TYPE_PROC_REF(/datum/campaign_mission, load_objective_description)), 5 SECONDS) //will be called before the map is entirely loaded otherwise, but this is cringe
addtimer(CALLBACK(src, TYPE_PROC_REF(/datum/campaign_mission, start_mission)), mission_start_delay)
start_timer = addtimer(CALLBACK(src, TYPE_PROC_REF(/datum/campaign_mission, start_mission)), mission_start_delay, TIMER_STOPPABLE)
load_pre_mission_bonuses()
RegisterSignals(SSdcs, list(COMSIG_GLOB_CAMPAIGN_TELEBLOCKER_DISABLED, COMSIG_GLOB_CAMPAIGN_DROPBLOCKER_DISABLED), PROC_REF(remove_mission_flag))

Expand Down Expand Up @@ -307,6 +309,7 @@
/datum/campaign_mission/proc/start_mission()
SHOULD_CALL_PARENT(TRUE)
SEND_SIGNAL(SSdcs, COMSIG_GLOB_CAMPAIGN_MISSION_STARTED)
start_timer = null
if(!shutter_open_delay[MISSION_STARTING_FACTION])
SEND_GLOBAL_SIGNAL(GLOB.faction_to_campaign_door_signal[starting_faction])
else
Expand Down
23 changes: 18 additions & 5 deletions code/datums/gamemodes/campaign/faction_stats.dm
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ GLOBAL_LIST_INIT(campaign_mission_pool, list(

///Elects a new faction leader
/datum/faction_stats/proc/choose_faction_leader()
faction_leader = null
var/new_leader
var/list/possible_candidates = GLOB.alive_human_list_faction[faction]
if(!length(possible_candidates))
faction_leader = null
return //army of ghosts

var/list/ranks = GLOB.ranked_jobs_by_faction[faction]
Expand All @@ -197,14 +198,26 @@ GLOBAL_LIST_INIT(campaign_mission_pool, list(
if(!length(senior_rank_list))
senior_rank_list.Cut()
continue
faction_leader = pick(senior_rank_list)
new_leader = pick(senior_rank_list)
break

if(!faction_leader)
faction_leader = pick(possible_candidates)
if(!new_leader)
new_leader = pick(possible_candidates)

set_faction_leader(new_leader)

///Sets the faction leader
/datum/faction_stats/proc/set_faction_leader(mob/living/new_leader)
var/old_leader = faction_leader
faction_leader = new_leader

if(old_leader && old_leader != faction_leader)
for(var/mob/living/carbon/human/human AS in GLOB.alive_human_list_faction[faction])
human.play_screen_text("<span class='maptext' style=font-size:24pt;text-align:left valign='top'><u>OVERWATCH</u></span><br>" + "[old_leader] has been demoted from the role of faction commander", faction_portrait)
if(!faction_leader)
return

for(var/mob/living/carbon/human/human AS in possible_candidates)
for(var/mob/living/carbon/human/human AS in GLOB.alive_human_list_faction[faction])
human.playsound_local(null, 'sound/effects/CIC_order.ogg', 30, 1)
human.play_screen_text("<span class='maptext' style=font-size:24pt;text-align:left valign='top'><u>OVERWATCH</u></span><br>" + "[faction_leader] has been promoted to the role of faction commander", faction_portrait)
to_chat(faction_leader, span_highdanger("You have been promoted to the role of commander for your faction. It is your responsibility to determine your side's course of action, and how to best utilise the resources at your disposal. \
Expand Down
1 change: 1 addition & 0 deletions code/modules/admin/holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ GLOBAL_PROTECT(admin_verbs_default)
/datum/admins/proc/toggle_prayers,
/datum/admins/proc/check_fingerprints,
/datum/admins/proc/display_tags,
/datum/admins/proc/open_campaign_panel,
/client/proc/mark_datum_mapview,
/client/proc/tag_datum_mapview,
/client/proc/cmd_admin_check_contents, /*displays the contents of an instance*/
Expand Down
147 changes: 147 additions & 0 deletions code/modules/admin/panels/Campaign_panel.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
GLOBAL_DATUM(campaign_admin_panel, /datum/campaign_admin_panel)

///Opens the campaign specific admin panel
/datum/admins/proc/open_campaign_panel()
set category = "Admin"
set name = "Campaign Panel"
set desc = "Opens the campaign panel UI."

if(!iscampaigngamemode(SSticker.mode))
return
if(!check_rights(R_ADMIN))
return

if(!GLOB.campaign_admin_panel)
GLOB.campaign_admin_panel = new /datum/campaign_admin_panel()

GLOB.campaign_admin_panel.ui_interact(usr)


/datum/campaign_admin_panel
interaction_flags = INTERACT_UI_INTERACT

/datum/campaign_admin_panel/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(ui)
return
ui = new(user, src, "CampaignAdminPanel")
ui.open()

/datum/campaign_admin_panel/ui_state(mob/user)
return GLOB.always_state

/datum/campaign_admin_panel/ui_static_data(mob/user)
var/datum/game_mode/hvh/campaign/current_mode = SSticker.mode

var/list/data = list()
var/list/faction_data_list = list()

for(var/faction in current_mode.factions)
var/datum/faction_stats/faction_datum = current_mode.stat_list[faction]
var/list/faction_data = list()
faction_data["faction"] = faction
faction_data["active_attrition"] = faction_datum.active_attrition_points
faction_data["total_attrition"] = faction_datum.total_attrition_points
faction_data["faction_leader"] = faction_datum.faction_leader
faction_data["victory_points"] = faction_datum.victory_points
faction_data["available_missions"] = faction_datum.available_missions
faction_data["assets"] = faction_datum.faction_assets

faction_data_list += list(faction_data)
data["faction_data"] = faction_data_list
data["vp_max"] = CAMPAIGN_MAX_VICTORY_POINTS

return data

/datum/campaign_admin_panel/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
var/mob/living/user = usr
var/datum/game_mode/hvh/campaign/current_mode = SSticker.mode
var/datum/faction_stats/faction_datum = current_mode?.stat_list[params["target_faction"]]

switch(action)
if("set_attrition_points")
var/combined_attrition = faction_datum.total_attrition_points + faction_datum.active_attrition_points
var/choice = tgui_input_number(user, "How much manpower would you like to dedicate to this mission?", "Attrition Point selection", 0, combined_attrition, 0, 60 SECONDS)
faction_datum.set_attrition(choice, user)
message_admins("[usr.client] set the active attrition for [faction_datum.faction] to [choice]")
log_admin("[usr.client] set the active attrition for [faction_datum.faction] to [choice]")
update_static_data_for_all_viewers()
return TRUE
if("add_attrition_points")
var/choice = tgui_input_number(user, "How much total attrition would you like to add?", "Attrition Point selection", 0, 9999, -9999)
faction_datum.total_attrition_points += choice
message_admins("[usr.client] added [choice] attrition to [faction_datum.faction]")
log_admin("[usr.client] added [choice] attrition to [faction_datum.faction]")
update_static_data_for_all_viewers()
return TRUE
if("set_leader")
var/choice = tgui_input_list(user, "Who would you like to promote to faction leader?", "Leader selection", GLOB.alive_human_list_faction[faction_datum.faction], null)
faction_datum.set_faction_leader(choice)
message_admins("[usr.client] set faction leader of [faction_datum.faction] to [choice ? choice : "no one"]")
log_admin("[usr.client] set faction leader of [faction_datum.faction] to [choice ? choice : "no one"]")
update_static_data_for_all_viewers()
return TRUE
if("set_victory_points")
var/choice = tgui_input_number(user, "How many victory points would you like to add?", "Attrition Point selection", 0, CAMPAIGN_MAX_VICTORY_POINTS, -CAMPAIGN_MAX_VICTORY_POINTS)
faction_datum.victory_points += choice
message_admins("[usr.client] set the victory points for [faction_datum.faction] to [choice]")
log_admin("[usr.client] set the victory points for [faction_datum.faction] to [choice]")
update_static_data_for_all_viewers()
return TRUE
if("add_mission")
var/choice = tgui_input_list(user, "What mission would you like to add?", "Add mission", subtypesof(/datum/campaign_mission), null)
if(!choice)
return FALSE
faction_datum.add_new_mission(choice)
message_admins("[usr.client] added the mission [choice] to [faction_datum.faction]")
log_admin("[usr.client] added the mission [choice] to [faction_datum.faction]")
return TRUE
if("add_asset")
var/choice = tgui_input_list(user, "What asset would you like to add?", "Add asset", subtypesof(/datum/campaign_asset), null)
if(!choice)
return FALSE
faction_datum.add_asset(choice)
message_admins("[usr.client] added the asset [choice] to [faction_datum.faction]")
log_admin("[usr.client] added the asst [choice] to [faction_datum.faction]")
return TRUE
if("force_autobalance")
current_mode.autobalance_cycle(TRUE)
message_admins("[usr.client] forced autobalance")
log_admin("[usr.client] forced autobalance")
return TRUE
if("mission_start_timer")
if(current_mode.current_mission.mission_state != MISSION_STATE_LOADED)
to_chat(user, "Mission is not in pregame.")
return FALSE
if(current_mode.current_mission.start_timer)
deltimer(current_mode.current_mission.start_timer)
current_mode.current_mission.start_timer = null
message_admins("[usr.client] cancelled the mission start timer")
log_admin("[usr.client] cancelled the mission start timer")
return TRUE
var/choice = tgui_input_number(user, "How long would you like to set the delay to?", "Mission start timer", current_mode.current_mission.mission_start_delay, 20 MINUTES, 1)
if(!choice)
return FALSE
current_mode.current_mission.start_timer = addtimer(CALLBACK(current_mode.current_mission, TYPE_PROC_REF(/datum/campaign_mission, start_mission)), choice, TIMER_STOPPABLE)
message_admins("[usr.client] resumed the mission start timer at [choice * 0.1] seconds.")
log_admin("[usr.client] resumed the mission start timer at [choice * 0.1] seconds.")
return TRUE
if("mission_timer")
if(current_mode.current_mission.mission_state != MISSION_STATE_ACTIVE)
to_chat(user, "Mission is not active.")
return FALSE
if(current_mode.current_mission.game_timer)
current_mode.current_mission.pause_mission_timer()
message_admins("[usr.client] paused the mission timer")
log_admin("[usr.client] paused the mission timer")
return TRUE
var/choice = tgui_input_list(user, "Force timer on?", "Force timer", list("Yes", "No"), "No")
if(choice != "Yes")
choice = null
current_mode.current_mission.resume_mission_timer(forced = choice)
message_admins("[usr.client] resumed the mission timer")
log_admin("[usr.client] resumed the mission timer")
return TRUE
1 change: 1 addition & 0 deletions tgmc.dme
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@
#include "code\modules\admin\topic.dm"
#include "code\modules\admin\panels\antag_panel.dm"
#include "code\modules\admin\panels\ban_panel.dm"
#include "code\modules\admin\panels\Campaign_panel.dm"
#include "code\modules\admin\panels\game_panel.dm"
#include "code\modules\admin\panels\mode_panel.dm"
#include "code\modules\admin\panels\note_panel.dm"
Expand Down
Loading

0 comments on commit ad5ecbd

Please sign in to comment.