Skip to content

Commit

Permalink
Merge branch 'master' into add-sniper
Browse files Browse the repository at this point in the history
  • Loading branch information
djwhitt authored Jun 26, 2017
2 parents a1adfca + c641b5f commit 37a7091
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/cljs/zetawar/game.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@
ffirst
(or 0)))

(defn faction-base-being-captured-count [db faction]
(-> (d/q '[:find (count ?b)
:in $ ?f
:where
[?b :terrain/owner ?f]
[(not= ?ef f)]
[?ef :faction/units ?u]
[?u :unit/terrain ?b]
[?u :unit/capturing true]]
db (e faction))
ffirst
(or 0)))

(defn enemy-base-count [db faction]
(-> (d/q '[:find (count ?b)
:in $ ?f
Expand Down Expand Up @@ -133,8 +146,9 @@

(defn income [db game faction]
(let [base-count (faction-base-count db faction)
captured-count (faction-base-being-captured-count db faction)
{:keys [game/credits-per-base]} game]
(* base-count credits-per-base)))
(* (- base-count captured-count) credits-per-base)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Terrain
Expand Down
19 changes: 18 additions & 1 deletion src/cljs/zetawar/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@
conn)
(into {})))

(deftrack faction-eid->base-being-captured-count [conn]
(->> @(posh/q '[:find ?f (count ?t)
:where
[_ :app/game ?g]
[?g :game/factions ?f]
[?t :terrain/owner ?f]
[(not= ?ef f)]
[?ef :faction/units ?u]
[?u :unit/terrain ?t]
[?u :unit/capturing true]]
conn)
(into {})))

(deftrack faction-eid->unit-count [conn]
(->> @(posh/q '[:find ?f (count ?u)
:where
Expand Down Expand Up @@ -194,13 +207,17 @@
(deftrack current-base-count [conn]
(get @(faction-eid->base-count conn) @(current-faction-eid conn)))

(deftrack current-base-being-captured-count [conn]
(get @(faction-eid->base-being-captured-count conn) @(current-faction-eid conn)))

(deftrack current-unit-count [conn]
(get @(faction-eid->unit-count conn) @(current-faction-eid conn)))

(deftrack current-income [conn]
(let [{:keys [game/credits-per-base]} @(game conn)]
(* credits-per-base
@(current-base-count conn))))
(- @(current-base-count conn)
@(current-base-being-captured-count conn)))))

(deftrack enemy-unit-count [conn]
(or (ffirst @(posh/q '[:find (count ?u)
Expand Down

0 comments on commit 37a7091

Please sign in to comment.