generated from fgardt/factorio-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.lua
126 lines (111 loc) · 3.65 KB
/
commands.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
local pickup_duration = 20
local dropoff_duration = 20
local commands = {}
---@class StopCommandWithSubtype : Command.defines_command_stop
---@field subtype string Subtype of the command
---comments
---@param position MapPosition Position to go to
---@param radius number|nil Distance allowed from the position. Defaults to 1
---@return Command.defines_command_go_to_location go_to_command
function commands.go_to_command(position, radius)
radius = radius or 1
return {
type = defines.command.go_to_location,
destination = position,
radius = radius,
distraction = defines.distraction.none,
pathfind_flags = {prefer_straight_paths = true, use_cache = true, allow_paths_through_own_entities = true}
}
end
---comments
---@param entity LuaEntity Entity to go to
---@return Command.defines_command_go_to_location go_to_command
function commands.go_to_entity_command(entity)
radius = radius or 1
return {
type = defines.command.go_to_location,
destination_entity = entity,
radius = 1,
distraction = defines.distraction.none,
pathfind_flags = {prefer_straight_paths = true, use_cache = true, allow_paths_through_own_entities = true}
}
end
---comments
---@param ticks_to_wait integer
---@return Command.defines_command_stop
function commands.wait_command(ticks_to_wait)
return {
type = defines.command.stop,
distraction = defines.distraction.none,
ticks_to_wait = ticks_to_wait,
}
end
---@class PickupCommand : StopCommandWithSubtype
---@field item string
---@field amount integer
---comments
---@param pickup_request any
---@return PickupCommand
function commands.pickup_command(pickup_request)
return {
type = defines.command.stop,
subtype = "pickup",
distraction = defines.distraction.none,
ticks_to_wait = pickup_duration,
item = pickup_request.item,
amount = pickup_request.amount
}
end
---@class DropoffChestCommand : StopCommandWithSubtype
---@field item_stack SimpleItemStack
---@field chest LuaEntity
---comments
---@param chest LuaEntity The chest to drop the item_stack in
---@return DropoffChestCommand
function commands.dropoff_chest_command(chest, item_stack)
return {
type = defines.command.stop,
subtype = "dropoff-chest",
distraction = defines.distraction.none,
ticks_to_wait = dropoff_duration,
item_stack = item_stack,
chest = chest
}
end
---@class PickupV2Command : StopCommandWithSubtype
---@field item string
---@field amount integer
---comments
---@param request BuildItemRequest|ItemDeliveryRequest
---@return PickupV2Command
function commands.pickup_v2_command(request)
return {
type = defines.command.stop,
subtype = "pickup",
distraction= defines.distraction.none,
ticks_to_wait = pickup_duration,
item = request.ingredient.name,
amount = request.ingredient.amount
}
end
---@class DropoffBuildCommand : StopCommandWithSubtype
---@field item string
---@field amount integer
---@field ghost_id integer
---@field ghost_pos MapPosition
---comments
---@param build_item_request BuildItemRequest
---@return DropoffBuildCommand
function commands.dropoff_build_command(build_item_request)
return {
type = defines.command.stop,
subtype = "dropoff-build",
distraction= defines.distraction.none,
ticks_to_wait = dropoff_duration,
item = build_item_request.ingredient.name,
amount = build_item_request.ingredient.amount,
ghost_id = build_item_request.ghost.unit_number,
ghost_pos = build_item_request.ghost.position
}
end
return commands