diff --git a/src/components/farm/Board.jsx b/src/components/farm/Board.jsx index ee4865a..fc1778b 100644 --- a/src/components/farm/Board.jsx +++ b/src/components/farm/Board.jsx @@ -1501,11 +1501,13 @@ class Harvest extends React.Component {
-

- {isCurrentPlayer ? 'You' : this.props.game.currentPlayer} - {currentExpense <= 0 ? ' lost ' : ' gained '} - ${formatMoney(Math.abs(currentExpense))}! -

+ {currentExpense ? ( +

+ {isCurrentPlayer ? 'You' : this.props.game.currentPlayer} + {currentExpense <= 0 ? ' lost ' : ' gained '} + ${formatMoney(Math.abs(currentExpense))}! +

+ ) : (<>)} {Object.keys(this.props.expenseValue) .filter(p => p !== this.props.game.currentPlayer) .map((p, i) => diff --git a/src/server/farm.scm b/src/server/farm.scm index 259ceb7..c415d8a 100644 --- a/src/server/farm.scm +++ b/src/server/farm.scm @@ -1719,6 +1719,24 @@ #f))) ) +(define (finish-ai-turn player game) + (when (< (player-cash player) 0) + (print "taking out loan") + (process-message player game "loan" `((amount . ,(/ (+ (abs (player-cash player)) + (remainder (abs (player-cash player)) 1000)) + 1000))))) + (when (and (>= (player-cash player) 1000) + (or (<= (player-debt player) 40000) + (>= (player-cash player) 75000))) + (print "repaying loan") + (process-message player game "loan" `((amount . ,(* (/ (- (player-cash player) + (remainder (player-cash player) 1000)) + 1000) + -1))))) + (print "ending turn") + (set! (player-processing-turn player) #f) + (process-message player game "turn-ended" '())) + (define (process-ai-push-message player game msg) (print (player-name player)) (print msg) @@ -1740,7 +1758,10 @@ (print "ai-next-action") (when (player-processing-turn player) (let ((res (process-message player game "next-action" '((type . "next-action"))))) - res + (if (and (equal? (alist-ref 'event res) "action") + (equal? (alist-ref 'action res) "actions-end")) + (finish-ai-turn player game) + res) ;; (display "res: ") ;; (write res) ;; (newline) @@ -1756,23 +1777,7 @@ (if (eq? (player-state player) 'pre-turn) (process-ai-push-message player game '((type . "update"))) ;; restarting at AI player's turn (if (player-processing-turn player) - (begin - (when (< (player-cash player) 0) - (print "taking out loan") - (process-message player game "loan" `((amount . ,(/ (+ (abs (player-cash player)) - (remainder (abs (player-cash player)) 1000)) - 1000))))) - (when (and (>= (player-cash player) 1000) - (or (<= (player-debt player) 40000) - (>= (player-cash player) 75000))) - (print "repaying loan") - (process-message player game "loan" `((amount . ,(* (/ (- (player-cash player) - (remainder (player-cash player) 1000)) - 1000) - -1))))) - (print "ending turn") - (set! (player-processing-turn player) #f) - (process-message player game "turn-ended" '())) + (finish-ai-turn player game) ;; this could happen if we restart the game in the middle of a turn ;; so lets just force the next turn ;; TODO this might get hit for every AI player?