world anchor

This commit is contained in:
Foghrye4 2016-07-10 15:15:42 +03:00
parent 581a30859a
commit 993e3cc0c5
23 changed files with 932 additions and 283 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
## Editors and Development environments
*~
## Those too big
*.xcf

View File

@ -1,5 +1,6 @@
saturn.space_station_pos = {x = -64, y = -64, z = -64}
saturn.default_slot_color = "listcolors[#80808069;#00000069;#141318;#30434C;#FFF]"
saturn.MAX_ITEM_WEAR = 65535 -- Internal minetest constant and should not be changed
saturn.REPAIR_PRICE_PER_WEAR = 0.0001
saturn.saturn_spaceships = {}
@ -9,8 +10,9 @@ saturn.save_timer = saturn.players_save_interval
saturn.market_update_interval = 1000
saturn.market_update_timer = saturn.market_update_interval
saturn.item_stats = {}
saturn.market_item_count = 0
saturn.market_items = {}
saturn.ore_market_items = {}
saturn.microfactory_market_items = {}
saturn.enemy_item_count = 0
saturn.enemy_items = {}
saturn.ores = {}
@ -22,6 +24,8 @@ saturn.hud_attack_info_text_id = -1
saturn.hud_attack_info_frame_id = -1
saturn.hud_hotbar_cooldown = {}
saturn.hotbar_cooldown = {}
saturn.microfactory_nets = {}
saturn.recipe_outputs = {}
local fov = minetest.setting_get("fov")
local fov_x = fov*1.1
@ -431,13 +435,26 @@ local throwable_item_entity={
minetest.register_entity("saturn:throwable_item_entity", throwable_item_entity)
local get_color_formspec_frame = function(x,y,w,h,color,thickness)
return "box["..(x-thickness)..","..(y-thickness)..";"..(w+thickness-0.2)..","..(thickness)..";"..color.."]"..
"box["..(x+w-0.2)..","..(y-thickness)..";"..(thickness)..","..(h+thickness-0.2)..";"..color.."]"..
"box["..x..","..(y+h-0.2)..";"..(w+thickness-0.2)..","..(thickness)..";"..color.."]"..
"box["..(x-thickness)..","..y..";"..(thickness)..","..(h+thickness-0.2)..";"..color.."]"
end
local get_formspec_label_with_bg_color = function(x,y,w,h,color,text)
return "box["..x..","..y..";"..w..","..h..";"..color.."]".."label["..x..","..(y-0.2)..";"..text.."]"
end
saturn.get_ship_equipment_formspec = function(player)
local inv = player:get_inventory()
local name = player:get_player_name()
local formspec = "list[current_player;ship_hull;0,0;1,1;]"..
local formspec = "list[current_player;ship_hull;0,0;1,1;]".."box[0,0;0.8,0.9;#FFFFFF]"..get_formspec_label_with_bg_color(0,1,0.8,0.2,"#FFFFFF","Hull")..
"image_button[0.81,0;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+ship_hull+1;]"
if inv:get_size("engine") > 0 then
formspec = formspec.."list[current_player;engine;1,0;2,4;]"
formspec = formspec.."box[1,0;1.8,3.9;#FFA800]"..get_formspec_label_with_bg_color(0,1.4,0.8,0.2,"#FFA800","Engine")..
"list[current_player;engine;1,0;2,4;]"
for ix = 1, 2 do
for iy = 0, math.ceil(inv:get_size("engine")/2)-1 do
formspec = formspec.."image_button["..(ix+0.81)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+engine+"..(ix+2*iy)..";]"
@ -445,31 +462,36 @@ saturn.get_ship_equipment_formspec = function(player)
end
end
if inv:get_size("power_generator") > 0 then
formspec = formspec.."list[current_player;power_generator;3,0;1,4;]"
formspec = formspec.."box[3,0;0.8,3.9;#FF2200]"..get_formspec_label_with_bg_color(0,1.8,0.8,0.2,"#FF2200","Power")..
"list[current_player;power_generator;3,0;1,4;]"
for iy = 0, inv:get_size("power_generator")-1 do
formspec = formspec.."image_button[3.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+power_generator+"..(iy+1)..";]"
end
end
if inv:get_size("droid") > 0 then
formspec = formspec.."list[current_player;droid;4,0;1,4;]"
formspec = formspec.."box[4,0;0.8,3.9;#770000]"..get_formspec_label_with_bg_color(0,2.2,0.8,0.2,"#770000","Droids")..
"list[current_player;droid;4,0;1,4;]"
for iy = 0, inv:get_size("droid")-1 do
formspec = formspec.."image_button[4.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+droid+"..(iy+1)..";]"
end
end
if inv:get_size("scaner") > 0 then
formspec = formspec.."list[current_player;scaner;5,0;1,4;]"
formspec = formspec.."box[5,0;0.8,3.9;#00FFF0]"..get_formspec_label_with_bg_color(0,2.6,0.8,0.2,"#00FFF0","Scaner")..
"list[current_player;scaner;5,0;1,4;]"
for iy = 0, inv:get_size("scaner")-1 do
formspec = formspec.."image_button[5.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+scaner+"..(iy+1)..";]"
end
end
if inv:get_size("forcefield_generator") > 0 then
formspec = formspec.."list[current_player;forcefield_generator;6,0;1,1;]"
formspec = formspec.."box[6,0;0.8,0.9;#A0A0FF]"..get_formspec_label_with_bg_color(0,3,0.8,0.2,"#A0A0FF","Forcefield")..
"list[current_player;forcefield_generator;6,0;1,1;]"
for iy = 0, inv:get_size("forcefield_generator")-1 do
formspec = formspec.."image_button[6.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+forcefield_generator+"..(iy+1)..";]"
end
end
if inv:get_size("special_equipment") > 0 then
formspec = formspec.."list[current_player;special_equipment;7,0;1,4;]"
formspec = formspec.."box[7,0;0.8,3.9;#A0FFA0]"..get_formspec_label_with_bg_color(0,3.4,0.8,0.2,"#A0FFA0","Special")..
"list[current_player;special_equipment;7,0;1,4;]"
for iy = 0, inv:get_size("special_equipment")-1 do
formspec = formspec.."image_button[7.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+special_equipment+"..(iy+1)..";]"
end
@ -477,21 +499,27 @@ saturn.get_ship_equipment_formspec = function(player)
return formspec
end
saturn.get_player_inventory_formspec = function(player, tab)
local name = player:get_player_name()
local default_formspec = "size[8,8.6]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"tabheader[0,0;tabs;Status,Hull;"..tab..";true;false]"
saturn.get_main_inventory_formspec = function(player, vertical_offset)
local default_formspec = "list[current_player;main;0,"..vertical_offset..";8,1;]"..
"list[current_player;main;0,"..(vertical_offset+1.25)..";8,3;8]"..
saturn.default_slot_color
for ix = 1, 8 do
for iy = 0, 3 do
if iy==0 then
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.25;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..vertical_offset..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
else
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy+4.5)..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy+vertical_offset+0.25)..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
end
end
end
return default_formspec
end
saturn.get_player_inventory_formspec = function(player, tab)
local name = player:get_player_name()
local default_formspec = "size[8,8.6]"..
"tabheader[0,0;tabs;Status,Hull;"..tab..";true;false]"..
saturn.get_main_inventory_formspec(player,4.25)
local hull = player:get_inventory():get_stack("ship_hull", 1)
local hull_stats = saturn.get_item_stats(hull:get_name())
if hull_stats then
@ -529,8 +557,7 @@ saturn.get_item_info_formspec = function(item_stack)
local formspec = "size[8,8.6]"..
"item_image[0,0;1,1;"..item_name.."]"..
"label[1,0.0;"..item_name.."]"..
"label[7,0;Back]"..
"image_button[7.5,0.1;0.5,0.4;saturn_back_button_icon.png;ii_return;]"
"image_button[6.5,0.1;1.5,0.4;saturn_back_button_icon.png;ii_return;Back ;false;false;saturn_back_button_icon.png]"
local row_step = 0.3
local row = 1-row_step
formspec = formspec.."label[0,"..row..";Basic properties:]"
@ -615,17 +642,12 @@ saturn.get_item_price = function(item_name)
return 0
end
local generate_random_market_item = function()
local item_name = saturn.market_items[math.random(saturn.market_item_count)]
return ItemStack(item_name)
end
saturn.get_pseudogaussian_random = function(median, scale)
return math.tan(math.random()*math.pi/2)*scale+median
end
saturn.generate_random_enemy_item = function()
local item_name = saturn.enemy_items[math.random(saturn.enemy_item_count)]
local item_name = saturn.enemy_items[math.random(#saturn.enemy_items)]
local item_stack = ItemStack(item_name)
local item_stats = saturn.item_stats[item_name]
local possible_modifications = item_stats.possible_modifications
@ -649,15 +671,6 @@ saturn.generate_random_enemy_item = function()
return item_stack
end
saturn.update_space_station_market = function()
local stack = generate_random_market_item()
if saturn.space_station_inv:room_for_item("market", stack) then
saturn.space_station_inv:add_item("market", stack)
else
saturn.space_station_inv:set_stack("market",math.random(8*3), stack)
end
end
minetest.register_globalstep(function(dtime)
saturn.save_timer = saturn.save_timer - 1
if saturn.save_timer <= 0 then
@ -693,7 +706,3 @@ end)
minetest.register_on_shutdown(function()
saturn:save_players()
end)
minetest.register_on_leaveplayer(function(player)
saturn:save_players()
end)

View File

@ -1,5 +1,6 @@
saturn.space_station_pos = {x = -64, y = -64, z = -64}
saturn.default_slot_color = "listcolors[#80808069;#00000069;#141318;#30434C;#FFF]"
saturn.MAX_ITEM_WEAR = 65535 -- Internal minetest constant and should not be changed
saturn.REPAIR_PRICE_PER_WEAR = 0.0001
saturn.saturn_spaceships = {}
@ -9,8 +10,9 @@ saturn.save_timer = saturn.players_save_interval
saturn.market_update_interval = 1000
saturn.market_update_timer = saturn.market_update_interval
saturn.item_stats = {}
saturn.market_item_count = 0
saturn.market_items = {}
saturn.ore_market_items = {}
saturn.microfactory_market_items = {}
saturn.enemy_item_count = 0
saturn.enemy_items = {}
saturn.ores = {}
@ -22,6 +24,8 @@ saturn.hud_attack_info_text_id = -1
saturn.hud_attack_info_frame_id = -1
saturn.hud_hotbar_cooldown = {}
saturn.hotbar_cooldown = {}
saturn.microfactory_nets = {}
saturn.recipe_outputs = {}
local fov = minetest.setting_get("fov")
local fov_x = fov*1.1
@ -271,11 +275,13 @@ saturn.punch_object = function(punched, puncher, damage)
for listpos,stack in pairs(list) do
if stack ~= nil and not stack:is_empty() then
inv:remove_item(list_name, stack)
saturn.create_explosion_effect(punched:getpos())
saturn.throw_item(stack, punched:get_attach(), punched:getpos())
if list_name ~= "ship_hull" then
saturn.throw_item(stack, punched:get_attach(), punched:getpos())
end
end
end
end
saturn.create_explosion_effect(punched:getpos())
inv:set_stack("ship_hull", 1, saturn:get_escape_pod())
else
inv:set_stack("ship_hull", 1, ship_hull_stack)
@ -429,13 +435,26 @@ local throwable_item_entity={
minetest.register_entity("saturn:throwable_item_entity", throwable_item_entity)
local get_color_formspec_frame = function(x,y,w,h,color,thickness)
return "box["..(x-thickness)..","..(y-thickness)..";"..(w+thickness-0.2)..","..(thickness)..";"..color.."]"..
"box["..(x+w-0.2)..","..(y-thickness)..";"..(thickness)..","..(h+thickness-0.2)..";"..color.."]"..
"box["..x..","..(y+h-0.2)..";"..(w+thickness-0.2)..","..(thickness)..";"..color.."]"..
"box["..(x-thickness)..","..y..";"..(thickness)..","..(h+thickness-0.2)..";"..color.."]"
end
local get_formspec_label_with_bg_color = function(x,y,w,h,color,text)
return "box["..x..","..y..";"..w..","..h..";"..color.."]".."label["..x..","..(y-0.2)..";"..text.."]"
end
saturn.get_ship_equipment_formspec = function(player)
local inv = player:get_inventory()
local name = player:get_player_name()
local formspec = "list[current_player;ship_hull;0,0;1,1;]"..
local formspec = "list[current_player;ship_hull;0,0;1,1;]".."box[0,0;0.8,0.9;#FFFFFF]"..get_formspec_label_with_bg_color(0,1,0.8,0.2,"#FFFFFF","Hull")..
"image_button[0.81,0;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+ship_hull+1;]"
if inv:get_size("engine") > 0 then
formspec = formspec.."list[current_player;engine;1,0;2,4;]"
formspec = formspec.."box[1,0;1.8,3.9;#FFA800]"..get_formspec_label_with_bg_color(0,1.4,0.8,0.2,"#FFA800","Engine")..
"list[current_player;engine;1,0;2,4;]"
for ix = 1, 2 do
for iy = 0, math.ceil(inv:get_size("engine")/2)-1 do
formspec = formspec.."image_button["..(ix+0.81)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+engine+"..(ix+2*iy)..";]"
@ -443,31 +462,36 @@ saturn.get_ship_equipment_formspec = function(player)
end
end
if inv:get_size("power_generator") > 0 then
formspec = formspec.."list[current_player;power_generator;3,0;1,4;]"
formspec = formspec.."box[3,0;0.8,3.9;#FF2200]"..get_formspec_label_with_bg_color(0,1.8,0.8,0.2,"#FF2200","Power")..
"list[current_player;power_generator;3,0;1,4;]"
for iy = 0, inv:get_size("power_generator")-1 do
formspec = formspec.."image_button[3.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+power_generator+"..(iy+1)..";]"
end
end
if inv:get_size("droid") > 0 then
formspec = formspec.."list[current_player;droid;4,0;1,4;]"
formspec = formspec.."box[4,0;0.8,3.9;#770000]"..get_formspec_label_with_bg_color(0,2.2,0.8,0.2,"#770000","Droids")..
"list[current_player;droid;4,0;1,4;]"
for iy = 0, inv:get_size("droid")-1 do
formspec = formspec.."image_button[4.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+droid+"..(iy+1)..";]"
end
end
if inv:get_size("scaner") > 0 then
formspec = formspec.."list[current_player;scaner;5,0;1,4;]"
formspec = formspec.."box[5,0;0.8,3.9;#00FFF0]"..get_formspec_label_with_bg_color(0,2.6,0.8,0.2,"#00FFF0","Scaner")..
"list[current_player;scaner;5,0;1,4;]"
for iy = 0, inv:get_size("scaner")-1 do
formspec = formspec.."image_button[5.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+scaner+"..(iy+1)..";]"
end
end
if inv:get_size("forcefield_generator") > 0 then
formspec = formspec.."list[current_player;forcefield_generator;6,0;1,1;]"
formspec = formspec.."box[6,0;0.8,0.9;#A0A0FF]"..get_formspec_label_with_bg_color(0,3,0.8,0.2,"#A0A0FF","Forcefield")..
"list[current_player;forcefield_generator;6,0;1,1;]"
for iy = 0, inv:get_size("forcefield_generator")-1 do
formspec = formspec.."image_button[6.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+forcefield_generator+"..(iy+1)..";]"
end
end
if inv:get_size("special_equipment") > 0 then
formspec = formspec.."list[current_player;special_equipment;7,0;1,4;]"
formspec = formspec.."box[7,0;0.8,3.9;#A0FFA0]"..get_formspec_label_with_bg_color(0,3.4,0.8,0.2,"#A0FFA0","Special")..
"list[current_player;special_equipment;7,0;1,4;]"
for iy = 0, inv:get_size("special_equipment")-1 do
formspec = formspec.."image_button[7.81,"..iy..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+special_equipment+"..(iy+1)..";]"
end
@ -475,21 +499,26 @@ saturn.get_ship_equipment_formspec = function(player)
return formspec
end
saturn.get_player_inventory_formspec = function(player, tab)
local name = player:get_player_name()
local default_formspec = "size[8,8.6]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"tabheader[0,0;tabs;Status,Hull;"..tab..";true;false]"
saturn.get_main_inventory_formspec = function(player, vertical_offset)
local default_formspec = "list[current_player;main;0,"..vertical_offset..";8,1;]"..
"list[current_player;main;0,"..(vertical_offset+1.25)..";8,3;8]"..
saturn.default_slot_color
for ix = 1, 8 do
for iy = 0, 3 do
if iy==0 then
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.25;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..vertical_offset..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
else
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy+4.5)..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy+vertical_offset+0.25)..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
end
end
end
return default_formspec
end
saturn.get_player_inventory_formspec = function(player, tab)
local name = player:get_player_name()
local default_formspec = "size[8,8.6]"..get_main_inventory_formspec(player,4.25)
"tabheader[0,0;tabs;Status,Hull;"..tab..";true;false]"..
local hull = player:get_inventory():get_stack("ship_hull", 1)
local hull_stats = saturn.get_item_stats(hull:get_name())
if hull_stats then
@ -527,8 +556,7 @@ saturn.get_item_info_formspec = function(item_stack)
local formspec = "size[8,8.6]"..
"item_image[0,0;1,1;"..item_name.."]"..
"label[1,0.0;"..item_name.."]"..
"label[7,0;Back]"..
"image_button[7.5,0.1;0.5,0.4;saturn_back_button_icon.png;ii_return;]"
"image_button[6.5,0.1;1.5,0.4;saturn_back_button_icon.png;ii_return;Back ;false;false;saturn_back_button_icon.png]"
local row_step = 0.3
local row = 1-row_step
formspec = formspec.."label[0,"..row..";Basic properties:]"
@ -613,17 +641,12 @@ saturn.get_item_price = function(item_name)
return 0
end
local generate_random_market_item = function()
local item_name = saturn.market_items[math.random(saturn.market_item_count)]
return ItemStack(item_name)
end
saturn.get_pseudogaussian_random = function(median, scale)
return math.tan(math.random()*math.pi/2)*scale+median
end
saturn.generate_random_enemy_item = function()
local item_name = saturn.enemy_items[math.random(saturn.enemy_item_count)]
local item_name = saturn.enemy_items[math.random(#saturn.enemy_items)]
local item_stack = ItemStack(item_name)
local item_stats = saturn.item_stats[item_name]
local possible_modifications = item_stats.possible_modifications
@ -647,15 +670,6 @@ saturn.generate_random_enemy_item = function()
return item_stack
end
saturn.update_space_station_market = function()
local stack = generate_random_market_item()
if saturn.space_station_inv:room_for_item("market", stack) then
saturn.space_station_inv:add_item("market", stack)
else
saturn.space_station_inv:set_stack("market",math.random(8*3), stack)
end
end
minetest.register_globalstep(function(dtime)
saturn.save_timer = saturn.save_timer - 1
if saturn.save_timer <= 0 then
@ -691,7 +705,3 @@ end)
minetest.register_on_shutdown(function()
saturn:save_players()
end)
minetest.register_on_leaveplayer(function(player)
saturn:save_players()
end)

View File

@ -1,4 +1,4 @@
-- Version 0.001
-- Version 0.002
-- Foghrye4
saturn = rawget(_G, "saturn") or {}
@ -12,8 +12,10 @@ local modpath = minetest.get_modpath("saturn")
dofile(modpath .. "/math_utils.lua")
dofile(modpath .. "/global_functions_and_variables.lua")
dofile(modpath .. "/nodes.lua")
dofile(modpath .. "/microfactories.lua")
dofile(modpath .. "/items.lua")
dofile(modpath .. "/space_station.lua")
dofile(modpath .. "/mapgen.lua")
dofile(modpath .. "/player.lua")
dofile(modpath .. "/enemy.lua")

View File

@ -1,4 +1,4 @@
-- Version 0.001
-- Version 0.002
-- Foghrye4
saturn = rawget(_G, "saturn") or {}
@ -9,6 +9,7 @@ minetest.setting_set("movement_gravity", 0)
local modpath = minetest.get_modpath("saturn")
dofile(modpath .. "/math_utils.lua")
dofile(modpath .. "/global_functions_and_variables.lua")
dofile(modpath .. "/nodes.lua")
dofile(modpath .. "/items.lua")
@ -16,3 +17,4 @@ dofile(modpath .. "/space_station.lua")
dofile(modpath .. "/mapgen.lua")
dofile(modpath .. "/player.lua")
dofile(modpath .. "/enemy.lua")
dofile(modpath .. "/microfactories.lua")

View File

@ -38,14 +38,10 @@ local function register_wearable_item(registry_name, tool_definition, stats)
minetest.register_tool(registry_name, tool_definition)
saturn.set_item_stats(registry_name, stats)
if stats.is_market_item then
local _market_item_count = saturn.market_item_count + 1
saturn.market_items[_market_item_count] = registry_name
saturn.market_item_count = _market_item_count
table.insert(saturn.market_items,registry_name)
end
if stats.is_enemy_item then
local _enemy_item_count = saturn.enemy_item_count + 1
saturn.enemy_items[_enemy_item_count] = registry_name
saturn.enemy_item_count = _enemy_item_count
table.insert(saturn.enemy_items,registry_name)
end
end
@ -598,68 +594,6 @@ register_wearable_item("saturn:enemy_particle_emitter",{
possible_modifications = default_enemy_weapon_item_possible_modifications,
})
-- Misc.
register_wearable_item("saturn:enemy_hull_shard_a",{
description = "Enemy hull shard A",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:1",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_wearable_item("saturn:enemy_hull_shard_b",{
description = "Enemy hull shard B",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:2",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 500,
volume = 10,
price = 120,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_wearable_item("saturn:enemy_hull_shard_c",{
description = "Enemy hull shard C",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:3",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_wearable_item("saturn:enemy_hull_shard_d",{
description = "Enemy hull shard D",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:4",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
minetest.register_chatcommand("give_enemy_item", {
params = "",
description = "Give to me random enemy item",
@ -681,3 +615,101 @@ minetest.register_chatcommand("give_enemy_item", {
end,
})
-- Craft items
local function register_craft_item(registry_name, item_definition, stats)
item_definition.wield_image = "null.png"
item_definition.on_drop = function(itemstack, player, pos)
minetest.sound_play("saturn_item_drop", {to_player = player:get_player_name()})
saturn.throw_item(itemstack, player, pos)
itemstack:clear()
return itemstack
end
minetest.register_craftitem(registry_name, item_definition)
saturn.set_item_stats(registry_name, stats)
if stats.is_market_item then
table.insert(saturn.market_items,registry_name)
end
if stats.is_enemy_item then
table.insert(saturn.enemy_items,registry_name)
end
if stats.is_ore then
table.insert(saturn.ore_market_items, registry_name)
end
end
register_craft_item("saturn:enemy_hull_shard_a",{
description = "Enemy hull shard A",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:1",
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:enemy_hull_shard_b",{
description = "Enemy hull shard B",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:2",
},{
weight = 500,
volume = 10,
price = 120,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:enemy_hull_shard_c",{
description = "Enemy hull shard C",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:3",
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:enemy_hull_shard_d",{
description = "Enemy hull shard D",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:4",
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:clean_water",{
description = "Clean water",
inventory_image = "saturn_cells.png^[verticalframe:64:1",
},{
weight = 10,
volume = 0.01,
price = 1,
is_ore = true,
})
register_craft_item("saturn:heavy_water",{
description = "Heavy water",
inventory_image = "saturn_cells.png^[verticalframe:64:2",
},{
weight = 10,
volume = 0.01,
price = 10,
is_ore = true,
})
register_craft_item("saturn:silicate_mix",{
description = "Silicate mix",
inventory_image = "saturn_cells.png^[verticalframe:64:3",
},{
weight = 10,
volume = 0.01,
price = 1,
is_ore = true,
})

View File

@ -38,14 +38,10 @@ local function register_wearable_item(registry_name, tool_definition, stats)
minetest.register_tool(registry_name, tool_definition)
saturn.set_item_stats(registry_name, stats)
if stats.is_market_item then
local _market_item_count = saturn.market_item_count + 1
saturn.market_items[_market_item_count] = registry_name
saturn.market_item_count = _market_item_count
table.insert(saturn.market_items,registry_name)
end
if stats.is_enemy_item then
local _enemy_item_count = saturn.enemy_item_count + 1
saturn.enemy_items[_enemy_item_count] = registry_name
saturn.enemy_item_count = _enemy_item_count
table.insert(saturn.enemy_items,registry_name)
end
end
@ -217,8 +213,8 @@ local retractor_on_use = function(stack, player, pointed_thing)
pos = object_pos,
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 0.1,
size = 6,
expirationtime = 1.0,
size = 16,
collisiondetection = false,
vertical = false,
texture = "saturn_green_halo.png"
@ -237,8 +233,8 @@ local retractor_on_use = function(stack, player, pointed_thing)
pos = object_pos,
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 0.1,
size = 6,
expirationtime = 1.0,
size = 16,
collisiondetection = false,
vertical = false,
texture = "saturn_green_halo.png"
@ -598,68 +594,6 @@ register_wearable_item("saturn:enemy_particle_emitter",{
possible_modifications = default_enemy_weapon_item_possible_modifications,
})
-- Misc.
register_wearable_item("saturn:enemy_hull_shard_a",{
description = "Enemy hull shard A",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:1",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_wearable_item("saturn:enemy_hull_shard_b",{
description = "Enemy hull shard B",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:2",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 500,
volume = 10,
price = 120,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_wearable_item("saturn:enemy_hull_shard_c",{
description = "Enemy hull shard C",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:3",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_wearable_item("saturn:enemy_hull_shard_d",{
description = "Enemy hull shard D",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:4",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {},
},
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
minetest.register_chatcommand("give_enemy_item", {
params = "",
description = "Give to me random enemy item",
@ -681,3 +615,101 @@ minetest.register_chatcommand("give_enemy_item", {
end,
})
-- Craft items
local function register_craft_item(registry_name, item_definition, stats)
item_definition.wield_image = "null.png"
item_definition.on_drop = function(itemstack, player, pos)
minetest.sound_play("saturn_item_drop", {to_player = player:get_player_name()})
saturn.throw_item(itemstack, player, pos)
itemstack:clear()
return itemstack
end
minetest.register_craftitem(registry_name, item_definition)
saturn.set_item_stats(registry_name, stats)
if stats.is_market_item then
table.insert(saturn.market_items,registry_name)
end
if stats.is_enemy_item then
table.insert(saturn.enemy_items,registry_name)
end
if stats.is_ore then
table.insert(saturn.ore_market_items, registry_name)
end
end
register_craft_item("saturn:enemy_hull_shard_a",{
description = "Enemy hull shard A",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:1",
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:enemy_hull_shard_b",{
description = "Enemy hull shard B",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:2",
},{
weight = 500,
volume = 10,
price = 120,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:enemy_hull_shard_c",{
description = "Enemy hull shard C",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:3",
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:enemy_hull_shard_d",{
description = "Enemy hull shard D",
inventory_image = "saturn_enemy_hull_shards.png^[verticalframe:4:4",
},{
weight = 400,
volume = 10,
price = 100,
max_wear = 2000, -- out of 65535
is_enemy_item = true,
})
register_craft_item("saturn:clean_water",{
description = "Clean water",
inventory_image = "saturn_cells.png^[verticalframe:64:2",
},{
weight = 10,
volume = 0.01,
price = 1,
is_ore = true,
})
register_craft_item("saturn:heavy_water",{
description = "Heavy water",
inventory_image = "saturn_cells.png^[verticalframe:64:3",
},{
weight = 10,
volume = 0.01,
price = 10,
is_ore = true,
})
register_craft_item("saturn:silicate_mix",{
description = "Silicate mix",
inventory_image = "saturn_cells.png^[verticalframe:64:4",
},{
weight = 10,
volume = 0.01,
price = 1,
is_ore = true,
})

View File

@ -0,0 +1,424 @@
local register_node_with_stats = saturn.register_node_with_stats
-- With small changes functions and objects taken from tenplus1/protector mod
local pos_to_block_pos = function(pos)
return {
x=pos.x - (pos.x % 16),
y=pos.y - (pos.y % 16),
z=pos.z - (pos.z % 16),}
end
saturn.get_member_list = function(meta)
return meta:get_string("members"):split(" ")
end
saturn.set_member_list = function(meta, list)
meta:set_string("members", table.concat(list, " "))
end
saturn.is_member = function (meta, name)
for _, n in pairs(saturn.get_member_list(meta)) do
if n == name then
return true
end
end
return false
end
saturn.position_protected_from = function(pos, digger_name)
local pos_min = pos_to_block_pos(pos)
local pos_max = {
x=pos_min.x + 16,
y=pos_min.y + 16,
z=pos_min.z + 16,}
local wap_poss = minetest.find_nodes_in_area(pos_min, pos_max, {"saturn:world_anchor_protector"})
for n = 1, #pos do
local meta = minetest.get_meta(pos[n])
local owner = meta:get_string("owner") or ""
if owner ~= digger_name then
if not saturn.is_member(meta, digger_name) then
return true
end
end
end
return false
end
local old_is_protected = minetest.is_protected
function minetest.is_protected(pos, name)
if saturn:position_protected_from(pos, name) then
return true
end
return old_is_protected(pos, name)
end
minetest.register_entity("saturn:display", {
physical = false,
collisionbox = {0, 0, 0, 0, 0, 0},
visual = "wielditem",
-- wielditem seems to be scaled to 1.5 times original node size
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5},
textures = {"saturn:display_node"},
timer = 0,
on_activate = function(self, staticdata)
-- Xanadu server only
if (mobs and mobs.entity and mobs.entity == false)
or not self then
self.object:remove()
end
end,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 5 then
self.object:remove()
end
end,
})
-- Display-zone node, Do NOT place the display as a node,
-- it is made to be used as an entity (see above)
local x = 8
minetest.register_node("saturn:display_node", {
tiles = {"saturn_cyan_frame.png"},
use_texture_alpha = true,
walkable = false,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
-- sides
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)},
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)},
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)},
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)},
-- top
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)},
-- bottom
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)},
-- middle (surround protector)
{-.55,-.55,-.55, .55,.55,.55},
},
},
selection_box = {
type = "regular",
},
paramtype = "light",
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "",
})
register_node_with_stats("saturn:world_anchor_protector", {
description = "World anchor and map block protector",
tiles = {"saturn_anchor_top.png", "saturn_anchor_top.png",
"saturn_anchor_side.png", "saturn_anchor_side.png",
"saturn_anchor_side.png", "saturn_anchor_side.png"},
groups = {cracky = 3},
legacy_mineral = true,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local old_pos = saturn.players_info[placer:get_player_name()]['forceload_pos']
if old_pos then
minetest.remove_node(old_pos)
end
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
meta:set_string("members", "")
minetest.forceload_block(pos)
saturn.players_info[placer:get_player_name()]['forceload_pos']=pos
end,
on_destruct = function (pos)
minetest.forceload_free_block(pos)
saturn.players_info[placer:get_player_name()]['forceload_pos']=nil
end,
on_punch = function(pos, node, puncher)
if minetest.is_protected(pos, puncher:get_player_name()) then
return
end
minetest.add_entity(vector.add(pos_to_block_pos(pos),8), "saturn:display")
end,
},{
weight = 8000,
volume = 1,
price = 1000,
noise_offset = -1.5,
is_microfactory = true,
single_per_player = true,
})
local get_node_power = function(pos)
local node_name = minetest.get_node(pos).name
local meta = minetest.get_meta(pos)
local rated_power = meta:get_int("rated_power")
local generated_power = meta:get_int("generated_power")
local stats = saturn.item_stats[node_name]
if stats ~= nil then
if stats['rated_power'] then
rated_power = rated_power + stats['rated_power']
end
if stats['generated_power'] then
generated_power = generated_power + stats['generated_power']
end
end
return generated_power - rated_power
end
local form_or_connect_to_net = function(_pos)
local all_mf_have_same_id = true
local microfactory_list = {}
local dxyz = {0,1,0,0,-1,0,0}
local pos = {x=_pos.x,
y=_pos.y,
z=_pos.z+1}
local meta = minetest.get_meta(pos)
local net_id = meta:get_int("microfactory_net_id")
local last_net_id = net_id
if net_id ~= 0 then
table.insert(microfactory_list,net_id)
end
-- Check all nodes around. Whenever they are microfactories they will have net_id~=0. Whatever founded will be added to list.
for i=1,5 do
pos.x = _pos.x + dxyz[i]
pos.y = _pos.y + dxyz[i+1]
pos.z = _pos.z + dxyz[i+2]
meta = minetest.get_meta(pos)
last_net_id = net_id
net_id = meta:get_int("microfactory_net_id")
if net_id~=0 then
table.insert(microfactory_list,net_id)
if last_net_id ~= 0 and last_net_id ~= net_id then
all_mf_have_same_id = false
end
last_net_id = net_id
end
end
-- First case - no microfactories around. Generate new net_id.
if #microfactory_list == 0 then
net_id = _pos.x * 31000 * 31000 + _pos.y * 31000 + _pos.z
meta = minetest.get_meta(_pos)
meta:set_int("microfactory_net_id",net_id)
saturn.microfactory_nets[net_id] = {}
saturn.microfactory_nets[net_id].pos_list = {}
table.insert(saturn.microfactory_nets[net_id].pos_list,_pos)
saturn.microfactory_nets[net_id].energy = saturn.microfactory_nets[net_id].energy + get_node_power(_pos)
-- Second case - only one microfactory or they all have same id. Connect to existing net.
elseif all_mf_have_same_id then
meta = minetest.get_meta(_pos)
meta:set_int("microfactory_net_id",last_net_id)
table.insert(saturn.microfactory_nets[last_net_id].pos_list,_pos)
saturn.microfactory_nets[last_net_id].energy = saturn.microfactory_nets[last_net_id].energy + get_node_power(_pos)
-- Third case - two or more microfactory nets. Connect them together.
else
for _,net_id_i in ipairs(microfactory_list) do
if net_id_i~=last_net_id then
for _,i_pos in ipairs(saturn.microfactory_nets[net_id_i].pos_list) do
table.insert(saturn.microfactory_nets[last_net_id].pos_list,i_pos)
saturn.microfactory_nets[last_net_id].energy = saturn.microfactory_nets[last_net_id].energy + get_node_power(i_pos)
meta = minetest.get_meta(i_pos)
meta:set_int("microfactory_net_id",last_net_id)
end
saturn.microfactory_nets[net_id_i].pos_list = nil
saturn.microfactory_nets[net_id_i].energy = 0
saturn.microfactory_nets[net_id_i] = nil
end
end
meta = minetest.get_meta(_pos)
meta:set_int("microfactory_net_id",last_net_id)
table.insert(saturn.microfactory_nets[last_net_id].pos_list,_pos)
saturn.microfactory_nets[last_net_id].energy = saturn.microfactory_nets[last_net_id].energy + get_node_power(_pos)
end
end
local reform_net = function(_pos)
local meta = minetest.get_meta(_pos)
local net_id = meta:get_int("microfactory_net_id")
-- Step 1 - destroy net.
for _,i_pos in ipairs(saturn.microfactory_nets[net_id].pos_list) do
meta = minetest.get_meta(i_pos)
meta:set_int("microfactory_net_id",0)
end
saturn.microfactory_nets[net_id].energy = 0
-- Step 2 - relaunch net formation, excluding current position.
for _,i_pos in ipairs(saturn.microfactory_nets[net_id].pos_list) do
if i_pos.x ~= _pos.x or i_pos.y ~= _pos.y or i_pos.z ~= _pos.z then
form_or_connect_to_net(i_pos)
end
end
end
local on_microfactory_generator_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "generator_slot" then
local stack_generated_power = saturn.get_item_stat(stack,"generated_power",0)
if stack_generated_power ~= 0 then
local meta = minetest.get_meta(pos)
local old_power = meta:get_int("generated_power")
meta:set_int("generated_power", old_power + stack_generated_power)
local net_id = meta:get_int("microfactory_net_id")
saturn.microfactory_nets[net_id].energy = saturn.microfactory_nets[net_id].energy + stack_generated_power
end
end
end
local on_microfactory_generator_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "generator_slot" then
local stack_generated_power = saturn.get_item_stat(stack,"generated_power",0)
if stack_generated_power ~= 0 then
local meta = minetest.get_meta(pos)
local old_power = meta:get_int("generated_power")
meta:set_int("generated_power", old_power - stack_generated_power)
local net_id = meta:get_int("microfactory_net_id")
saturn.microfactory_nets[net_id].energy = saturn.microfactory_nets[net_id].energy - stack_generated_power
end
end
end,
register_node_with_stats("saturn:microfactory_power_generator", {
description = "Microfactory power generator",
tiles = "saturn_microfactory_power_generator.png",
groups = {cracky = 3},
after_place_node = function(pos, placer, itemstack, pointed_thing)
form_or_connect_to_net(pos)
end,
on_destruct = function (pos)
reform_net(pos)
end,
on_punch = function(pos, node, puncher)
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if from_list~=to_list then
--i'm so confused right now
--on_microfactory_generator_metadata_inventory_put(pos, to_list, to_index, stack, player)
--on_microfactory_generator_metadata_inventory_take(pos, from_listname, from_index, stack, player)
end
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
on_microfactory_generator_metadata_inventory_put(pos, listname, index, stack, player)
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
on_microfactory_generator_metadata_inventory_take(pos, listname, index, stack, player)
end,
},{
weight = 8000,
volume = 1,
price = 200,
is_microfactory = true,
})
local microfactory_formspec = function(pos, progress, cycle_time)
default_formspec = "size[8,9.75]"..
saturn.get_main_inventory_formspec(player,5.75)..
"list[contex;src;0,0;1,4;]"..
"list[contex;dst;7,0;1,4;]"..
end
local on_microfactory_node_timer = function(pos,elapsed)
-- Check power. If power balance lower than 0, schedule next check in 1 minute later.
local meta = minetest.get_meta(pos)
local node_name = minetest.get_node(pos).name
local cycle_time = saturn.item_stats[node_name].cycle_time
local net_id = meta:get_int("microfactory_net_id")
if saturn.microfactory_nets[net_id].energy < 0 then
local timer = minetest.get_node_timer(pos)
timer:start(60.0)
return true
end
-- Check input slot if its possible to process something from it.
local input_items_list = meta:get_inventory():get_list("src")
table.insert(input_items_list, ItemStack(node_name))
local output, input_result = minetest.get_craft_result({method="shapeless", width=1, items=input_items_list})
if output.item:is_empty() then
meta:set_int("progress", 0)
else
local progress = meta:get_int("progress")
if progress > 0 then
if progress > cycle_time then
local r_input = minetest.get_craft_recipe(output.item)
for _,stack in ipairs(r_input.items) do
meta:get_inventory():remove_item("src", stack)
end
for _,stack in ipairs(input_result.items) do
meta:get_inventory():add_item("src", stack)
end
if output.item:is_known() then
meta:get_inventory():add_item("dst", output.item)
else
for _,stack in ipairs(saturn.recipe_outputs[output.item:get_name()]) do
meta:get_inventory():add_item("dst", stack)
end
end
meta:set_int("progress", 0)
else
meta:set_int("progress", progress + 1)
end
else
meta:set_int("progress", 1)
end
timer:start(1.0)
end
return true
end
register_node_with_stats("saturn:microfactory_fluid_purificator", {
description = "Microfactory fluid purificator",
tiles = "saturn_microfactory_fluid_purificator.png",
groups = {cracky = 3},
after_place_node = function(pos, placer, itemstack, pointed_thing)
form_or_connect_to_net(pos)
end,
on_destruct = function (pos)
reform_net(pos)
end,
on_punch = function(pos, node, puncher)
end,
on_timer = on_microfactory_node_timer,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
on_microfactory_generator_metadata_inventory_put(pos, listname, index, stack, player)
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
on_microfactory_generator_metadata_inventory_take(pos, listname, index, stack, player)
end,
},{
weight = 2000,
volume = 1,
price = 970,
is_microfactory = true,
cycle_time = 60.0,
})
local register_microfactory_craft = function(_recipe, _output)
local item_stack_output = ""
if type(_output) == "table" then
local ro_list = {}
for _,item_stack_string in ipairs(_output) do
table.insert(ro_list,ItemStack(item_stack_string))
item_stack_output = item_stack_output .. string.gsub(string.gsub(item_stack_string,"^saturn:",""),"[%d ]","").."_"
end
item_stack_output = "saturn:" .. item_stack_output
saturn.recipe_outputs[item_stack_output] = ro_list
else
item_stack_output = _output
end
minetest.register_craft({
type = "shapeless",
output = item_stack_output,
recipe = _recipe
})
end
register_microfactory_craft({
"saturn:microfactory_fluid_purificator",
"saturn:water_ice",
}, {"saturn:clean_water 80",
"saturn:heavy_water 1",
"saturn:silicate_mix 8"})

View File

@ -22,7 +22,9 @@ local function register_node_with_stats(registry_name, node_definition, stats)
return itemstack
end
local t = node_definition.tiles
node_definition.tiles = {t,t,t,t,t,t}
if type(t) == "string" then
node_definition.tiles = {t,t,t,t,t,t}
end
node_definition.wield_image = "null.png"
node_definition.sounds = {
dig = {name="saturn_retractor", gain=0.5},
@ -31,15 +33,19 @@ local function register_node_with_stats(registry_name, node_definition, stats)
minetest.register_node(registry_name, node_definition)
saturn.set_item_stats(registry_name, stats)
if stats.is_market_item then
local _market_item_count = saturn.market_item_count + 1
saturn.market_items[_market_item_count] = registry_name
saturn.market_item_count = _market_item_count
table.insert(saturn.market_items, registry_name)
end
if stats.is_ore then
table.insert(saturn.ore_market_items, registry_name)
saturn.ores[registry_name] = stats
end
if stats.is_microfactory then
table.insert(saturn.microfactory_market_items, registry_name)
end
end
saturn.register_node_with_stats = register_node_with_stats
register_node_with_stats("saturn:water_ice", {
description = "Water ice",
tiles = "saturn_water_ice.png",

View File

@ -31,15 +31,19 @@ local function register_node_with_stats(registry_name, node_definition, stats)
minetest.register_node(registry_name, node_definition)
saturn.set_item_stats(registry_name, stats)
if stats.is_market_item then
local _market_item_count = saturn.market_item_count + 1
saturn.market_items[_market_item_count] = registry_name
saturn.market_item_count = _market_item_count
table.insert(saturn.market_items, registry_name)
end
if stats.is_ore then
table.insert(saturn.ore_market_items, registry_name)
saturn.ores[registry_name] = stats
end
if stats.is_microfactory then
table.insert(saturn.microfactory_market_items, registry_name)
end
end
saturn.register_node_with_stats = register_node_with_stats
register_node_with_stats("saturn:water_ice", {
description = "Water ice",
tiles = "saturn_water_ice.png",

View File

@ -20,7 +20,7 @@ local function define_player_inventory_slots(player, start_hull)
local forcefield_generator_slots = hull_stats.forcefield_generator_slots
local special_equipment_slots = hull_stats.special_equipment_slots
player_inv:set_size("ship_hull", 1)
player_inv:set_size("hangar", 8)
player_inv:set_size("hangar", 6)
remove_unfitted_items_to_hold(player_inv, "engine", engine_slots)
remove_unfitted_items_to_hold(player_inv, "power_generator", power_generator_slots)
remove_unfitted_items_to_hold(player_inv, "droid", droid_slots)
@ -674,6 +674,19 @@ minetest.register_on_joinplayer(function(player)
if saturn.players_info[name] == nil then
create_new_player(player)
end
local flb_pos = saturn.players_info[name]['forceload_pos']
if flb_pos then
minetest.forceload_block(flb_pos)
end
end)
minetest.register_on_leaveplayer(function(player)
saturn:save_players()
local flb_pos = saturn.players_info[placer:get_player_name()]['forceload_pos']
if flb_pos then
minetest.forceload_free_block(flb_pos)
end
end)
minetest.register_on_player_inventory_add_item(function(player, list_to, slot, stack)

View File

@ -20,7 +20,7 @@ local function define_player_inventory_slots(player, start_hull)
local forcefield_generator_slots = hull_stats.forcefield_generator_slots
local special_equipment_slots = hull_stats.special_equipment_slots
player_inv:set_size("ship_hull", 1)
player_inv:set_size("hangar", 8)
player_inv:set_size("hangar", 6)
remove_unfitted_items_to_hold(player_inv, "engine", engine_slots)
remove_unfitted_items_to_hold(player_inv, "power_generator", power_generator_slots)
remove_unfitted_items_to_hold(player_inv, "droid", droid_slots)
@ -306,7 +306,7 @@ local hud_attack_info_text_definition = {
local hud_attack_info_frame_definition = {
hud_elem_type = "image",
scale = { x=4, y=4 },
scale = { x=2, y=2 },
position = { x=0.5, y=0.5 },
size = { x=2, y=24 },
text = "null.png",
@ -674,6 +674,19 @@ minetest.register_on_joinplayer(function(player)
if saturn.players_info[name] == nil then
create_new_player(player)
end
local flb_pos = saturn.players_info[placer:get_player_name()]['forceload_pos']
if flb_pos then
minetest.forceload_block(flb_pos)
end
end)
minetest.register_on_leaveplayer(function(player)
saturn:save_players()
local flb_pos = saturn.players_info[placer:get_player_name()]['forceload_pos']
if flb_pos then
minetest.forceload_free_block(flb_pos)
end
end)
minetest.register_on_player_inventory_add_item(function(player, list_to, slot, stack)

View File

@ -37,46 +37,50 @@ saturn.get_space_station_formspec = function(player, tab)
local name = player:get_player_name()
local default_formspec =
"label[0,3.75;"..minetest.formspec_escape("Money: ")..string.format ('%4.0f',saturn.players_info[name]['money']).." Cr.]"..
"tabheader[0,0;tabs;Market,Hangar and ship;"..tab..";true;false]"
"tabheader[0,0;tabs;Equipment market,Ore market,Microfactory market,Hangar and ship;"..tab..";true;false]"..
saturn.default_slot_color..
"label[6.8,4.1;Buyout spot:]".."image[7,4.5;1,1;saturn_money.png]"..
"list[detached:space_station;buying_up_spot;7,4.5;1,1;]"..
"label[0,4.1;"..minetest.formspec_escape("Hangar: ").."]"..
"list[current_player;hangar;0,4.5;6,1;]"
for ix = 1, 6 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.5;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+hangar+"..ix..";]"
end
if tab == 1 then
default_formspec = "size[8,7]"..
default_formspec..
"list[detached:space_station;market;0,0;8,3;]"
"list[detached:space_station;market;0,0;8,4;]"..
"button[0,6;8,1;repair;Repair all player equipment. Price: "..string.format ('%4.0f',saturn.repair_player_inventory_and_get_price(player, false)).." Cr.]"
for ix = 1, 8 do
for iy = 0, 2 do
for iy = 0, 3 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_detached+space_station+market+"..(ix+8*iy)..";]"
end
end
default_formspec = default_formspec .. "list[detached:space_station;buying_up_spot;0,3;8,1;]"..
"label[0,4;"..minetest.formspec_escape("Hangar: ").."]"..
"list[current_player;hangar;0,4.5;8,1;]"
for ix = 1, 8 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.5;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+hangar+"..ix..";]"
end
default_formspec = default_formspec..
elseif tab == 2 then
default_formspec = "size[8,7]"..
default_formspec..
"list[detached:space_station;ore_market;0,0;8,4;]"..
"button[0,6;8,1;repair;Repair all player equipment. Price: "..string.format ('%4.0f',saturn.repair_player_inventory_and_get_price(player, false)).." Cr.]"
for ix = 1, 8 do
for iy = 0, 3 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_detached+space_station+ore_market+"..(ix+8*iy)..";]"
end
end
elseif tab == 3 then
default_formspec = "size[8,7]"..
default_formspec..
"list[detached:space_station;microfactory_market;0,0;8,4;]"..
"button[0,6;8,1;repair;Repair all player equipment. Price: "..string.format ('%4.0f',saturn.repair_player_inventory_and_get_price(player, false)).." Cr.]"
for ix = 1, 8 do
for iy = 0, 3 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_detached+space_station+microfatory_market+"..(ix+8*iy)..";]"
end
end
else
default_formspec = "size[8,9.75]"..
default_formspec..
saturn.get_ship_equipment_formspec(player)..
"label[0,4;"..minetest.formspec_escape("Hangar: ").."]"..
"list[current_player;hangar;0,4.5;8,1;]"
for ix = 1, 8 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.5;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+hangar+"..ix..";]"
end
default_formspec = default_formspec..
"list[current_player;main;0,5.75;8,1;]"..
"list[current_player;main;0,7;8,3;8]"
for ix = 1, 8 do
for iy = 0, 3 do
if iy==0 then
default_formspec = default_formspec.."image_button["..(ix-0.19)..",5.75;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
else
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy+6)..";0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+main+"..(ix+8*iy)..";]"
end
end
end
saturn.get_main_inventory_formspec(player,5.75)
end
return default_formspec
end
@ -109,8 +113,10 @@ saturn.space_station_inv = minetest.create_detached_inventory("space_station", {
end,
})
saturn.space_station_inv:set_size("market", 8 * 3)
saturn.space_station_inv:set_size("buying_up_spot", 8)
saturn.space_station_inv:set_size("market", 8 * 4)
saturn.space_station_inv:set_size("ore_market", 8 * 4)
saturn.space_station_inv:set_size("microfactory_market", 8 * 4)
saturn.space_station_inv:set_size("buying_up_spot", 1)
minetest.register_node("saturn:space_station_hull", {
description = "Space station hull",
@ -145,10 +151,44 @@ minetest.register_node("saturn:space_station_hatch", {
end,
})
for i=0, 8*3 do
saturn:update_space_station_market()
saturn:update_space_station_market()
saturn:update_space_station_market()
saturn:update_space_station_market()
saturn:update_space_station_market()
local generate_random_market_item = function()
local item_name = saturn.market_items[math.random(#saturn.market_items)]
return ItemStack(item_name)
end
local generate_random_ore_market_item = function()
local item_name = saturn.ore_market_items[math.random(#saturn.ore_market_items)]
return ItemStack(item_name.." 99")
end
local generate_random_microfactory_market_item = function()
local item_name = saturn.microfactory_market_items[math.random(#saturn.microfactory_market_items)]
return ItemStack(item_name)
end
local update_space_station_market = function()
local stack = generate_random_market_item()
if saturn.space_station_inv:room_for_item("market", stack) then
saturn.space_station_inv:add_item("market", stack)
else
saturn.space_station_inv:set_stack("market",math.random(8*4), stack)
end
local stack = generate_random_ore_market_item()
if saturn.space_station_inv:room_for_item("ore_market", stack) then
saturn.space_station_inv:add_item("ore_market", stack)
else
saturn.space_station_inv:set_stack("ore_market",math.random(8*4), stack)
end
local stack = generate_random_microfactory_market_item()
if saturn.space_station_inv:room_for_item("microfactory_market", stack) then
saturn.space_station_inv:add_item("microfactory_market", stack)
else
saturn.space_station_inv:set_stack("microfactory_market",math.random(8*4), stack)
end
end
saturn.update_space_station_market = update_space_station_market
for i=0, 8*4 do
update_space_station_market()
end

View File

@ -37,34 +37,49 @@ saturn.get_space_station_formspec = function(player, tab)
local name = player:get_player_name()
local default_formspec =
"label[0,3.75;"..minetest.formspec_escape("Money: ")..string.format ('%4.0f',saturn.players_info[name]['money']).." Cr.]"..
"tabheader[0,0;tabs;Market,Hangar and ship;"..tab..";true;false]"
"tabheader[0,0;tabs;Equipment market,Ore market,Microfactory market,Hangar and ship;"..tab..";true;false]"..
saturn.default_slot_color..
"label[6.8,4.1;Buyout spot:]".."image[7,4.5;1,1;saturn_money.png]"..
"list[detached:space_station;buying_up_spot;7,4.5;1,1;]"..
"label[0,4.1;"..minetest.formspec_escape("Hangar: ").."]"..
"list[current_player;hangar;0,4.5;6,1;]"
for ix = 1, 6 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.5;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+hangar+"..ix..";]"
end
if tab == 1 then
default_formspec = "size[8,7]"..
default_formspec..
"list[detached:space_station;market;0,0;8,3;]"
"list[detached:space_station;market;0,0;8,4;]"..
"button[0,6;8,1;repair;Repair all player equipment. Price: "..string.format ('%4.0f',saturn.repair_player_inventory_and_get_price(player, false)).." Cr.]"
for ix = 1, 8 do
for iy = 0, 2 do
for iy = 0, 3 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_detached+space_station+market+"..(ix+8*iy)..";]"
end
end
default_formspec = default_formspec .. "list[detached:space_station;buying_up_spot;0,3;8,1;]"..
"label[0,4;"..minetest.formspec_escape("Hangar: ").."]"..
"list[current_player;hangar;0,4.5;8,1;]"
for ix = 1, 8 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.5;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+hangar+"..ix..";]"
end
default_formspec = default_formspec..
elseif tab == 2 then
default_formspec = "size[8,7]"..
default_formspec..
"list[detached:space_station;ore_market;0,0;8,4;]"..
"button[0,6;8,1;repair;Repair all player equipment. Price: "..string.format ('%4.0f',saturn.repair_player_inventory_and_get_price(player, false)).." Cr.]"
for ix = 1, 8 do
for iy = 0, 3 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_detached+space_station+ore_market+"..(ix+8*iy)..";]"
end
end
elseif tab == 3 then
default_formspec = "size[8,7]"..
default_formspec..
"list[detached:space_station;microfactory_market;0,0;8,4;]"..
"button[0,6;8,1;repair;Repair all player equipment. Price: "..string.format ('%4.0f',saturn.repair_player_inventory_and_get_price(player, false)).." Cr.]"
for ix = 1, 8 do
for iy = 0, 3 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..","..(iy)..";0.3,0.4;saturn_info_button_icon.png;item_info_detached+space_station+microfatory_market+"..(ix+8*iy)..";]"
end
end
else
default_formspec = "size[8,9.75]"..
default_formspec..
saturn.get_ship_equipment_formspec(player)..
"label[0,4;"..minetest.formspec_escape("Hangar: ").."]"..
"list[current_player;hangar;0,4.5;8,1;]"
for ix = 1, 8 do
default_formspec = default_formspec.."image_button["..(ix-0.19)..",4.5;0.3,0.4;saturn_info_button_icon.png;item_info_player+"..name.."+hangar+"..ix..";]"
end
default_formspec = default_formspec..
"list[current_player;main;0,5.75;8,1;]"..
"list[current_player;main;0,7;8,3;8]"
for ix = 1, 8 do
@ -76,7 +91,6 @@ saturn.get_space_station_formspec = function(player, tab)
end
end
end
end
return default_formspec
end
@ -109,8 +123,10 @@ saturn.space_station_inv = minetest.create_detached_inventory("space_station", {
end,
})
saturn.space_station_inv:set_size("market", 8 * 3)
saturn.space_station_inv:set_size("buying_up_spot", 8)
saturn.space_station_inv:set_size("market", 8 * 4)
saturn.space_station_inv:set_size("ore_market", 8 * 4)
saturn.space_station_inv:set_size("microfactory_market", 8 * 4)
saturn.space_station_inv:set_size("buying_up_spot", 1)
minetest.register_node("saturn:space_station_hull", {
description = "Space station hull",
@ -144,3 +160,45 @@ minetest.register_node("saturn:space_station_hatch", {
)
end,
})
local generate_random_market_item = function()
local item_name = saturn.market_items[math.random(#saturn.market_items)]
return ItemStack(item_name)
end
local generate_random_ore_market_item = function()
local item_name = saturn.ore_market_items[math.random(#saturn.ore_market_items)]
return ItemStack(item_name.." 99")
end
local generate_random_microfactory_market_item = function()
local item_name = saturn.microfactory_market_items[math.random(#saturn.microfactory_market_items)]
return ItemStack(item_name)
end
local update_space_station_market = function()
local stack = generate_random_market_item()
if saturn.space_station_inv:room_for_item("market", stack) then
saturn.space_station_inv:add_item("market", stack)
else
saturn.space_station_inv:set_stack("market",math.random(8*4), stack)
end
local stack = generate_random_ore_market_item()
if saturn.space_station_inv:room_for_item("ore_market", stack) then
saturn.space_station_inv:add_item("ore_market", stack)
else
saturn.space_station_inv:set_stack("ore_market",math.random(8*4), stack)
end
local stack = generate_random_microfactory_market_item()
if saturn.space_station_inv:room_for_item("microfactory_market", stack) then
saturn.space_station_inv:add_item("microfactory_market", stack)
else
saturn.space_station_inv:set_stack("microfactory_market",math.random(8*4), stack)
end
end
saturn.update_space_station_market = update_space_station_market
for i=0, 8*4 do
update_space_station_market()
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 B

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B