water refuel added, climb now dependent on boyler pressure

This commit is contained in:
Alexsandro Percy 2022-05-25 17:45:27 -03:00
parent 9c86a9f404
commit 640e244a4a
6 changed files with 82 additions and 46 deletions

View File

@ -62,8 +62,12 @@ function steampunk_blimp.control(self, dtime, hull_direction, longit_speed, acce
end
end
self._is_going_up = false
if ctrl.jump then
self._baloon_buoyancy = 1.02
if self._boiler_pressure > 0 then
self._baloon_buoyancy = 1.02
end
self._is_going_up = true
elseif ctrl.sneak then
self._baloon_buoyancy = -1.02
end

View File

@ -1,7 +1,13 @@
steampunk_blimp.PRESSURE_CONSUMPTION = 500
local lost_power = (1/steampunk_blimp.FUEL_CONSUMPTION)*500
local gained_power = (2/steampunk_blimp.FUEL_CONSUMPTION)*500
local adjust_variable = 500
local lost_power = (1/steampunk_blimp.FUEL_CONSUMPTION)*adjust_variable
local gained_pressure = (2/steampunk_blimp.FUEL_CONSUMPTION)*adjust_variable
local lost_water = (1/steampunk_blimp.WATER_CONSUMPTION)
steampunk_blimp.boyler_min = 155
steampunk_blimp.boyler_max = 310
function steampunk_blimp.start_boyler(self)
if self._boiler_pressure < 150 then
@ -31,31 +37,39 @@ local function boiler_step(self, accel)
local consumed_pressure = self._power_lever/steampunk_blimp.PRESSURE_CONSUMPTION
if self._engine_running == false then consumed_pressure = consumed_pressure + lost_power end
if self._boiler_pressure > 310 then self._boiler_pressure = 310 end
if self._boiler_pressure > 155 then
if self._boiler_pressure > steampunk_blimp.boyler_max then self._boiler_pressure = steampunk_blimp.boyler_max end
if self._boiler_pressure > steampunk_blimp.boyler_min then
--[[-- sound and animation
steampunk_blimp.engineSoundPlay(self)
self.object:set_animation_frame_speed(steampunk_blimp.iddle_rotation)]]--
steampunk_blimp.engine_set_sound_and_animation(self)
self._water_level = self._water_level - lost_water
end
if self._boiler_pressure < 155 then
if self._boiler_pressure < steampunk_blimp.boyler_min then
self._power_lever = 0
--if self.sound_handle_pistons then minetest.sound_stop(self.sound_handle_pistons) end
self.object:set_animation_frame_speed(0)
end
self._boiler_pressure = self._boiler_pressure - consumed_pressure
--lets lose more pressure if it's going up
if self._is_going_up == true then
--minetest.chat_send_all("subindo "..consumed_pressure)
self._boiler_pressure = self._boiler_pressure - (200/steampunk_blimp.PRESSURE_CONSUMPTION)
end
if self._boiler_pressure < 0 then self._boiler_pressure = 0 end
if self._water_level < 0 then self._water_level = 0 end
end
local function furnace_step(self, accel)
if self._energy > 0 and self._engine_running then
local consumed_power = (1/steampunk_blimp.FUEL_CONSUMPTION)
self._boiler_pressure = self._boiler_pressure + gained_power --pressure for the boiler
self._boiler_pressure = self._boiler_pressure + gained_pressure --pressure for the boiler
self._energy = self._energy - consumed_power; --removes energy
end
if self._energy <= 0 then
if self._energy <= 0 or self._water_level <= 0 then
self._engine_running = false
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
end
@ -69,7 +83,7 @@ function steampunk_blimp.engine_step(self, accel)
local player = minetest.get_player_by_name(self.driver_name)
local pressure = steampunk_blimp.get_pointer_angle(self._boiler_pressure, 200 )
local water = steampunk_blimp.get_pointer_angle(self._water_level, steampunk_blimp.MAX_FUEL)
local water = steampunk_blimp.get_pointer_angle(self._water_level, steampunk_blimp.MAX_WATER)
local coal = self._energy
steampunk_blimp.update_hud(player, coal, 180-water, -pressure)
end

View File

@ -38,8 +38,9 @@ initial_properties = {
--
minetest.register_entity('steampunk_blimp:stand_base',{
initial_properties = {
physical = false,
collide_with_objects=false,
physical = true,
collide_with_objects=true,
collisionbox = {-2, -2, -2, 2, 0, 2},
pointable=false,
visual = "mesh",
mesh = "steampunk_blimp_stand_base.b3d",
@ -62,7 +63,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
initial_properties = {
physical = true,
collide_with_objects = true, --true,
collisionbox = {-4, -2.5, -4, 4, 10, 4}, --{-1,0,-1, 1,0.3,1},
collisionbox = {-4, -2.5, -4, 4, 9, 4}, --{-1,0,-1, 1,0.3,1},
--selectionbox = {-0.6,0.6,-0.6, 0.6,1,0.6},
visual = "mesh",
backface_culling = false,
@ -97,6 +98,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
_energy = 1.0,--0.001,
_water_level = 1.0,
_boiler_pressure = 1.0, --min 155 max 310
_is_going_up = false, --to tell the boiler to lose pressure
_passengers = {}, --passengers list
_passengers_base = {}, --obj id
_passengers_base_pos = steampunk_blimp.copy_vector({}),
@ -380,6 +382,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
if is_attached == true then
--refuel
steampunk_blimp.load_fuel(self, puncher)
steampunk_blimp.load_water(self, puncher)
end
if is_attached == false then

View File

@ -31,7 +31,7 @@ function steampunk_blimp.pilot_formspec(name)
if ent.anchored == true then anchor = "true" end
basic_form = basic_form.."button[1,1.0;4,1;turn_on;Start/Stop the fire]"
basic_form = basic_form.."button[1,2.0;4,1;hud;Show/Hide Gauges]"
basic_form = basic_form.."button[1,2.0;4,1;water;Load water from bellow]"
basic_form = basic_form.."checkbox[1,4.6;take_control;Take the Control;"..take_control.."]"
basic_form = basic_form.."checkbox[1,5.2;anchor;Anchor away;"..anchor.."]"
@ -169,11 +169,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.turn_on then
steampunk_blimp.start_furnace(ent)
end
if fields.hud then
if ent._show_hud == true then
ent._show_hud = false
if fields.water then
if ent.isinliquid then
if ent._engine_running == true then
steampunk_blimp.start_furnace(ent)
end
if ent._boiler_pressure > 0 then
minetest.sound_play({name = "default_cool_lava"},
{object = ent.object, gain = 1.0,
pitch = 1.0,
max_hear_distance = 32,
loop = false,}, true)
end
ent._boiler_pressure = 0
ent._water_level = steampunk_blimp.MAX_WATER
else
ent._show_hud = true
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> Impossible. The ship needs to be in the water."))
end
end
if fields.take_control then

View File

@ -4,28 +4,8 @@
steampunk_blimp.MAX_FUEL = minetest.settings:get("steampunk_blimp_max_fuel") or 99
steampunk_blimp.FUEL_CONSUMPTION = minetest.settings:get("steampunk_blimp_fuel_consumption") or 6000
minetest.register_entity('steampunk_blimp:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "pointer.b3d",
textures = {"steampunk_blimp_interior.png"},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})
steampunk_blimp.MAX_WATER = 10
steampunk_blimp.WATER_CONSUMPTION = 50000
function steampunk_blimp.contains(table, val)
for k,v in pairs(table) do
@ -53,13 +33,6 @@ function steampunk_blimp.load_fuel(self, player)
self._energy = self._energy + fuel.amount
if self._energy > steampunk_blimp.MAX_FUEL then self._energy = steampunk_blimp.MAX_FUEL end
--minetest.chat_send_all(self.energy)
if fuel.drop then
local leftover = inv:add_item("main", fuel.drop)
if leftover then
minetest.item_drop(leftover, player, player:get_pos())
end
end
--local energy_indicator_angle = steampunk_blimp.get_pointer_angle(self._energy, steampunk_blimp.MAX_FUEL)
end
@ -70,3 +43,33 @@ function steampunk_blimp.load_fuel(self, player)
return false
end
function steampunk_blimp.load_water(self, player)
local inv = player:get_inventory()
local itmstck=player:get_wielded_item()
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
--minetest.chat_send_all("water: ".. dump(item_name))
local water = steampunk_blimp.contains(steampunk_blimp.water, item_name)
if water then
if self._water_level < steampunk_blimp.MAX_WATER then
local itemstack = ItemStack(item_name .. " 1")
inv:remove_item("main", itemstack)
local indx = item_name:find('bucket:bucket')
if indx then
itemstack = ItemStack("bucket:bucket_empty")
inv:add_item("main", itemstack)
player:set_wielded_item(itemstack)
end
self._water_level = self._water_level + water.amount
if self._water_level > steampunk_blimp.MAX_WATER then self._water_level = steampunk_blimp.MAX_WATER end
end
return true
end
return false
end

View File

@ -2,6 +2,7 @@ steampunk_blimp={}
steampunk_blimp.gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.8
steampunk_blimp.trunk_slots = 50
steampunk_blimp.fuel = {['default:coal_lump'] = {amount=1},['default:coalblock'] = {amount=10}}
steampunk_blimp.water = {['default:water_source'] = {amount=1},['default:river_water_source'] = {amount=1}, ['bucket:bucket_water'] = {amount=1}, ['bucket:bucket_river_water'] = {amount=1}} --bucket:bucket_empty
steampunk_blimp.ideal_step = 0.02
steampunk_blimp.rudder_limit = 30
steampunk_blimp.iddle_rotation = 0