z_mirror/Krastorio2
git clone https://git.raiguard.me/z_mirror/Krastorio2
0139d686
discrete-steel-pipes
1local function add_starting_items () 2local items =remote . call ( "freeplay" , "get_created_items" ) 3-- Shelter 4items [ "kr-shelter" ] =1 5-- Electric poles 6if script . active_mods [ "aai-industry" ] and prototypes . item [ "medium-electric-pole" ] then 7items [ "medium-electric-pole" ] =10 8end 9remote . call ( "freeplay" , "set_created_items" , items ) 10end 11 12local new_ship_parts ={ 13{ 14name ="kr-spaceship-reactor" , 15angle_deviation =0.2 , 16max_distance =25 , 17min_separation =10 , 18fire_count =3 , 19explosion_count =1 , 20force ="player" , 21} , 22{ 23name ="kr-spaceship-research-computer" , 24angle_deviation =0.05 , 25max_distance =30 , 26min_separation =10 , 27fire_count =3 , 28explosion_count =1 , 29force ="player" , 30} , 31{ 32name ="kr-spaceship-material-fabricator-1" , 33repeat_count =2 , 34angle_deviation =0.3 , 35max_distance =20 , 36min_separation =5 , 37fire_count =1 , 38force ="player" , 39} , 40{ 41name ="kr-spaceship-material-fabricator-2" , 42repeat_count =2 , 43angle_deviation =0.3 , 44max_distance =20 , 45min_separation =5 , 46fire_count =1 , 47force ="player" , 48} , 49{ 50name ="crash-site-chest-1" , 51repeat_count =3 , 52angle_deviation =0.1 , 53max_distance =20 , 54min_separation =3 , 55fire_count =1 , 56} , 57{ 58name ="crash-site-chest-2" , 59repeat_count =3 , 60angle_deviation =0.1 , 61max_distance =20 , 62min_separation =2 , 63fire_count =1 , 64} , 65} 66 67local function add_to_crash_site () 68if 69not remote . interfaces . freeplay . get_disable_crashsite 70or remote . call ( "freeplay" , "get_disable_crashsite" ) 71or remote . call ( "freeplay" , "get_init_ran" ) 72then 73return 74end 75 76local ship_parts =remote . call ( "freeplay" , "get_ship_parts" ) 77for _ , part in pairs ( new_ship_parts ) do 78ship_parts [ # ship_parts + 1 ] =part 79end 80remote . call ( "freeplay" , "set_ship_parts" , ship_parts ) 81 82-- If playing a treeless game, add wood to the spaceship 83local nauvis =game . get_surface ( "nauvis" ) 84if nauvis then 85local tree_setting =nauvis . map_gen_settings . autoplace_controls . trees 86if not tree_setting or tree_setting . size == 0 then 87-- Add wood to the ship inventory 88local items =remote . call ( "freeplay" , "get_ship_items" ) 89-- This is overkill for base K2, but should provide for plenty of margin of error 90items [ "wood" ] =400 91remote . call ( "freeplay" , "set_ship_items" , items ) 92end 93end 94end 95 96local function set_custom_intro () 97if not remote . interfaces . freeplay . set_custom_intro_message then 98return 99end 100remote . call ( "freeplay" , "set_custom_intro_message" , { "message.kr-intro" } ) 101end 102 103local function disable_rocket_victory () 104if remote . interfaces . silo_script then 105remote . call ( "silo_script" , "set_no_victory" , true ) 106end 107end 108 109local function run () 110if not remote . interfaces . freeplay then 111return 112end 113add_starting_items () 114add_to_crash_site () 115set_custom_intro () 116disable_rocket_victory () 117end 118 119--- @param entity_name EntityID 120--- @param value boolean 121local function set_minable ( entity_name , value ) 122for _ , entity in pairs ( game . surfaces . nauvis . find_entities_filtered ( { name =entity_name } )) do 123entity . minable =value 124entity . destructible =value 125end 126end 127 128--- @param e EventData.on_research_finished 129local function on_research_finished ( e ) 130for _ , effect in pairs ( e . research . prototype . effects ) do 131if effect . type ~= "unlock-recipe" then 132goto continue 133end 134 135local recipe_name =effect . recipe 136if recipe_name == "assembling-machine-1" then 137set_minable ( "kr-spaceship-material-fabricator-1" , true ) 138set_minable ( "kr-spaceship-material-fabricator-2" , true ) 139elseif recipe_name == "lab" then 140set_minable ( "kr-spaceship-research-computer" , true ) 141elseif recipe_name == "steam-engine" then 142set_minable ( "kr-spaceship-reactor" , true ) 143end 144 145:: continue :: 146end 147end 148 149local function on_player_created () 150if not remote . interfaces . freeplay then 151return 152end 153if storage . crash_site_init_ran then 154return 155end 156storage . crash_site_init_ran =true 157 158local recipes =game . forces . player . recipes 159set_minable ( "kr-spaceship-material-fabricator-1" , recipes [ "assembling-machine-1" ]. enabled ) 160set_minable ( "kr-spaceship-material-fabricator-2" , recipes [ "assembling-machine-1" ]. enabled ) 161set_minable ( "kr-spaceship-research-computer" , recipes [ "lab" ]. enabled ) 162set_minable ( "kr-spaceship-reactor" , recipes [ "steam-engine" ]. enabled ) 163end 164 165local freeplay ={} 166 167freeplay . on_init =run 168freeplay . on_configuration_changed =run 169 170freeplay . events ={ 171[ defines . events . on_research_finished ] =on_research_finished , 172[ defines . events . on_player_created ] =on_player_created , 173} 174 175return freeplay