[MIRROR] ai syncing / unsyncing in modify robot (#9054)

Co-authored-by: Heroman3003 <31296024+Heroman3003@users.noreply.github.com>
Co-authored-by: CHOMPStation2 <chompsation2@gmail.com>
This commit is contained in:
CHOMPStation2
2024-09-27 09:58:35 -07:00
committed by GitHub
parent 1fe9557421
commit a1366ac570
9 changed files with 132 additions and 15 deletions

View File

@@ -6,12 +6,14 @@
return return
var/datum/eventkit/modify_robot/modify_robot = new() var/datum/eventkit/modify_robot/modify_robot = new()
modify_robot.target = target modify_robot.target = isrobot(target) ? target : null
modify_robot.selected_ai = target.is_slaved()
modify_robot.tgui_interact(src.mob) modify_robot.tgui_interact(src.mob)
/datum/eventkit/modify_robot /datum/eventkit/modify_robot
var/mob/living/silicon/robot/target var/mob/living/silicon/robot/target
var/mob/living/silicon/robot/source var/mob/living/silicon/robot/source
var/mob/living/silicon/ai/selected_ai
var/ion_law = "IonLaw" var/ion_law = "IonLaw"
var/zeroth_law = "ZerothLaw" var/zeroth_law = "ZerothLaw"
var/inherent_law = "InherentLaw" var/inherent_law = "InherentLaw"
@@ -49,6 +51,7 @@
.["target"]["name"] = target.name .["target"]["name"] = target.name
.["target"]["ckey"] = target.ckey .["target"]["ckey"] = target.ckey
.["target"]["module"] = target.module .["target"]["module"] = target.module
.["target"]["emagged"] = target.emagged
.["target"]["crisis_override"] = target.crisis_override .["target"]["crisis_override"] = target.crisis_override
.["target"]["active_restrictions"] = target.restrict_modules_to .["target"]["active_restrictions"] = target.restrict_modules_to
var/list/possible_restrictions = list() var/list/possible_restrictions = list()
@@ -121,6 +124,15 @@
package_laws(., "supplied_laws", target.laws.supplied_laws) package_laws(., "supplied_laws", target.laws.supplied_laws)
.["isAI"] = isAI(target) .["isAI"] = isAI(target)
.["isMalf"] = is_malf(user)
.["isSlaved"] = target.is_slaved()
var/list/active_ais = list()
for(var/mob/living/silicon/ai/ai in active_ais())
if(!ai.loc)
continue
active_ais += list(list("displayText" = "[ai]", "value" = "\ref[ai]"))
.["active_ais"] = active_ais
.["selected_ai"] = selected_ai ? selected_ai.name : null
var/list/channels = list() var/list/channels = list()
for(var/ch_name in target.law_channels()) for(var/ch_name in target.law_channels())
@@ -144,6 +156,8 @@
target.real_name = params["new_name"] target.real_name = params["new_name"]
return TRUE return TRUE
if("select_target") if("select_target")
var/new_target = locate(params["new_target"])
if(new_target != target)
target = locate(params["new_target"]) target = locate(params["new_target"])
log_and_message_admins("changed robot modifictation target to [target]") log_and_message_admins("changed robot modifictation target to [target]")
return TRUE return TRUE
@@ -498,6 +512,41 @@
if(usr != target) if(usr != target)
to_chat(usr, "<span class='notice'>Laws displayed.</span>") to_chat(usr, "<span class='notice'>Laws displayed.</span>")
return TRUE return TRUE
if("select_ai")
selected_ai = locate(params["new_ai"])
return TRUE
if("swap_sync")
var/new_ai = selected_ai ? selected_ai : select_active_ai_with_fewest_borgs()
if(new_ai)
target.lawupdate = 1
target.connect_to_ai(new_ai)
return TRUE
if("disconnect_ai")
if(target.is_slaved())
target.disconnect_from_ai()
target.lawupdate = 0
return TRUE
if("toggle_emag")
if(target.emagged)
target.emagged = 0
target.clear_supplied_laws()
target.clear_inherent_laws()
target.laws = new global.using_map.default_law_type
target.laws.show_laws(target)
target.hud_used.update_robot_modules_display()
else
target.emagged = 1
target.lawupdate = 0
target.disconnect_from_ai()
target.clear_supplied_laws()
target.clear_inherent_laws()
target.laws = new /datum/ai_laws/syndicate_override
if(target.bolt)
if(!target.bolt.malfunction)
target.bolt.malfunction = MALFUNCTION_PERMANENT
target.laws.show_laws(target)
target.hud_used.update_robot_modules_display()
return TRUE
/datum/eventkit/modify_robot/proc/get_target_items(var/mob/user) /datum/eventkit/modify_robot/proc/get_target_items(var/mob/user)
var/list/target_items = list() var/list/target_items = list()
@@ -650,3 +699,9 @@
package_laws(packaged_laws, "supplied_laws", ALs.supplied_laws) package_laws(packaged_laws, "supplied_laws", ALs.supplied_laws)
law_sets[++law_sets.len] = list("name" = ALs.name, "header" = ALs.law_header, "ref" = "\ref[ALs]","laws" = packaged_laws) law_sets[++law_sets.len] = list("name" = ALs.name, "header" = ALs.law_header, "ref" = "\ref[ALs]","laws" = packaged_laws)
return law_sets return law_sets
/datum/eventkit/modify_robot/proc/is_malf(var/mob/user)
return (is_admin(user) && !target.is_slaved()) || is_special_role(user)
/datum/eventkit/modify_robot/proc/is_special_role(var/mob/user)
return user.mind.special_role ? TRUE : FALSE

View File

@@ -29,7 +29,7 @@ export const ModifyRobotAccess = (props: {
return ( return (
<> <>
{!target.active && <NoSpriteWarning name={target.name} />} {!target.active && <NoSpriteWarning name={target.name} />}
<Flex height={!target.active ? '80%' : '85%'}> <Flex height={!target.active ? '75%' : '80%'}>
<Flex.Item width="30%" fill> <Flex.Item width="30%" fill>
<AccessSection <AccessSection
title="Add Access" title="Add Access"

View File

@@ -38,7 +38,7 @@ export const ModifyRobotComponent = (props: {
return ( return (
<> <>
{!target.active && <NoSpriteWarning name={target.name} />} {!target.active && <NoSpriteWarning name={target.name} />}
<Flex height={!target.active ? '80%' : '85%'}> <Flex height={!target.active ? '75%' : '80%'}>
<Flex.Item width="35%" fill> <Flex.Item width="35%" fill>
<ComponentSection <ComponentSection
title="Repair Component" title="Repair Component"

View File

@@ -31,7 +31,7 @@ export const ModifyRobotModules = (props: {
return ( return (
<> <>
{!target.active && <NoSpriteWarning name={target.name} />} {!target.active && <NoSpriteWarning name={target.name} />}
<Flex height={!target.active ? '80%' : '85%'}> <Flex height={!target.active ? '75%' : '80%'}>
<Flex.Item width="40%" fill> <Flex.Item width="40%" fill>
<Section title="Source Module" scrollable fill> <Section title="Source Module" scrollable fill>
<Box>Robot to salvage</Box> <Box>Robot to salvage</Box>

View File

@@ -27,7 +27,7 @@ export const ModifyRobotPKA = (props: { target: Target }) => {
{!target.pka ? ( {!target.pka ? (
<NoticeBox danger>{target.name} has no PKA installed.</NoticeBox> <NoticeBox danger>{target.name} has no PKA installed.</NoticeBox>
) : ( ) : (
<Flex height={!target.active ? '80%' : '85%'}> <Flex height={!target.active ? '75%' : '80%'}>
<Flex.Item width="35%" fill> <Flex.Item width="35%" fill>
<Divider /> <Divider />
<Box>Remaining Capacity: {target.pka.capacity}</Box> <Box>Remaining Capacity: {target.pka.capacity}</Box>

View File

@@ -25,7 +25,7 @@ export const ModifyRobotRadio = (props: { target: Target }) => {
return ( return (
<> <>
{!target.active && <NoSpriteWarning name={target.name} />} {!target.active && <NoSpriteWarning name={target.name} />}
<Flex height={!target.active ? '80%' : '85%'}> <Flex height={!target.active ? '75%' : '80%'}>
<Flex.Item width="30%" fill> <Flex.Item width="30%" fill>
<RadioSection <RadioSection
title="Add Radio Channel" title="Add Radio Channel"

View File

@@ -65,7 +65,7 @@ export const ModifyRobotUpgrades = (props: { target: Target }) => {
/> />
</Flex.Item> </Flex.Item>
</Flex> </Flex>
<Flex height={!target.active ? '45%' : '50%'}> <Flex height={!target.active ? '40%' : '45%'}>
<Flex.Item width="25%" fill> <Flex.Item width="25%" fill>
<UpgradeSection <UpgradeSection
title="Utility Upgrade" title="Utility Upgrade"

View File

@@ -50,6 +50,10 @@ export const ModifyRobot = (props) => {
has_inherent_laws, has_inherent_laws,
has_supplied_laws, has_supplied_laws,
isAI, isAI,
isMalf,
isSlaved,
active_ais,
selected_ai,
channel, channel,
channels, channels,
law_sets, law_sets,
@@ -90,9 +94,8 @@ export const ModifyRobot = (props) => {
tabs[6] = ( tabs[6] = (
<LawManagerLaws <LawManagerLaws
isAdmin isAdmin
isMalf
hasScroll hasScroll
sectionHeight="85%" sectionHeight="80%"
ion_law_nr={ion_law_nr} ion_law_nr={ion_law_nr}
ion_law={ion_law} ion_law={ion_law}
zeroth_law={zeroth_law} zeroth_law={zeroth_law}
@@ -108,15 +111,16 @@ export const ModifyRobot = (props) => {
has_inherent_laws={has_inherent_laws} has_inherent_laws={has_inherent_laws}
has_supplied_laws={has_supplied_laws} has_supplied_laws={has_supplied_laws}
isAI={isAI} isAI={isAI}
isMalf={isMalf}
channel={channel} channel={channel}
channels={channels} channels={channels}
/> />
); );
tabs[7] = ( tabs[7] = (
<Section scrollable fill height="85%"> <Section scrollable fill height="80%">
<LawManagerLawSets <LawManagerLawSets
isAdmin isAdmin
isMalf isMalf={isMalf}
law_sets={law_sets} law_sets={law_sets}
ion_law_nr={ion_law_nr} ion_law_nr={ion_law_nr}
searchLawName={searchLawName} searchLawName={searchLawName}
@@ -154,7 +158,7 @@ export const ModifyRobot = (props) => {
<> <>
<Stack.Item> <Stack.Item>
<Input <Input
width="300px" width="200px"
value={robotName} value={robotName}
onChange={(e, value) => setRobotName(value)} onChange={(e, value) => setRobotName(value)}
/> />
@@ -162,7 +166,7 @@ export const ModifyRobot = (props) => {
<Stack.Item> <Stack.Item>
<Button <Button
disabled={robotName.length < 3} disabled={robotName.length < 3}
onClick={(value) => onClick={() =>
act('rename', { act('rename', {
new_name: robotName, new_name: robotName,
}) })
@@ -171,10 +175,63 @@ export const ModifyRobot = (props) => {
Rename Rename
</Button> </Button>
</Stack.Item> </Stack.Item>
<Stack.Item grow />
<Stack.Item>
<Button
icon={target.emagged ? 'sd-card' : 'bolt'}
color={target.emagged ? 'green' : 'red'}
onClick={() => act('toggle_emag')}
tooltip={
(target.emagged ? 'Disables' : 'Enables') +
' hacked state'
}
>
EMAG
</Button>
</Stack.Item>
</> </>
)} )}
</Stack> </Stack>
</LabeledList.Item> </LabeledList.Item>
<LabeledList.Item label="AI Selection">
{!!target?.module && (
<Stack inline align="baseline">
<Stack.Item>
<Dropdown
selected={selected_ai || ''}
options={active_ais}
onSelected={(value) =>
act('select_ai', {
new_ai: value,
})
}
/>
</Stack.Item>
<Stack.Item>
<Button
icon="plug"
disabled={selected_ai === isSlaved}
color="green"
tooltip="Connect the robot to an AI"
onClick={() => act('swap_sync')}
>
{isSlaved ? isSlaved : 'Connect AI'}
</Button>
</Stack.Item>
<Stack.Item>
<Button
icon="plug-circle-minus"
disabled={!isSlaved}
color="red"
tooltip="Disconnects the robot from the AI"
onClick={() => act('disconnect_ai')}
>
DC
</Button>
</Stack.Item>
</Stack>
)}
</LabeledList.Item>
</LabeledList> </LabeledList>
<Divider /> <Divider />
{!!target && {!!target &&

View File

@@ -24,9 +24,13 @@ export type Data = {
has_inherent_laws: number; has_inherent_laws: number;
has_supplied_laws: number; has_supplied_laws: number;
isAI: BooleanLike; isAI: BooleanLike;
isMalf: BooleanLike;
isSlaved: string | null;
channel: string; channel: string;
channels: { channel: string }[]; channels: { channel: string }[];
law_sets: law_pack[]; law_sets: law_pack[];
active_ais: DropdownEntry[];
selected_ai: string | null;
}; };
export type DropdownEntry = { export type DropdownEntry = {
@@ -38,6 +42,7 @@ export type Target = {
name: string; name: string;
ckey: string; ckey: string;
module: string; module: string;
emagged: BooleanLike;
active: BooleanLike; active: BooleanLike;
crisis_override: BooleanLike; crisis_override: BooleanLike;
active_restrictions: string[]; active_restrictions: string[];