       (merge-with - infmap singledinfmap))
       infmap)))
 
-(defn influence-count [deck]
-  "Returns sum of influence count used by a deck"
+(defn mostwanted-count
+  "Returns total number of MWL restricted cards in a deck."
+  [deck]
+  (apply + (vals (mostwanted deck))))
+
+(defn influence-count
+  "Returns sum of influence count used by a deck."
+  [deck]
   (apply + (vals (influence deck))))
+
+(defn deck-inf-limit [deck]
+  (let [originf (id-inf-limit (:identity deck))
+        postmwlinf (- originf (mostwanted-count deck))]
+    (if (= originf INFINITY) ; FIXME this ugly 'if' could get cut when we get a proper nonreducible infinity in CLJS
+      INFINITY (if (> 1 postmwlinf) 1 postmwlinf))))
 
 (defn card-count [cards]
   (reduce #(+ %1 (:qty %2)) 0 cards))

        str (reduce #(str %1 (:qty %2) " " (get-in %2 [:card :title]) "\n") "" cards)]
    (om/set-state! owner :deck-edit str)))

(defn influence [deck]
  "Returns a map of faction keywords to influence values from the faction's cards."
  (let [identity (:identity deck)
        cards (:cards deck)
        infhelper (fn [currmap line]


(defn noinfcost? [identity card]
  (or (= (:faction card) (:faction identity))
      (zero? (:factioncost card)) (= INFINITY (id-inf-limit identity))))

(defn search [query cards]
  (filter #(if (= (.indexOf (.toLowerCase (:title %)) query) -1) false true) cards))
