Skip to content

Commit 066e947

Browse files
committed
Mininmal fix to get capsules back; clicking cliffs with cliff explosives works again
1 parent a8390f8 commit 066e947

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

control.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,22 @@ local function kb_click_hand(event)
30693069
CircuitNetworks.drag_wire_and_read(pindex)
30703070
else
30713071
local proto = stack.prototype
3072-
if proto.place_result or proto.place_as_tile_result then
3072+
local capsule_action = proto.capsule_action
3073+
if capsule_action then
3074+
-- Handle capsules and grenades
3075+
if capsule_action.type == "use-on-self" then
3076+
-- Use capsule on the player
3077+
player.use_from_cursor(player.position)
3078+
elseif capsule_action.type == "throw" then
3079+
-- Use smart aiming for throwable capsules
3080+
local target_pos = Combat.smart_aim_grenades_and_capsules(pindex, false)
3081+
if target_pos then player.use_from_cursor(target_pos) end
3082+
else
3083+
-- For other capsule types (artillery-remote, destroy-cliffs, etc.), use at cursor
3084+
local vp = Viewpoint.get_viewpoint(pindex)
3085+
player.use_from_cursor(vp:get_cursor_pos())
3086+
end
3087+
elseif proto.place_result or proto.place_as_tile_result then
30733088
-- Item can be placed/built
30743089
local vp = Viewpoint.get_viewpoint(pindex)
30753090
BuildingTools.build_item_in_hand_with_params({

scripts/combat.lua

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -245,38 +245,23 @@ function mod.aim_gun_at_nearest_enemy(pindex, enemy_in)
245245
return true
246246
end
247247

248-
--Max ranges are determined by the game GUI, min ranges represent the minimum distance where you will not get damaged.
248+
---Get the throw range for a capsule or grenade.
249+
---Returns 0 for anything but a throwable attack, otherwise returns the range from attack parameters.
250+
---@param stack LuaItemStack
251+
---@return number min_range
252+
---@return number max_range
249253
function mod.get_grenade_or_capsule_range(stack)
250-
local max_range = 20
251-
local min_range = 0
252-
if stack == nil or stack.valid_for_read == false then
253-
return min_range, max_range
254-
elseif stack.name == "grenade" then
255-
max_range = 15
256-
min_range = 7
257-
elseif stack.name == "cluster-grenade" then
258-
max_range = 20
259-
min_range = 12
260-
elseif stack.name == "poison-capsule" then
261-
max_range = 25
262-
min_range = 12
263-
elseif stack.name == "slowdown-capsule" then
264-
max_range = 25
265-
min_range = 0
266-
elseif stack.name == "cliff-explosives" then
267-
max_range = 10
268-
min_range = 0
269-
elseif stack.name == "defender-capsule" then
270-
max_range = 20
271-
min_range = 0
272-
elseif stack.name == "distractor-capsule" then
273-
max_range = 25
274-
min_range = 0
275-
elseif stack.name == "destroyer-capsule" then
276-
max_range = 20
277-
min_range = 0
278-
end
279-
return min_range, max_range
254+
if stack == nil or not stack.valid_for_read then return 0, 0 end
255+
256+
local capsule_action = stack.prototype.capsule_action
257+
if not capsule_action then return 0, 0 end
258+
259+
if capsule_action.type ~= "throw" then return 0, 0 end
260+
261+
local attack_params = capsule_action.attack_parameters
262+
if not attack_params then return 0, 0 end
263+
264+
return attack_params.min_range or 0, attack_params.range or 0
280265
end
281266

282267
--[[

0 commit comments

Comments
 (0)