Gather and sow food before other work when food is short

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

author
Marijn Besseling <njirambem@gmail.com> · 2026-10-24 21:39 UTC
commit
047e40b9a3beca69cbf111d6636a9c1b568647a2
parent
5b0b7f3e37
tree
browse at this commit

2 files changed +55 -0

src/jobs/mod.rs +6 -0

@@ -905,6 +905,12 @@ fn choose_jobs(
905 905 })
906 906 .flatten()
907 907 })
908 + .or_else(|| find_work(&map, &reservations, tile.0, |k| k.is_food() && wanted(k)))
909 + .or_else(|| {
910 + wanted(ItemKind::Vegetables)
911 + .then(|| find_sowing(&map, &zones, &reservations, tile.0))
912 + .flatten()
913 + })
908 914 .or_else(|| find_bed_site(&build, colonist_count, tile.0))
909 915 .or_else(|| find_blueprint_work(&build, tile.0))
910 916 .or_else(|| find_work(&map, &reservations, tile.0, wanted))

src/jobs/tests.rs +49 -0

@@ -922,6 +922,55 @@ fn colonists_sow_empty_farm_tiles() {
922 922 );
923 923 }
924 924
925 +// Sowing used to be the last resort, so a colony with any material or construction demand
926 +// never planted its farm and starved once wild food ran out.
927 +#[test]
928 +fn hungry_colonies_sow_before_gathering_materials() {
929 + let farm = [UVec2::new(8, 8)];
930 + let mut app = farm_app(&farm);
931 + app.world_mut()
932 + .resource_mut::<WorldMap>()
933 + .set_plant(UVec2::new(3, 2), Some(Plant::Tree));
934 + set_goals(
935 + &mut app,
936 + &[(ItemKind::Vegetables, 30), (ItemKind::Wood, 30)],
937 + );
938 + let colonist = spawn_colonist(&mut app, UVec2::new(2, 2));
939 + run_ticks(&mut app, 61);
940 + assert!(matches!(
941 + task(&app, colonist),
942 + Some(Task::Work {
943 + kind: WorkKind::Sow,
944 + ..
945 + })
946 + ));
947 +}
948 +
949 +#[test]
950 +fn hungry_colonies_harvest_before_gathering_materials() {
951 + let farm = [UVec2::new(8, 8)];
952 + let mut app = farm_app(&farm);
953 + {
954 + let mut map = app.world_mut().resource_mut::<WorldMap>();
955 + map.set_plant(UVec2::new(3, 2), Some(Plant::Tree));
956 + map.set_plant(farm[0], Some(Plant::Crop));
957 + map.set_growth(farm[0], 1.0);
958 + }
959 + set_goals(
960 + &mut app,
961 + &[(ItemKind::Vegetables, 30), (ItemKind::Wood, 30)],
962 + );
963 + let colonist = spawn_colonist(&mut app, UVec2::new(2, 2));
964 + run_ticks(&mut app, 61);
965 + assert!(matches!(
966 + task(&app, colonist),
967 + Some(Task::Work {
968 + kind: WorkKind::Harvest,
969 + ..
970 + })
971 + ));
972 +}
973 +
925 974 #[test]
926 975 fn ripe_crops_are_harvested_into_vegetables_and_resown() {
927 976 let farm = [UVec2::new(8, 8)];