Spawning items on rotated tiles

I’m working on adding another mission into the game, where there is an end-mission function that spawns a bunch of items. However the tile I’m placing the items on (evac_center_19, the evac center storage room) can be rotated, depending on the orientation of the refugee center. Is there any way I can place items in a way that will make them appear in a consistent location (on specific display racks in this case) regardless of tile rotation?

My first idea was to detect the rotation somehow and shift coordinates to match, but I haven’t been able to find a method that does that. My second idea was to see if there was a rotation independent placement method somewhere, but I haven’t managed to find that either (possibbly due to my unfamiliarity with the code base). Anyone know if methods like those I mentioned exist, or if there might be another way of placing already existing tiles?

I think you are misunderstanding what I am asking. I am producing a new function in mission_end.cpp which will cause items to appear in an already existing tile. I think a line like what you posted would be for controlling item spawn upon tile generation.

I am currently using the map::spawn_item function from map.cpp to do this, in a manner similar to how things are constructed in the ranch mission chains, where the settlement gets built over time. However the ranch appears to be able to just hardcode the coordinates of items that will be placed, because the ranch has a fixed orientation. The refugee center however can spawn in any orientation, so I cannot simply rely on fixed values to spawn in items, and need something slightly more sophisticated.

Here is an example:

[
  {
    "type": "mapgen",
    "method": "json",
    "om_terrain": [ "church" ],
    "//": "New England Church",
    "weight": 1000,
    "object": {
      "fill_ter": "t_dirt",
      "rows": [
        "          ^^^^^^         ",
        "      |---|--------|     ",
        "     ||dh.|.6ooo.ll||    ",
        "     |l...+.........Dsss ",
        "   ^^|--+-|------+--|^^s ",
        "   ^||..............||^s ",
        "    w....b..tt..b....w s ",
        "    |................| s ",
        "   ^w................w^s ",
        "   ^|.######..######.|^s ",
        "   ^w................w^s ",
        "   ^|.######..######.|^s ",
        "    w................w s ",
        "    |.######..######.| s ",
        "   ^w................w^s ",
        "   ^|.######..######.|^s ",
        "   ^|................|^s ",
        "    |-w|----..----|w-| s ",
        "     ^^|ll|....|ST|^^  s ",
        "      ^|.......+..|^   s ",
        "       |----++-|--|    s ",
        "          O ss O       s ",
        "      ^^    ss    ^^   s ",
        "      ^^    ss    ^^   s "
      ],
      "palettes": [ "church" ],
      "mapping": { "b": { "furniture": "f_brazier" } },
      "items": {
        "#": { "item": "church", "chance": 40 },
        ".": { "item": "church", "chance": 5 },
        "d": { "item": "office", "chance": 30 },
        "l": { "item": "jackets", "chance": 60 },
        "o": { "item": "church", "chance": 40 }
      },
      "computers": {
        "6": {
          "name": "Church Bells 1.2",
          "options": [
            { "name": "Gathering Toll", "action": "toll" },
            { "name": "Wedding Toll", "action": "toll" },
            { "name": "Funeral Toll", "action": "toll" }
          ]
        }
      }
    }
  },
  {
    "type": "mapgen",
    "method": "json",
    "om_terrain": [ "church" ],
    "//": "Gothic Church",
    "weight": 1000,
    "object": {
      "fill_ter": "t_dirt",
      "rows": [
        " $$    W        W    $$ ",
        " $$  WWWWGVBBVGWWWW  $$ ",
        "     W..h.cccc.h..W     ",
        " WWVWWR..........RWWBWW ",
        "WW#.#.R.b..cc..b.R.#.#WW",
        " G#.#.R..........R.#.#V ",
        " V#.#.Rrrrr..rrrrR.#.#B ",
        "WW#..................#WW",
        " WW+WW#####..#####WW+WW ",
        "ssss V............B ssss",
        "s   WW#####..#####WW   s",
        "s $ WW............WW $ s",
        "s $  G#####..#####V  $ s",
        "s $  B............G  $ s",
        "s $ WW#####..#####WW $ s",
        "s $ WW............WW $ s",
        "s    V####....####B    s",
        "s WWWW--|--gg-----WWWW s",
        "s WLLWTS|.....lll.W..W s",
        "s W..+..+.........+..W s",
        "s W..WWWWWW++WWWWWW6.W s",
        "s W.CWW$$WWssWW$$WW..W s",
        "s WWWWW    ss    WWWWW s",
        "ssssssssssssssssssssssss"
      ],
      "palettes": [ "church" ],
      "mapping": { "b": { "furniture": "f_brazier" } },
      "terrain": {
        "#": "t_rock_floor",
        "$": "t_shrub",
        ".": "t_rock_floor",
        "B": "t_window_stained_blue",
        "C": "t_rock_floor",
        "G": "t_window_stained_green",
        "R": "t_railing_v",
        "S": "t_rock_floor",
        "T": "t_rock_floor",
        "V": "t_window_stained_red",
        "W": "t_rock",
        "b": "t_rock_floor",
        "L": "t_rock_floor",
        "c": "t_rock_floor",
        "g": "t_door_glass_c",
        "h": "t_rock_floor",
        "l": "t_rock_floor",
        "r": "t_railing_h",
        "t": "t_rock_floor"
      },
      "items": {
        "#": { "item": "church", "chance": 40 },
        ".": { "item": "church", "chance": 5 },
        "L": { "item": "cleaning", "chance": 30 },
        "c": { "item": "church", "chance": 40 },
        "l": { "item": "jackets", "chance": 60 }
      },
      "computers": {
        "6": {
          "name": "Church Bells 1.2",
          "options": [
            { "name": "Gathering Toll", "action": "toll" },
            { "name": "Wedding Toll", "action": "toll" },
            { "name": "Funeral Toll", "action": "toll" }
          ]
        }
      }
    }
  }
]

Once again, this Json controls items that exist upon tile spawn, while I am trying to add items to an already existing tile upon completion of a mission. Unless I am severely misunderstanding something about how item spawning works (which is entirely possible) then nothing in a json file is likely to help me. I need a way to access either tile rotation, or rotation indepependant coordinates from a c++ function.

Yes, sorry. You need to rotate item spawn points coordinates according to rotation of overmap terrain then.

I know that I have to rotate the spawn coordinates. I just don’t know how to detect which orientation the tile is in. Do you know of a way to detect that from c++ code?

You can check id of current overmap terrain - it would contain suffix (e.g.
house_south) which defines how much you should rotate item spawn point.

1 Like