diff --git a/code/defines/procs/helpers.dm b/code/defines/procs/helpers.dm index af377e2bfb..1880b2c4aa 100644 --- a/code/defines/procs/helpers.dm +++ b/code/defines/procs/helpers.dm @@ -364,25 +364,32 @@ Turf and target are seperate in case you want to teleport some distance from a t return borgs[select] //When a borg is activated, it can choose which AI it wants to be slaved to -/proc/activeais() - var/select = null - var/list/names = list() - var/list/ais = list() - var/list/namecounts = list() - for (var/mob/living/silicon/ai/A in living_mob_list) - var/name = A.real_name - if (A.stat == 2) +/proc/active_ais() + . = list() + for(var/mob/living/silicon/ai/A in living_mob_list) + if(A.stat == DEAD) continue - if (A.control_disabled == 1) + if(A.control_disabled == 1) continue - else - names.Add(name) - namecounts[name] = 1 - ais[name] = A + . += A + return . +//Find an active ai with the least borgs. VERBOSE PROCNAME HUH! +/proc/select_active_ai_with_fewest_borgs() + var/mob/living/silicon/ai/selected + var/list/active = active_ais() + for(var/mob/living/silicon/ai/A in active) + if(!selected || (selected.connected_robots > A.connected_robots)) + selected = A + + return selected + +/proc/select_active_ai(var/mob/user) + var/list/ais = active_ais() if(ais.len) - select = input("AI signals detected:", "AI selection") in ais - return ais[select] + if(user) . = input(usr,"AI signals detected:", "AI selection") in ais + else . = pick(ais) + return . //Returns a list of all mobs with their name /proc/getmobs() diff --git a/code/game/machinery/computer/law.dm b/code/game/machinery/computer/law.dm index f0faf4c903..7d2ba43783 100644 --- a/code/game/machinery/computer/law.dm +++ b/code/game/machinery/computer/law.dm @@ -40,7 +40,7 @@ usr << "The upload computer is broken!" return - src.current = activeais() + src.current = select_active_ai(user) if (!src.current) usr << "No active AIs detected." diff --git a/code/modules/mob/living/silicon/robot/login.dm b/code/modules/mob/living/silicon/robot/login.dm index 93425cb3d3..3aef61fb3d 100644 --- a/code/modules/mob/living/silicon/robot/login.dm +++ b/code/modules/mob/living/silicon/robot/login.dm @@ -1,46 +1,6 @@ -/mob/living/silicon/robot/Login(var/syndie = 0) +/mob/living/silicon/robot/Login() ..() regenerate_icons() - - if(!started) - if(!syndie) - connected_ai = activeais() - if(connected_ai) - connected_ai.connected_robots += src - // laws = connected_ai.laws //The borg inherits its AI's laws - laws = new /datum/ai_laws - lawsync() - src << "Unit slaved to [connected_ai.name], downloading laws." - lawupdate = 1 - else - laws = new /datum/ai_laws/asimov - lawupdate = 0 - src << "Unable to locate an AI, reverting to standard Asimov laws." - else - laws = new /datum/ai_laws/antimov - lawupdate = 0 - scrambledcodes = 1 - src << "Follow your laws." - cell.maxcharge = 25000 - cell.charge = 25000 - module = new /obj/item/weapon/robot_module/syndicate(src) - hands.icon_state = "standard" - icon_state = "secborg" - modtype = "Synd" - - radio = new /obj/item/device/radio/borg(src) - if(!scrambledcodes && !camera) - camera = new /obj/machinery/camera(src) - camera.c_tag = real_name - camera.network = "SS13" - if(isWireCut(5)) // 5 = BORG CAMERA - camera.status = 0 - if(!cell) - var/obj/item/weapon/cell/C = new(src) - C.charge = 1500 - cell = C - if(mind) - ticker.mode.remove_revolutionary(mind) - started = 1 - + show_laws(0) + if(mind) ticker.mode.remove_revolutionary(mind) return \ No newline at end of file diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index 9d2fbd1010..ffa141b124 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -5,7 +5,6 @@ icon_state = "robot" maxHealth = 300 health = 300 - var/started = null//A fix to ensure people don't try to bypass law assignment. Initial assignment sets it to one but it check on login whether they have been initiated -Sieve var/sight_mode = 0 //Hud stuff @@ -60,15 +59,43 @@ spark_system.set_up(5, 0, src) spark_system.attach(src) - if(real_name == "Cyborg") + if(cmptext(real_name,"Cyborg")) ident = rand(1, 999) real_name += "-[ident]" name = real_name if(!cell) - var/obj/item/weapon/cell/C = new(src) - C.charge = 1500 - cell = C + cell = new /obj/item/weapon/cell(src) + cell.maxcharge = 7500 + cell.charge = 7500 + + if(syndie) + laws = new /datum/ai_laws/antimov() + lawupdate = 0 + scrambledcodes = 1 + cell.maxcharge = 25000 + cell.charge = 25000 + module = new /obj/item/weapon/robot_module/syndicate(src) + hands.icon_state = "standard" + icon_state = "secborg" + modtype = "Synd" + else + laws = new /datum/ai_laws/asimov() + connected_ai = select_active_ai_with_fewest_borgs() + if(connected_ai) + connected_ai.connected_robots += src + lawsync() + lawupdate = 1 + else + lawupdate = 0 + + radio = new /obj/item/device/radio/borg(src) + if(!scrambledcodes && !camera) + camera = new /obj/machinery/camera(src) + camera.c_tag = real_name + camera.network = "SS13" + if(isWireCut(5)) // 5 = BORG CAMERA + camera.status = 0 ..() //If there's an MMI in the robot, have it ejected when the mob goes away. --NEO @@ -102,16 +129,12 @@ module = new /obj/item/weapon/robot_module/butler(src) hands.icon_state = "service" var/icontype = input("Select an icon!", "Robot", null, null) in list("Waitress", "Bro", "Butler", "Kent", "Rich") - if(icontype== "Waitress") - icon_state = "Service" - else if(icontype == "Kent") - icon_state = "toiletbot" - else if(icontype == "Bro") - icon_state = "Brobot" - else if(icontype == "Rich") - icon_state = "maximillion" - else - icon_state = "Service2" + switch(icontype) + if("Waitress") icon_state = "Service" + if("Kent") icon_state = "toiletbot" + if("Bro") icon_state = "Brobot" + if("Rich") icon_state = "maximillion" + else icon_state = "Service2" modtype = "Butler" feedback_inc("cyborg_service",1) @@ -166,7 +189,7 @@ //not really necessary but just to avoid annoying people with //unique names seeming as nobody could give me a straight answer as //to whether to remove custom borg names completely. - if(copytext(real_name, 1, 7) == "Cyborg") + if(cmptext(copytext(real_name, 1, 7),"Cyborg")) real_name = "[prefix] [real_name]" name = real_name diff --git a/code/modules/mob/living/silicon/robot/wires.dm b/code/modules/mob/living/silicon/robot/wires.dm index 6a159e0c9c..1b0e2a0561 100644 --- a/code/modules/mob/living/silicon/robot/wires.dm +++ b/code/modules/mob/living/silicon/robot/wires.dm @@ -77,7 +77,7 @@ if (BORG_WIRE_AI_CONTROL) //pulse the AI wire to make the borg reselect an AI if(!src.emagged) - src.connected_ai = activeais() + src.connected_ai = select_active_ai() if (BORG_WIRE_CAMERA) if(!isnull(src.camera) && src.camera.status && !scrambledcodes)