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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
/*
Hurry Curry! - a game about cooking
Copyright 2024 metamuffin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//? Is this a good idea? Probably not.
export interface Recipe {
tile?: string,
inputs: (Item | null | undefined)[],
outputs: (Item | null | undefined)[],
action: "instant" | "passive" | "active" | "demand" | "demand"
duration?: number
revert_duration?: number,
warn?: boolean,
points?: number,
}
const all_items = new Set<Item>()
const all_recipes = new Set<Recipe>()
export function out(r: Recipe) {
r.inputs.forEach(i => i ? all_items.add(i) : void 0)
r.outputs.forEach(i => i ? all_items.add(i) : void 0)
r.inputs = r.inputs.filter(e => e)
r.outputs = r.outputs.filter(e => e)
all_recipes.add(r);
}
export function finish() {
const k = new Set<string>()
for (const r of all_recipes) {
let s = `- action: !${r.action}\n`
s += ` inputs: [${r.inputs.map(e => JSON.stringify(e!.toString())).join(",")}]\n`
s += ` outputs: [${r.outputs.map(e => JSON.stringify(e!.toString())).join(",")}]\n`
if (r.warn) s += ` warn: true\n`
if (r.duration) s += ` duration: ${r.duration}\n`
if (r.revert_duration) s += ` revert_duration: ${r.revert_duration}\n`
if (r.points) s += ` points: ${r.points}\n`
if (r.tile) s += ` tile: ${r.tile}\n`
k.add(s)
}
for (const r of k)
console.log(r);
}
function auto_trash() {
for (const i of all_items) {
if (i instanceof Container) continue
if (!i.container) out({ action: "instant", inputs: [i], outputs: [], tile: "trash" })
else {
out({
action: "instant",
inputs: [i],
outputs: [i.container.dispose ?? i.container],
tile: i.container.dispose_tile ?? "trash"
})
}
}
}
class Item {
constructor(
public name: string,
public container?: Container
) { }
as(s: string) { this.name = s; return this }
tr(container?: Container) {
const o = new Item(this.name, container)
if (this.container == container) return o
if (this.container) out({ action: "instant", inputs: [this, container], outputs: [this.container, o] })
else out({ action: "instant", inputs: [container, this], outputs: [o] })
return o
}
toString() {
return (this.container ? this.container + ":" : "") + this.name
}
}
class Container extends Item { constructor(name: string, public dispose?: Item, public dispose_tile?: string) { super(name) } }
const FP = new Container("foodprocessor")
const POT = new Container("pot")
const PAN = new Container("pan")
const PL = new Container("plate", new Container("dirty-plate"))
const GL = new Container("glass", undefined, "sink")
function crate(s: string): Item {
const item = new Item(s);
out({ action: "instant", inputs: [], outputs: [item], tile: `${s}-crate`, points: -1 })
out({ action: "instant", inputs: [item], outputs: [], tile: `${s}-crate`, points: 1 })
return item
}
function cut(s: Item, two?: boolean): Item {
const o = new Item(`sliced-${s.name}`, s.container)
out({ action: "active", inputs: [s], outputs: [o, two ? o : null], tile: "cuttingboard", duration: 2 })
return o
}
function cook(s: Item, duration = 20): Item {
const o = new Item(`cooked-${s.name}`, s.container)
out({ action: "passive", duration, tile: "stove", inputs: [s], outputs: [o] })
out({ action: "passive", duration: duration / 3, revert_duration: 20, tile: "stove", inputs: [o], outputs: [new Item("burned", POT)], warn: true })
return o
}
function sear(s: Item, duration = 15): Item {
s = s.tr(PAN)
const o = new Item(`seared-${s.name}`, s.container)
out({ action: "passive", duration, tile: "stove", inputs: [s], outputs: [o] })
out({ action: "passive", duration: duration / 3, revert_duration: 20, tile: "stove", inputs: [o], outputs: [new Item("burned", PAN)], warn: true })
return o
}
function bake(s: Item, duration = 25): Item {
const o = new Item(`sliced-${s.name}`, s.container)
out({ action: "passive", duration, tile: "oven", inputs: [s], outputs: [o] })
out({ action: "passive", duration: duration / 2, revert_duration: 20, tile: "oven", inputs: [o], outputs: [new Item("burned")], warn: true })
return o
}
function freeze(s: Item): Item {
const o = new Item(`frozen-${s.name}`, s.container)
out({ action: "passive", duration: 25, tile: "freezer", inputs: [s], outputs: [o] })
return o
}
function process(s: Item): Item {
const o = new Item(`processed-${s.name}`, s.container)
out({ action: "passive", duration: 5, inputs: [s], outputs: [o] })
return o
}
function container_add(base: Item, add: Item): Item {
const o = new Item("!!!", base.container)
out({ action: "instant", inputs: [base, add], outputs: [o, add.container] })
return o
}
function combine(c: Container, ...items: Item[]): Item {
if (items.length == 1) return items[0].tr(c)
const open = items.map(i => (i.tr(c), [i.name]))
const seen = new Set<string>()
let result
while (1) {
const cur = open.pop()
if (!cur) break;
for (const new_item of items) {
if (cur.includes(new_item.name)) continue
const rkey = cur.join(",") + "#" + new_item
if (seen.has(rkey)) continue
seen.add(rkey)
const parts = [...cur, new_item.name]
parts.sort()
open.push(parts)
const i = new Item(cur.join(","), c)
const o = new Item(parts.join(","), c)
if (parts.length == items.length) result = o
out({
action: "instant",
inputs: [i, new_item],
outputs: [o, new_item.container]
})
}
}
return result!
}
function edible(...items: Item[]) {
for (const i of items) {
out({ action: "demand", inputs: [i], outputs: [i.container?.dispose ?? i.container], duration: 10 })
}
}
function either(a: Item, b: Item) {
if (a.name != b.name) throw new Error("either options are named differently");
if (a.container != b.container) throw new Error("either options are contained differently");
return a
}
function sink_fill(c: Container) {
const o = new Item("water", c)
out({ action: "active", inputs: [c], outputs: [o], tile: "sink", duration: 1 })
return o
}
out({ action: "active", duration: 2, tile: "sink", inputs: [new Container("dirty-plate")], outputs: [PL] })
const tomato = crate("tomato")
const steak = crate("steak")
const flour = crate("flour")
const leek = crate("leek")
const rice = crate("rice")
const fish = crate("fish")
const coconut = crate("coconut")
const strawberry = crate("strawberry")
const cheese = crate("cheese")
const lettuce = crate("lettuce")
// Buns
const dough = process(flour.tr(FP)).as("dough").tr()
const bun = bake(dough).as("bun")
edible(bun.tr(PL))
// Steak
const steak_pot = sear(steak).as("steak")
edible(
combine(PL, steak_pot, bun),
combine(PL, steak_pot),
)
// Salad
edible(
combine(PL, cut(tomato), cut(lettuce)),
combine(PL, cut(lettuce)),
)
// Burger
const b_bun = cut(bun)
const b_patty = sear(cut(steak).as("patty"))
const b_tomato = cut(tomato)
const b_lettuce = cut(lettuce)
const b_cheese = cut(cheese)
edible(
combine(PL, b_bun, b_patty, b_cheese),
combine(PL, b_bun, b_patty, b_cheese, b_lettuce),
combine(PL, b_bun, b_patty, b_cheese, b_tomato),
combine(PL, b_bun, b_cheese, b_lettuce, b_tomato),
)
// Soup
const tomato_juice = process(tomato.tr(FP)).as("tomato-juice")
const leek_tj_pot = combine(POT, leek, tomato_juice)
const tomato_soup_plate = cook(leek_tj_pot).as("tomato-soup").tr(PL)
edible(tomato_soup_plate)
// Rice and nigiri
const nigiri = container_add(cut(fish), cook(rice.tr(POT))).as("nigiri").tr(PL)
edible(nigiri)
// coconut milk and strawberry puree
const strawberry_puree = process(strawberry.tr(FP)).as("strawberry-puree")
const milk = process(coconut.tr(FP)).as("milk")
const strawberry_shake = either(
process(container_add(milk, strawberry).as("milk,strawberry")).as("strawberry-shake"),
process(container_add(strawberry_puree, coconut).as("coconut,strawberry-puree")).as("strawberry-shake")
)
// Icecream
edible(freeze(strawberry_shake).as("strawberry-icecream").tr(PL))
// Mochi
const rice_flour = process(rice.tr(FP)).as("rice-flour")
const mochi_dough = cook(rice_flour.tr(POT), 5).as("mochi-dough")
const strawberry_mochi = container_add(strawberry, mochi_dough).as("strawberry-mochi")
edible(strawberry_mochi)
// Drinks
edible(
strawberry_shake.tr(GL),
tomato_juice.tr(GL),
sink_fill(GL)
)
// Curry
const curry_with_rice = combine(PL, cook(rice.tr(POT)), cook(combine(POT, milk, tomato, leek)).as("curry"))
edible(curry_with_rice)
auto_trash()
finish()
|