-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfakes.lua
84 lines (71 loc) · 2.2 KB
/
fakes.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--[[
Copyright (C) 2018-2022 ZwerOxotnik <zweroxotnik@gmail.com>
Licensed under the EUPL, Version 1.2 only (the "LICENCE");
Source: github.com/ZwerOxotnik/zk-lib
]]--
---- ####
---- The library generates various fake entities
---- ####
local fakes = {}
local corpses = data.raw["character-corpse"]
-- Creates a fake corpse using an entitty
-- WARNING: The corpses don't support collision and you can't modify their inventory
fakes.create_fake_corpse_by_entity = function(entity)
if entity == nil then
log("Can't create a fake corpse because parameter is nil")
return false
end
local fake_corpse_name = "fake_" .. entity.name
if corpses[fake_corpse_name] then
log("\"" .. fake_corpse_name .. "\" already exists")
return corpses[fake_corpse_name]
end
data:extend(
{
{
type = "character-corpse",
name = fake_corpse_name,
icon = entity.icon,
icon_size = entity.icon_size, icon_mipmaps = entity.icon_mipmaps,
minable = {mining_time = 2},
time_to_live = 4294967295,
collision_box = entity.collision_box,
selection_box = entity.selection_box,
selection_priority = entity.selection_priority or 200, -- 0-255 value with 255 being on-top of everything else
flags = entity.flags,
open_sound = entity.open_sound,
close_sound = entity.close_sound,
picture = entity.picture,
pictures = entity.pictures,
render_layer = entity.render_layer,
vehicle_impact_sound = entity.vehicle_impact_sound
}
})
return corpses[fake_corpse_name]
end
local tiles = data.raw.tile
-- Creates a fake walkable tile using another tile by its name
fakes.create_fake_walkable_tile = function(name)
if tiles[name] == nil then
log("Tile \"" .. name .. "\" doesn't exists in the game")
return false
end
local fake_tile_name = "fakeW_" .. name
if tiles[fake_tile_name] then
log("Tile \"" .. fake_tile_name .. "\" already exists")
return tiles[fake_tile_name]
end
local new_tile = util.table.deepcopy(tiles[fake_tile_name])
new_tile.name = fake_tile_name
new_tile.collision_mask = {
"water_tile",
"ground_tile",
"item",
"resource",
"object"
}
new_tile.autoplace = nil
new_tile.localised_name = {"", {"tile-name." .. name}, " [fake-W]"}
return data:extend({new_tile})
end
return fakes