Add REFUEL and GET-ENERGY

This commit is contained in:
Novatux 2015-01-25 14:47:23 +01:00
parent 042e4881ec
commit edcf3d337a
4 changed files with 20 additions and 15 deletions

28
api.lua
View File

@ -1,5 +1,5 @@
local MOVE_COST = 100 local MOVE_COST = 100
local FUEL_EFFICIENCY = 300 local FUEL_EFFICIENCY = 10000
tl = {} tl = {}
local function delay(x) local function delay(x)
@ -216,11 +216,9 @@ local function stack_set_count(stack, count)
end end
function tl.refuel(turtle, cptr, slot, nmax) function tl.refuel(turtle, cptr, slot, nmax)
-- TODO: update that
local info = turtles.get_turtle_info(turtle) local info = turtles.get_turtle_info(turtle)
info.energy = info.energy + 100 * MOVE_COST local inv = turtles.get_turtle_inventory(turtle)
--[[local info = get_turtle_info(turtle) local stack = inv:get_stack("main", slot)
local stack = turtle_invs:get_stack(turtle, slot)
local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = {stack}}) local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = {stack}})
if fuel.time <= 0 then if fuel.time <= 0 then
cptr.X = 0 cptr.X = 0
@ -238,15 +236,19 @@ function tl.refuel(turtle, cptr, slot, nmax)
end end
if afterfuel ~= nil then if afterfuel ~= nil then
afterfuel = stack_set_count(afterfuel, afterfuel:get_count()*count) afterfuel = stack_set_count(afterfuel, afterfuel:get_count()*count)
end
if afterfuel ~= nil then
local leftover = stack:add_item(ItemStack(afterfuel)) local leftover = stack:add_item(ItemStack(afterfuel))
turtle_invs:set_stack(turtle, slot, stack) inv:set_stack("main", slot, stack)
local leftover2 = turtle_invs:add_item(turtle, leftover) local leftover2 = inv:add_item("main", leftover)
minetest.add_item(info.spos,leftover2) minetest.add_item(info.spos, leftover2)
else else
turtle_invs:set_stack(turtle, slot, stack) inv:set_stack("main", slot, stack)
end end
info.fuel = info.fuel+FUEL_EFFICIENCY*count*fuel.time info.energy = info.energy + FUEL_EFFICIENCY * count * fuel.time
cptr.X = u16(FUEL_EFFICIENCY*count*fuel.time)]] cptr.X = u16(-1)
end
function tl.get_energy(turtle, cptr)
local info = turtles.get_turtle_info(turtle)
cptr.Y = u16(info.energy)
cptr.X = u16(math.floor(info.energy / 0x10000))
end end

View File

@ -306,7 +306,8 @@ ITABLE_RAW = {
[0x76] = "tl.placedown(turtle, cptr)", [0x76] = "tl.placedown(turtle, cptr)",
[0x80] = "tl.refuel(turtle, cptr, cptr.X, cptr.Y)", [0x80] = "tl.refuel(turtle, cptr, cptr.X, cptr.Y)",
[0x81] = "tl.select(turtle, cptr, cptr.X)" [0x81] = "tl.select(turtle, cptr, cptr.X)",
[0x82] = "tl.get_energy(turtle, cptr)",
} }
ITABLE = {} ITABLE = {}

View File

@ -103,6 +103,7 @@ ASSEMBLER
: REFUEL PLY PLX 0x80 PHX NXT ; : REFUEL PLY PLX 0x80 PHX NXT ;
: SELECT PLX 0x81 NXT ; : SELECT PLX 0x81 NXT ;
: GET-ENERGY 0x82 PHY PHX NXT ;
ENVIRONMENT ENVIRONMENT
256 CONSTANT /COUNTED-STRING 256 CONSTANT /COUNTED-STRING
@ -282,6 +283,7 @@ FORTH
: (abort") ROT IF TYPE ABORT THEN 2DROP ; : (abort") ROT IF TYPE ABORT THEN 2DROP ;
: ABORT" POSTPONE S" ['] (abort") , ; IMMEDIATE : ABORT" POSTPONE S" ['] (abort") , ; IMMEDIATE
: DABS DUP 0< IF OVER NEGATE ROT IF SWAP INVERT ELSE SWAP NEGATE THEN THEN ; : DABS DUP 0< IF OVER NEGATE ROT IF SWAP INVERT ELSE SWAP NEGATE THEN THEN ;
: D. DUP >R DABS <# BL HOLD #S R> SIGN #> TYPE ;
: SM/REM OVER >R 2DUP XOR >R ABS >R DABS R> UM/MOD R> 0< IF NEGATE THEN SWAP R> 0< IF NEGATE THEN SWAP ; : SM/REM OVER >R 2DUP XOR >R ABS >R DABS R> UM/MOD R> 0< IF NEGATE THEN SWAP R> 0< IF NEGATE THEN SWAP ;
\ : KEY BEGIN RAWKEY DUP 31 > OVER 127 < AND IF EXIT THEN DROP AGAIN ; \ : KEY BEGIN RAWKEY DUP 31 > OVER 127 < AND IF EXIT THEN DROP AGAIN ;
: ON SET-CHANNEL S" on" SEND ; : ON SET-CHANNEL S" on" SEND ;

File diff suppressed because one or more lines are too long