Skip to content

Commit

Permalink
add nutrition to filters
Browse files Browse the repository at this point in the history
  • Loading branch information
garbados committed Nov 13, 2023
1 parent 491645d commit ad2fd3b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/the_longtime_game/event_text.clj
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@
["Disability is produced by inaccessibility."
"An order which excludes by design, limits its own potential."
"Such an order can prevail even silently,"
"as though no such barrier could exist."
"They must be rooted out," (:name healcow) "knows."
"imagining no such barrier could exist."
"It must be rooted out," (:name healcow) "knows."
"Accommodations call for quality of craft and heartful vision."
"Some wounds never really heal, mental or physical,"
"but we can make the changes we need,"
Expand Down
15 changes: 11 additions & 4 deletions src/the_longtime_game/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@
:ready? false)}
{:name "Hold festival"
:description "Surprise and tantalize with feats of physical prowess and dextrous excellence!"
:detail "Consumes nutrition and raises fulfillment."
:detail "Consumes 1 nutrition per 5 individuals, and raises fulfillment."
:uses [:athletics :organizing]
:filter {:stores {:nutrition 1/5}}
:filter-fn
#(core/herd-has-nutrition? % 1/5)
:effect
Expand Down Expand Up @@ -604,9 +605,15 @@
stores-filter (get-in project [:filter :stores])
update-stores
#(reduce
(fn [herd [resource amount]]
(let [amount (cond-> amount
(< 0 amount 1) (* (count (:individuals herd)))
(fn [herd [resource required]]
(if (= :nutrition resource)
(core/consume-nutrition herd required)
(>= (get-in herd [:stores resource] 0)
(if (> 1 required 0)
(int (* required (count (:individuals herd))))
required)))
(let [amount (cond-> required
(< 0 required 1) (* (count (:individuals herd)))
:finally int)]
(update-in herd [:stores resource] - amount)))
%
Expand Down
11 changes: 2 additions & 9 deletions src/the_longtime_game/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,10 @@
ok? (>= (get-in herd [:stores :poultices] 0) need)
! (if ok? "" "!")]
(println "├─ Sickness:"
(as-> (:sickness herd) $
(/ $ population)
(* $ 100)
(float $)
(format "%.2f" $)
(str $ "%"))
(str (int (* (/ (:sickness herd) population) 100)) "%")
(str "(-" need ! ")")))
(let [fulfillments (map :fulfillment (:individuals herd))
average (as-> fulfillments $
(reduce + 0 $)
(/ $ population))
average (/ (reduce + 0 fulfillments) population)
minimum (reduce min fulfillments)
maximum (reduce max fulfillments)]
(println "├─ Fulfillment:"
Expand Down
19 changes: 9 additions & 10 deletions src/the_longtime_game/select.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(s/def ::power pos-int?)

(s/def ::stores
(s/map-of ::core/resource
(s/map-of (conj core/resources :nutrition)
(s/or :n pos-int?
:x (s/and number? #(< 0 % 1)))))

Expand Down Expand Up @@ -50,15 +50,14 @@
(if season
(= (core/get-season herd) season)
true)
(reduce
(fn [ok? [resource required]]
(let [required (cond-> required
(> 1 required 0)
(* (count (:individuals herd))))
amount (get-in herd [:stores resource] 0)]
(and ok?
(>= amount required))))
true
(every?
(fn [[resource required]]
(if (= :nutrition resource)
(core/herd-has-nutrition? herd required)
(>= (get-in herd [:stores resource] 0)
(if (> 1 required 0)
(int (* required (count (:individuals herd))))
required))))
(or stores {}))
(if (and contacts (s/valid? ::contacts contacts))
(let [[kind x] (s/conform ::contacts contacts)]
Expand Down
8 changes: 5 additions & 3 deletions src/the_longtime_game/text.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
(defn normalize-name
[x]
(cond
(keyword? x) (name x)
(string? x) x
:else (str x)))
(keyword? x) (name x)
(and (number? x)
(< 0 x 1)) (str (int (* 100 (float x))) "%")
(string? x) x
:else (str x)))

(s/fdef normalize-name
:args (s/cat :x any?)
Expand Down

0 comments on commit ad2fd3b

Please sign in to comment.