Another simple mod for the game "Factorio". Automatically strings circuit wire on long distance poles.
Revisión | b2df8c1a26e1680bc152a66692e1ac369b559e7f (tree) |
---|---|
Tiempo | 2018-11-04 14:52:04 |
Autor | Eric Hopper <hopper@omni...> |
Commiter | Eric Hopper |
Fix a whole host of different small stupid errors.
@@ -17,38 +17,43 @@ | ||
17 | 17 | end) |
18 | 18 | |
19 | 19 | local function is_long_distance_pole(entity) |
20 | - if entity.type != "electric-pole" then | |
21 | - return false | |
22 | - elseif entity.supply_area_distance > 2 then | |
23 | - return false | |
24 | - elseif entity.maximum_wire_distance < 30 then | |
20 | + if entity.type ~= "electric-pole" then | |
25 | 21 | return false |
26 | 22 | else |
27 | - return true | |
23 | + local poleproto = entity.prototype | |
24 | + if poleproto.supply_area_distance > 2 then | |
25 | + return false | |
26 | + elseif poleproto.max_wire_distance < 30 then | |
27 | + return false | |
28 | + else | |
29 | + return true | |
30 | + end | |
28 | 31 | end |
29 | 32 | end |
30 | 33 | |
31 | 34 | local function has_red_wire(pole) |
32 | - local redwires = pole.neighbors["red"] | |
35 | + local redwires = pole.neighbours["red"] | |
33 | 36 | return (redwires ~= nil) and (#redwires > 0) |
37 | +end | |
34 | 38 | |
35 | 39 | local function has_green_wire(pole) |
36 | - local greenwires = pole.neighbors["green"] | |
37 | - return (redwires ~= nil) and (#redwires > 0) | |
40 | + local greenwires = pole.neighbours["green"] | |
41 | + return (greenwires ~= nil) and (#greenwires > 0) | |
42 | +end | |
38 | 43 | |
39 | 44 | script.on_event(defines.events.on_built_entity, function(event) |
40 | - if not conf_enable then | |
45 | + if not conf_enable[event.player_index] then | |
41 | 46 | return |
42 | 47 | end |
43 | 48 | local entity = event.created_entity |
44 | 49 | if (not entity) or (not is_long_distance_pole(entity)) then |
45 | 50 | return |
46 | 51 | end |
47 | - local copperbuddies = entity.neighbors["copper"] | |
52 | + local copperbuddies = entity.neighbours["copper"] | |
48 | 53 | if not copperbuddies then |
49 | 54 | return |
50 | 55 | end |
51 | - local otherpole | |
56 | + local otherpole = nil | |
52 | 57 | local newconnects = {} |
53 | 58 | for _, otherpole in pairs(copperbuddies) do |
54 | 59 | if is_long_distance_pole(otherpole) then |
@@ -64,4 +69,6 @@ | ||
64 | 69 | end |
65 | 70 | local newconnect |
66 | 71 | for _, newconnect in pairs(newconnects) do |
67 | - entity.connect_neighbor(newconnect) | |
72 | + entity.connect_neighbour(newconnect) | |
73 | + end | |
74 | +end) |
@@ -1,7 +1,7 @@ | ||
1 | 1 | _G.data:extend({ |
2 | 2 | { |
3 | 3 | type = "bool-setting", |
4 | - name = "ld_autocircuit-endabled", | |
4 | + name = "ld_autocircuit-enabled", | |
5 | 5 | setting_type = "runtime-per-user", |
6 | 6 | default_value = true, |
7 | 7 | }, |