-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtank.lua
675 lines (631 loc) · 20.3 KB
/
tank.lua
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
-- compatibility stuff
local hud_elem_type_key = minetest.features.hud_def_type_field and "type" or "hud_elem_type"
local function set_bone_position(obj, bone, pos, rot)
if obj.set_bone_override then
pos = {vec = pos, interpolation = 0, absolute = true}
rot = {vec = vector.apply(rot, math.rad), interpolation = 0, absolute = true}
obj:set_bone_override(bone, {position = pos, rotation = rot})
else
obj:set_bone_position(bone, pos, rot)
end
end
local registered_turrets = {}
function mvehicles.register_tank_turret(name, def)
def.bones = def.bones or {}
def.on_activate = def.on_activate or function(tank)
tank.turret = minetest.add_entity(tank.object:get_pos(), def.entity, "stay")
tank.turret:set_attach(tank.object, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
end
registered_turrets[name] = def
end
local gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.81
local function create_id(self)
for i, obj in pairs(minetest.object_refs) do
if obj == self.object then
self.id = i
break
end
end
end
local function create_inv(self, inv_content)
self.inv = minetest.create_detached_inventory("mvehicles:tank"..self.id, {
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
if to_list == "fuel" then
local stack = inv:get_stack(from_list, from_index)
stack:set_count(count)
local output, _decremented_input = minetest.get_craft_result({method = "fuel", width = 1, items = {stack}})
if output.time == 0 then
return 0
end
return math.floor((100-self.fuel)/output.time)
end
return count
end,
allow_put = function(inv, listname, index, stack, player)
if listname == "fuel" then
local output, _decremented_input = minetest.get_craft_result({method = "fuel", width = 1, items = {stack}})
if output.time == 0 then
return 0
end
return math.floor((100-self.fuel)/output.time)
end
return stack:get_count()
end,
--~ allow_take = func(inv, listname, index, stack, player),
--~ -- ^ Called when a player wants to take something out of the inventory
--~ -- ^ Return value: number of items allowed to take
--~ -- ^ Return value: -1: Allow and don't modify item count in inventory
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
if to_list == "fuel" then
local stack = inv:get_stack(to_list, to_index)
stack:set_count(count)
local player_inv = player:get_inventory()
local pos = player:get_pos()
local input = {method = "fuel", width = 1, items = {stack}}
repeat
local output
output, input = minetest.get_craft_result(input)
if output.time == 0 then
break
end
self.fuel = self.fuel + output.time
if output.item then
local lo = player_inv:add_item("main", output.item)
if not lo:is_empty() then
minetest.item_drop(lo, player, pos)
end
end
for i = 1, #output.replacements do
local lo = player_inv:add_item("main", output.replacements[i])
if not lo:is_empty() then
minetest.item_drop(lo, player, pos)
end
end
until input.items[1]:is_empty()
inv:set_stack("fuel", to_index, ItemStack(nil))
local lo = player_inv:add_item("main", input.items[1])
if not lo:is_empty() then
minetest.item_drop(lo, player, pos)
end
return
end
end,
on_put = function(inv, listname, index, stack, player)
if listname == "fuel" then
local player_inv = player:get_inventory()
local pos = player:get_pos()
local input = {method = "fuel", width = 1, items = {stack}}
repeat
local output
output, input = minetest.get_craft_result(input)
if output.time == 0 then
break
end
self.fuel = self.fuel + output.time
if output.item then
local lo = player_inv:add_item("main", output.item)
if not lo:is_empty() then
minetest.item_drop(lo, player, pos)
end
end
for i = 1, #output.replacements do
local lo = player_inv:add_item("main", output.replacements[i])
if not lo:is_empty() then
minetest.item_drop(lo, player, pos)
end
end
until input.items[1]:is_empty()
inv:set_stack("fuel", index, ItemStack(nil))
local lo = player_inv:add_item("main", input.items[1])
if not lo:is_empty() then
minetest.item_drop(lo, player, pos)
end
return
end
end,
--~ on_take = func(inv, listname, index, stack, player),
--~ -- ^ Called after the actual action has happened, according to what was allowed.
--~ -- ^ No return value
})
self.inv:set_size("fuel", 1)
self.inv:set_size("ammo", 2*4)
for listname, list in pairs(inv_content) do
for i = 1, #list do
list[i] = ItemStack(list[i])
end
self.inv:set_list(listname, list)
end
end
minetest.register_entity("mvehicles:tank", {
initial_properties = {
hp_max = 10,
physical = true,
collide_with_objects = true,
weight = 5,
collisionbox = {-1.9,-0.99,-1.9, 1.9,0.3,1.9},
visual = "mesh",
visual_size = {x=10, y=10},
mesh = "mvehicles_tank_bottom.b3d",
textures = {"mvehicles_tank.png"},
makes_footstep_sound = false,
automatic_rotate = 0,
stepheight = 1.5,
},
on_activate = function(self, staticdata)
local inv_content
if staticdata == "" then -- initial activate
self.fuel = 15
self.turret_name = "cannon"
self.owner = ""
--~ self.object:set_armor_groups({level=5, fleshy=100, explody=250, snappy=50})
else
local s = minetest.deserialize(staticdata) or {}
self.fuel = tonumber(s.fuel) or 15
self.turret_name = s.turret_name
self.owner = s.owner or ""
self.id = s.id
inv_content = s.inv_content
end
if not self.id then
create_id(self)
end
self.inv = minetest.get_inventory({type="detached", name="mvehicles:tank"..self.id})
if not self.inv then
create_inv(self, inv_content or {})
end
local turret_def = registered_turrets[self.turret_name]
if not turret_def then
self.turret_name = "cannon"
turret_def = registered_turrets[self.turret_name]
end
turret_def.on_activate(self)
self.object:set_acceleration(vector.new(0, -gravity, 0))
self.cannon_direction_horizontal = self.object:get_yaw()
self.cannon_direction_vertical = -90
self.shooting_range = 30
self.timer = 0
end,
--~ on_death = function(self, killer)
--~ self.turret:remove()
--~ local pos = self.object:get_pos()
--~ if self.exhaust then
--~ minetest.delete_particlespawner(self.exhaust)
--~ self.exhaust = nil
--~ end
--~ if self.engine_sound then
--~ minetest.sound_stop(self.engine_sound)
--~ self.engine_sound = nil
--~ end
--~ for _listname, list in pairs(self.inv:get_lists()) do
--~ for i = 1, #list do
--~ minetest.add_item(pos, list[i])
--~ end
--~ end
--~ tnt.boom(vector.round(pos), {damage_radius=4,radius=3})
--~ if not self.driver then
--~ return
--~ end
--~ self.driver:set_detach()
--~ self.driver:set_properties({visual_size = {x=1, y=1}})
--~ self.driver:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
--~ default.player_set_animation(self.driver, "stand")
--~ self.driver:hud_remove(self.fuel_hud_l)
--~ self.driver:hud_remove(self.fuel_hud_r)
--~ self.driver:hud_remove(self.shooting_range_hud_l)
--~ self.driver:hud_remove(self.shooting_range_hud_r)
--~ player_api.player_attached[self.driver:get_player_name()] = false
--~ self.driver:set_hp(0)
--~ end,
get_staticdata = function(self)
local inv_content = {}
for listname, list in pairs(self.inv:get_lists()) do
inv_content[listname] = {}
for i = 1, #list do
inv_content[listname][i] = list[i]:to_string()
end
end
return minetest.serialize({
fuel = self.fuel,
turret_name = self.turret_name,
owner = self.owner,
id = self.id,
inv_content = inv_content,
})
end,
on_rightclick = function(self, clicker)
if not clicker or not clicker:is_player() then
return
end
if clicker:get_player_control().aux1 then
minetest.show_formspec(clicker:get_player_name(), "mvehicles:tank"..self.id,
"size[8,9]"..
"list[current_player;main;0,5;8,4;]"..
"list[detached:mvehicles:tank"..self.id..";fuel;0,0;1,1;]"..
"label[0.2,0.9;fuel]"..
"list[detached:mvehicles:tank"..self.id..";ammo;5,0.5;2,4;]"..
"vertlabel[7,1;ammunation]"..
"listring[current_player;main]"..
"listring[detached:mvehicles:tank"..self.id..";ammo]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots)
return
end
if clicker == self.driver then
self.driver:set_detach()
self.driver:set_properties({visual_size = {x=1, y=1}})
self.driver:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
self.object:set_animation({x=0, y=0}, 0, 0)
default.player_set_animation(self.driver, "stand")
if self.exhaust then
minetest.delete_particlespawner(self.exhaust)
self.exhaust = nil
end
if self.engine_sound then
minetest.sound_stop(self.engine_sound)
self.engine_sound = nil
end
self.driver:hud_remove(self.fuel_hud_l)
self.driver:hud_remove(self.fuel_hud_r)
self.driver:hud_remove(self.shooting_range_hud_l)
self.driver:hud_remove(self.shooting_range_hud_r)
player_api.player_attached[self.driver:get_player_name()] = false
self.driver = nil
return
elseif self.driver or clicker:get_attach() or
player_api.player_attached[clicker:get_player_name()] then
return
end
self.driver = clicker
player_api.player_attached[self.driver:get_player_name()] = true
self.driver:set_attach(self.object, "", {x=0,y=-0.55,z=0}, {x=0,y=0,z=0})
self.driver:set_properties({visual_size = {x=0.1, y=0.1}})
self.driver:set_eye_offset({x=0,y=2,z=0}, {x=0,y=10,z=-3})
default.player_set_animation(self.driver, "sit")
if self.fuel then
if self.fuel > 0 then
minetest.chat_send_all("fuel: "..self.fuel)
else
minetest.chat_send_all("no fuel, spawn a new tank")
end
self.fuel_hud_1 = self.fuel
self.fuel_hud_2 = 0
while self.fuel_hud_1 > 30 do
self.fuel_hud_1 = self.fuel_hud_1 - 1
self.fuel_hud_2 = self.fuel_hud_2 + 1
end
else
self.fuel_hud_1 = 0
self.fuel_hud_2 = 0
end
self.fuel_hud_l = self.driver:hud_add({
[hud_elem_type_key] = "statbar", -- see HUD element types
-- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory"
position = {x=0.01, y=0.89},
-- ^ Left corner position of element
name = "tankhud",
scale = {x=2, y=2},
text = "mvehicles_fuel_can.png",
number = self.fuel_hud_1,
item = 3,
-- ^ Selected item in inventory. 0 for no item selected.
direction = 3,
-- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top
alignment = {x=0, y=0},
-- ^ See "HUD Element Types"
offset = {x=0, y=0},
-- ^ See "HUD Element Types"
size = { x=50, y=50},
-- ^ Size of element in pixels
})
self.fuel_hud_r = self.driver:hud_add({
[hud_elem_type_key] = "statbar",
position = {x=0.02, y=0.89},
name = "tankhud",
scale = {x=2, y=2},
text = "mvehicles_fuel_can.png",
number = self.fuel_hud_2,
item = 3,
direction = 3,
alignment = {x=0, y=0},
offset = {x=0, y=0},
size = { x=50, y=50},
})
--[[local shooting_range_2 = ((30 - shooting_range_1)^2)^0.5
local shooting_range_1 = shooting_range_1 - math.abs(shooting_range_1 - 30)
local shooting_range_2 = shooting_range_2 - (30 - shooting_range_2)]]
self.shooting_range_hud_l = self.driver:hud_add({
[hud_elem_type_key] = "statbar",
position = {x=0.06, y=0.89},
name = "tankhud",
scale = {x=2, y=2},
text = "default_mese_crystal.png",
number = 0,
item = 3,
direction = 3,
alignment = {x=0, y=0},
offset = {x=0, y=0},
size = { x=50, y=50},
})
self.shooting_range_hud_r = self.driver:hud_add({
[hud_elem_type_key] = "statbar",
position = {x=0.07, y=0.89},
name = "tankhud",
scale = {x=2, y=2},
text = "default_mese_crystal.png",
number = 0,
item = 3,
direction = 3,
alignment = {x=0, y=0},
offset = {x=0, y=0},
size = { x=50, y=50},
})
self.exhaust = minetest.add_particlespawner({
amount = 10,
time = 0,
minpos = {x=-0.5,y=1.25,z=-1.2},
maxpos = {x=-0.5,y=1.25,z=-1.2},
minvel = {x=-0.1, y=1, z=-0.1},
maxvel = {x=0.1, y=1.5, z=0.1},
minacc = {x=0, y=0, z=0},
maxacc = {x=0, y=0, z=0},
minexptime = 1,
maxexptime = 2,
minsize = 1,
maxsize = 3,
collisiondetection = true,
collision_removal = false,
attached = self.object,
vertical = false,
texture = "tnt_smoke.png",
})
self.engine_sound = minetest.sound_play("mvehicles_engine", {
object = self.object,
gain = 0.5,
max_hear_distance = 32,
loop = true,
})
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
local vel = self.object:get_velocity()
if vel.y == 0 and (vel.x ~= 0 or vel.z ~= 0) then
vel = vector.new()
self.object:set_velocity(vel)
end
if not self.driver or self.fuel <= 0 then
return
end
self.fuel = self.fuel - 0.001 * dtime
local yaw = self.object:get_yaw()
local ctrl = self.driver:get_player_control()
local turned
local moved -- luacheck: ignore
if vel.y == 0 then
local anim
if ctrl.left then
yaw = yaw + dtime
self.cannon_direction_horizontal = self.cannon_direction_horizontal + dtime
anim = {{x=80, y=99}, 30, 0}
turned = true
elseif ctrl.right then
self.cannon_direction_horizontal = self.cannon_direction_horizontal - dtime
yaw = yaw - dtime
anim = {{x=60, y=79}, 30, 0}
turned = true
else
anim = {{x=0, y=0}, 0, 0}
turned = false
end
if turned then
self.object:set_yaw((yaw+2*math.pi)%(2*math.pi))
self.fuel = self.fuel - 0.01*dtime
else
if ctrl.up then
self.object:set_velocity({x=math.cos(yaw+math.pi/2)*2, y=vel.y, z=math.sin(yaw+math.pi/2)*2})
anim = {{x=0, y=19}, 30, 0}
self.fuel = self.fuel - 0.1*dtime
moved = true
elseif ctrl.down then
self.object:set_velocity({x=math.cos(yaw+math.pi/2)*-1, y=vel.y, z=math.sin(yaw+math.pi/2)*-1})
anim = {{x=20, y=39}, 15, 0}
self.fuel = self.fuel - 0.05*dtime
moved = true
else
moved = false
end
end
self.object:set_animation(unpack(anim))
end
local turret_def = registered_turrets[self.turret_name]
if self.turret and not (ctrl.sneak or self.static_turret) then
local dlh = self.driver:get_look_horizontal()
local dlv = self.driver:get_look_vertical()
self.cannon_direction_horizontal = dlh
self.cannon_direction_vertical = math.max(-100,math.min(-60,(-math.deg(dlv)-90)))
if turret_def.bones[1] then
set_bone_position(self.turret, turret_def.bones[1], {x=0, y=0, z=0},
{x=0, y=math.deg(yaw-dlh), z=0})
end
if turret_def.bones[2] then
set_bone_position(self.turret, turret_def.bones[2], {x=0,y=1.2,z=0},
{x=self.cannon_direction_vertical,y=0,z=0})
end
end
local shooted = false
if ctrl.jump and (not self.last_shoot_time or
self.timer >= self.last_shoot_time + turret_def.shoot_cooldown) then
shooted = true
turret_def.shoot(self, dtime)
self.last_shoot_time = self.timer
end
if turret_def.on_step then
turret_def.on_step(self, dtime, shooted)
end
if self.shooting_range then
self.shooting_range_hud_1 = self.shooting_range
self.shooting_range_hud_2 = 0
while self.shooting_range_hud_1 > 30 do
self.shooting_range_hud_1 = self.shooting_range_hud_1 - 1
self.shooting_range_hud_2 = self.shooting_range_hud_2 + 1
end
else
self.shooting_range_hud_1 = 0
self.shooting_range_hud_2 = 0
end
self.driver:hud_change(self.shooting_range_hud_l, "number", self.shooting_range_hud_1)
self.driver:hud_change(self.shooting_range_hud_r, "number", self.shooting_range_hud_2)
if self.fuel <= 0 then
self.fuel = 0
self.object:set_animation({x=0, y=0}, 0, 0)
if self.exhaust then
minetest.delete_particlespawner(self.exhaust)
self.exhaust = nil
end
if self.engine_sound then
minetest.sound_stop(self.engine_sound)
self.engine_sound = nil
end
minetest.chat_send_all("no fuel, spawn a new tank")
end
end,
})
minetest.register_entity("mvehicles:tank_shoot", {
initial_properties = {
physical = true,
collide_with_objects = true,
weight = 5,
collisionbox = {-0.1,-0.1,-0.1, 0.1,0.1,0.1},
visual = "mesh",
visual_size = {x=5, y=5},
mesh = "mvehicles_tank_shoot.b3d",
textures = {"mvehicles_tank_shoot.png"},
automatic_rotate = 0,
automatic_face_movement_dir = 90.0,
automatic_face_movement_max_rotation_per_sec = -1,
},
on_activate = function(self, staticdata)
if staticdata ~= "stay" then
self.object:remove()
return
end
self.object:set_acceleration(vector.new(0, -gravity, 0))
end,
on_step = function(self, dtime)
local vel = self.object:get_velocity()
-- collision detection
if self.oldvel and
((self.oldvel.x ~= 0 and vel.x == 0) or
(self.oldvel.y ~= 0 and vel.y == 0) or
(self.oldvel.z ~= 0 and vel.z == 0)) then
tnt.boom(vector.round(self.object:get_pos()), {damage_radius=3,radius=2})
self.object:remove()
return
end
-- rotate in fly direction
local rot
if math.abs(vel.y) < 1.0e-3 then
rot = 0
else
rot = -math.deg(math.atan2(vel.y, (vel.x^2+vel.z^2)^0.5))
end
self.object:set_animation({x=rot+90, y=rot+90}, 0, 0)
self.oldvel = vel
end
})
minetest.register_entity("mvehicles:tank_top", {
initial_properties = {
physical = false,
weight = 5,
collisionbox = {0,0,0, 0,0,0},
visual = "mesh",
visual_size = {x=1, y=1},
mesh = "mvehicles_tank_top.b3d",
textures = {"mvehicles_tank.png"},
},
on_activate = function(self, staticdata, dtime_s)
if staticdata ~= "stay" then
self.object:remove()
end
end,
})
mvehicles.register_tank_turret("cannon", {
entity = "mvehicles:tank_top",
shoot_cooldown = 3,
bones = {"top_master", "cannon_barrel"},
shoot = function(tank)
local vel = tank.object:get_velocity()
local shoot = minetest.add_entity(tank.object:get_pos():offset(0, 1.2, 0),
"mvehicles:tank_shoot", "stay")
-- wtf does this do?
shoot:set_velocity(vector.add(vel, vector.new(
math.cos(tank.cannon_direction_horizontal + math.rad(90))
* math.sin(math.rad(-tank.cannon_direction_vertical))*tank.shooting_range,
math.cos(math.rad(-tank.cannon_direction_vertical))*tank.shooting_range,
math.sin(tank.cannon_direction_horizontal + math.rad(90))
* math.sin(math.rad(-tank.cannon_direction_vertical))*tank.shooting_range
)))
minetest.sound_play("mvehicles_tank_shoot", {
pos = tank.object:get_pos(),
gain = 0.5,
max_hear_distance = 32,
}, true)
end,
})
if minetest.get_modpath("carts") then
mvehicles.register_tank_turret("railgun", {
entity = "mvehicles:tank_top",
shoot_cooldown = 0,
bones = {"top_master", "cannon_barrel"},
shoot = function(tank, dtime)
if not tank.railgun_load_start then
tank.static_turret = true
tank.railgun_load_start = tank.timer
elseif math.floor(tank.railgun_load_start-tank.timer) < math.floor(tank.railgun_load_start+dtime-tank.timer) then
minetest.chat_send_player(tank.driver:get_player_name(), tostring(math.floor(tank.railgun_load_start-tank.timer+6)))
end
end,
on_step = function(tank, dtime, shooting)
if not shooting and tank.railgun_load_start then
if tank.timer >= tank.railgun_load_start + 5 then
local vel = tank.object:get_velocity()
local pos = tank.object:get_pos()
local rail = minetest.add_item(pos, ItemStack("carts:rail"))
rail:set_velocity(vector.offset(vel,
math.cos(tank.cannon_direction_horizontal + math.rad(90))
* math.sin(math.rad(-tank.cannon_direction_vertical))*tank.shooting_range*2,
math.cos(math.rad(-tank.cannon_direction_vertical))*tank.shooting_range*2,
math.sin(tank.cannon_direction_horizontal + math.rad(90))
* math.sin(math.rad(-tank.cannon_direction_vertical))*tank.shooting_range*2
))
end
tank.static_turret = false
tank.railgun_load_start = nil
end
end,
})
end
mvehicles.register_tank_turret("drill", {
entity = "mvehicles:tank_top",
shoot_cooldown = 0.5,
shoot = function(tank)
local dir = minetest.yaw_to_dir(tank.object:get_yaw())
local drill_pos = tank.object:get_pos() + dir * 2
local less = dir.x > dir.z and "z" or "x"
for y = 0, 2 do
for i = -1.5, 1.5 do
local pos = drill_pos:copy()
pos.y = pos.y + y
pos[less] = pos[less] + i
local drops = minetest.get_node_drops(minetest.get_node(pos).name, "")
minetest.dig_node(pos)
for j = 1, #drops do
local leftover = tank.inv:add_item("ammo", drops[j])
if not leftover:is_empty() then
minetest.item_drop(leftover, tank.driver, pos)
end
end
end
end
end,
})