|
1 | | -// Power Cells |
2 | | -/obj/item/cell |
3 | | - name = "power cell" |
4 | | - desc = "A rechargeable electrochemical power cell." |
5 | | - icon = 'icons/obj/power.dmi' |
6 | | - icon_state = "cell" |
7 | | - item_state = "cell" |
8 | | - origin_tech = @'{"powerstorage":1}' |
9 | | - throw_speed = 3 |
10 | | - throw_range = 5 |
11 | | - w_class = ITEM_SIZE_NORMAL |
12 | | - material = /decl/material/solid/metal/steel |
13 | | - matter = list( |
14 | | - /decl/material/solid/fiberglass = MATTER_AMOUNT_REINFORCEMENT, |
15 | | - /decl/material/solid/organic/plastic = MATTER_AMOUNT_TRACE |
16 | | - ) |
17 | | - var/charge // Current charge |
18 | | - var/maxcharge = 1000 // Capacity in Wh |
19 | | - |
20 | | -/obj/item/cell/Initialize() |
21 | | - . = ..() |
22 | | - if(isnull(charge)) |
23 | | - charge = maxcharge |
24 | | - update_icon() |
25 | | - |
26 | | -/obj/item/cell/drain_power(var/drain_check, var/surge, var/power = 0) |
27 | | - |
28 | | - if(drain_check) |
29 | | - return 1 |
30 | | - |
31 | | - if(charge <= 0) |
32 | | - return 0 |
33 | | - |
34 | | - var/cell_amt = power * CELLRATE |
35 | | - |
36 | | - return use(cell_amt) / CELLRATE |
37 | | - |
38 | | -/obj/item/cell/on_update_icon() |
39 | | - . = ..() |
40 | | - var/overlay_state = null |
41 | | - switch(percent()) |
42 | | - if(95 to 100) |
43 | | - overlay_state = "cell-o2" |
44 | | - if(25 to 95) |
45 | | - overlay_state = "cell-o1" |
46 | | - if(0.05 to 25) |
47 | | - overlay_state = "cell-o0" |
48 | | - if(overlay_state) |
49 | | - add_overlay(overlay_state) |
50 | | - |
51 | | -/obj/item/cell/proc/percent() // return % charge of cell |
52 | | - return maxcharge && (100.0*charge/maxcharge) |
53 | | - |
54 | | -/obj/item/cell/proc/fully_charged() |
55 | | - return (charge == maxcharge) |
56 | | - |
57 | | -// checks if the power cell is able to provide the specified amount of charge |
58 | | -/obj/item/cell/proc/check_charge(var/amount) |
59 | | - return (charge >= amount) |
60 | | - |
61 | | -// use power from a cell, returns the amount actually used |
62 | | -/obj/item/cell/proc/use(var/amount) |
63 | | - var/used = min(charge, amount) |
64 | | - charge -= used |
65 | | - update_icon() |
66 | | - return used |
67 | | - |
68 | | -// Checks if the specified amount can be provided. If it can, it removes the amount |
69 | | -// from the cell and returns 1. Otherwise does nothing and returns 0. |
70 | | -/obj/item/cell/proc/checked_use(var/amount) |
71 | | - if(!check_charge(amount)) |
72 | | - return 0 |
73 | | - use(amount) |
74 | | - return 1 |
75 | | - |
76 | | -/obj/item/cell/proc/give(var/amount) |
77 | | - var/amount_used = min(maxcharge-charge,amount) |
78 | | - charge += amount_used |
79 | | - update_icon() |
80 | | - return amount_used |
81 | | - |
82 | | -/obj/item/cell/get_examine_strings(mob/user, distance, infix, suffix) |
83 | | - . = ..() |
84 | | - . += "The label states it's capacity is [maxcharge] Wh." |
85 | | - . += "The charge meter reads [round(src.percent(), 0.1)]%." |
86 | | - |
87 | | -/obj/item/cell/emp_act(severity) |
88 | | - // remove this if EMPs are ever rebalanced so that they don't instantly drain borg cells |
89 | | - // todo: containers (partially) shielding contents? |
90 | | - if(isrobot(loc)) |
91 | | - var/mob/living/silicon/robot/robot = loc |
92 | | - severity *= robot.cell_emp_mult |
93 | | - |
94 | | - // Lose 1/2, 1/4, 1/6 of the current charge per hit or 1/4, 1/8, 1/12 of the max charge per hit, whichever is highest |
95 | | - charge -= max(charge / (2 * severity), maxcharge/(4 * severity)) |
96 | | - if (charge < 0) |
97 | | - charge = 0 |
98 | | - ..() |
99 | | - |
100 | | - |
101 | | -/obj/item/cell/proc/get_electrocute_damage() |
102 | | - switch (charge) |
103 | | - if (1000000 to INFINITY) |
104 | | - return min(rand(50,160),rand(50,160)) |
105 | | - if (200000 to 1000000-1) |
106 | | - return min(rand(25,80),rand(25,80)) |
107 | | - if (100000 to 200000-1)//Ave powernet |
108 | | - return min(rand(20,60),rand(20,60)) |
109 | | - if (50000 to 100000-1) |
110 | | - return min(rand(15,40),rand(15,40)) |
111 | | - if (1000 to 50000-1) |
112 | | - return min(rand(10,20),rand(10,20)) |
113 | | - else |
114 | | - return 0 |
115 | | - |
116 | | -/obj/item/cell/get_cell() |
117 | | - return src //no shit Sherlock |
118 | | - |
119 | | -// SUBTYPES BELOW |
120 | | - |
121 | 1 | // Smaller variant, used by energy guns and similar small devices. |
122 | 2 | /obj/item/cell/device |
123 | 3 | name = "device power cell" |
|
0 commit comments