Skip to content

Commit

Permalink
fuel management improved
Browse files Browse the repository at this point in the history
  • Loading branch information
APercy committed Jul 11, 2020
1 parent 5895ba7 commit ccf3ff0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
22 changes: 12 additions & 10 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ minetest.register_entity("minekart:kart", {
if player_attach then
if player_attach == self.object then is_attached = true end
end

--reload fuel at refuel point
------------------------------
if self._energy < 0.90 then
local speed = minekart.get_hipotenuse_value(vector.new(), self._lastvelocity)
local pos = self.object:get_pos()
if minetest.find_node_near(pos, 5, {"checkpoints:refuel"}) ~= nil and self._engine_running == false and speed <= 0.1 then
minekart_load_fuel(self, self.driver_name, true)
end
end
end
end

Expand Down Expand Up @@ -498,21 +508,13 @@ minetest.register_entity("minekart:kart", {

--refuel procedure
--[[
refuel works in 2 situations:
1- if my car doesn't have a race_id, ok, punch it anywhere with bio fuel while player attached and ok
2- if it have a race_id, you must stop near a "checkpoints:refuel" node to punch with the biofuel
refuel works it car is stopped and engine is off
]]--
local velocity = self.object:get_velocity()
local speed = minekart.get_hipotenuse_value(vector.new(), velocity)
if is_attached == true and item_name == "biofuel:biofuel" and self._engine_running == false and speed <= 0.1 then
local pos = self.object:get_pos()
if minetest.find_node_near(pos, 5, {"checkpoints:refuel"}) ~= nil then
minekart_load_fuel(self, puncher:get_player_name())
else
if self._race_id == "" then
minekart_load_fuel(self, puncher:get_player_name())
end
end
minekart_load_fuel(self, puncher:get_player_name())
end
-- end refuel

Expand Down
12 changes: 7 additions & 5 deletions minekart_fuel_management.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
-- fuel
--

function minekart_load_fuel(self, player_name)
function minekart_load_fuel(self, player_name, free)
free = free or false
if self._energy < 0.90 then
local player = minetest.get_player_by_name(player_name)
local inv = player:get_inventory()
local inventory_fuel = "biofuel:biofuel"

if inv:contains_item("main", inventory_fuel) then
local stack = ItemStack(inventory_fuel .. " 1")
local taken = inv:remove_item("main", stack)
if inv:contains_item("main", inventory_fuel) or free == true then
if free == false then
local stack = ItemStack(inventory_fuel .. " 1")
local taken = inv:remove_item("main", stack)
end

self._energy = self._energy + 1
if self._energy > 1 then self._energy = 1 end
Expand All @@ -21,4 +24,3 @@ function minekart_load_fuel(self, player_name)
minetest.chat_send_player(player_name, "No refuel for you! You have more than 90% of fuel in the tank.")
end
end

0 comments on commit ccf3ff0

Please sign in to comment.