# Spawning items on rotated tiles

**URL:** <https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238>\
**Category:** The Toolbox\
**Created:** [January 8, 2019, 2:46am UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238 "2019-01-08T02:46:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hydroplatypus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/hydroplatypus/32/4070_2.png) [@hydroplatypus](https://discourse.cataclysmdda.org/u/hydroplatypus)\
**Post date:** [January 8, 2019, 2:46am UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238/1 "2019-01-08T02:46:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hydroplatypus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/hydroplatypus/32/4070_2.png) [@hydroplatypus](https://discourse.cataclysmdda.org/u/hydroplatypus)\
**Post date:** [January 8, 2019, 4:11am UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238/3 "2019-01-08T04:11:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [January 8, 2019, 8:33am UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238/4 "2019-01-08T08:33:01Z")

</div>

Here is an example:

```auto
[
  {
    "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" }
          ]
        }
      }
    }
  }
]

```

---

<div class="post-metadata">

**Author:** ![hydroplatypus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/hydroplatypus/32/4070_2.png) [@hydroplatypus](https://discourse.cataclysmdda.org/u/hydroplatypus)\
**Post date:** [January 8, 2019, 1:45pm UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238/5 "2019-01-08T13:45:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [January 8, 2019, 4:46pm UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238/6 "2019-01-08T16:46:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hydroplatypus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/hydroplatypus/32/4070_2.png) [@hydroplatypus](https://discourse.cataclysmdda.org/u/hydroplatypus)\
**Post date:** [January 8, 2019, 7:03pm UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238/7 "2019-01-08T19:03:04Z")

</div>

> [@Zhilkin](#):
>
> You need to rotate item spawn points…

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?

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [January 8, 2019, 7:12pm UTC](https://discourse.cataclysmdda.org/t/spawning-items-on-rotated-tiles/18238/8 "2019-01-08T19:12:28Z")

</div>

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.
