Optimalisations

This commit is contained in:
Atlantiscze
2014-12-31 01:53:53 +01:00
parent 7ceade9320
commit 3c41d77b1a
2 changed files with 14 additions and 8 deletions

View File

@@ -411,8 +411,14 @@
drain_complete(H) drain_complete(H)
return return
// Attempts to drain up to 40kW if(holder.cell.fully_charged())
var/target_drained = interfaced_with.drain_power(0,0,40000) H << "<span class = 'warning'>Your power sink flashes an amber light; your rig cell is full.</span>"
drain_complete(H)
return
// Attempts to drain up to 40kW, determines this value from remaining cell capacity to ensure we don't drain too much..
var/to_drain = min(40000, ((holder.cell.maxcharge - holder.cell.charge) / CELLRATE))
var/target_drained = interfaced_with.drain_power(0,0,to_drain)
if(target_drained <= 0) if(target_drained <= 0)
H << "<span class = 'danger'>Your power sink flashes a red light; there is no power left in [interfaced_with].</span>" H << "<span class = 'danger'>Your power sink flashes a red light; there is no power left in [interfaced_with].</span>"
drain_complete(H) drain_complete(H)
@@ -421,19 +427,16 @@
holder.cell.give(target_drained * CELLRATE) holder.cell.give(target_drained * CELLRATE)
total_power_drained += target_drained total_power_drained += target_drained
if(holder.cell.fully_charged())
H << "<span class = 'warning'>Your power sink flashes an amber light; your rig cell is full.</span>"
drain_complete(H)
return
return 1 return 1
/obj/item/rig_module/power_sink/proc/drain_complete(var/mob/living/M) /obj/item/rig_module/power_sink/proc/drain_complete(var/mob/living/M)
if(!interfaced_with) if(!interfaced_with)
if(M) M << "<font color='blue'><b>Total power drained:</b> [total_power_drained]J.</font>" if(M) M << "<font color='blue'><b>Total power drained:</b> [round(total_power_drained/1000)]kJ.</font>"
else else
if(M) M << "<font color='blue'><b>Total power drained from [interfaced_with]:</b> [total_power_drained]J.</font>" if(M) M << "<font color='blue'><b>Total power drained from [interfaced_with]:</b> [round(total_power_drained/1000)]kJ.</font>"
interfaced_with.drain_power(0,1,0) // Damage the victim. interfaced_with.drain_power(0,1,0) // Damage the victim.
interfaced_with = null interfaced_with = null

View File

@@ -14,6 +14,9 @@
if(drain_check) if(drain_check)
return 1 return 1
if(charge <= 0)
return 0
var/cell_amt = min((amount * CELLRATE), charge) var/cell_amt = min((amount * CELLRATE), charge)
use(cell_amt) use(cell_amt)
return cell_amt / CELLRATE return cell_amt / CELLRATE