z_mirror/CursorEnhancements

git clone https://git.raiguard.me/z_mirror/CursorEnhancements

raiguardAdd "transfer from network" functionalityb9cfe41

proxies
1.4 KiB50 linesraw
1local global_data = {}
2
3local constants = require("constants")
4
5local util = require("scripts.util")
6
7function global_data.init()
8  global.players = {}
9  global.proxies = {
10    -- proxy unit_number -> target unit_number
11    by_proxy = {},
12    -- target unit_number -> proxy entity
13    by_target = {}
14  }
15
16  global_data.build_global_registry()
17end
18
19-- build the default upgrade/downgrade registry
20function global_data.build_global_registry()
21  local entity_prototypes = game.entity_prototypes
22  local item_prototypes = game.item_prototypes
23  local data = {}
24
25  -- auto-generated
26  for name, prototype in pairs(entity_prototypes) do
27    if prototype.next_upgrade and prototype.items_to_place_this then
28      local next_item = prototype.next_upgrade.name
29      for _, item in ipairs(prototype.items_to_place_this) do
30        if not data[item.name] then data[item.name] = {} end
31        data[item.name].next = next_item
32      end
33      for _, item in ipairs(entity_prototypes[next_item].items_to_place_this) do
34        if not data[item.name] then data[item.name] = {} end
35        data[item.name].previous = name
36      end
37    end
38  end
39
40  -- default overrides
41  for mod_name, overrides in pairs(constants.default_overrides) do
42    if script.active_mods[mod_name] then
43      util.apply_overrides(data, overrides, item_prototypes)
44    end
45  end
46
47  global.registry = data
48end
49
50return global_data