Skip to content

Feat/build zone check#75

Open
inqus637 wants to merge 3 commits intoIlyaChichkov:developfrom
inqus637:feat/build-zone-check
Open

Feat/build zone check#75
inqus637 wants to merge 3 commits intoIlyaChichkov:developfrom
inqus637:feat/build-zone-check

Conversation

@inqus637
Copy link
Copy Markdown
Contributor

Builder Check-Zone API Design

Overview

Add a new endpoint to check if a rectangular area can be used for building heavy constructions.

Endpoint

POST /api/v1/builder/check-zone

Request

{
  "mapId": "uuid",
  "pointA": { "x": 10, "z": 20 },
  "pointB": { "x": 50, "z": 60 }
}
  • mapId: UUID of the map
  • pointA: First corner of the area
  • pointB: Second corner of the area

Response

{
  "canBuild": false,
  "issues": {
    "terrain": [
      { "x": 15, "z": 25, "defName": "Soil", "label": "Dirt" }
    ],
    "ores": [
      { "x": 30, "z": 40, "defName": "MineableChrome", "label": "Chrome" }
    ],
    "buildings": [
      { "x": 45, "z": 55, "defName": "Table", "label": "Table" }
    ],
    "zones": [
      { "x": 35, "z": 45, "zoneType": "Growing", "label": "Farm 1" },
      { "x": 10, "z": 15, "zoneType": "Stockpile", "label": "Storage" }
    ]
  }
}
  • canBuild: true if no issues, false otherwise
  • issues: Grouped by category
    • terrain: Cells with terrain lacking Heavy affordance
    • ores: Mineable rocks/ores
    • buildings: Existing buildings
    • zones: Growing or Stockpile zones

Implementation Details

Logic

  1. Normalize coordinates - Ensure min/max X and Z are correct regardless of point order
  2. Iterate all cells in the rectangular area
  3. For each cell, check:
    • Terrain: map.terrainGrid.TerrainAt(cell) - check if affordances does NOT contain Heavy
    • Ores: cell.GetThingList(map) - check thing.def.building.mineable
    • Buildings: Same thing list, check thing.def.category == ThingCategory.Building
  4. Zone check: Iterate map.zoneManager.AllZones, filter by Zone_Growing and Zone_Stockpile, check if any cell in the zone overlaps with the check area

Data Structures

  • Add CheckZoneRequestDto to BuilderDtos.cs
  • Add CheckZoneResultDto to BuilderDtos.cs with nested DTOs for each issue type
  • Add CheckZone method to IBuilderService and BuilderService
  • Add endpoint to BuilderController

RimWorld API References

  • map.terrainGrid.TerrainAt(IntVec3) - get terrain at cell
  • TerrainDef.affordances - list of affordance defs (check for Heavy)
  • cell.GetThingList(Map) - get all things at cell
  • ThingDef.building.mineable - check if mineable
  • ThingCategory.Building - category for buildings
  • map.zoneManager.AllZones - all zones on map
  • Zone_Growing, Zone_Stockpile - zone types to check
  • Zone.cells - cells belonging to a zone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant