# Creating new types of gaseous clouds

**URL:** <https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910>\
**Category:** The Toolbox\
**Created:** [June 22, 2015, 5:27pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910 "2015-06-22T17:27:58Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 22, 2015, 5:27pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/1 "2015-06-22T17:27:58Z")

</div>

We were thinking about creating a new chemical sprayer type weapon to combat the fungus with sprayable fungicide or other chemicals.

How difficult would it be to implement new gases? I picture the weapon working similar to the flame thrower in that it creates a 3x3 aoe of ‘fungicide gas’ which then spreads like toxic gas or smoke would, albeit not dissipating as fast and only affecting fungus-type enemies and terrain. So it would, for example, remove fungal beds and kill off fungal entities.

I haven’t really coded in the last couple of years and seeing how well the process is documented, I’m actually quite eager to get my hands on contributing. Would this endeavour be too hard for a ‘beginner project’? 😉

Lastly, where would the changes have to be made? Can this be done via JSONs only or would it require a deeper modification of the code?

---

<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:** [June 22, 2015, 8:55pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/2 "2015-06-22T20:55:30Z")

</div>

Pretty simple.

You’d need to declare the gas itself in field.h, then implement it in field.cpp. Somewhere on the top of field.cpp there are definitions of different fields (gases are fields). You’d need to add your gas there. Then add handling for it in the “big switch” around the middle of the file. For handling, you’ll want just the spread\_gas with parameters, like toxic gas has. You can just search for fd\_toxic and copy the code.  
Then in player/monster\_in\_field you’d implement the appropriate effects on creatures.

That’s for gas itself. For the weapon, you have two different ways of handling it: one would be to create a grenade-type item by copying acid bomb code (in iuse.h, iuse.cpp and item\_factory.cpp), the other would be to implement an on-hit effect in damage.cpp.  
Then create a new weapon/grenade that uses the appropriate functions. For grenade, you’d want to copy (and adjust, of course) the acid bomb. For flamethrower, you’d want to copy the flamethrower, gasoline and gasoline ammo type. Set the damage on the thrower and ammo to 0 - all guns are hardcoded to deal piercing damage now.

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 22, 2015, 9:04pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/3 "2015-06-22T21:04:12Z")

</div>

Oh wow, thanks \<3

Can’t wait to try it out, once I find some spare time!

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 23, 2015, 4:23am UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/4 "2015-06-23T04:23:48Z")

</div>

Been fiddling around with this for the last hour and so far I managed to create the gas and make it only damage monsters with the FUNGUS-species. I took the dmg and slowdown calculations from other fields :\>

Now I also want to make the fungal beds and trees go away and replace the tile below with the original one if there is any value for that? Otherwise it would just have to be a random value for dirt or grass (or snow, I guess depending on the season?).

How do I access the terain on the tile? I thought I’d be able to get it via submap getters but I dont even know the corresponding IDs for the fungus infected terrain. Where would I get those?

Have not compiled anything yet.

```auto
	[...]
	fd_hot_air3,
	fd_hot_air4,
	fd_fungicidal_gas,
	num_fields
};
```

```auto
{
	"fd_fungicidal_gas",
	{_("hazy cloud"),_("fungicidal gas"),_("thick fungicidal gas")}, '8', 8,
	{c_white, c_ltgray, c_dkgray}, {true, true, false}, {false, true, true}, MINUTES(30),
	{0,0,0}
}

[...]

case fd_fungicidal_gas:
	dirty_transparency_cache = true;
	spread_gas( cur, p, curtype, 50, 30 );
break;

[...]

case fd_fungicidal_gas:
	// Fungicidal gas makes you cough.
	// Thick fungicidal gas has a chance to poison you.
	{
                bool inhaled = false;
                if( cur->getFieldDensity() == 3 && !inside ) {
                    inhaled = u.add_env_effect("poison", bp_mouth, 5, 30);
		} else if( cur->getFieldDensity() == 2 && !inside ) {
                    inhaled = u.add_env_effect("smoke", bp_mouth, 2, 7);
                } 
                if( inhaled ) {
                    // player does not know how the npc feels, so no message.
                    u.add_msg_if_player(m_bad, _("You feel sick from inhaling the %s"), cur->name().c_str());
                } 
            }
            break;

[...]

case fd_fungicidal_gas:
	if( z.type->in_species("FUNGUS") ) {
		const int density = cur->getFieldDensity();
		z.moves -= rng( 10 * density, 30 * density );
		dam += rng( 10, 15 * density );
	}
```

---

<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:** [June 23, 2015, 4:56am UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/5 "2015-06-23T04:56:01Z")

</div>

[quote=“skYman, post:4, topic:9910”]Now I also want to make the fungal beds and trees go away and replace the tile below with the original one if there is any value for that? Otherwise it would just have to be a random value for dirt or grass (or snow, I guess depending on the season?).

How do I access the terain on the tile? I thought I’d be able to get it via submap getters but I dont even know the corresponding IDs for the fungus infected terrain. Where would I get those?[/quote]

There is no way to get the original terrain - it isn’t really stored anywhere. Just changing it to dirt should be fine in most cases. Don’t set to grass or tree - the fungus kills plant life.

You can see flags being checked in fd\_fire processing code. On the top of the fire processing code, you have terrain and furniture being accessed. Later you’ve got them being checked for FLAMMABLE flag. They are always checked with a helper function, which is declared in the same file.  
In your case you want to check fungal terrain and furniture separately, because one of those can easily be non-fungal while the other one is.

Don’t check for terrain ids until you need exact ids. Check for flags where possible.

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 23, 2015, 5:21am UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/6 "2015-06-23T05:21:17Z")

</div>

Okay I managed to make that work as well, thank you again.

Now where is the behaviour for the flamethrower defined? Ideally I would just copy the item and make it spit fungicidal gas instead of fire or an explosion.

---

<div class="post-metadata">

**Author:** ![vache](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@vache](https://discourse.cataclysmdda.org/u/vache)\
**Post date:** [June 23, 2015, 1:56pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/7 "2015-06-23T13:56:45Z")

</div>

Flamethrower works through ammo effects of the NAPALM ammo type. You need to create a fungicide ammo type and add a process for it to handle it that creates the field. I think the ammo type processing is in ranged.cpp

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 23, 2015, 2:48pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/8 "2015-06-23T14:48:27Z")

</div>

Found the ammo effects in map.cpp

I’m having trouble with the terrain conversion, though. How do I set the terrain/furniture of the current tile? There are getters but no setters as far as I have seen. Also, I found no flag for fungal terrain or furniture so I’d have to compare IDs. Or would it be easier to add a flag?

---

<div class="post-metadata">

**Author:** ![vache](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@vache](https://discourse.cataclysmdda.org/u/vache)\
**Post date:** [June 23, 2015, 3:27pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/9 "2015-06-23T15:27:00Z")

</div>

There’s ter\_set, furn\_set, and just plain set for settings terrain and furniture. Fungal terrain and furniture have the “FUNGUS” tag. It looks like you want damage.cpp for the ammo effect processing, I’m not sure if map.cpp is the right place for it.

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 23, 2015, 3:34pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/10 "2015-06-23T15:34:05Z")

</div>

The way I planned on implementing it, is that the gas doesnt do damage itself. It is more of a utilitarian appraoch so that only the field effects of the spreading gas take effect.

I therefore created a new ammo effect called STREAM\_GAS in map.cpp that creates a certain amount of fungicidal-gas-fields at the target location and gave that effect to a new ammo type called gas\_fungicidal which in turn is used by he new weapon chemical\_thrower.

---

<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:** [June 23, 2015, 4:20pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/11 "2015-06-23T16:20:34Z")

</div>

As I said: for gas explosion, you want to define the tag in damage.cpp

Stream effect should probably be in ranged.cpp, in the Creature::projectile\_attack function.

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 23, 2015, 4:25pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/12 "2015-06-23T16:25:10Z")

</div>

I’m getting an (unrelated?) error when trying to compile with Code::Blocks13.12 using MinGW:

 ![](http://i.imgur.com/MdW66nB.png)

---

<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:** [June 23, 2015, 4:44pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/13 "2015-06-23T16:44:06Z")

</div>

Did you change anything in item.cpp? I don’t think you need to touch that file at all. item\_factory.cpp yes, but not item.cpp

If not, then you must have changed some header included by item.cpp. Probably a badly placed brace or a lack of comma.

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 23, 2015, 4:59pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/14 "2015-06-23T16:59:24Z")

</div>

Nope, didn’t touch item.cpp.

But the GitHub GUI thingy shows me several deletions and additions of the same line in field.cpp. Never touched them, though.

Should I just try and re-fork it and add my changes in again?

---

<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:** [June 23, 2015, 5:24pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/15 "2015-06-23T17:24:05Z")

</div>

It’s probably better to keep going.

You could PR the whole deal with [WiP] in title. That way we could see the code and correct it way more easily.

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 23, 2015, 6:29pm UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/16 "2015-06-23T18:29:42Z")

</div>

Ok I think I managed to create a PR.

> <https://github.com/CleverRaven/Cataclysm-DDA/pull/12765/files>

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 24, 2015, 3:16am UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/17 "2015-06-24T03:16:16Z")

</div>

I’m currently at a dead end. I don’t know enough C++ to decipher the code without breaking my head.

The basic framework for the terrain alteration is in I’d say, unless there is a really smart way how one would go about that 😉

---

<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:** [June 24, 2015, 5:30am UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/18 "2015-06-24T05:30:00Z")

</div>

I find this thread’s lack of fart jokes disturbing.

---

<div class="post-metadata">

**Author:** ![skYman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/skyman/32/465_2.png) [@skYman](https://discourse.cataclysmdda.org/u/skYman)\
**Post date:** [June 24, 2015, 6:12am UTC](https://discourse.cataclysmdda.org/t/creating-new-types-of-gaseous-clouds/9910/19 "2015-06-24T06:12:54Z")

</div>

Now you know how i felt, everytime I came across ‘toxic\_gas’ :\>
