-
-
Notifications
You must be signed in to change notification settings - Fork 452
/
pneumaticCannon.dm
389 lines (358 loc) · 13.5 KB
/
pneumaticCannon.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#define PCANNON_FIREALL 1 // Shoot all items on fire.
#define PCANNON_FILO 2 // Shoot the newest (last) item inserted on fire.
#define PCANNON_FIFO 3 // Shoot the oldest (first) item inserted on fire.
/obj/item/pneumatic_cannon
name = "pneumatic cannon"
desc = "A gas-powered cannon that can fire any object loaded into it."
w_class = WEIGHT_CLASS_BULKY
force = 8 //Very heavy
attack_verb = list("bludgeoned", "smashed", "beaten")
icon = 'icons/obj/pneumaticCannon.dmi'
icon_state = "pneumaticCannon"
item_state = "bulldog"
lefthand_file = 'icons/mob/inhands/weapons/guns_lefthand.dmi'
righthand_file = 'icons/mob/inhands/weapons/guns_righthand.dmi'
armor = list(MELEE = 0, BULLET = 0, LASER = 0, ENERGY = 0, BOMB = 0, BIO = 0, RAD = 0, FIRE = 60, ACID = 50)
trigger_guard = TRIGGER_GUARD_NORMAL
/// The max weight of items that can fit in the cannon.
var/maxWeightClass = 20
/// The weight of items currently in the cannon.
var/loadedWeightClass = 0
/// The loaded items in the cannon that will be fired out.
var/list/loadedItems = list()
/// The multiplier for how far will the items be thrown. 1 is exact distance of the target; higher will multiply by that number.
var/range_multiplier = 1
/// How many items in `loadedItems` will be thrown per fire if not on PCANNON_FIREALL?
var/throw_amount = 20
/// The sound played upon firing.
var/fire_sound = 'sound/weapons/sonic_jackhammer.ogg'
/// Should projectiles spin when they are launched?
var/spin_item = TRUE
/// Prevents firing if there is no tank.
var/checktank = TRUE
/// The gas tank that is drawn from to fire things.
var/obj/item/tank/internals/tank = null
/// How much gas is removed from a tank's pressure when fired?
var/gasPerThrow = 3
/// How powerful the cannon is. Higher pressure = more gas cost (if there is one), further distance, faster speed, etc.
var/pressureSetting = 1
/// The fire mode. Can be PCANNON_FIREALL, PCANNON_FILO, or PCANNON_FIFO.
var/fire_mode = PCANNON_FIREALL
/// Can you shoot this cannon automatically via click-and-hold?
var/automatic = FALSE
/// Should clumsy people have a chance to fail/backfire?
var/clumsyCheck = TRUE
/// List of allowed items to be loaded. Leave as null to allow all.
var/list/allowed_typecache
/// Should this cannon automatically recharge?
var/selfcharge = FALSE
/// How many `charge_type` should be loaded if `self-charge` is true and `charge_cooldown` seconds have passed?
var/charge_amount = 1
/// What item path should be loaded into the cannon for `self-charge`?
var/charge_type
/// How many seconds before it self-recharges?
var/recharge_cooldown = 2 SECONDS // 1 tick = 2 seconds.
/// How many seconds passed since last `process()` and haven't been spent on self-recharging?
var/seconds_time_remaining = 0
/// A list of items that cannot ever be inserted into the cannon.
var/list/blacklist_items = list(
/obj/item/melee/baton,
/obj/item/melee/supermatter_sword
)
/obj/item/pneumatic_cannon/Initialize(mapload)
. = ..()
if(selfcharge)
START_PROCESSING(SSobj, src)
// There was a `/proc/init_charge` that had a comment that suggested that admins can call it to enable self-recharging. So, this replaced that; now they can just set the variable to do the same thing.
/// Starts and stops processing based on `self_recharging` variable.
/obj/item/pneumatic_cannon/vv_edit_var(var_name, var_value)
if(var_name == "selfcharge")
switch(var_value)
if(-INFINITY to 0)
STOP_PROCESSING(SSobj, src)
else
START_PROCESSING(SSobj, src)
return ..()
/obj/item/pneumatic_cannon/process(delta_time)
if(selfcharge && charge_amount && charge_type && recharge_cooldown)
seconds_time_remaining += delta_time * 1 SECONDS // You might think that this should use `COOLDOWN_DECLARE()`, but it shouldn't because process is inconsistent.
var/attempts = 1
while(seconds_time_remaining > recharge_cooldown)
attempts += 1
seconds_time_remaining -= recharge_cooldown
fill_with_type(charge_type, charge_amount)
if(attempts > 10) // Prevents an infinite if anything goes wrong (bad adminbus).
seconds_time_remaining = 0
break
/obj/item/pneumatic_cannon/Destroy()
STOP_PROCESSING(SSobj, src)
return ..()
/obj/item/pneumatic_cannon/CanItemAutoclick()
return automatic
/obj/item/pneumatic_cannon/examine(mob/user)
. = ..()
var/list/out = list()
if(!in_range(user, src))
out += span_notice("You'll need to get closer to see any more.")
return
for(var/obj/item/I in loadedItems)
out += span_info("[icon2html(I, user)] It has \a [I] loaded.")
CHECK_TICK
if(tank)
out += span_notice("[icon2html(tank, user)] It has \a [tank] mounted onto it.")
. += out.Join("\n")
/obj/item/pneumatic_cannon/attackby(obj/item/W, mob/living/user, params)
if(user.combat_mode)
return ..()
if(istype(W, /obj/item/tank/internals))
if(!tank)
var/obj/item/tank/internals/IT = W
if(IT.volume <= 3)
to_chat(user, span_warning("\The [IT] is too small for \the [src]."))
return
updateTank(W, 0, user)
else
load_item(W, user) // if there's already a tank attached, load it instead
else if(W.type == type)
to_chat(user, span_warning("You're fairly certain that putting a pneumatic cannon inside another pneumatic cannon would cause a spacetime disruption."))
else if(W.tool_behaviour == TOOL_WRENCH)
switch(pressureSetting)
if(1)
pressureSetting = 2
if(2)
pressureSetting = 3
if(3)
pressureSetting = 1
to_chat(user, span_notice("You tweak \the [src]'s pressure output to [pressureSetting]."))
else if(W.tool_behaviour == TOOL_SCREWDRIVER)
if(tank)
updateTank(tank, 1, user)
else if(loadedWeightClass >= maxWeightClass)
to_chat(user, span_warning("\The [src] can't hold any more items!"))
else if(isitem(W))
var/obj/item/IW = W
load_item(IW, user)
/obj/item/pneumatic_cannon/proc/can_load_item(obj/item/I, mob/user)
if(!istype(I)) //Players can't load non items, this allows for admin varedit inserts.
return TRUE
if(blacklist_items && is_type_in_list(I, blacklist_items))
if(user)
to_chat(user, span_warning("You are prevented from putting [I] into [src]!"))
return
if(allowed_typecache && !is_type_in_typecache(I, allowed_typecache))
if(user)
to_chat(user, span_warning("[I] won't fit into [src]!"))
return
if((loadedWeightClass + I.w_class) > maxWeightClass) //Only make messages if there's a user
if(user)
to_chat(user, span_warning("\The [I] won't fit into \the [src]!"))
return FALSE
if(I.w_class > w_class)
if(user)
to_chat(user, span_warning("\The [I] is too large to fit into \the [src]!"))
return FALSE
return TRUE
/obj/item/pneumatic_cannon/proc/load_item(obj/item/I, mob/user)
if(!can_load_item(I, user))
return FALSE
if(user) //Only use transfer proc if there's a user, otherwise just set loc.
if(!user.transferItemToLoc(I, src))
return FALSE
to_chat(user, span_notice("You load \the [I] into \the [src]."))
else
I.forceMove(src)
loadedItems += I
loadedWeightClass += I.w_class
return TRUE
/obj/item/pneumatic_cannon/afterattack(atom/target, mob/living/user, flag, params)
. = ..()
if(flag && user.combat_mode) //melee attack
return
if(!istype(user))
return
Fire(user, target)
/obj/item/pneumatic_cannon/proc/Fire(mob/living/user, atom/target)
if(!istype(user) && !target)
return
var/discharge = 0
if(!can_trigger_gun(user))
return
if(!loadedItems || !loadedWeightClass)
to_chat(user, span_warning("\The [src] has nothing loaded."))
return
if(!tank && checktank)
to_chat(user, span_warning("\The [src] can't fire without a source of gas."))
return
if(tank && !tank.air_contents.remove(gasPerThrow * pressureSetting))
to_chat(user, span_warning("\The [src] lets out a weak hiss and doesn't react!"))
return
if(HAS_TRAIT(user, TRAIT_CLUMSY) && prob(75) && clumsyCheck && iscarbon(user))
var/mob/living/carbon/C = user
C.visible_message(span_warning("[C] loses [C.p_their()] grip on [src], causing it to go off!"), span_userdanger("[src] slips out of your hands and goes off!"))
C.dropItemToGround(src, TRUE)
if(prob(10))
target = get_turf(user)
else
var/list/possible_targets = range(3,src)
target = pick(possible_targets)
discharge = 1
if(!discharge)
user.visible_message(span_danger("[user] fires \the [src]!"), \
span_danger("You fire \the [src]!"))
log_combat(user, target, "fired at", src)
var/turf/T = get_target(target, get_turf(src))
playsound(src, fire_sound, 50, 1)
fire_items(T, user)
if(pressureSetting >= 3 && iscarbon(user))
var/mob/living/carbon/C = user
C.visible_message(span_warning("[C] is thrown down by the force of the cannon!"), "<span class='userdanger'>[src] slams into your shoulder, knocking you down!")
C.Paralyze(60)
/obj/item/pneumatic_cannon/proc/fire_items(turf/target, mob/user)
if(fire_mode == PCANNON_FIREALL)
for(var/obj/item/ITD in loadedItems) //Item To Discharge
if(!throw_item(target, ITD, user))
break
else
for(var/i in 1 to throw_amount)
if(!loadedItems.len)
break
var/obj/item/I
if(fire_mode == PCANNON_FILO)
I = loadedItems[loadedItems.len]
else
I = loadedItems[1]
if(!throw_item(target, I, user))
break
/obj/item/pneumatic_cannon/proc/throw_item(turf/target, obj/item/I, mob/user)
if(!istype(I))
return FALSE
loadedItems -= I
loadedWeightClass -= I.w_class
I.forceMove(get_turf(src))
I.throw_at(target, pressureSetting * 10 * range_multiplier, pressureSetting * 2, user, spin_item)
return TRUE
/obj/item/pneumatic_cannon/proc/get_target(turf/target, turf/starting)
if(range_multiplier == 1)
return target
var/x_o = (target.x - starting.x)
var/y_o = (target.y - starting.y)
var/new_x = clamp((starting.x + (x_o * range_multiplier)), 0, world.maxx)
var/new_y = clamp((starting.y + (y_o * range_multiplier)), 0, world.maxy)
var/turf/newtarget = locate(new_x, new_y, starting.z)
return newtarget
/obj/item/pneumatic_cannon/handle_atom_del(atom/A)
. = ..()
if (loadedItems.Remove(A))
var/obj/item/I = A
loadedWeightClass -= I.w_class
else if (A == tank)
tank = null
update_appearance(UPDATE_ICON)
/obj/item/pneumatic_cannon/ghetto //Obtainable by improvised methods; more gas per use, less capacity
name = "improvised pneumatic cannon"
desc = "A gas-powered, object-firing cannon made out of common parts."
force = 5
maxWeightClass = 7
gasPerThrow = 5
/obj/item/pneumatic_cannon/proc/updateTank(obj/item/tank/internals/thetank, removing = 0, mob/living/carbon/human/user)
if(removing)
if(!tank)
return
to_chat(user, span_notice("You detach \the [thetank] from \the [src]."))
tank.forceMove(user.drop_location())
user.put_in_hands(tank)
tank = null
if(!removing)
if(tank)
to_chat(user, span_warning("\The [src] already has a tank."))
return
if(!user.transferItemToLoc(thetank, src))
return
to_chat(user, span_notice("You hook \the [thetank] up to \the [src]."))
tank = thetank
update_appearance(UPDATE_ICON)
/obj/item/pneumatic_cannon/update_overlays()
. = ..()
if(!tank)
return
. += tank.icon_state
/obj/item/pneumatic_cannon/proc/fill_with_type(type, amount)
if(!ispath(type, /obj) && !ispath(type, /mob))
return FALSE
var/loaded = 0
for(var/i in 1 to amount)
var/obj/item/I = new type
if(!load_item(I, null))
qdel(I)
return loaded
loaded++
CHECK_TICK
/obj/item/pneumatic_cannon/pie
name = "pie cannon"
desc = "Load cream pie for optimal results."
force = 10
icon_state = "piecannon"
gasPerThrow = 0
checktank = FALSE
range_multiplier = 3
fire_mode = PCANNON_FIFO
throw_amount = 1
maxWeightClass = 150 //50 pies. :^)
clumsyCheck = FALSE
var/static/list/pie_typecache = typecacheof(/obj/item/reagent_containers/food/snacks/pie)
/obj/item/pneumatic_cannon/pie/Initialize(mapload)
. = ..()
allowed_typecache = pie_typecache
/obj/item/pneumatic_cannon/pie/selfcharge
automatic = TRUE
selfcharge = TRUE
charge_type = /obj/item/reagent_containers/food/snacks/pie/cream
maxWeightClass = 60 //20 pies.
/obj/item/pneumatic_cannon/pie/selfcharge/compact
name = "honkinator-4 compact pie cannon"
desc = "A compact, self-loading pie cannon for tactical pranking action."
w_class = WEIGHT_CLASS_NORMAL
/obj/item/pneumatic_cannon/pie/selfcharge/cyborg
name = "low velocity pie cannon"
automatic = FALSE
charge_type = /obj/item/reagent_containers/food/snacks/pie/cream/nostun
maxWeightClass = 6 //2 pies
recharge_cooldown = 4 SECONDS
/obj/item/pneumatic_cannon/speargun
name = "kinetic speargun"
desc = "A weapon favored by carp hunters. Fires specialized spears using kinetic energy."
icon = 'icons/obj/guns/projectile.dmi'
icon_state = "speargun"
item_state = "speargun"
w_class = WEIGHT_CLASS_BULKY
force = 10
fire_sound = 'sound/weapons/grenadelaunch.ogg'
pressureSetting = 2 //yogs: makes spears embed without messing with the speargun
gasPerThrow = 0
checktank = FALSE
range_multiplier = 3
throw_amount = 1
maxWeightClass = 2 //a single magspear
spin_item = FALSE
var/static/list/magspear_typecache = typecacheof(/obj/item/throwing_star/magspear)
/obj/item/pneumatic_cannon/speargun/Initialize(mapload)
. = ..()
allowed_typecache = magspear_typecache
/obj/item/storage/magspear_quiver
name = "quiver"
desc = "A quiver for holding magspears."
slot_flags = ITEM_SLOT_POCKETS
icon_state = "quiver"
item_state = "quiver"
/obj/item/storage/magspear_quiver/Initialize(mapload)
. = ..()
var/datum/component/storage/STR = GetComponent(/datum/component/storage)
STR.max_items = 20
STR.max_combined_w_class = 40
STR.display_numerical_stacking = TRUE
STR.set_holdable(list(
/obj/item/throwing_star/magspear,
))
/obj/item/storage/magspear_quiver/PopulateContents()
for(var/i in 1 to 20)
new /obj/item/throwing_star/magspear(src)