Skip to content

Commit

Permalink
belt item inserting/message
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiplacon committed Jan 15, 2023
1 parent ab72374 commit 1fbb555
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 37 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---------------------------------------------------------------------------------------------------
Version: 1.1.10
Date: 1/14/2023
Changes:
- Items thrown on belts now use the proper item insert command instead of spawning the item on the floor and hoping it sticks to the belt.
- Added the number of items a thrower is holding into consideration when calculating overflow for throwing onto a transport belt. I probably should have had this to begin with.
- Added a message on hovering a thrower if it will overflow the belt it's targeting.
---------------------------------------------------------------------------------------------------
Version: 1.1.9
Date: 1/12/2023
Bugfixes:
Expand Down
76 changes: 53 additions & 23 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,6 @@ function(event)
global.MagnetRamps[unitID] = nil
end
end

-- for each, world in pairs(game.surfaces) do
-- for every, ZiplinePart in pairs(world.find_entities_filtered{name = {"RTZipline", "RTZiplinePowerDrain"}}) do
-- local owned = false
-- for all, player in pairs(global.AllPlayers) do
-- if ((player.ChuggaChugga and ZiplinePart.unit_number == player.ChuggaChugga.unit_number)
-- or (player.succ and ZiplinePart.unit_number == player.succ.unit_number)
-- ) then
-- owned = true
-- end
-- end
-- if (owned == false) then
-- ZiplinePart.destroy()
-- end
-- end
-- end
end)

-- Thrower Check
Expand Down Expand Up @@ -140,11 +124,39 @@ function(event)
for name, count in pairs(global.OnTheWay[properties.targets[catapult.held_stack.name].unit_number]) do
incomming = incomming + count
end
local total = incomming + properties.targets[catapult.held_stack.name].get_transport_line(1).get_item_count() + properties.targets[catapult.held_stack.name].get_transport_line(2).get_item_count()
if (total <= 6) then
local total = incomming + properties.targets[catapult.held_stack.name].get_transport_line(1).get_item_count() + properties.targets[catapult.held_stack.name].get_transport_line(2).get_item_count() + catapult.held_stack.count
if (total <= 8) then
catapult.active = true
if (global.HoverGFX[catapult.unit_number]) then
for playerID, graphic in pairs(global.HoverGFX[catapult.unit_number]) do
rendering.destroy(graphic)
end
global.HoverGFX[catapult.unit_number] = {}
end
else
catapult.active = false
if (global.HoverGFX[catapult.unit_number] == nil) then
global.HoverGFX[catapult.unit_number] = {}
end
for ID, player in pairs(game.players) do
if (global.HoverGFX[catapult.unit_number][ID] == nil) then
local hovering = false
if (player.selected and player.selected.unit_number == catapult.unit_number) then
hovering = true
end
global.HoverGFX[catapult.unit_number][ID] = rendering.draw_text
{
text = {"RTmisc.EightMax"},
surface = catapult.surface,
target = catapult,
alignment = "center",
scale = 0.5,
color = {1,1,1},
players = {player},
visible = hovering
}
end
end
end
end

Expand Down Expand Up @@ -262,11 +274,11 @@ function(event)
rendering.set_target(sprite, catapult.position)
rendering.set_target(shadow, catapult.position)
-- catapult.surface.play_sound
-- {
-- path = "RTEjector",
-- position = catapult.position,
-- volume = 0.7
-- }
-- {
-- path = "RTEjector",
-- position = catapult.position,
-- volume = 0.7
-- }
else
-- catapult.surface.play_sound
-- {
Expand Down Expand Up @@ -426,3 +438,21 @@ require("script.GUIs")
script.on_event(defines.events.on_gui_click,
require("script.event.ClickGUI")
)

-- displaying things on hover
script.on_event(defines.events.on_selected_entity_changed,
--player_index :: uint The player whose selected entity changed.
--last_entity :: LuaEntity? The last selected entity if it still exists and there was one.
function(event)
local player = game.players[event.player_index]
if (event.last_entity
and event.last_entity.unit_number
and global.HoverGFX[event.last_entity.unit_number]
and global.HoverGFX[event.last_entity.unit_number][event.player_index]) then
rendering.set_visible(global.HoverGFX[event.last_entity.unit_number][event.player_index], false)
end
if (player.selected and player.selected.unit_number and global.HoverGFX[player.selected.unit_number] and global.HoverGFX[player.selected.unit_number][event.player_index]) then
rendering.set_visible(global.HoverGFX[player.selected.unit_number][event.player_index], true)
end
end)

2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RenaiTransportation",
"version": "1.1.9",
"version": "1.1.10",
"title": "Renai Transportation",
"author": "Kiplacon",
"factorio_version": "1.1",
Expand Down
6 changes: 5 additions & 1 deletion locale/en/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ RTShowRange=Show Range Indicator on Built Bounce Pads
RTBounceSetting=Circuit Bounce Pad and Primer Bounce Pad
RTZiplineSmoothSetting=At faster speeds with poles closer together, the bobbing camera motion might be dizzying for some people.
RTModdedThrowers=Enables thrower varients of modded inserters, otherwise only vanilla inserter throwers are made.
RTOverflowComp=Toggles on or off the logic that helps minimize overflow from throwers spilling items all over the place.
RTOverflowComp=Toggles on or off the logic that helps minimize overflow from throwers spilling items all over the place. Calculation-wise, transport belts have an "inventory" of 8 slots meaning stack inserters with >8 items in hand aiming at a belt will never throw.
RTThrowersSetting=Enables the base features of thrower inserters, bounce pads, player launchers, and hatches. Required to be on for modded throwers to be created.
RTImpactGrouping=The maximum number of projectiles created for each kind of item in an Impact Wagon. Creating fewer projectiles helps reduce lag by grouping more items into each projectile, but looks way less cool.
RTShowRange=The range indicators for bounce pads in alt-view can be toggled on or off by clicking on the bounce pad. This setting toggles whether they are visible or not by default when they are first built.
Expand Down Expand Up @@ -207,6 +207,10 @@ rename=Rename
ChangeName=Confirm name change
select=Select Destination
[RTmisc]
EightMax=Belts can hold 8 items before thrown items spill off
[thrower-gen]
DefaultDesc=This inserter has been re-wired to throw items __1__ tiles through the air. Range can be configured once researched using Interact (default F).
HasDesc=This inserter has been re-wired to throw items __1__ tiles through the air. Range can be configured once researched using Interact (default F).\n__2__
Expand Down
15 changes: 4 additions & 11 deletions script/event/FlyingItems.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,23 @@ local function on_tick(event)

---- otherwise it bounces off whatever it landed on and lands as an item on the nearest empty space within 10 tiles. destroyed if no space ----
else
if (FlyingItem.CloudStorage) then -- for things with data/tags or whatever
if (FlyingItem.CloudStorage) then -- for things with data/tags or whatever, should only ever be 1 in stack
if (ThingLandedOn.type == "transport-belt") then
for l = 1, 2 do
for i = 0, 1, 0.1 do
for i = 0, 0.9, 0.1 do
if (FlyingItem.CloudStorage[1].count > 0 and ThingLandedOn.get_transport_line(l).can_insert_at(i) == true) then
ThingLandedOn.get_transport_line(l).insert_at(i, {name=FlyingItem.CloudStorage[1].name, count=1})
ThingLandedOn.get_transport_line(l).insert_at(i, FlyingItem.CloudStorage[1])
FlyingItem.CloudStorage[1].count = FlyingItem.CloudStorage[1].count - 1
end
end
end
end
if (FlyingItem.CloudStorage[1].count > 0) then
rendering.get_surface(FlyingItem.sprite).spill_item_stack
(
rendering.get_surface(FlyingItem.sprite).find_non_colliding_position("item-on-ground",FlyingItem.target, 0, 0.1),
FlyingItem.CloudStorage[1]
)
end
FlyingItem.CloudStorage.destroy()
else -- depreciated drop method from old item tracking system
local total = FlyingItem.amount
if (ThingLandedOn.type == "transport-belt") then
for l = 1, 2 do
for i = 0, 1, 0.1 do
for i = 0, 0.9, 0.1 do
if (total > 0 and ThingLandedOn.get_transport_line(l).can_insert_at(i) == true) then
ThingLandedOn.get_transport_line(l).insert_at(i, {name=FlyingItem.item, count=1})
total = total - 1
Expand Down
4 changes: 4 additions & 0 deletions script/event/config_changed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ local function config_changed()
global.ZiplineTerminals = {}
end

if (global.HoverGFX == nil) then
global.HoverGFX = {}
end

end

return config_changed
3 changes: 3 additions & 0 deletions script/event/entity_destroyed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ local function entity_destroyed(event)
entity.destroy()
end
end
if (global.HoverGFX[event.unit_number]) then
global.HoverGFX[event.unit_number] = nil
end
global.CatapultList[event.unit_number] = nil
end

Expand Down
2 changes: 2 additions & 0 deletions script/event/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ local function on_int()
global.clock = {}

global.ZiplineTerminals = {}

global.HoverGFX = {}
end

return on_int
2 changes: 1 addition & 1 deletion script/event/player_created.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local function player_created(event)
if (global.AllPlayers[event.player_index] == nil) then
global.AllPlayers[event.player_index] = {state="default", PlayerLauncher={}, zipline={}, RangeAdjusting=false, SettingRampRange={SettingRange=false}, GUI={}, preferences={}}
global.AllPlayers[event.player_index] = {state="default", PlayerLauncher={}, zipline={}, RangeAdjusting=false, SettingRampRange={SettingRange=false}, GUI={}, preferences={}, HoverGraphic=0}
end
end

Expand Down

0 comments on commit 1fbb555

Please sign in to comment.