# Make a dimension shift device

**URL:** <https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026>\
**Category:** The Toolbox\
**Created:** [February 24, 2018, 8:31pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026 "2018-02-24T20:31:19Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)\
**Post date:** [February 24, 2018, 8:31pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/1 "2018-02-24T20:31:20Z")

</div>

I recently bought Titanfall II. That game has an ability called phase shift, which I think would be very interesting to have in this game.

What this ability does is that it momentarily teleport you into an identical but player free game world, lets you walk a few paces and then returns you to reality, possibly telefragging a player.

Heres a video of how it looks like [https://www.youtube.com/watch?v=vGcCdXyxF3Y](https://www.youtube.com/watch?v=vGcCdXyxF3Y)

Now no Idea of how its implemened in there, I imagine it simply applies a filter to yor vision and turns your models visibility/hit-detection off.

* * *

Now the real question, how do I implement this in Cataclysm?

Should I grab the current terrain, making a copy of it somewhere not usually accessible (say current z-level +100) and then teleport the player there and back; or would it be better to make the player completely invisible and turn their collision off, even if that means filling the game movement, vehicle and monster detection code with special cases?

I imagine the terrain copying approach is better and wanted to ask were the relevant code for saving/loading the map is?

---

<div class="post-metadata">

**Author:** ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)\
**Post date:** [February 24, 2018, 9:02pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/2 "2018-02-24T21:02:24Z")

</div>

Actually teleporting the player is going to be simpler and more robust, so I’d recommend doing that.  
Also that leaves open things like there being _other_ monsters in the new area…

Probably the code you’re looking for is mapbuffer.cpp, that’s the class that “owns” the map data and is in charge of saving and loading it.

---

<div class="post-metadata">

**Author:** ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)\
**Post date:** [February 24, 2018, 9:20pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/3 "2018-02-24T21:20:53Z")

</div>

Alright, thank you!

Gonna read around there to make sense of it. Probably going to bother you again in a few days, well If i get anything working.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [February 24, 2018, 9:33pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/4 "2018-02-24T21:33:10Z")

</div>

This sounds really hard to be honest.  
If I were doing it the mapbuffer way, I’d expect 6+ hours of hard work with my skills. Unless you can come up with some shortcut that I’m not aware of.

The way I see it, you’d want to change the mapbuffer to remember which “dimension” you’re looking at.  
If the dimension was the “prime” one, you’d let it happen like usual. If it was the “other” one, you’d first look up saved maps from “other” and load those (if they exist), otherwise load (possibly invoking mapgen) “prime” map and then strip it off monsters and items and save this stripped copy as “other” map.  
You’d need to save “other” maps in some different directory from the “prime” ones, so that you can always tell them apart.

---

<div class="post-metadata">

**Author:** ![psyxypher](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/psyxypher/32/11778_2.png) [@psyxypher](https://discourse.cataclysmdda.org/u/psyxypher)\
**Post date:** [February 24, 2018, 9:42pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/5 "2018-02-24T21:42:24Z")

</div>

Holy crap, John, Hi.

My question is why no one seems to have cracked the code of _directed_ teleportation. Seems kinda hazardous to have people teleport completely randomly…

---

<div class="post-metadata">

**Author:** ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)\
**Post date:** [February 24, 2018, 9:50pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/6 "2018-02-24T21:50:30Z")

</div>

I was thinking abut just creating the submaps somewhere up in the sky when the device is triggered and then removing them without saving when the player teleport’s out. Basically like a one time use z-level.

In fasct the place could just be a big open plain of “Subspace matter” ground and maybe randomized features, that would probably be easier to code and serve the gameplay just as well.

But yes I can see how this could be extremely hard to do.

---

<div class="post-metadata">

**Author:** ![darktoes](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@darktoes](https://discourse.cataclysmdda.org/u/darktoes)\
**Post date:** [February 24, 2018, 11:53pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/7 "2018-02-24T23:53:54Z")

</div>

This sounds really cool, but it could be fun to have some danger/cool stuff as well. Maybe this plane occasionally has artifacts in it? Or special monsters? Maybe corrupted copies of items that exist in the real world show up, and these have randomized stats or the evil ability.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [February 25, 2018, 12:08am UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/8 "2018-02-25T00:08:06Z")

</div>

The z-level idea is risky: all z-levels are interconnected and can’t “hang” infinitely high in the sky, so you’d be altering the 10th z-level. Now, 10th z-level is unused (except for very adventurous birds and spores), but it’s still visible from the ground in 3D FoV mode and can be heard on 0 z-level even without it.  
If you dug a hole in 10th z-level and jumped down, you’d splatter on 0 z-level.  
-10th z-level is similar, but in the opposite way. It is also much easier to reach - you can dig down to it.

---

<div class="post-metadata">

**Author:** ![mark](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@mark](https://discourse.cataclysmdda.org/u/mark)\
**Post date:** [February 25, 2018, 5:24am UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/9 "2018-02-25T05:24:04Z")

</div>

If it’s necessary to implement a truly extradimensional z-level to do this, wouldn’t it be also be useful for implementing some flavor of alien dimension to explore, as well as a somewhat complicated short-range teleporter?

---

<div class="post-metadata">

**Author:** ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)\
**Post date:** [February 25, 2018, 7:35am UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/10 "2018-02-25T07:35:57Z")

</div>

Z-level manipulation wouldn’t be particularly stable, but the good news is I think Coolthulu is overestimating how hard it would be to create a new save directory etc. I’m not saying it would be trivial, but it is fairly straightforward.

And yes, this kind of feature would build some groundwork for other extra-dimensional exploration.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [February 25, 2018, 12:20pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/11 "2018-02-25T12:20:30Z")

</div>

> I think Coolthulu is overestimating how hard it would be to create a new save directory etc.

I tried to do it once and found that the game/map/mapbuffer are rather hard to separate. Though I tried to do it “the right way” and not with hacks on globals.  
Still, even the hacks on globals may require a lot of weird special cases. For example, NPCs are on the overmap and not the map.

---

<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:** [February 25, 2018, 1:01pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/12 "2018-02-25T13:01:55Z")

</div>

It should be pretty easy to implement direction teleportation in Lua using `game.choose_adjacent` function.

Activate an item, select one of eight directions and teleport player in that direction a few tiles, destroying or swapping terrain/trap/furniture/monster in the process (or just telefragging monster).

---

<div class="post-metadata">

**Author:** ![John\_Candlebury](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/john_candlebury/32/6437_2.png) [@John\_Candlebury](https://discourse.cataclysmdda.org/u/John_Candlebury)\
**Post date:** [February 25, 2018, 2:59pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/13 "2018-02-25T14:59:53Z")

</div>

Alright thanks for the further suggestions!

---

<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:** [February 25, 2018, 3:27pm UTC](https://discourse.cataclysmdda.org/t/make-a-dimension-shift-device/15026/14 "2018-02-25T15:27:15Z")

</div>

Try this one:

> **[lua\_item\_PDTD.zip](https://www.dropbox.com/s/y5k53uy11y6sq4i/lua_item_PDTD.zip?dl=0)**
>
> Shared with Dropbox
