 				return items.length <= 0
 					? null
 					: items[index]
+			}
+
+			function addInventoryItem (name, count) {
+				const { items, index } = state.player.inventory
+
+				const entry = items.find((entry) => entry.name === name)
+				if (entry != null) {
+					entry.count += count
+				} else {
+					items.push({ name, count })
+				}
 			}
 
 			function getNeighbors (position) {

		ruleLines = makeList()
		rules.forEach (rule) ->
			ruleLines.push compileLeaveRule rule
			return
		push ruleLines.join ' else '


			#{compileNearRules spec.nearRules}

			#{compileLeaveRules spec.leaveRules}

			#{compileEnterRules spec.enterRules}
		"""

	{
