From 897e96cdbc5ff1da5b1f1061fc362f5236441128 Mon Sep 17 00:00:00 2001
From: Daniel Vedder <daniel.vedder@idiv.de>
Date: Thu, 20 Jun 2024 12:47:25 +0200
Subject: [PATCH] Fixed skylark migration bug

closes #90
---
 CHANGELOG.md                  | 23 ++++++++++++++++++++++-
 src/nature/species/skylark.jl | 20 ++++++++++++--------
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e4dfb0..c340578 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 
+## [0.5.2] - unreleased
+
+### Added
+
+### Changed
+
+- input files that are now copied to a separate `inputs` directory within the output directory
+
+- `EventType` renamed to `Management` for clarity
+
+- `insectbiomass()` uses units
+
+### Deprecated
+
+### Removed
+
+### Fixed
+
+- all skylarks now migrate (#90)
+
+
 ## [v0.5.1] - 13-06-2024
 
 ### Added
@@ -115,7 +136,7 @@ way the species definition macros work and are used.
 
 <!-- Template
 
-## [Unreleased] - <date>
+## [version] - unreleased
 
 <comments>
 
diff --git a/src/nature/species/skylark.jl b/src/nature/species/skylark.jl
index 776d909..6400bbc 100644
--- a/src/nature/species/skylark.jl
+++ b/src/nature/species/skylark.jl
@@ -126,7 +126,7 @@ As a non-breeding adult, move around with other individuals and check for migrat
     month, day = monthday(model.date)
     migrate = (((month < arrive[1]) || (month == arrive[1] && day < arrive[2])) ||
                ((month > leave[1]) || (month == leave[1] && day >= leave[2])))
-    if migrate #FIXME not all migrate?
+    if migrate
         @kill(self.migrationmortality, "migration")
         returndate = Date(year(model.date)+1, arrive[1], arrive[2])
         @setphase(mating)
@@ -146,9 +146,9 @@ Move around until a mate is found.
             self.mate = -1
             return
         end
-        month, day = monthday(model.date)
-        nest = ((month == self.nestingbegin[1] && day >= self.nestingbegin[2]
-                 && @chance(0.05)) || (month > self.nestingbegin[1])) #XXX why the chance?
+        mon, day = monthday(model.date)
+        nest = ((mon == self.nestingbegin[1] && day >= self.nestingbegin[2]
+                 && @chance(0.05)) || (mon > self.nestingbegin[1])) #XXX why the chance?
         nest && @setphase(nestbuilding)
         return
     end
@@ -162,7 +162,11 @@ Move around until a mate is found.
         end
     end
     #@debug("$(animalid(self)) didn't find a mate.")
-    @walk("random", 100m) #XXX magic number
+    if month(model.date) > self.nestingend # stop trying to find a mate if it's too late
+        @setphase(nonbreeding)
+    else
+        @walk("random", 100m) #XXX magic number
+    end
 end
 
 """
@@ -256,9 +260,9 @@ should currently be on migration. Also sets other individual-specific variables.
     # calculate migration dates for this individual
     self.migrationdates = migrationdates(self, model)
     leave, arrive = self.migrationdates
-    month, day = monthday(model.date)
-    migrate = (((month < arrive[1]) || (month == arrive[1] && day < arrive[2])) ||
-               ((month > leave[1]) || (month == leave[1] && day >= leave[2])))
+    mon, day = monthday(model.date)
+    migrate = (((mon < arrive[1]) || (mon == arrive[1] && day < arrive[2])) ||
+               ((mon > leave[1]) || (mon == leave[1] && day >= leave[2])))
     if migrate
         returndate = Date(year(model.date), arrive[1], arrive[2])
         model.date != @param(core.startdate) && (returndate += Year(1))
-- 
GitLab