@@ -8,27 +8,14 @@ require "gui"
88
99MOD_NAME = " ModuleInserter"
1010
11- types = {[" mining-drill" ]= true ,[" assembling-machine" ]= true ,lab = true , [" rocket-silo" ] = true , furnace = true , beacon = true }
12-
1311typeToSlot = {}
1412typeToSlot .lab = defines .inventory .lab_modules
1513typeToSlot [" assembling-machine" ] = defines .inventory .assembling_machine_modules
1614typeToSlot [" mining-drill" ] = defines .inventory .mining_drill_modules
17- typeToSlot [" furnace" ] = defines .inventory .assembling_machine_modules -- TODO 0.13 change to furnace_modules
15+ typeToSlot [" furnace" ] = defines .inventory .furnace_modules -- TODO 0.13 change to furnace_modules
1816typeToSlot [" rocket-silo" ] = defines .inventory .assembling_machine_modules
1917typeToSlot [" beacon" ] = 1
2018
21- function subPos (p1 ,p2 )
22- p2 = p2 or {x = 0 ,y = 0 }
23- return {x = p1 .x - p2 .x , y = p1 .y - p2 .y }
24- end
25-
26- function expandPos (pos , range )
27- range = range or 0.5
28- if not pos or not pos .x then error (" invalid pos" ,3 ) end
29- return {{pos .x - range , pos .y - range }, {pos .x + range , pos .y + range }}
30- end
31-
3219function entityKey (ent )
3320 if ent .position and ent .direction then
3421 return ent .position .x .. " :" .. ent .position .y -- ..":"..ent.direction
@@ -45,7 +32,7 @@ function count_keys(hashmap)
4532end
4633
4734-- /c game.player.print(serpent.dump(game.player.surface.find_logistic_network_by_position(game.player.position, game.player.force.name).find_cell_closest_to(game.player.position)))
48- function hasPocketBots (player )
35+ local function hasPocketBots (player )
4936 local logisticCell = player .character .logistic_cell
5037 local port = false
5138 if logisticCell and logisticCell .transmitting and logisticCell .mobile then
@@ -156,17 +143,15 @@ function on_player_selected_area(event)
156143 player .print (" Can't insert " .. module .. " in " .. entity .name )
157144 valid_modules = false
158145 end
159- if global .productivityAllowed and entity .type == " assembling-machine" then
160- if entity .recipe and not global .productivityAllowed [entity .recipe .name ] == true then
161- player .print (" Can't use " .. module .. " with recipe: " .. entity .recipe .name )
162- valid_modules = false
163- end
146+ if entity .type == " assembling-machine" and entity .recipe and next (prototype .limitations ) and not prototype .limitations [entity .recipe ] then
147+ player .print ({" " , " Can't use " , module .localised_name , " with recipe: " , entity .recipe .localised_name })
148+ valid_modules = false
164149 end
165150 end
166151 end
167152 end
168- local inventory = entity . get_inventory ( typeToSlot [ entity . type ])
169- local contents = inventory .get_contents ()
153+
154+ local contents = entity . get_inventory ( typeToSlot [ entity . type ]) .get_contents ()
170155 if valid_modules and not util .table .compare (cTable ,contents ) then
171156 -- proxy entity that the robots fly to
172157 local new_entity = {
@@ -177,13 +162,13 @@ function on_player_selected_area(event)
177162 force = entity .force
178163 }
179164 -- game.player.surface.create_entity{name = "item-request-proxy", position = game.player.selected.position, force = game.player.force, target = game.player.selected, modules={{item="speed-module-3", count=2}}}
180- -- local module_proxy = {
181- -- name = "item-request-proxy",
182- -- position = game.player.selected.position,
183- -- force = game.player.force,
184- -- target = game.player.selected,
185- -- request_filters = {count=2, item="speed-module-3"}
186- -- }
165+ -- local module_proxy = {
166+ -- name = "item-request-proxy",
167+ -- position = game.player.selected.position,
168+ -- force = game.player.force,
169+ -- target = game.player.selected,
170+ -- request_filters = {count=2, item="speed-module-3"}
171+ -- }
187172
188173 local key = entityKey (new_entity )
189174 if global .entitiesToInsert [key ] then
@@ -253,12 +238,6 @@ local function getMetaItemData()
253238 global .nameToSlots [ent .name ] = ent .amount
254239 end
255240
256- game .forces .player .technologies [" mi-meta-productivityRecipes" ].reload ()
257- productivityRecipes = game .forces .player .technologies [" mi-meta-productivityRecipes" ].effects
258- global .productivityAllowed = # productivityRecipes > 0 and global .productivityAllowed or false
259- for _ , recipe in pairs (productivityRecipes ) do
260- global .productivityAllowed [recipe .recipe ] = true
261- end
262241end
263242
264243local function remove_invalid_items ()
@@ -320,7 +299,6 @@ local function init_global()
320299 global [" config-tmp" ] = global [" config-tmp" ] or {}
321300 global [" storage" ] = global [" storage" ] or {}
322301 global .nameToSlots = global .nameToSlots or {}
323- global .productivityAllowed = global .productivityAllowed or {}
324302 global .settings = global .settings or {}
325303end
326304
@@ -439,6 +417,10 @@ local function on_configuration_changed(data)
439417 end
440418 on_load ()
441419 end
420+
421+ if oldVersion < " 0.2.2" then
422+ global .productivityAllowed = nil
423+ end
442424 global .version = newVersion
443425 -- mod was updated
444426 -- update/change gui for all players via game.players.gui ?
@@ -467,17 +449,6 @@ script.on_event(defines.events.on_player_created, on_player_created)
467449script .on_event (defines .events .on_force_created , on_force_created )
468450script .on_event (defines .events .on_forces_merging , on_forces_merging )
469451
470- function get_config_item (player , index , type1 )
471- if not global [" config-tmp" ][player .index ]
472- or index > # global [" config-tmp" ][player .index ]
473- or global [" config-tmp" ][player .index ][index ][type1 ] == " " or type (global [" config-tmp" ][player .index ][index ][type1 ]) == " table" then
474-
475- return {" upgrade-planner-item-not-set" }
476-
477- end
478- return game .item_prototypes [global [" config-tmp" ][player .index ][index ][type1 ]].localised_name
479- end
480-
481452script .on_event (defines .events .on_robot_built_entity , function (event )
482453 local status , err = pcall (function ()
483454 local entity = event .created_entity
@@ -588,10 +559,7 @@ script.on_event(defines.events.on_research_finished, function(event)
588559 gui_init (player , true )
589560 end
590561 end
591- if event .research .name == ' mi-meta-productivityRecipes' then
592- event .research .force .technologies [" mi-meta-productivityRecipes" ].enabled = false
593- event .research .force .technologies [" mi-meta-productivityRecipes" ].researched = false
594- end
562+
595563end )
596564
597565function debugDump (var , force )
@@ -619,10 +587,7 @@ remote.add_interface("mi",
619587 saveVar = function (name )
620588 saveVar (global , name )
621589 end ,
622- limits = function ()
623- debugDump (productivityAllowed ,true )
624- debugDump (productivityRecipes ,true )
625- end ,
590+
626591 init = function ()
627592 init_global ()
628593 init_players ()
0 commit comments