                install-cost (if (and (ice? c) (not no-install-cost))
                               (count dest-zone) 0)
                install-state (or install-state (:install-state cdef))]
-           (when (not (and (has-subtype? c "Region")
-                           (some #(has-subtype? % "Region") dest-zone)))
+           (when (corp-can-install? card dest-zone)
              (when-let [cost-str (pay state side card extra-cost :credit install-cost)]
-               (when (#{"Asset" "Agenda"} (:type c))
-                 (when-let [prev-card (some #(when (#{"Asset" "Agenda"} (:type %)) %) dest-zone)]
-                   (system-msg state side (str "trashes " (card-str state prev-card)))
-                   (trash state side prev-card {:keep-server-alive true})))
-               (let [card-name (if (or (= :rezzed-no-cost install-state)
-                                       (= :face-up install-state)
-                                       (:rezzed c))
-                                 (:title card)
-                                 (if (ice? c) "ICE" "a card"))]
-                 (system-msg state side (str (build-spend-msg cost-str "install")
-                                             card-name (if (ice? c) " protecting " " in ") server)))
+               (corp-install-asset-agenda state side c dest-zone)
+               (corp-install-message state side c server install-state cost-str)
                (let [moved-card (move state side c slot)]
                  (trigger-event state side :corp-install moved-card)
                  (when (is-type? c "Agenda")

                 (when-let [dre (:derezzed-events cdef)]
                   (register-events state side dre moved-card))))))))))

(defn runner-install
  ([state side card] (runner-install state side card nil))
  ([state side {:keys [title type cost memoryunits uniqueness ] :as card}
    {:keys [extra-cost no-cost host-card facedown custom-message] :as params}]
   (when (not (seq (get-in @state [side :locked (-> card :zone first)])))
     (if-let [hosting (and (not host-card) (not facedown) (:hosting (card-def card)))]
       (resolve-ability state side
                        {:choices hosting
                         :effect (effect (runner-install card (assoc params :host-card target)))} card nil)
       (do
         (trigger-event state side :pre-install card)
         (let [cost (install-cost state side card
                                  (concat extra-cost (when (and (not no-cost) (not facedown)) [:credit cost])
                                          (when (and memoryunits (not facedown)) [:memory memoryunits])))]
           (when (and (or (not uniqueness) (not (in-play? state card)) facedown)
                      (if-let [req (:req (card-def card))]
                        (or facedown (req state side card nil)) true))
             (when-let [cost-str (pay state side card cost)]
               (let [c (if host-card
                         (host state side host-card card)
                         (move state side card [:rig (if facedown :facedown (to-keyword type))]))
                     installed-card (if facedown
                                      (update! state side (assoc c :installed true))
                                      (card-init state side (assoc c :installed true) true))]
                 (if facedown
                   (system-msg state side "installs a card facedown")
                   (if custom-message
                     (system-msg state side custom-message)
                     (system-msg state side (str (build-spend-msg cost-str "install") title
                                                 (when host-card (str " on " (:title host-card)))
                                                 (when no-cost " at no cost")))))
                 ;Apply added-virus-counter flag for this turn if the card enters play with a counter
                 (if (and (contains? installed-card :counter)
                          (contains? installed-card :subtype)
                          (has-subtype? card "Virus")
                          (pos? (:counter installed-card)))
                   (update! state side (assoc installed-card :added-virus-counter true)))
                 (trigger-event state side :runner-install installed-card)
                 (when (has-subtype? c "Icebreaker") (update-breaker-strength state side c))))))
         (when (is-type? card "Resource")
           (swap! state assoc-in [:runner :register :installed-resource] true))
         (swap! state update-in [:bonus] dissoc :install-cost))))))

       (register-events state side events c))
     (when resolve
       (resolve-ability state side cdef c nil))
     (when-let [in-play (:in-play cdef)]
       (apply gain state side in-play))
     (get-card state c))))


;;; Intalling a corp card
(defn- corp-can-install?
  "Checks region restrictions"
  [card dest-zone]
  (not (and (has-subtype? card "Region")
            (some #(has-subtype? % "Region") dest-zone))))

(defn- corp-install-asset-agenda
  "Takes care of installing an asset or agenda in a server"
  [state side card dest-zone]
  (when (#{"Asset" "Agenda"} (:type card))
    (when-let [prev-card (some #(when (#{"Asset" "Agenda"} (:type %)) %) dest-zone)]
      (system-msg state side (str "trashes " (card-str state prev-card)))
      (trash state side prev-card {:keep-server-alive true}))))

(defn- corp-install-message
  "Prints the correct install message."
  [state side card server install-state cost-str]
  (let [card-name (if (or (= :rezzed-no-cost install-state)
                          (= :face-up install-state)
                          (:rezzed card))
                    (:title card)
                    (if (ice? card) "ICE" "a card"))]
    (system-msg state side (str (build-spend-msg cost-str "install") card-name
                                (if (ice? card) " protecting " " in ") server))))

(defn corp-install
  ([state side card server] (corp-install state side card server nil))
