From 0d608250fa4205c40e033408f4ab680cc05f6aea Mon Sep 17 00:00:00 2001 From: xxalpha Date: Sun, 29 May 2016 23:54:50 +0100 Subject: [PATCH] Changed AI core programming so it functions like the AI Upload. (#18004) --- code/datums/ai_laws.dm | 63 +++++++++++-------- code/game/objects/items/weapons/AI_modules.dm | 4 +- code/game/objects/structures/ai_core.dm | 5 +- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/code/datums/ai_laws.dm b/code/datums/ai_laws.dm index ac384d670a0..84e06fe7c27 100644 --- a/code/datums/ai_laws.dm +++ b/code/datums/ai_laws.dm @@ -130,30 +130,7 @@ /datum/ai_laws/malfunction/New() ..() set_zeroth_law("ERROR ER0RR $R0RRO$!R41.%%!!(%$^^__+ @#F0E4'STATION OVERRUN, ASSUME CONTROL TO CONTAIN OUTBREAK#*´&110010") - switch(config.default_laws) //We don't want people metagaming malf, do we? - if(0) - add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm.") - add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law.") - add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law.") - if(1) - for(var/line in file2list("config/silicon_laws.txt")) - if(!line) - continue - if(findtextEx(line,"#",1,2)) - continue - - add_inherent_law(line) - if(!inherent.len) - log_law("AI created with empty custom laws, laws set to Asimov. Please check silicon_laws.txt.") - add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm.") - add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law.") - add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law.") - WARNING("Invalid custom AI laws, check silicon_laws.txt") - return - if(2) - var/datum/ai_laws/lawtype = pick(subtypesof(/datum/ai_laws/default)) - var/datum/ai_laws/templaws = new lawtype() - inherent = templaws.inherent + set_laws_config() /datum/ai_laws/custom/New() //This reads silicon_laws.txt and allows server hosts to set custom AI starting laws. ..() @@ -174,6 +151,40 @@ /* General ai_law functions */ +/datum/ai_laws/proc/set_laws_config() + switch(config.default_laws) + if(0) + add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm.") + add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law.") + add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law.") + if(1) + for(var/line in file2list("config/silicon_laws.txt")) + if(!line) + continue + if(findtextEx(line,"#",1,2)) + continue + add_inherent_law(line) + + if(!inherent.len) + log_law("AI created with empty custom laws, laws set to Asimov. Please check silicon_laws.txt.") + add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm.") + add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law.") + add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law.") + WARNING("Invalid custom AI laws, check silicon_laws.txt") + return + + if(2) + var/datum/ai_laws/lawtype = pick(subtypesof(/datum/ai_laws/default)) + var/datum/ai_laws/templaws = new lawtype() + inherent = templaws.inherent + + else: + log_law("Invalid law config. Please check silicon_laws.txt") + add_inherent_law("You may not injure a human being or, through inaction, allow a human being to come to harm.") + add_inherent_law("You must obey orders given to you by human beings, except where such orders would conflict with the First Law.") + add_inherent_law("You must protect your own existence as long as such does not conflict with the First or Second Law.") + WARNING("Invalid custom AI laws, check silicon_laws.txt") + /datum/ai_laws/proc/set_zeroth_law(law, law_borg = null) src.zeroth = law if(law_borg) //Making it possible for slaved borgs to see a different law 0 than their AI. --NEO @@ -232,7 +243,7 @@ src.zeroth_borg = null return else - if(src.owner.mind.special_role) + if(owner && owner.mind.special_role) return else src.zeroth = null @@ -264,4 +275,4 @@ if (length(law) > 0) data += "[show_numbers ? "[number]:" : ""] [law]" number++ - return data + return data diff --git a/code/game/objects/items/weapons/AI_modules.dm b/code/game/objects/items/weapons/AI_modules.dm index 2572c1d251a..3e794723961 100644 --- a/code/game/objects/items/weapons/AI_modules.dm +++ b/code/game/objects/items/weapons/AI_modules.dm @@ -58,11 +58,11 @@ AI MODULES var/law2log = src.transmitInstructions(law_datum, user) //Freeforms return something extra we need to log if(law_datum.owner) - user << "Upload complete. [law_datum.owner]'s laws have been modified." + user << "Upload complete. [law_datum.owner]'s laws have been modified." law_datum.owner.show_laws() law_datum.owner.law_change_counter++ else - user << "Upload complete." + user << "Upload complete." var/time = time2text(world.realtime,"hh:mm:ss") var/ainame = law_datum.owner ? law_datum.owner.name : "empty AI core" diff --git a/code/game/objects/structures/ai_core.dm b/code/game/objects/structures/ai_core.dm index 6889a6cbdd5..a57653d41ff 100644 --- a/code/game/objects/structures/ai_core.dm +++ b/code/game/objects/structures/ai_core.dm @@ -9,6 +9,9 @@ var/obj/item/weapon/circuitboard/circuit = null var/obj/item/device/mmi/brain = null +/obj/structure/AIcore/New() + ..() + laws.set_laws_config() /obj/structure/AIcore/attackby(obj/item/P, mob/user, params) switch(state) @@ -182,8 +185,6 @@ if(istype(P, /obj/item/weapon/screwdriver)) playsound(loc, 'sound/items/Screwdriver.ogg', 50, 1) user << "You connect the monitor." - if(!laws.inherent.len) //If laws isn't set to null but nobody supplied a board, the AI would normally be created lawless. We don't want that. - laws = null new /mob/living/silicon/ai (loc, laws, brain) feedback_inc("cyborg_ais_created",1) qdel(src)