Skip to content

Commit

Permalink
[MIRROR] Improves code for power usage of energy weapons [MDB IGNORE]…
Browse files Browse the repository at this point in the history
… (#24323)

* Improves code for power usage of energy weapons

* Modular update

* This comment was wrong, it was 10 before

* One last modular

---------

Co-authored-by: GPeckman <[email protected]>
Co-authored-by: Giz <[email protected]>
  • Loading branch information
3 people authored and Iajret committed Oct 15, 2023
1 parent 3ab93db commit 198cd24
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 84 deletions.
6 changes: 6 additions & 0 deletions code/__DEFINES/projectiles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@

#define RETURN_POINT_VECTOR(ATOM, ANGLE, SPEED) (new /datum/point/vector(ATOM, null, null, null, null, ANGLE, SPEED))
#define RETURN_POINT_VECTOR_INCREMENT(ATOM, ANGLE, SPEED, AMT) (new /datum/point/vector(ATOM, null, null, null, null, ANGLE, SPEED, AMT))

/// The amount of energy that a standard energy weapon cell can hold
#define STANDARD_CELL_CHARGE 1000
/// Macro to turn a number of laser shots into an energy cost, based on the above define
/// e.g. LASER_SHOTS(12, STANDARD_CELL_CHARGE) means 12 shots
#define LASER_SHOTS(X, MAX_CHARGE) (((100 * MAX_CHARGE) - ((100 * MAX_CHARGE) % X)) / (100 * X)) // I wish I could just use round, but it can't be used in datum members
2 changes: 1 addition & 1 deletion code/modules/capture_the_flag/ctf_equipment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

/obj/item/ammo_casing/energy/instakill
projectile_type = /obj/projectile/beam/instakill
e_cost = 0
e_cost = 0 // Not possible to use the macro
select_name = "DESTROY"

/obj/projectile/beam/instakill
Expand Down
68 changes: 34 additions & 34 deletions code/modules/power/cell.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
///Current charge in cell units
var/charge = 0
///Maximum charge in cell units
var/maxcharge = 1000
var/maxcharge = STANDARD_CELL_CHARGE
custom_materials = list(/datum/material/iron=SMALL_MATERIAL_AMOUNT*7, /datum/material/glass=SMALL_MATERIAL_AMOUNT*0.5)
grind_results = list(/datum/reagent/lithium = 15, /datum/reagent/iron = 5, /datum/reagent/silicon = 5)
///If the cell has been booby-trapped by injecting it with plasma. Chance on use() to explode.
var/rigged = FALSE
///If the power cell was damaged by an explosion, chance for it to become corrupted and function the same as rigged.
var/corrupted = FALSE
///how much power is given every tick in a recharger
var/chargerate = 100
var/chargerate = STANDARD_CELL_CHARGE * 0.1
///If true, the cell will state it's maximum charge in it's description
var/ratingdesc = TRUE
///If it's a grown that acts as a battery, add a wire overlay to it.
Expand All @@ -51,7 +51,7 @@
create_reagents(5, INJECTABLE | DRAINABLE)
if (override_maxcharge)
maxcharge = override_maxcharge
rating = max(round(maxcharge / 10000, 1), 1)
rating = max(round(maxcharge / (STANDARD_CELL_CHARGE * 10), 1), 1)
if(!charge)
charge = maxcharge
if(empty)
Expand Down Expand Up @@ -82,7 +82,7 @@
. = COMPONENT_ITEM_CHARGED

if(prob(80))
maxcharge -= 200
maxcharge -= STANDARD_CELL_CHARGE * 0.2

if(maxcharge <= 1) // Div by 0 protection
maxcharge = 1
Expand Down Expand Up @@ -289,7 +289,7 @@
/obj/item/stock_parts/cell/crap
name = "\improper Nanotrasen brand rechargeable AA battery"
desc = "You can't top the plasma top." //TOTALLY TRADEMARK INFRINGEMENT
maxcharge = 500
maxcharge = STANDARD_CELL_CHARGE * 0.5
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.4)

/obj/item/stock_parts/cell/crap/empty
Expand All @@ -298,77 +298,77 @@
/obj/item/stock_parts/cell/upgraded
name = "upgraded power cell"
desc = "A power cell with a slightly higher capacity than normal!"
maxcharge = 2500
maxcharge = STANDARD_CELL_CHARGE * 2.5
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.5)
chargerate = 1000
chargerate = STANDARD_CELL_CHARGE

/obj/item/stock_parts/cell/upgraded/plus
name = "upgraded power cell+"
desc = "A power cell with an even higher capacity than the base model!"
maxcharge = 5000
maxcharge = STANDARD_CELL_CHARGE * 5

/obj/item/stock_parts/cell/secborg
name = "security borg rechargeable D battery"
maxcharge = 600 //600 max charge / 100 charge per shot = six shots
maxcharge = STANDARD_CELL_CHARGE * 0.6
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.4)

/obj/item/stock_parts/cell/secborg/empty
empty = TRUE

/obj/item/stock_parts/cell/mini_egun
name = "miniature energy gun power cell"
maxcharge = 600
maxcharge = STANDARD_CELL_CHARGE * 0.6

/obj/item/stock_parts/cell/hos_gun
name = "X-01 multiphase energy gun power cell"
maxcharge = 1200
maxcharge = STANDARD_CELL_CHARGE * 1.2

/obj/item/stock_parts/cell/pulse //200 pulse shots
name = "pulse rifle power cell"
maxcharge = 40000
chargerate = 1500
maxcharge = STANDARD_CELL_CHARGE * 40
chargerate = STANDARD_CELL_CHARGE * 1.5

/obj/item/stock_parts/cell/pulse/carbine //25 pulse shots
name = "pulse carbine power cell"
maxcharge = 5000
maxcharge = STANDARD_CELL_CHARGE * 5

/obj/item/stock_parts/cell/pulse/pistol //10 pulse shots
name = "pulse pistol power cell"
maxcharge = 2000
maxcharge = STANDARD_CELL_CHARGE * 2

/obj/item/stock_parts/cell/ninja
name = "black power cell"
icon_state = "bscell"
maxcharge = 10000
maxcharge = STANDARD_CELL_CHARGE * 10
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.6)
chargerate = 2000
chargerate = STANDARD_CELL_CHARGE * 2

/obj/item/stock_parts/cell/high
name = "high-capacity power cell"
icon_state = "hcell"
maxcharge = 10000
maxcharge = STANDARD_CELL_CHARGE * 10
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*0.6)
chargerate = 1500
chargerate = STANDARD_CELL_CHARGE * 1.5

/obj/item/stock_parts/cell/high/empty
empty = TRUE

/obj/item/stock_parts/cell/super
name = "super-capacity power cell"
icon_state = "scell"
maxcharge = 20000
maxcharge = STANDARD_CELL_CHARGE * 20
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT * 3)
chargerate = 2000
chargerate = STANDARD_CELL_CHARGE * 2

/obj/item/stock_parts/cell/super/empty
empty = TRUE

/obj/item/stock_parts/cell/hyper
name = "hyper-capacity power cell"
icon_state = "hpcell"
maxcharge = 30000
maxcharge = STANDARD_CELL_CHARGE * 30
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT * 4)
chargerate = 3000
chargerate = STANDARD_CELL_CHARGE * 3

/obj/item/stock_parts/cell/hyper/empty
empty = TRUE
Expand All @@ -377,9 +377,9 @@
name = "bluespace power cell"
desc = "A rechargeable transdimensional power cell."
icon_state = "bscell"
maxcharge = 40000
maxcharge = STANDARD_CELL_CHARGE * 40
custom_materials = list(/datum/material/glass=SMALL_MATERIAL_AMOUNT*6)
chargerate = 4000
chargerate = STANDARD_CELL_CHARGE * 4

/obj/item/stock_parts/cell/bluespace/empty
empty = TRUE
Expand All @@ -400,7 +400,7 @@
desc = "An alien power cell that produces energy seemingly out of nowhere."
icon = 'icons/obj/antags/abductor.dmi'
icon_state = "cell"
maxcharge = 50000
maxcharge = STANDARD_CELL_CHARGE * 50
ratingdesc = FALSE

/obj/item/stock_parts/cell/infinite/abductor/Initialize(mapload)
Expand All @@ -413,7 +413,7 @@
icon = 'icons/obj/service/hydroponics/harvest.dmi'
icon_state = "potato"
charge = 100
maxcharge = 300
maxcharge = STANDARD_CELL_CHARGE * 0.3
charge_light_type = null
connector_type = null
custom_materials = null
Expand All @@ -423,7 +423,7 @@
/obj/item/stock_parts/cell/emproof
name = "\improper EMP-proof cell"
desc = "An EMP-proof cell."
maxcharge = 500
maxcharge = STANDARD_CELL_CHARGE * 0.5

/obj/item/stock_parts/cell/emproof/Initialize(mapload)
AddElement(/datum/element/empprotection, EMP_PROTECT_SELF)
Expand All @@ -441,15 +441,15 @@
icon = 'icons/mob/simple/slimes.dmi'
icon_state = "yellow slime extract"
custom_materials = null
maxcharge = 5000
maxcharge = STANDARD_CELL_CHARGE * 5
charge_light_type = null
connector_type = "slimecore"

/obj/item/stock_parts/cell/beam_rifle
name = "beam rifle capacitor"
desc = "A high powered capacitor that can provide huge amounts of energy in an instant."
maxcharge = 50000
chargerate = 5000 //Extremely energy intensive
maxcharge = STANDARD_CELL_CHARGE * 50
chargerate = STANDARD_CELL_CHARGE * 5 //Extremely energy intensive

/obj/item/stock_parts/cell/beam_rifle/corrupt()
return
Expand All @@ -463,7 +463,7 @@
/obj/item/stock_parts/cell/emergency_light
name = "miniature power cell"
desc = "A tiny power cell with a very low power capacity. Used in light fixtures to power them in the event of an outage."
maxcharge = 120 //Emergency lights use 0.2 W per tick, meaning ~10 minutes of emergency power from a cell
maxcharge = STANDARD_CELL_CHARGE * 0.12 //Emergency lights use 0.2 W per tick, meaning ~10 minutes of emergency power from a cell
custom_materials = list(/datum/material/glass = SMALL_MATERIAL_AMOUNT*0.2)
w_class = WEIGHT_CLASS_TINY

Expand All @@ -478,15 +478,15 @@
name = "crystal power cell"
desc = "A very high power cell made from crystallized plasma"
icon_state = "crystal_cell"
maxcharge = 50000
maxcharge = STANDARD_CELL_CHARGE * 50
chargerate = 0
charge_light_type = null
connector_type = "crystal"
custom_materials = null
grind_results = null

/obj/item/stock_parts/cell/inducer_supply
maxcharge = 5000
maxcharge = STANDARD_CELL_CHARGE * 5

#undef CELL_DRAIN_TIME
#undef CELL_POWER_GAIN
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/_energy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
caliber = ENERGY
projectile_type = /obj/projectile/energy
slot_flags = null
var/e_cost = 100 //The amount of energy a cell needs to expend to create this shot.
var/e_cost = LASER_SHOTS(10, STANDARD_CELL_CHARGE) //The amount of energy a cell needs to expend to create this shot.
var/select_name = CALIBER_ENERGY
fire_sound = 'sound/weapons/laser.ogg'
firing_effect_type = /obj/effect/temp_visual/dir_setting/firing_effect/energy
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/ebow.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/obj/item/ammo_casing/energy/bolt
projectile_type = /obj/projectile/energy/bolt
select_name = "bolt"
e_cost = 500
e_cost = LASER_SHOTS(1, STANDARD_CELL_CHARGE * 0.5)
fire_sound = 'sound/weapons/gun/general/heavy_shot_suppressed.ogg' // Even for non-suppressed crossbows, this is the most appropriate sound

/obj/item/ammo_casing/energy/bolt/halloween
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/gravity.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/obj/item/ammo_casing/energy/gravity
e_cost = 0
e_cost = 0 // Not possible to use the macro
fire_sound = 'sound/weapons/wave.ogg'
select_name = "gravity"
delay = 50
Expand Down
25 changes: 11 additions & 14 deletions code/modules/projectiles/ammunition/energy/laser.dm
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
/obj/item/ammo_casing/energy/laser
projectile_type = /obj/projectile/beam/laser
e_cost = 83
e_cost = LASER_SHOTS(12, STANDARD_CELL_CHARGE)
select_name = "kill"

/obj/item/ammo_casing/energy/laser/hellfire
projectile_type = /obj/projectile/beam/laser/hellfire
e_cost = 100
e_cost = LASER_SHOTS(10, STANDARD_CELL_CHARGE)
select_name = "maim"

/obj/item/ammo_casing/energy/laser/hellfire/antique
e_cost = 100

/obj/item/ammo_casing/energy/lasergun
projectile_type = /obj/projectile/beam/laser
e_cost = 62.5
e_cost = LASER_SHOTS(16, STANDARD_CELL_CHARGE)
select_name = "kill"

/obj/item/ammo_casing/energy/lasergun/carbine
projectile_type = /obj/projectile/beam/laser/carbine
e_cost = 25 // 40 shots
e_cost = LASER_SHOTS(40, STANDARD_CELL_CHARGE)
select_name = "kill"

/obj/item/ammo_casing/energy/lasergun/old
projectile_type = /obj/projectile/beam/laser
e_cost = 200
e_cost = LASER_SHOTS(5, STANDARD_CELL_CHARGE)
select_name = "kill"

/obj/item/ammo_casing/energy/laser/hos
e_cost = 120
e_cost = LASER_SHOTS(10, STANDARD_CELL_CHARGE * 1.2)

/obj/item/ammo_casing/energy/laser/musket
projectile_type = /obj/projectile/beam/laser/musket
e_cost = 1000
e_cost = LASER_SHOTS(1, STANDARD_CELL_CHARGE)

/obj/item/ammo_casing/energy/laser/musket/prime
projectile_type = /obj/projectile/beam/laser/musket/prime
Expand All @@ -43,7 +40,7 @@

/obj/item/ammo_casing/energy/chameleon
projectile_type = /obj/projectile/energy/chameleon
e_cost = 0
e_cost = 0 // Can't really use the macro here, unfortunately
var/projectile_vars = list()

/obj/item/ammo_casing/energy/chameleon/ready_proj()
Expand Down Expand Up @@ -83,7 +80,7 @@

/obj/item/ammo_casing/energy/laser/pulse
projectile_type = /obj/projectile/beam/pulse
e_cost = 200
e_cost = LASER_SHOTS(200, STANDARD_CELL_CHARGE * 40)
select_name = "DESTROY"
fire_sound = 'sound/weapons/pulse.ogg'

Expand All @@ -105,7 +102,7 @@

/obj/item/ammo_casing/energy/xray
projectile_type = /obj/projectile/beam/xray
e_cost = 50
e_cost = LASER_SHOTS(20, STANDARD_CELL_CHARGE)
fire_sound = 'sound/weapons/laser3.ogg'

/obj/item/ammo_casing/energy/mindflayer
Expand All @@ -121,7 +118,7 @@
/obj/item/ammo_casing/energy/nanite
projectile_type = /obj/projectile/bullet/c10mm //henk
select_name = "bullet"
e_cost = 120
e_cost = LASER_SHOTS(8, STANDARD_CELL_CHARGE)
fire_sound = 'sound/weapons/thermalpistol.ogg'

/obj/item/ammo_casing/energy/nanite/inferno
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/lmg.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
projectile_type = /obj/projectile/bullet/c3d
select_name = "spraydown"
fire_sound = 'sound/weapons/gun/smg/shot.ogg'
e_cost = 20
e_cost = LASER_SHOTS(30, STANDARD_CELL_CHARGE * 0.6)
firing_effect_type = /obj/effect/temp_visual/dir_setting/firing_effect
4 changes: 2 additions & 2 deletions code/modules/projectiles/ammunition/energy/plasma.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
select_name = "plasma burst"
fire_sound = 'sound/weapons/plasma_cutter.ogg'
delay = 15
e_cost = 25
e_cost = LASER_SHOTS(40, STANDARD_CELL_CHARGE)

/obj/item/ammo_casing/energy/plasma/adv
projectile_type = /obj/projectile/plasma/adv
delay = 10
e_cost = 10
e_cost = LASER_SHOTS(100, STANDARD_CELL_CHARGE)
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/portal.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/obj/item/ammo_casing/energy/wormhole
projectile_type = /obj/projectile/beam/wormhole
e_cost = 0
e_cost = 0 // Can't use the macro
harmful = FALSE
fire_sound = 'sound/weapons/pulse3.ogg'
select_name = "blue"
Expand Down
Loading

0 comments on commit 198cd24

Please sign in to comment.