Robot code clean up and fixes.

Fixes runtime when a borg is reset.
Fixes issue where /proc/select_active_ai_with_fewest_borgs() would not always return the intended AI.
Fixes issues with new borgs spamming the master AI with creation messages under some circumstances.
This commit is contained in:
PsiOmega
2015-03-10 13:37:20 +01:00
parent d3d9e0b2ed
commit 533ccef0ab
11 changed files with 43 additions and 37 deletions
+1 -1
View File
@@ -374,7 +374,7 @@ Turf and target are seperate in case you want to teleport some distance from a t
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))
if(!selected || (selected.connected_robots.len > A.connected_robots.len))
selected = A
return selected
+3 -8
View File
@@ -34,8 +34,7 @@ var/const/BORG_WIRE_CAMERA = 16
if (BORG_WIRE_AI_CONTROL) //Cut the AI wire to reset AI control
if(!mended)
if (R.connected_ai)
R.connected_ai = null
R.disconnect_from_ai()
if (BORG_WIRE_CAMERA)
if(!isnull(R.camera) && !R.scrambledcodes)
@@ -56,12 +55,8 @@ var/const/BORG_WIRE_CAMERA = 16
if (BORG_WIRE_AI_CONTROL) //pulse the AI wire to make the borg reselect an AI
if(!R.emagged)
var/mob/living/silicon/ai/new_ai = select_active_ai(R)
if(new_ai && (new_ai != R.connected_ai))
R.connected_ai.connected_robots -= src
R.connected_ai = new_ai
new_ai.connected_robots += src
R.notify_ai(1)
R.sync()
R.connect_to_ai(new_ai)
if (BORG_WIRE_CAMERA)
if(!isnull(R.camera) && R.camera.can_use() && !R.scrambledcodes)
R.camera.kick_viewers() // Kick anyone watching the Cyborg's camera
-1
View File
@@ -38,7 +38,6 @@
playsound(src.loc, 'sound/machines/ping.ogg', 50, 0)
if(robot)
robot.SetLockDown(0)
robot.notify_ai(1)
/obj/machinery/transformer/conveyor/New()
..()
@@ -226,7 +226,6 @@
feedback_inc("cyborg_birth",1)
callHook("borgify", list(O))
O.notify_ai(1)
O.Namepick()
del(src)
@@ -36,12 +36,12 @@
icon = 'icons/mob/custom-synthetic.dmi'
R.icon_state = "[R.ckey]-Standard"
del(R.module)
R.notify_ai(ROBOT_NOTIFICATION_MODULE_RESET, R.module.name)
R.module = null
R.camera.remove_networks(list("Engineering","Medical","MINE"))
R.updatename("Default")
R.status_flags |= CANPUSH
R.updateicon()
R.notify_ai(2)
return 1
@@ -57,7 +57,7 @@
/obj/item/borg/upgrade/rename/action(var/mob/living/silicon/robot/R)
if(..()) return 0
R.notify_ai(3, R.name, heldname)
R.notify_ai(ROBOT_NOTIFICATION_NEW_NAME, R.name, heldname)
R.name = heldname
R.custom_name = heldname
R.real_name = heldname
@@ -84,7 +84,7 @@
R.stat = CONSCIOUS
dead_mob_list -= R
living_mob_list |= R
R.notify_ai(1)
R.notify_ai(ROBOT_NOTIFICATION_NEW_UNIT)
return 1
@@ -54,8 +54,6 @@
/mob/living/silicon/robot/drone/init()
laws = new /datum/ai_laws/drone()
connected_ai = null
aiCamera = new/obj/item/device/camera/siliconcam/drone_camera(src)
playsound(src.loc, 'sound/machines/twobeep.ogg', 50, 0)
@@ -226,9 +226,7 @@
if(tra.current)
var/I = image('icons/mob/mob.dmi', loc = tra.current, icon_state = "traitor")
src.client.images += I
if(src.connected_ai)
src.connected_ai.connected_robots -= src
src.connected_ai = null
src.disconnect_from_ai()
if(src.mind)
if(!src.mind.special_role)
src.mind.special_role = "traitor"
+29 -16
View File
@@ -164,11 +164,10 @@ var/list/robot_verbs_default = list(
aiCamera = new/obj/item/device/camera/siliconcam/robot_camera(src)
laws = new /datum/ai_laws/nanotrasen()
additional_law_channels += "Binary"
connected_ai = select_active_ai_with_fewest_borgs()
if(connected_ai)
connected_ai.connected_robots += src
var/new_ai = select_active_ai_with_fewest_borgs()
if(new_ai)
lawupdate = 1
sync()
connect_to_ai(new_ai)
else
lawupdate = 0
@@ -365,7 +364,7 @@ var/list/robot_verbs_default = list(
choose_icon(6,module_sprites)
radio.config(module.channels)
notify_ai(2)
notify_ai(ROBOT_NOTIFICATION_NEW_MODULE, module.name)
/mob/living/silicon/robot/proc/updatename(var/prefix as text)
if(prefix)
@@ -385,7 +384,7 @@ var/list/robot_verbs_default = list(
else
changed_name = "[modtype] [braintype]-[num2text(ident)]"
notify_ai(3, real_name, changed_name)
notify_ai(ROBOT_NOTIFICATION_NEW_NAME, real_name, changed_name)
real_name = changed_name
name = real_name
@@ -802,7 +801,7 @@ var/list/robot_verbs_default = list(
if(prob(50))
emagged = 1
lawupdate = 0
connected_ai = null
disconnect_from_ai()
user << "You emag [src]'s interface."
message_admins("[key_name_admin(user)] emagged cyborg [key_name_admin(src)]. Laws overridden.")
log_game("[key_name(user)] emagged cyborg [key_name(src)]. Laws overridden.")
@@ -1134,8 +1133,7 @@ var/list/robot_verbs_default = list(
return
/mob/living/silicon/robot/proc/UnlinkSelf()
if (src.connected_ai)
src.connected_ai = null
disconnect_from_ai()
lawupdate = 0
lockcharge = 0
canmove = 1
@@ -1245,14 +1243,29 @@ var/list/robot_verbs_default = list(
return 1
return 0
/mob/living/silicon/robot/proc/notify_ai(var/notifytype, var/oldname, var/newname)
/mob/living/silicon/robot/proc/notify_ai(var/notifytype, var/first_arg, var/second_arg)
if(!connected_ai)
return
switch(notifytype)
if(1) //New Robot
if(ROBOT_NOTIFICATION_NEW_UNIT) //New Robot
connected_ai << "<br><br><span class='notice'>NOTICE - New [lowertext(braintype)] connection detected: <a href='byond://?src=\ref[connected_ai];track2=\ref[connected_ai];track=\ref[src]'>[name]</a></span><br>"
if(2) //New Module
connected_ai << "<br><br><span class='notice'>NOTICE - [braintype] module change detected: [name] has loaded the [module.name].</span><br>"
if(3) //New Name
if(oldname != newname)
connected_ai << "<br><br><span class='notice'>NOTICE - [braintype] reclassification detected: [oldname] is now designated as [newname].</span><br>"
if(ROBOT_NOTIFICATION_NEW_MODULE) //New Module
connected_ai << "<br><br><span class='notice'>NOTICE - [braintype] module change detected: [name] has loaded the [first_arg].</span><br>"
if(ROBOT_NOTIFICATION_MODULE_RESET)
connected_ai << "<br><br><span class='notice'>NOTICE - [braintype] module reset detected: [name] has unladed the [first_arg].</span><br>"
if(ROBOT_NOTIFICATION_NEW_NAME) //New Name
if(first_arg != second_arg)
connected_ai << "<br><br><span class='notice'>NOTICE - [braintype] reclassification detected: [first_arg] is now designated as [second_arg].</span><br>"
/mob/living/silicon/robot/proc/disconnect_from_ai()
if(connected_ai)
connected_ai.connected_robots -= src
connected_ai = null
/mob/living/silicon/robot/proc/connect_to_ai(var/mob/living/silicon/ai/AI)
if(AI && AI != connected_ai)
disconnect_from_ai()
connected_ai = AI
connected_ai.connected_robots |= src
notify_ai(ROBOT_NOTIFICATION_NEW_UNIT)
sync()
-1
View File
@@ -168,7 +168,6 @@
O.mmi.transfer_identity(src)
callHook("borgify", list(O))
O.notify_ai(1)
O.Namepick()
spawn(0)//To prevent the proc from returning null.
@@ -24,7 +24,6 @@
if(istype(M, /mob/living/silicon/robot))
var/mob/living/silicon/robot/Robot = M
if(Robot.mmi) del(Robot.mmi)
Robot.notify_ai(1)
else
for(var/obj/item/W in M)
if(istype(W, /obj/item/weapon/implant)) //TODO: Carn. give implants a dropped() or something
+6
View File
@@ -762,3 +762,9 @@ var/list/be_special_flags = list(
//General-purpose life speed define for plants.
#define HYDRO_SPEED_MULTIPLIER 1
#define NANO_IGNORE_DISTANCE 1
// Robot AI notifications
#define ROBOT_NOTIFICATION_NEW_UNIT 1
#define ROBOT_NOTIFICATION_NEW_NAME 2
#define ROBOT_NOTIFICATION_NEW_MODULE 3
#define ROBOT_NOTIFICATION_MODULE_RESET 4