Fixing player year rules to be serializiable.

logins
Thomas Hintz 5 years ago
parent fc3a49ce6b
commit 618d95f3b0

@ -567,14 +567,14 @@
(game-farmers-fates game))) (game-farmers-fates game)))
(push! (make-player-year-rule (push! (make-player-year-rule
0 0
`((?p cows player-action-post-harvest '((?p cows player-action-post-harvest
,(make-remove-farmers-fate-from-hand 'cows-15)) (remove-farmers-fate-from-hand cows-15))
(?p cows))) (?p cows)))
(player-year-rules player)) (player-year-rules player))
(push! (make-player-year-rule (push! (make-player-year-rule
1 1
`((?d player-action ?p `((?d player-action ?p
,(make-remove-farmers-fate-after 'cows-15 40)))) (remove-farmers-fate-after cows-15 40))))
(player-year-rules player)))))) (player-year-rules player))))))
(define (find-player-by-name game name) (define (find-player-by-name game name)
@ -1508,8 +1508,7 @@
0 0
'(ridge1 ridge2 ridge3 ridge4))) '(ridge1 ridge2 ridge3 ridge4)))
(define (make-remove-farmers-fate-from-hand id) (define (remove-farmers-fate-from-hand player id)
(lambda (player)
(let ((game (*game*))) (let ((game (*game*)))
(safe-set! (game-farmers-fates game) (safe-set! (game-farmers-fates game)
(append (game-farmers-fates game) (append (game-farmers-fates game)
@ -1517,12 +1516,15 @@
(player-farmers-fates player))))) (player-farmers-fates player)))))
(safe-set! (player-farmers-fates player) (safe-set! (player-farmers-fates player)
(filter (lambda (x) (not (eq? (alist-ref 'internal-id x) id))) (filter (lambda (x) (not (eq? (alist-ref 'internal-id x) id)))
(player-farmers-fates player))))) (player-farmers-fates player))))
(define (make-remove-farmers-fate-after id space) (define (remove-farmers-fate-after p id space)
(lambda (p)
(when (>= (player-space p) space) (when (>= (player-space p) space)
((make-remove-farmers-fate-from-hand id) p)))) (remove-farmers-fate-from-hand p id)))
(define *action-map*
`((remove-farmers-fate-from-hand . ,remove-farmers-fate-from-hand)
(remove-farmers-fate-after . ,remove-farmers-fate-after)))
(define (farmers-fate-spec->farmers-fate-card spec id) (define (farmers-fate-spec->farmers-fate-card spec id)
`((contents . ,(sxml->html* (list-ref spec 0))) `((contents . ,(sxml->html* (list-ref spec 0)))
@ -1594,13 +1596,13 @@
(push! (make-player-year-rule (push! (make-player-year-rule
3 3
`((?p wheat player-action-post-harvest `((?p wheat player-action-post-harvest
,(make-remove-farmers-fate-from-hand 'windy-spring)) (remove-farmers-fate-from-hand windy-spring))
(?p grain))) (?p grain)))
(player-year-rules player)) (player-year-rules player))
(push! (make-player-year-rule (push! (make-player-year-rule
4 4
`((?d player-action ?p `((?d player-action ?p
,(make-remove-farmers-fate-after 'windy-spring 34)))) (remove-farmers-fate-after windy-spring 34))))
(player-year-rules player)) (player-year-rules player))
'()) '())
#t #t
@ -1687,13 +1689,13 @@
(push! (make-player-year-rule (push! (make-player-year-rule
8 8
`((?p cherries player-action-post-harvest `((?p cherries player-action-post-harvest
,(make-remove-farmers-fate-from-hand 'cherries-05)) (remove-farmers-fate-from-hand cherries-05))
(?p fruit))) (?p fruit)))
(player-year-rules player))) (player-year-rules player)))
(push! (make-player-year-rule (push! (make-player-year-rule
8 8
`((?d player-action ?p `((?d player-action ?p
,(make-remove-farmers-fate-after 'cherries-05 26)))) (make-remove-farmers-fate-after cherries-05 26))))
(player-year-rules player)) (player-year-rules player))
'()) '())
#t #t
@ -1997,7 +1999,10 @@
`((actions . ,((alist-ref 'action (car new-ff)) player game)) `((actions . ,((alist-ref 'action (car new-ff)) player game))
(contents . ,(alist-ref 'contents (car new-ff)))))) (contents . ,(alist-ref 'contents (car new-ff))))))
((or (eq? a 'player-action) (eq? a 'player-action-post-harvest)) ((or (eq? a 'player-action) (eq? a 'player-action-post-harvest))
((alist-ref '?value action) player)) (let ((value (alist-ref '?value action)))
(if (procedure? value)
(value player)
(apply (alist-ref (car value) *action-map*) player (cdr value)))))
((eq? a 'harvest-mult) ((eq? a 'harvest-mult)
(safe-set! (player-harvest-mult player) (safe-set! (player-harvest-mult player)
(* (player-harvest-mult player) (alist-ref '?value action)))) (* (player-harvest-mult player) (alist-ref '?value action))))

Loading…
Cancel
Save