diff --git a/plant-eyes/scripts/list-utils.ss b/plant-eyes/scripts/list-utils.ss index e274ee4..cbaa01d 100644 --- a/plant-eyes/scripts/list-utils.ss +++ b/plant-eyes/scripts/list-utils.ss @@ -50,3 +50,8 @@ ((null? l) #f) ((eq? (car l) k) n) (else (which-element k (cdr l) (+ n 1))))) + +(define (last l) + (cond ((null? (cdr l)) (car l)) + (else + (last (cdr l))))) diff --git a/plant-eyes/scripts/logic.ss b/plant-eyes/scripts/logic.ss index e61af46..d8d648f 100644 --- a/plant-eyes/scripts/logic.ss +++ b/plant-eyes/scripts/logic.ss @@ -36,6 +36,7 @@ (define insect-send-prob 3) (define update-count 0) +(define num-checks 0) ; moveme (define (collide? line objs) @@ -353,11 +354,34 @@ ; adds the ornament if it's close, and checks sub-twigs ; returns true if it's succeded - (define/public (check-pickup pickup) + (define/public (check-pickup pickup) + ; check last point in our twig + (set! num-checks (+ num-checks 1)) + ; if we havent found anything yet and it's intersecting + (cond ((and (not (null? points)) + (< (vdist-sq (vadd (send plant get-pos) (last points)) + (send pickup get-pos)) + 100 #;(+ width (send pickup get-size)))) + (set! pickedups (cons (list pickup (- (length points) 1)) pickedups)) + (send pickup pick-up) ; this will remove the pickup for us + (send-message 'pick-up-highlight + (list (list 'pickup-id (send pickup get-id)) + (list 'plant-id (send plant get-id)))) + #t) + (else + (foldl + (lambda (twig found) + (if (not found) + (send (cadr twig) check-pickup pickup) + #f)) + #f + twigs))) + ; check each point in our twig - (let* ((i -1) (found (foldl + #;(let* ((i -1) (found (foldl (lambda (point found) (set! i (+ i 1)) + (set! num-checks (+ num-checks 1)) ; if we havent found anything yet and it's intersecting (cond ((and (not found) (< (vdist (vadd (send plant get-pos) point) (send pickup get-pos)) @@ -371,6 +395,7 @@ (else #f))) #f points))) + ; now check each sub-twig (if (not found) (foldl @@ -795,7 +820,9 @@ (printf "num updates ~a~n" update-count) (printf "num pickups ~a~n" (length pickups)) + (printf "num checks ~a~n" num-checks) (set! update-count 0) + (set! num-checks 0) (run-auto-pilot t d) diff --git a/plant-eyes/scripts/view.ss b/plant-eyes/scripts/view.ss index d068bd9..202e638 100644 --- a/plant-eyes/scripts/view.ss +++ b/plant-eyes/scripts/view.ss @@ -1602,7 +1602,7 @@ ((eq? type 'leaf) "found a nutrient from the leaf plant") ((eq? type 'horn) "found a nutrient from the horn plant") ((eq? type 'inflatoe) "found an inflatoe growing ability") - ((eq? type 'fork) "found a nutrient from the hanging plant") + ((eq? type 'fork) "found a nutrient from the canopy plant") ((eq? type 'flower) "found a nutrient from the flower plant")) 4)))))) (define/public (add-ornament plant-id twig-id point-index property)