Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Digtron 2.0 digpocalypse #89

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6a38e68
clean the slate! Old code will be brought back as it's needed.
FaceDeer Aug 17, 2019
4e2ac43
can now create detached inventory. May be very buggy yet.
FaceDeer Aug 18, 2019
90c2315
persisting inventory between runs
FaceDeer Aug 18, 2019
ff22918
can now reliably construct and deconstruct
FaceDeer Aug 18, 2019
27c9d82
a bit of naming work
FaceDeer Aug 18, 2019
9d52699
make constructed controllers pick-uppable
FaceDeer Aug 18, 2019
fda6aa9
a little more setup for placing constructed Digtrons
FaceDeer Aug 18, 2019
e88a3fa
basic ability to pick up and put down a complete digtron
FaceDeer Aug 19, 2019
4031ea0
tidy up aftermath of building a constructed digtron
FaceDeer Aug 19, 2019
e16035b
save bounding box relative to root.
FaceDeer Aug 19, 2019
1c732ae
change metadata naming standard, add some corrupted data checks
FaceDeer Aug 19, 2019
a9420ea
explosions automatically deconstruct Digtrons.
FaceDeer Aug 20, 2019
03c9a81
so... much... error checking...
FaceDeer Aug 20, 2019
2283cdb
hide digtron_id from clients, change "construct" to "assemble", vario…
FaceDeer Aug 20, 2019
f14b0a9
no need to expose caches globally
FaceDeer Aug 20, 2019
2928896
indicator entities for when Digtron can't be built
FaceDeer Aug 21, 2019
7f5cf4d
add a digger head model
FaceDeer Aug 21, 2019
5d7eea2
static digger variant for unassembled digtrons
FaceDeer Aug 22, 2019
c295999
digtron 2.0 can now move
FaceDeer Aug 23, 2019
80b9530
add a basic beginning to dig prediction
FaceDeer Aug 24, 2019
63ea131
remove origin displacement, not really needed
FaceDeer Aug 24, 2019
a0f47b5
no need to persist derived values. Cache digger targets.
FaceDeer Aug 25, 2019
a74cc14
add setting formspec to disassembled digger
FaceDeer Aug 25, 2019
cafb2ec
add config, add material cost to predict_dig
FaceDeer Aug 25, 2019
683b941
split inventory functions into a separate file, add predictive invent…
FaceDeer Aug 25, 2019
426cd4d
IT DIGS
FaceDeer Aug 25, 2019
b90e571
Executing all on-dig callbacks "properly" with a fake player
FaceDeer Aug 25, 2019
7b2b296
pull some code out into subroutines
FaceDeer Aug 25, 2019
1333748
further subroutine breakdown
FaceDeer Aug 25, 2019
beed475
begin reintroducing builder nodes
FaceDeer Aug 26, 2019
e0d0270
IT BUILDS
FaceDeer Aug 26, 2019
256ec95
bring back the hacked item place function
FaceDeer Aug 26, 2019
a410187
extrusion, and account for diggers/builders pointing at the same targ…
FaceDeer Aug 27, 2019
395a794
offset/periodicity implemented
FaceDeer Aug 27, 2019
861d9b2
messy formspec code, but can now translate Digtron around freely
FaceDeer Aug 27, 2019
e63f016
implement rotation. Broke builders in the process.
FaceDeer Aug 28, 2019
8ecc738
add can-build check to rotation
FaceDeer Aug 28, 2019
c35104e
Make control formspec a bit snugger, eliminate unnecessary disassembl…
FaceDeer Aug 28, 2019
df4c7f7
add a distinct rotation sound
FaceDeer Aug 28, 2019
70e1649
create separate unassembled controller, make builder "read" work.
FaceDeer Aug 31, 2019
7c08241
add sequencer tab. Digtron doesn't yet actually use the sequence set …
FaceDeer Aug 31, 2019
263aba9
fix/remove a few TODOs
FaceDeer Aug 31, 2019
b1cd43c
in theory, Digtron 2.0 can now recover from total metadata write-to-m…
FaceDeer Sep 1, 2019
0eb3d1f
add dual digger nodes, recipes
FaceDeer Sep 1, 2019
d743636
make dual diggers function dually
FaceDeer Sep 1, 2019
e717f09
stair digging is now possible, if a bit hacky.
FaceDeer Sep 2, 2019
1fa10d8
make soft diggers work
FaceDeer Sep 2, 2019
63a7f6a
implement duplicator
FaceDeer Sep 2, 2019
ce6f05c
digtrons can do hp damage now
FaceDeer Sep 3, 2019
a998fd9
tidy recipes
FaceDeer Sep 3, 2019
772bcdd
add paging to inventory tabs
FaceDeer Sep 3, 2019
ace967d
make sequencer data structure more robust
FaceDeer Sep 3, 2019
fe5979a
sequencer can now advance through the sequence. Still not actually ho…
FaceDeer Sep 8, 2019
8732366
command UI now lets multiple cycles be requested.
FaceDeer Sep 8, 2019
f83f5cb
remove need to pass formname around
FaceDeer Sep 8, 2019
61be57e
give builder items a little love
FaceDeer Sep 8, 2019
926f722
more loopable engine sound, supporting sequences better
FaceDeer Sep 8, 2019
8f70b98
fix a bug with building into freshly-dug spots
FaceDeer Sep 8, 2019
b568fff
fix bug in rotate, wasn't invalidating adjacent node cache
FaceDeer Sep 8, 2019
d79b226
rearrange context cache to play nice with players using multiple digt…
FaceDeer Sep 9, 2019
1e776de
update to client-side translation system
FaceDeer Feb 22, 2020
6745446
fix name preservation, add stop button
FaceDeer Feb 24, 2020
3c0fbca
make it possible to edit builders that are part of an assembled digtron
FaceDeer Mar 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add a basic beginning to dig prediction
FaceDeer committed Aug 24, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 80b95300334dbbd6e358ee7db005093e9345f8d9
9 changes: 8 additions & 1 deletion controller.lua
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ local get_controller_assembled_formspec = function(pos, digtron_id, player_name)
.. "field[1.2,0.25;2,1;digtron_name;Digtron name;"..digtron.get_name(digtron_id).."]"
.. "field_close_on_enter[digtron_name;false]"
.. "button[3,0;1,1;move_forward;Move forward]"
.. "button[4,0;1,1;test_dig;Test dig]"
.. "container_end[]"
.. "container[0.5,1]"
.. "list[detached:" .. digtron_id .. ";main;0,0;8,2]" -- TODO: paging system for inventory, guard against non-existent listname
@@ -96,7 +97,7 @@ minetest.register_node("digtron:controller", {
end
-- call on_dignodes callback
if digtron_id ~= "" then
local removed = digtron.remove_from_world(digtron_id, pos, player_name)
local removed = digtron.remove_from_world(digtron_id, player_name)
for _, removed_pos in ipairs(removed) do
minetest.check_for_falling(removed_pos)
end
@@ -258,6 +259,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end

if fields.test_dig then
local products, nodes_to_dig, cost = digtron.predict_dig(digtron_id, player_name)
minetest.chat_send_all("products: " .. dump(products))
minetest.chat_send_all("positions: " .. dump(nodes_to_dig))
end

--TODO: this isn't recording the field when using ESC to exit the formspec
if fields.key_enter_field == "digtron_name" or fields.digtron_name then
local pos = digtron.get_pos(digtron_id)
84 changes: 71 additions & 13 deletions functions.lua
Original file line number Diff line number Diff line change
@@ -466,18 +466,27 @@ end
-- Removes the in-world nodes of a digtron
-- Does not destroy its layout info
-- returns a table of vectors of all the nodes that were removed
digtron.remove_from_world = function(digtron_id, root_pos, player_name)
digtron.remove_from_world = function(digtron_id, player_name)
local layout = retrieve_layout(digtron_id)
local root_pos = retrieve_pos(digtron_id)

if not layout then
minetest.log("error", "Unable to find layout record for " .. digtron_id
minetest.log("error", "digtron.remove_from_world Unable to find layout record for " .. digtron_id
.. ", wiping any remaining metadata for this id to prevent corruption. Sorry!")
local meta = minetest.get_meta(root_pos)
meta:set_string("digtron_id", "")
if root_pos then
local meta = minetest.get_meta(root_pos)
meta:set_string("digtron_id", "")
end
dispose_id(digtron_id)
return {}
end

if not root_pos then
minetest.log("error", "digtron.remove_from_world Unable to find position for " .. digtron_id
.. ", it may have already been removed from the world.")
return {}
end

local root_hash = minetest.hash_node_position(root_pos)
local nodes_to_destroy = {}
for hash, data in pairs(layout) do
@@ -541,9 +550,10 @@ end
digtron.build_to_world = function(digtron_id, root_pos, player_name)
local layout = retrieve_layout(digtron_id)
local root_hash = minetest.hash_node_position(root_pos)
local root_hash_minus_origin = root_hash - origin_hash

for hash, data in pairs(layout) do
local node_pos = minetest.get_position_from_hash(hash + root_hash - origin_hash)
local node_pos = minetest.get_position_from_hash(hash + root_hash_minus_origin)
minetest.set_node(node_pos, data.node)
local meta = minetest.get_meta(node_pos)
for field, value in pairs(data.meta.fields) do
@@ -561,28 +571,76 @@ end

digtron.move = function(digtron_id, dest_pos, player_name)
minetest.chat_send_all("move attempt")
local current_pos = retrieve_pos(digtron_id)
if current_pos == nil then
minetest.chat_send_all("no pos recorded for digtron")
return
end
local permitted, succeeded, failed = digtron.is_buildable_to(digtron_id, dest_pos, player_name)
if permitted then
local removed = digtron.remove_from_world(digtron_id, current_pos, player_name)
local removed = digtron.remove_from_world(digtron_id, player_name)
digtron.build_to_world(digtron_id, dest_pos, player_name)
minetest.sound_play("digtron_truck", {gain = 0.5, pos=dest_pos})
for _, removed_pos in ipairs(removed) do
minetest.check_for_falling(removed_pos)
end
else
digtron.show_buildable_nodes({}, failed)
minetest.sound_play("digtron_squeal", {gain = 0.5, pos=current_pos})
minetest.sound_play("digtron_squeal", {gain = 0.5, pos=dest_pos})
end
end


digtron.predict_dig = function(digtron_id, player_name)
local layout = retrieve_layout(digtron_id)
local root_pos = retrieve_pos(digtron_id)
-- TODO standard check for nil returns, not bothering right now because I'm lazy
local root_hash = minetest.hash_node_position(root_pos)
local root_hash_minus_origin = root_hash - origin_hash

local products = {}
local dug_positions = {}
local cost = 0

for hash, data in pairs(layout) do
if data.node.name == "digtron:digger" then -- TODO: something better than this based on group, ideally pre-gather this info on assembly
local node_pos = minetest.get_position_from_hash(hash + root_hash_minus_origin)
local target_pos = vector.add(node_pos, minetest.facedir_to_dir(data.node.param2))
if not layout[minetest.hash_node_position(target_pos)] then -- check if the digger is pointed inward, if so ignore it. TODO some way to cull these permanently upon assembly, probably factoring in to the "something better than this" above
--TODO protection test, can_dig test, periodicity test
--if minetest.get_item_group(target.name, "digtron") ~= 0 or
--minetest.get_item_group(target.name, "digtron_protected") ~= 0 or
--minetest.get_item_group(target.name, "immortal") ~= 0 then
local target_node = minetest.get_node(target_pos)

-- TODO: move this into some kind of shared definition
--if digtron.config.uses_resources then
-- if minetest.get_item_group(target.name, "cracky") ~= 0 then
-- in_known_group = true
-- material_cost = math.max(material_cost, digtron.config.dig_cost_cracky)
-- end
-- if minetest.get_item_group(target.name, "crumbly") ~= 0 then
-- in_known_group = true
-- material_cost = math.max(material_cost, digtron.config.dig_cost_crumbly)
-- end
-- if minetest.get_item_group(target.name, "choppy") ~= 0 then
-- in_known_group = true
-- material_cost = math.max(material_cost, digtron.config.dig_cost_choppy)
-- end
-- if not in_known_group then
-- material_cost = digtron.config.dig_cost_default
-- end
--end

local drops = minetest.get_node_drops(target_node.name, "")
for _, drop in ipairs(drops) do
products[drop] = (products[drop] or 0) + 1
end
table.insert(dug_positions, target_pos)
end
end
end

return products, dug_positions, cost
end

---------------------------------------------------------------------------------
-- Misc
-- Node callbacks

-- If the digtron node has an assigned ID and a layout for that ID exists and
-- a matching node exists in the layout then don't let it be dug.
Binary file modified textures/digtron_axel_side.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/digtron_control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/digtron_core.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/digtron_digger_yb_frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/digtron_drill_head_animated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/digtron_marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/digtron_motor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/digtron_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.