now collision system and added 2 more positions
This commit is contained in:
parent
7bd55a3fe5
commit
0527d6cbf5
38
entities.lua
38
entities.lua
@ -102,6 +102,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
|
||||
_passengers = {}, --passengers list
|
||||
_passengers_base = {}, --obj id
|
||||
_passengers_base_pos = steampunk_blimp.copy_vector({}),
|
||||
_passenger_is_sit = {}, -- 0, 1, 2, 3 or 4 ==> stand, 0, 90, 180, 270 --the sit rotation
|
||||
_passengers_locked = false,
|
||||
_disconnection_check_time = 0,
|
||||
_inv = nil,
|
||||
@ -155,7 +156,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
|
||||
self.hull_integrity = data.stored_hull_integrity
|
||||
self.item = data.stored_item
|
||||
self._inv_id = data.stored_inv_id
|
||||
self._passengers = data.stored_passengers or steampunk_blimp.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil,})
|
||||
self._passengers = data.stored_passengers or steampunk_blimp.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil, [6]=nil, [7]=nil})
|
||||
self._passengers_locked = data.stored_passengers_locked
|
||||
--minetest.debug("loaded: ", self._energy)
|
||||
local properties = self.object:get_properties()
|
||||
@ -176,30 +177,17 @@ minetest.register_entity("steampunk_blimp:blimp", {
|
||||
fire:set_attach(self.object,'',{x=0.0,y=0.0,z=0.0},{x=0,y=0,z=0})
|
||||
self.fire = fire
|
||||
|
||||
self._passengers_base = steampunk_blimp.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil,})
|
||||
self._passengers_base_pos = steampunk_blimp.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil,})
|
||||
self._passengers_base_pos = {
|
||||
[1]=steampunk_blimp.copy_vector(steampunk_blimp.passenger_pos[1]),
|
||||
[2]=steampunk_blimp.copy_vector(steampunk_blimp.passenger_pos[2]),
|
||||
[3]=steampunk_blimp.copy_vector(steampunk_blimp.passenger_pos[3]),
|
||||
[4]=steampunk_blimp.copy_vector(steampunk_blimp.passenger_pos[4]),
|
||||
[5]=steampunk_blimp.copy_vector(steampunk_blimp.passenger_pos[5]),} --curr pos
|
||||
--self._passengers = {[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil,} --passenger names
|
||||
|
||||
self._passengers_base[1]=minetest.add_entity(pos,'steampunk_blimp:stand_base')
|
||||
self._passengers_base[1]:set_attach(self.object,'',self._passengers_base_pos[1],{x=0,y=0,z=0})
|
||||
|
||||
self._passengers_base[2]=minetest.add_entity(pos,'steampunk_blimp:stand_base')
|
||||
self._passengers_base[2]:set_attach(self.object,'',self._passengers_base_pos[2],{x=0,y=0,z=0})
|
||||
|
||||
self._passengers_base[3]=minetest.add_entity(pos,'steampunk_blimp:stand_base')
|
||||
self._passengers_base[3]:set_attach(self.object,'',self._passengers_base_pos[3],{x=0,y=0,z=0})
|
||||
|
||||
self._passengers_base[4]=minetest.add_entity(pos,'steampunk_blimp:stand_base')
|
||||
self._passengers_base[4]:set_attach(self.object,'',self._passengers_base_pos[4],{x=0,y=0,z=0})
|
||||
|
||||
self._passengers_base[5]=minetest.add_entity(pos,'steampunk_blimp:stand_base')
|
||||
self._passengers_base[5]:set_attach(self.object,'',self._passengers_base_pos[5],{x=0,y=0,z=0})
|
||||
--passengers positions
|
||||
self._passenger_is_sit = ap_airship.copy_vector({})
|
||||
self._passengers_base = ap_airship.copy_vector({})
|
||||
self._passengers_base_pos = ap_airship.copy_vector({})
|
||||
for i = 1,ap_airship.max_pos,1
|
||||
do
|
||||
self._passenger_is_sit[i] = 0
|
||||
self._passengers_base_pos[i] = ap_airship.copy_vector(ap_airship.passenger_pos[i])
|
||||
self._passengers_base[i]=minetest.add_entity(pos,'steampunk_blimp:stand_base')
|
||||
self._passengers_base[i]:set_attach(self.object,'',self._passengers_base_pos[i],{x=0,y=0,z=0})
|
||||
end
|
||||
|
||||
--animation load - stoped
|
||||
self.object:set_animation({x = 1, y = 47}, 0, 0, true)
|
||||
|
7
init.lua
7
init.lua
@ -7,7 +7,7 @@ steampunk_blimp.ideal_step = 0.02
|
||||
steampunk_blimp.rudder_limit = 30
|
||||
steampunk_blimp.iddle_rotation = 0
|
||||
steampunk_blimp.max_engine_acc = 3
|
||||
steampunk_blimp.max_seats = 5
|
||||
steampunk_blimp.max_seats = 7
|
||||
steampunk_blimp.pilot_base_pos = {x=0.0,y=20.821,z=-30}
|
||||
steampunk_blimp.passenger_pos = {
|
||||
[1] = {x=0.0,y=0,z=-15},
|
||||
@ -15,6 +15,8 @@ steampunk_blimp.passenger_pos = {
|
||||
[3] = {x=11,y=0,z=-12},
|
||||
[4] = {x=-11,y=0,z=14},
|
||||
[5] = {x=11,y=0,z=14},
|
||||
[6] = {x=-11,y=0,z=13},
|
||||
[7] = {x=11,y=0,z=13},
|
||||
}
|
||||
|
||||
steampunk_blimp.canvas_texture = "wool_white.png^[colorize:#f4e7c1:128"
|
||||
@ -76,6 +78,7 @@ steampunk_blimp.colors ={
|
||||
yellow='yellow',
|
||||
}
|
||||
|
||||
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "walk_map.lua")
|
||||
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "utilities.lua")
|
||||
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "control.lua")
|
||||
dofile(minetest.get_modpath("steampunk_blimp") .. DIR_DELIM .. "fuel_management.lua")
|
||||
@ -129,7 +132,7 @@ minetest.register_craftitem("steampunk_blimp:blimp", {
|
||||
local blimp = minetest.add_entity(pointed_pos, "steampunk_blimp:blimp")
|
||||
if blimp and placer then
|
||||
local ent = blimp:get_luaentity()
|
||||
ent._passengers = steampunk_blimp.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil,})
|
||||
ent._passengers = steampunk_blimp.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil, [6]=nil, [7]=nil})
|
||||
--minetest.chat_send_all('passengers: '.. dump(ent._passengers))
|
||||
local owner = placer:get_player_name()
|
||||
ent.owner = owner
|
||||
|
257
utilities.lua
257
utilities.lua
@ -74,7 +74,7 @@ end
|
||||
function steampunk_blimp.check_passenger_is_attached(self, name)
|
||||
local is_attached = false
|
||||
if is_attached == false then
|
||||
for i = 5,1,-1
|
||||
for i = steampunk_blimp.max_seats,1,-1
|
||||
do
|
||||
if self._passengers[i] == name then
|
||||
is_attached = true
|
||||
@ -91,7 +91,7 @@ function steampunk_blimp.rescueConnectionFailedPassengers(self)
|
||||
if self._disconnection_check_time > 1 then
|
||||
--minetest.chat_send_all(dump(self._passengers))
|
||||
self._disconnection_check_time = 0
|
||||
for i = 5,1,-1
|
||||
for i = steampunk_blimp.max_seats,1,-1
|
||||
do
|
||||
if self._passengers[i] then
|
||||
local player = minetest.get_player_by_name(self._passengers[i])
|
||||
@ -142,7 +142,7 @@ function steampunk_blimp.attach_pax(self, player, slot)
|
||||
|
||||
--now yes, lets attach the player
|
||||
--randomize the seat
|
||||
local t = {1,2,3,4,5}
|
||||
local t = {1,2,3,4,5,6,7}
|
||||
for i = 1, #t*2 do
|
||||
local a = math.random(#t)
|
||||
local b = math.random(#t)
|
||||
@ -156,6 +156,7 @@ function steampunk_blimp.attach_pax(self, player, slot)
|
||||
i = t[k]
|
||||
if self._passengers[i] == nil then
|
||||
do_attach(self, player, i)
|
||||
--minetest.chat_send_all(i)
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -168,7 +169,7 @@ function steampunk_blimp.dettach_pax(self, player, side)
|
||||
steampunk_blimp.remove_hud(player)
|
||||
|
||||
-- passenger clicked the object => driver gets off the vehicle
|
||||
for i = 5,1,-1
|
||||
for i = steampunk_blimp.max_seats,1,-1
|
||||
do
|
||||
if self._passengers[i] == name then
|
||||
self._passengers[i] = nil
|
||||
@ -328,7 +329,7 @@ function steampunk_blimp.checkAttach(self, player)
|
||||
if player then
|
||||
local player_attach = player:get_attach()
|
||||
if player_attach then
|
||||
for i = 5,1,-1
|
||||
for i = steampunk_blimp.max_seats,1,-1
|
||||
do
|
||||
if player_attach == self._passengers_base[i] then
|
||||
retVal = true
|
||||
@ -417,116 +418,12 @@ function steampunk_blimp.start_furnace(self)
|
||||
end
|
||||
end
|
||||
|
||||
function steampunk_blimp.boat_upper_deck_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, -47, -16)
|
||||
|
||||
if position.z >= -49 and position.z < -32 then --limit 10
|
||||
new_pos.y = 20.821
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -8, 8)
|
||||
return new_pos
|
||||
function steampunk_blimp.copy_vector(original_vector)
|
||||
local tablecopy = {}
|
||||
for k, v in pairs(original_vector) do
|
||||
tablecopy[k] = v
|
||||
end
|
||||
if position.z >= -32 and position.z < -14 then --limit 11
|
||||
new_pos.y = 20.821
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -11, 11)
|
||||
if position.z >= -28 then --timao
|
||||
if orig_pos.x <= -4 or orig_pos.x >= 4 then
|
||||
new_pos.x = steampunk_blimp.reclamp(new_pos.x, -4, 4)
|
||||
else
|
||||
new_pos.z = steampunk_blimp.reclamp(new_pos.z, -28, -20)
|
||||
end
|
||||
end
|
||||
if position.z > -24 then --escada
|
||||
if orig_pos.x <= 4 then
|
||||
new_pos.z = steampunk_blimp.reclamp(new_pos.z, -24, -12)
|
||||
end
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
|
||||
function steampunk_blimp.boat_lower_deck_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, -29, 45)
|
||||
if position.z > -31 and position.z < -14 then --limit 10
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -10, 10)
|
||||
return new_pos
|
||||
end
|
||||
if position.z >= -14 and position.z < -4 then --limit 11
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -12, 12)
|
||||
if position.z > -9 then
|
||||
if orig_pos.x <= -6 or orig_pos.x >= 6 then
|
||||
new_pos.x = steampunk_blimp.reclamp(new_pos.x, -6, 6)
|
||||
else
|
||||
new_pos.z = steampunk_blimp.reclamp(new_pos.z, -9, -4)
|
||||
end
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
if position.z >= -4 and position.z <= 4 then --limit 14
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(position.x, -14, 14)
|
||||
if orig_pos.x <= -6 or orig_pos.x >= 6 then new_pos.x = steampunk_blimp.reclamp(new_pos.x, -6, 6) end
|
||||
return new_pos
|
||||
end
|
||||
if position.z > 4 and position.z <= 19 then --limit 11
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(position.x, -12, 12)
|
||||
if position.z < 14 then
|
||||
if orig_pos.x <= -6 or orig_pos.x >= 6 then
|
||||
new_pos.x = steampunk_blimp.reclamp(new_pos.x, -6, 6)
|
||||
else
|
||||
new_pos.z = steampunk_blimp.reclamp(new_pos.z, 4, 14)
|
||||
end
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
if position.z > 19 and position.z <= 22 then --limit 10
|
||||
new_pos.y = 4.4
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -10, 10)
|
||||
return new_pos
|
||||
end
|
||||
if position.z > 22 and position.z <= 30 then --limit 7
|
||||
new_pos.y = 8.5
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -7, 7)
|
||||
return new_pos
|
||||
end
|
||||
if position.z > 30 and position.z <= 36 then --limit 5
|
||||
new_pos.y = 8.5
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -5, 5)
|
||||
return new_pos
|
||||
end
|
||||
if position.z > 36 and position.z < 47 then --limit 1
|
||||
new_pos.y = 8.5
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -2, 2)
|
||||
return new_pos
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
|
||||
function steampunk_blimp.ladder_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, -18, -12)
|
||||
if position.z > -20 and position.z < -10 then --limit 10
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, 4, 12)
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
|
||||
local function is_ladder_zone(pos)
|
||||
local ladder_zone = false
|
||||
if pos.z <= -12 and pos.z >= -18 and pos.x > 4 and pos.x < 12 then ladder_zone = true end
|
||||
return ladder_zone
|
||||
return tablecopy
|
||||
end
|
||||
|
||||
function steampunk_blimp.play_rope_sound(self)
|
||||
@ -536,136 +433,12 @@ function steampunk_blimp.play_rope_sound(self)
|
||||
ephemeral = true,})
|
||||
end
|
||||
|
||||
--note: index variable just for the walk
|
||||
local function get_result_pos(self, player, index)
|
||||
local pos = nil
|
||||
if player then
|
||||
local ctrl = player:get_player_control()
|
||||
|
||||
local direction = player:get_look_horizontal()
|
||||
local rotation = self.object:get_rotation()
|
||||
direction = direction - rotation.y
|
||||
|
||||
pos = vector.new()
|
||||
|
||||
local y_rot = -math.deg(direction)
|
||||
pos.y = y_rot --okay, this is strange to keep here, but as I dont use it anyway...
|
||||
|
||||
if ctrl.up or ctrl.down or ctrl.left or ctrl.right then
|
||||
player_api.set_animation(player, "walk", 30)
|
||||
|
||||
local speed = 0.7
|
||||
|
||||
dir = vector.new(ctrl.up and -1 or ctrl.down and 1 or 0, 0, ctrl.left and 1 or ctrl.right and -1 or 0)
|
||||
dir = vector.normalize(dir)
|
||||
dir = vector.rotate(dir, {x = 0, y = -direction, z = 0})
|
||||
|
||||
local time_correction = (self.dtime/steampunk_blimp.ideal_step)
|
||||
local move = speed * time_correction
|
||||
|
||||
pos.x = move * dir.x
|
||||
pos.z = move * dir.z
|
||||
|
||||
--lets fake walk sound
|
||||
if self._passengers_base_pos[index].dist_moved == nil then self._passengers_base_pos[index].dist_moved = 0 end
|
||||
self._passengers_base_pos[index].dist_moved = self._passengers_base_pos[index].dist_moved + move;
|
||||
if math.abs(self._passengers_base_pos[index].dist_moved) > 5 then
|
||||
self._passengers_base_pos[index].dist_moved = 0
|
||||
minetest.sound_play({name = "default_wood_footstep"},
|
||||
--{object = self._passengers_base_pos[index].object, gain = 0.1,
|
||||
{object = player,
|
||||
gain = 0.1,
|
||||
max_hear_distance = 5,
|
||||
ephemeral = true,})
|
||||
end
|
||||
else
|
||||
player_api.set_animation(player, "stand")
|
||||
end
|
||||
end
|
||||
return pos
|
||||
end
|
||||
|
||||
function steampunk_blimp.navigate_deck(pos, dpos, player)
|
||||
local pos_d = dpos
|
||||
local ladder_zone = is_ladder_zone(pos)
|
||||
local upper_deck_y = 20.821
|
||||
if player then
|
||||
if pos.y == upper_deck_y then
|
||||
pos_d = steampunk_blimp.boat_upper_deck_map(pos, dpos)
|
||||
elseif pos.y <= 8.5 and pos.y >= 0 then
|
||||
if ladder_zone == false then
|
||||
pos_d = steampunk_blimp.boat_lower_deck_map(pos, dpos)
|
||||
end
|
||||
elseif pos.y > 8.5 and pos.y < upper_deck_y then
|
||||
pos_d = steampunk_blimp.ladder_map(pos, dpos)
|
||||
end
|
||||
|
||||
local ctrl = player:get_player_control()
|
||||
if ctrl.jump or ctrl.sneak then --ladder
|
||||
if ladder_zone then
|
||||
--minetest.chat_send_all(dump(pos))
|
||||
if ctrl.jump then
|
||||
pos_d.y = pos_d.y + 0.9
|
||||
if pos_d.y > upper_deck_y then pos_d.y = upper_deck_y end
|
||||
end
|
||||
if ctrl.sneak then
|
||||
pos_d.y = pos_d.y - 0.9
|
||||
if pos_d.y < 0 then pos_d.y = 0 end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return pos_d
|
||||
end
|
||||
|
||||
function steampunk_blimp.move_persons(self)
|
||||
--self._passenger = nil
|
||||
if self.object == nil then return end
|
||||
for i = 5,1,-1
|
||||
do
|
||||
local player = nil
|
||||
if self._passengers[i] then player = minetest.get_player_by_name(self._passengers[i]) end
|
||||
|
||||
if self.driver_name and self._passengers[i] == self.driver_name then
|
||||
--clean driver if it's nil
|
||||
if player == nil then
|
||||
self._passengers[i] = nil
|
||||
self.driver_name = nil
|
||||
end
|
||||
else
|
||||
if self._passengers[i] ~= nil then
|
||||
--minetest.chat_send_all("pass: "..dump(self._passengers[i]))
|
||||
--the rest of the passengers
|
||||
if player then
|
||||
local result_pos = get_result_pos(self, player, i)
|
||||
local y_rot = 0
|
||||
if result_pos then
|
||||
y_rot = result_pos.y -- the only field that returns a rotation
|
||||
local new_pos = steampunk_blimp.copy_vector(self._passengers_base_pos[i])
|
||||
new_pos.x = new_pos.x - result_pos.z
|
||||
new_pos.z = new_pos.z - result_pos.x
|
||||
--minetest.chat_send_all(dump(new_pos))
|
||||
--local pos_d = steampunk_blimp.boat_lower_deck_map(self._passengers_base_pos[i], new_pos)
|
||||
local pos_d = steampunk_blimp.navigate_deck(self._passengers_base_pos[i], new_pos, player)
|
||||
--minetest.chat_send_all(dump(height))
|
||||
self._passengers_base_pos[i] = steampunk_blimp.copy_vector(pos_d)
|
||||
self._passengers_base[i]:set_attach(self.object,'',self._passengers_base_pos[i],{x=0,y=0,z=0})
|
||||
end
|
||||
--minetest.chat_send_all(dump(self._passengers_base_pos[i]))
|
||||
player:set_attach(self._passengers_base[i], "", {x = 0, y = 0, z = 0}, {x = 0, y = y_rot, z = 0})
|
||||
else
|
||||
--self._passengers[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function steampunk_blimp.copy_vector(original_vector)
|
||||
function steampunk_blimp.table_copy(table_here)
|
||||
local tablecopy = {}
|
||||
for k, v in pairs(original_vector) do
|
||||
for k, v in pairs(table_here) do
|
||||
tablecopy[k] = v
|
||||
end
|
||||
return tablecopy
|
||||
end
|
||||
|
||||
|
||||
|
353
walk_map.lua
Normal file
353
walk_map.lua
Normal file
@ -0,0 +1,353 @@
|
||||
function steampunk_blimp.clamp(value, min, max)
|
||||
local retVal = value
|
||||
if value < min then retVal = min end
|
||||
if value > max then retVal = max end
|
||||
--minetest.chat_send_all(value .. " - " ..retVal)
|
||||
return retVal
|
||||
end
|
||||
|
||||
function steampunk_blimp.reclamp(value, min, max)
|
||||
local retVal = value
|
||||
local mid = (max-min)/2
|
||||
if value > min and value <= (min+mid) then retVal = min end
|
||||
if value < max and value > (max-mid) then retVal = max end
|
||||
--minetest.chat_send_all(value .. " - return: " ..retVal .. " - mid: " .. mid)
|
||||
return retVal
|
||||
end
|
||||
|
||||
local function is_obstacle_zone(pos, start_point, end_point)
|
||||
local retVal = steampunk_blimp.table_copy(pos)
|
||||
|
||||
local min_x = 0
|
||||
local min_z = 0
|
||||
local max_x = 0
|
||||
local max_z = 0
|
||||
|
||||
if start_point.x <= end_point.x then min_x = start_point.x else min_x = end_point.x end
|
||||
if start_point.z <= end_point.z then min_z = start_point.z else min_z = end_point.z end
|
||||
if start_point.x > end_point.x then max_x = start_point.x else max_x = end_point.x end
|
||||
if start_point.z > end_point.z then max_z = start_point.z else max_z = end_point.z end
|
||||
|
||||
local mid_x = (max_x - min_x)/2
|
||||
local mid_z = (max_z - min_z)/2
|
||||
|
||||
if pos.x < max_x and pos.x > min_x+mid_x and
|
||||
pos.z < max_z and pos.z > min_z then
|
||||
retVal.x = max_x + 1
|
||||
return retVal
|
||||
end
|
||||
if pos.x > min_x and pos.x <= min_x+mid_x and
|
||||
pos.z < max_z and pos.z > min_z then
|
||||
retVal.x = min_x - 1
|
||||
return retVal
|
||||
end
|
||||
|
||||
local death_zone = 1.5 --to avoid the "slip" when colliding in y direction
|
||||
if pos.z < max_z + death_zone and pos.z > min_z+mid_z and
|
||||
pos.x > min_x and pos.x < max_x then
|
||||
retVal.z = max_z + 1
|
||||
return retVal
|
||||
end
|
||||
if pos.z > min_z - death_zone and pos.z <= min_z+mid_z and
|
||||
pos.x > min_x and pos.x < max_x then
|
||||
retVal.z = min_z - 1
|
||||
return retVal
|
||||
end
|
||||
|
||||
return retVal
|
||||
end
|
||||
|
||||
|
||||
function steampunk_blimp.boat_upper_deck_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, -47, -16)
|
||||
new_pos = is_obstacle_zone(new_pos, {x=4, z=-28}, {x=-4, z=-20}) --timao
|
||||
new_pos = is_obstacle_zone(new_pos, {x=-30, z=-24}, {x=4, z=-12})
|
||||
|
||||
if position.z >= -49 and position.z < -32 then --limit 10
|
||||
new_pos.y = 20.821
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -8, 8)
|
||||
return new_pos
|
||||
end
|
||||
if position.z >= -32 and position.z < -14 then --limit 11
|
||||
new_pos.y = 20.821
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -11, 11)
|
||||
|
||||
if position.z > -24 then --escada
|
||||
if orig_pos.x <= 4 then
|
||||
new_pos.z = steampunk_blimp.reclamp(new_pos.z, -24, -12)
|
||||
end
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
|
||||
local function is_ladder_zone(pos)
|
||||
local ladder_zone = false
|
||||
if pos.z <= -12 and pos.z >= -18 and pos.x > 4 and pos.x < 12 then ladder_zone = true end
|
||||
return ladder_zone
|
||||
end
|
||||
|
||||
function steampunk_blimp.boat_lower_deck_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, -29, 45)
|
||||
|
||||
if position.z > -31 and position.z < -14 then --limit 10
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -10, 10)
|
||||
new_pos = is_obstacle_zone(new_pos, {x=-6, z=-9}, {x=6, z=14}) --caldeira
|
||||
return new_pos
|
||||
end
|
||||
|
||||
if position.z >= -14 and position.z < -4 then --limit 11
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -12, 12)
|
||||
new_pos = is_obstacle_zone(new_pos, {x=-6, z=-9}, {x=6, z=14}) --caldeira
|
||||
return new_pos
|
||||
end
|
||||
|
||||
if position.z >= -4 and position.z <= 4 then --limit 14
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(position.x, -14, 14)
|
||||
new_pos = is_obstacle_zone(new_pos, {x=-6, z=-9}, {x=6, z=14}) --caldeira
|
||||
return new_pos
|
||||
end
|
||||
|
||||
if position.z > 4 and position.z <= 19 then --limit 11
|
||||
new_pos.y = 0
|
||||
new_pos.x = steampunk_blimp.clamp(position.x, -12, 12)
|
||||
new_pos = is_obstacle_zone(new_pos, {x=-6, z=-9}, {x=6, z=14}) --caldeira
|
||||
return new_pos
|
||||
end
|
||||
|
||||
if position.z > 19 and position.z <= 22 then --limit 10
|
||||
new_pos.y = 4.4
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -10, 10)
|
||||
return new_pos
|
||||
end
|
||||
|
||||
if position.z > 22 and position.z <= 30 then --limit 7
|
||||
new_pos.y = 8.5
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -7, 7)
|
||||
return new_pos
|
||||
end
|
||||
|
||||
if position.z > 30 and position.z <= 36 then --limit 5
|
||||
new_pos.y = 8.5
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -5, 5)
|
||||
return new_pos
|
||||
end
|
||||
|
||||
if position.z > 36 and position.z < 47 then --limit 1
|
||||
new_pos.y = 8.5
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -2, 2)
|
||||
return new_pos
|
||||
end
|
||||
|
||||
return new_pos
|
||||
end
|
||||
|
||||
--[[function steampunk_blimp.passengers_deck_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
local ladder_zone = is_ladder_zone(pos)
|
||||
|
||||
if ladder_zone then
|
||||
--limiting ladder space
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, 3, 118)
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -8.42, -2)
|
||||
else
|
||||
--limiting upper deck
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, 3, 109)
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -43, 43)
|
||||
|
||||
new_pos = is_obstacle_zone(new_pos, {x=30, z=10}, {x=2, z=48})
|
||||
new_pos = is_obstacle_zone(new_pos, {x=-30, z=10}, {x=-2, z=48})
|
||||
|
||||
new_pos = function steampunk_blimp.ladder_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, -18, -12)
|
||||
if position.z > -20 and position.z < -10 then --limit 10
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, 4, 12)
|
||||
end
|
||||
return new_pos
|
||||
endis_obstacle_zone(new_pos, {x=30, z=55}, {x=2, z=90})
|
||||
new_pos = is_obstacle_zone(new_pos, {x=-30, z=55}, {x=-2, z=90})
|
||||
end
|
||||
new_pos.y = 0
|
||||
|
||||
--minetest.chat_send_all("x: "..new_pos.x.." - z: "..new_pos.z)
|
||||
return new_pos
|
||||
end]]--
|
||||
|
||||
function steampunk_blimp.ladder_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, -18, -12)
|
||||
if position.z > -20 and position.z < -10 then --limit 10
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, 4, 12)
|
||||
end
|
||||
return new_pos
|
||||
end
|
||||
|
||||
--[[function steampunk_blimp.ladder_map(pos, dpos)
|
||||
local orig_pos = steampunk_blimp.copy_vector(pos)
|
||||
local position = steampunk_blimp.copy_vector(dpos)
|
||||
local new_pos = steampunk_blimp.copy_vector(dpos)
|
||||
new_pos.z = steampunk_blimp.clamp(new_pos.z, 112, 117)
|
||||
new_pos.x = steampunk_blimp.clamp(new_pos.x, -8.42, -2)
|
||||
|
||||
return new_pos
|
||||
end]]--
|
||||
|
||||
function steampunk_blimp.navigate_deck(pos, dpos, player)
|
||||
local pos_d = dpos
|
||||
local ladder_zone = is_ladder_zone(pos)
|
||||
|
||||
local upper_deck_y = 20.821
|
||||
local lower_deck_y = 0
|
||||
if player then
|
||||
if pos.y == upper_deck_y then
|
||||
pos_d = steampunk_blimp.boat_upper_deck_map(pos, dpos)
|
||||
elseif pos.y <= 8.5 and pos.y >= 0 then
|
||||
if ladder_zone == false then
|
||||
pos_d = steampunk_blimp.boat_lower_deck_map(pos, dpos)
|
||||
end
|
||||
elseif pos.y > 8.5 and pos.y < upper_deck_y then
|
||||
pos_d = steampunk_blimp.ladder_map(pos, dpos)
|
||||
end
|
||||
|
||||
local ctrl = player:get_player_control()
|
||||
if ctrl.jump or ctrl.sneak then --ladder
|
||||
if ladder_zone then
|
||||
--minetest.chat_send_all(dump(pos))
|
||||
if ctrl.jump then
|
||||
pos_d.y = pos_d.y + 0.9
|
||||
if pos_d.y > upper_deck_y then pos_d.y = upper_deck_y end
|
||||
end
|
||||
if ctrl.sneak then
|
||||
pos_d.y = pos_d.y - 0.9
|
||||
if pos_d.y < lower_deck_y then pos_d.y = lower_deck_y end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--minetest.chat_send_all(dump(pos_d))
|
||||
|
||||
return pos_d
|
||||
end
|
||||
|
||||
--note: index variable just for the walk
|
||||
--this function was improved by Auri Collings on steampumove_personsnk_blimp
|
||||
local function get_result_pos(self, player, index)
|
||||
local pos = nil
|
||||
if player then
|
||||
local ctrl = player:get_player_control()
|
||||
|
||||
local direction = player:get_look_horizontal()
|
||||
local rotation = self.object:get_rotation()
|
||||
direction = direction - rotation.y
|
||||
|
||||
pos = vector.new()
|
||||
|
||||
local y_rot = -math.deg(direction)
|
||||
pos.y = y_rot --okay, this is strange to keep here, but as I dont use it anyway...
|
||||
|
||||
|
||||
if ctrl.up or ctrl.down or ctrl.left or ctrl.right then
|
||||
player_api.set_animation(player, "walk", 30)
|
||||
|
||||
local speed = 0.4
|
||||
|
||||
dir = vector.new(ctrl.up and -1 or ctrl.down and 1 or 0, 0, ctrl.left and 1 or ctrl.right and -1 or 0)
|
||||
dir = vector.normalize(dir)
|
||||
dir = vector.rotate(dir, {x = 0, y = -direction, z = 0})
|
||||
|
||||
local time_correction = (self.dtime/steampunk_blimp.ideal_step)
|
||||
local move = speed * time_correction
|
||||
|
||||
pos.x = move * dir.x
|
||||
pos.z = move * dir.z
|
||||
|
||||
--lets fake walk sound
|
||||
if self._passengers_base_pos[index].dist_moved == nil then self._passengers_base_pos[index].dist_moved = 0 end
|
||||
self._passengers_base_pos[index].dist_moved = self._passengers_base_pos[index].dist_moved + move;
|
||||
if math.abs(self._passengers_base_pos[index].dist_moved) > 5 then
|
||||
self._passengers_base_pos[index].dist_moved = 0
|
||||
minetest.sound_play({name = "default_wood_footstep"},
|
||||
{object = player, gain = 0.1,
|
||||
max_hear_distance = 5,
|
||||
ephemeral = true,})
|
||||
end
|
||||
else
|
||||
player_api.set_animation(player, "stand")
|
||||
end
|
||||
end
|
||||
return pos
|
||||
end
|
||||
|
||||
|
||||
function steampunk_blimp.move_persons(self)
|
||||
--self._passenger = nil
|
||||
if self.object == nil then return end
|
||||
|
||||
for i = steampunk_blimp.max_seats,1,-1
|
||||
do
|
||||
local player = nil
|
||||
if self._passengers[i] then player = minetest.get_player_by_name(self._passengers[i]) end
|
||||
|
||||
if self.driver_name and self._passengers[i] == self.driver_name then
|
||||
--clean driver if it's nil
|
||||
if player == nil then
|
||||
self._passengers[i] = nil
|
||||
self.driver_name = nil
|
||||
end
|
||||
else
|
||||
if self._passengers[i] ~= nil then
|
||||
--minetest.chat_send_all("pass: "..dump(self._passengers[i]))
|
||||
--the rest of the passengers
|
||||
if player then
|
||||
if self._passenger_is_sit[i] == 0 then
|
||||
local result_pos = get_result_pos(self, player, i)
|
||||
local y_rot = 0
|
||||
if result_pos then
|
||||
y_rot = result_pos.y -- the only field that returns a rotation
|
||||
local new_pos = steampunk_blimp.copy_vector(self._passengers_base_pos[i])
|
||||
new_pos.x = new_pos.x - result_pos.z
|
||||
new_pos.z = new_pos.z - result_pos.x
|
||||
--minetest.chat_send_all(dump(new_pos))
|
||||
local pos_d = steampunk_blimp.navigate_deck(self._passengers_base_pos[i], new_pos, player)
|
||||
--minetest.chat_send_all(dump(height))
|
||||
self._passengers_base_pos[i] = steampunk_blimp.copy_vector(pos_d)
|
||||
self._passengers_base[i]:set_attach(self.object,'',self._passengers_base_pos[i],{x=0,y=0,z=0})
|
||||
end
|
||||
--minetest.chat_send_all(dump(self._passengers_base_pos[i]))
|
||||
player:set_attach(self._passengers_base[i], "", {x = 0, y = 0, z = 0}, {x = 0, y = y_rot, z = 0})
|
||||
else
|
||||
local y_rot = 0
|
||||
if self._passenger_is_sit[i] == 1 then y_rot = 0 end
|
||||
if self._passenger_is_sit[i] == 2 then y_rot = 90 end
|
||||
if self._passenger_is_sit[i] == 3 then y_rot = 180 end
|
||||
if self._passenger_is_sit[i] == 4 then y_rot = 270 end
|
||||
player:set_attach(self._passengers_base[i], "", {x = 0, y = 3.6, z = 0}, {x = 0, y = y_rot, z = 0})
|
||||
airutils.sit(player)
|
||||
end
|
||||
else
|
||||
--self._passengers[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user