summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.lisp17
-rw-r--r--src/inventory.lisp3
-rw-r--r--src/player.lisp7
3 files changed, 24 insertions, 3 deletions
diff --git a/src/game.lisp b/src/game.lisp
index 51c3a4d..979e4e2 100644
--- a/src/game.lisp
+++ b/src/game.lisp
@@ -3,7 +3,9 @@
(:export :new-game
:buy-item
:sell-item
- :change-zone))
+ :change-zone
+ :get-profit
+ :get-profit-in-zone))
(in-package :game)
@@ -40,3 +42,16 @@
zones)))
(when z
(setq cur-zone z)))))
+
+(defmethod get-profit-in-zone ((g game) name zone)
+ (with-slots (player) g
+ (let ((player-item (car (player:find-item player name)))
+ (zone-item (zone:get-commodity zone name)))
+ (if (and player-item zone-item)
+ (- (commodities:price zone-item)
+ (commodities:price player-item))
+ 0))))
+
+(defmethod get-profit ((g game) name)
+ (with-slots (cur-zone) g
+ (get-profit-in-zone g name cur-zone)))
diff --git a/src/inventory.lisp b/src/inventory.lisp
index e122364..8aa590f 100644
--- a/src/inventory.lisp
+++ b/src/inventory.lisp
@@ -3,7 +3,8 @@
(:export :new-inventory
:filled
:add-item
- :remove-item))
+ :remove-item
+ :find-item))
(in-package :inventory)
diff --git a/src/player.lisp b/src/player.lisp
index 394cee9..32757d0 100644
--- a/src/player.lisp
+++ b/src/player.lisp
@@ -6,7 +6,8 @@
:get-debt
:repay-debt
:buy-item
- :sell-item))
+ :sell-item
+ :find-item))
(in-package :player)
@@ -61,6 +62,10 @@
(+ cash (* (cdr stocked-item)
(commodities:price item))))))))
+(defmethod find-item ((p player) name)
+ (with-slots (stock) p
+ (inventory:find-item stock name)))
+
(defmethod repay-debt ((p player) amount)
(with-slots (debt cash) p
(when (and (<= amount debt)