Skip to content

Instantly share code, notes, and snippets.

'''
Direct implementation if DeadlineQueue from Lua.
'''
from game_tick import game
import math
class DeadlineQueue:
def __init__(self, slice_ticks, slice_count):
self.SLICE_TICKS = slice_ticks
self.SLICE_COUNT = slice_count
@bengardner
bengardner / DeadlineQueue.lua
Last active May 6, 2024 12:47
Factorio Lua DeadlineQueue
--[[
This provides a deadline queue, where the item is retured at the appropriate
tick or soon after if it has already expired.
Keys must be unique for the item. (entity.unit_number)
Values must be a table. The field "_deadline" is added to the table.
Conceptually, this is an infinite series of buckets with each spanning SLICE_TICKS tick.
The buckets are processed until empty and expired. Then we advance to the
next bucket. The prior buckets are always empty, so they are discarded.