🔍 Module Scanned
src/world/worldgen/ (automated audit scan)
📝 Summary
The isInCoastalNoTreeZone function in surface_builder.zig contains incorrect boolean logic. It uses AND (and) to combine three conditions when the intended logic (checking if a value is within a range OR above a minimum threshold) requires OR. The function is currently dead code (not called anywhere) but would produce incorrect results if used.
📍 Location
- File:
src/world/worldgen/surface_builder.zig:240
- Function/Scope:
SurfaceBuilder.isInCoastalNoTreeZone
🔴 Severity: Medium
- Medium: Incorrect logic that would cause wrong tree placement decisions if the function were used
💥 Impact
If isInCoastalNoTreeZone were called with a height value, the function would return incorrect results. For example, with default parameters (sea_level=64, coastal_no_tree_min=8, coastal_no_tree_max=18):
isInCoastalNoTreeZone(70) (diff=6) returns false instead of true
isInCoastalNoTreeZone(72) (diff=8) returns true (correct)
The function creates a gap in coverage from diff=1 to diff=7 where the function returns false even though those positions might need to be in the no-tree zone depending on design intent.
🔎 Evidence
Problem analysis:
- With parameters min=8, max=18:
- diff=6:
true and true and false = false (incorrect if the no-tree zone should start at diff=0)
- diff=10:
true and true and true = true (correct)
- diff=25:
true and false and true = false (correct)
The AND logic requires ALL three conditions to be true simultaneously, which creates an impossible constraint (diff >= 0 AND diff <= 18 AND diff >= 8 simplifies to diff >= 8 AND diff <= 18).
The intended logic (checking if diff is in range [0, max] OR >= min) requires OR between the range check and the minimum check.
🛠️ Proposed Fix
The fix depends on the intended semantics:
Option 1: If the no-tree zone is [0, max]:
Option 2: If the no-tree zone is [min, max]:
Option 3: If the no-tree zone is [0, max] OR >= min (i.e., NOT in gap):
The parameters suggest Option 2 (a bounded zone from 8 to 18) or Option 3 might be intended, since having coastal_no_tree_min = 8 suggests the zone doesn't start at sea level.
✅ Acceptance Criteria
📚 References
- Related:
coastal_no_tree_min and coastal_no_tree_max parameters in SurfaceParams (surface_builder.zig:49-50)
- Note: The
coastal_plains biome in biome_registry.zig already handles coastal tree restrictions via biome-specific vegetation settings
- This function appears to be unused dead code that was likely intended to handle tree placement near coasts
🔍 Module Scanned
src/world/worldgen/(automated audit scan)📝 Summary
The
isInCoastalNoTreeZonefunction insurface_builder.zigcontains incorrect boolean logic. It uses AND (and) to combine three conditions when the intended logic (checking if a value is within a range OR above a minimum threshold) requires OR. The function is currently dead code (not called anywhere) but would produce incorrect results if used.📍 Location
src/world/worldgen/surface_builder.zig:240SurfaceBuilder.isInCoastalNoTreeZone🔴 Severity: Medium
💥 Impact
If
isInCoastalNoTreeZonewere called with a height value, the function would return incorrect results. For example, with default parameters (sea_level=64,coastal_no_tree_min=8,coastal_no_tree_max=18):isInCoastalNoTreeZone(70)(diff=6) returnsfalseinstead oftrueisInCoastalNoTreeZone(72)(diff=8) returnstrue(correct)The function creates a gap in coverage from diff=1 to diff=7 where the function returns
falseeven though those positions might need to be in the no-tree zone depending on design intent.🔎 Evidence
Problem analysis:
true and true and false= false (incorrect if the no-tree zone should start at diff=0)true and true and true= true (correct)true and false and true= false (correct)The AND logic requires ALL three conditions to be true simultaneously, which creates an impossible constraint (
diff >= 0 AND diff <= 18 AND diff >= 8simplifies todiff >= 8 AND diff <= 18).The intended logic (checking if diff is in range [0, max] OR >= min) requires OR between the range check and the minimum check.
🛠️ Proposed Fix
The fix depends on the intended semantics:
Option 1: If the no-tree zone is [0, max]:
Option 2: If the no-tree zone is [min, max]:
Option 3: If the no-tree zone is [0, max] OR >= min (i.e., NOT in gap):
The parameters suggest Option 2 (a bounded zone from 8 to 18) or Option 3 might be intended, since having
coastal_no_tree_min = 8suggests the zone doesn't start at sea level.✅ Acceptance Criteria
isInCoastalNoTreeZonefunction returns correct values for all diff values📚 References
coastal_no_tree_minandcoastal_no_tree_maxparameters inSurfaceParams(surface_builder.zig:49-50)coastal_plainsbiome inbiome_registry.zigalready handles coastal tree restrictions via biome-specific vegetation settings