Code for doing Explosions

Playing FortressCraft Evolved, I played with explosives.  I was not particularly happy with how the explosives were handled – and I was on vacation, and I had no internet access, so my creativity got into my brain and I tried writing code that would handle explosions better.

I shoved the code here:

Here’s the basics of what I did:

  • I did this in 2D instead of 3D because easier to Console.WriteLine()
  • I created a TwoDSpace<T> so I could store an arbitrarily large number of T’s in a 2-D plane
  • I created a function which mapped out, given a center 0,0, what the distances were to each X,Y. 
    • I kept distances as squares, so I didn’t have to do square roots.
    • I did it with an initial max-radius, but the final version in my head would jit-figure out what it needs and save the resulting calculations in a static – it only needs to calculate it once.  Bigger explosion might need to calculate some more.  
  • That function can then call to a lambda, giving it:
    • the X,Y of the point that is being visited by the explosion
    • an array of parent points for the explosion and the ratios by which to weight them
  • The caller then says, “circle visit an explosion starting from here”, and keeps track of the force per X,Y that is being experienced.  The caller is responsible for all the code that says “Ores are hard, but dirt is soft”, for example, or “Diamond cannot be damaged by the explosion”
  • I think its pretty fast. O(r^2), which given its a 2D explosion in 2D, is expected. 

Fun Fun stuff.   I miss the days of mud coding.   You just don’t need to do explosions like these in real-world paid programming.

FortressCraft Evolved: Tier 1 Tour

I am continuing to thoroughly enjoy FortressCraft Evolved, an early-access game on Steam.   Just about every week, I wait in anticipation of the stuff that DJ Arcas is putting into the game.  This last time, it was an auto-excavator to automate creating large vertical shafts and a conveyor belt builder. 

The final vision of the game is something where there is a definite resource-gathering, base-building, automating story, combined with a Tower-Defense game as the local Fauna try to dispatch your base (and you).  

I’ve probably worked on 4 or 5 worlds now.  Every time, I learn of something I could do better, and then I have the desire to start over and be more “perfect”.   68 hours into the game now.  And I only just (last game) got down to Tier 2 technology, and there are three Tiers so far that I could play with.

Here’s a tour of my latest world, with my preferred way (so far) of doing things.  This is at Tier 1 level, probably 3-4 hours into the game.

Central Power Hub and Smelter

  • I’ve ended up putting a coal storage hopper under the Central Power Hub (CPH) (the thing with the laser shooting out of it).  The CPH draws coal from it to burn to create energy.
  • I then put a Pyrothermic Generator (PTG) next to the hopper.
  • Both the PTG and the CPH burn coal to generate energy, and charge up the battery (big block with a sphere in it).  It seems like between the two of them, they can generate energy at about 10 units per second?  (I’m averaging more like 7, but I’m not running it at max capacity yet).
  • This provides enough energy to run the smelter (front picture, “insert more ore”), as well as send enough power down the single laser to the rest of the base (only ore extractors right now).
  • The smelter takes in raw ore from the hopper below, and deposits the smelted bars into the hopper on the right (Front view).  If I need to leave for a while, the hopper on the right gets a conveyor leading to another hopper so I can keep collecting while I’m AFK without the system backing up.
  • A single conveyor belt brings the ores in.   This is enough for 4 types of ore, at the first upgraded level of drill motor (which means it generates 4 ore every N seconds instead of 2).  
    • At first, I though “meh, why build an upgraded drill motor when I can just build a 2nd extractor for cheaper”.  But, when I got to the 4x and 8x drill motors, I understood the wisdom of investing early.

Vertical Access Shaft

The Roof
Looking Down
Looking Up
Important Floor (Looking down, mid-fall)
  • My first worlds were wide more than they were tall.. at first.  What I found when digging down is, you very often hit an ore vein on the way down.  So now, I pretty much try to dig down rather than out, in search of ore. 
  • I rely on the grappling hook (F) to get me back up.  I use two torches on the roof to signify “which way is out” (its easy to get turned around) (See the “Looking Up” picture in more detail)
  • Now that we have falling damage (just this last week!), I have to build in ledges along the way to jump down to.  Note that once I have a battery at a level, I can jump and take the fall damage (energy loss) and then recharge from the battery.   I always put a torch under the ledge.
  • My guess is in the future, the grappling hook fire distance will be decreased and I’ll have to build room for lifts.
  • I line one side of the shaft with power, and the other side with conveyors.  Right now, I’m only at tier 1, so a single laser is enough going down, and a single conveyor is enough coming up.  So far, the most I’ve needed is 3 lasers and 2 conveyors, but I haven’t gotten very far.
  • Any level always has a “lip” around it, for safe landing purposes.

Floor / Level Exit from Shaft


  • I send power down into a battery, and then send it right back down the shaft again in the same vertical line.
  • Note that if ores block the laser’s path, sometimes I manually dig through the ore, or else I’ll shift the shaft to the left or right to accommodate. 
  • At higher power levels, I set up the lasers next to each other, and likewise a receiving bank of batteries.  Because the batteries share with each other, it evens out the power flow at that level.
  • I try to dig my conveyors one deep from the floor so I can walk over them with impunity.   I have to route them to the other side of the vertical shaft to keep them out of the way of the lasers.
  • I started to build lasers so that they were above my height, however, I’ve given up on that now.  Its just easier at ground height.

Coal Generation and PTG’s


  • I’ve found that for up to 5-6 PTG’s, I can have a single extractor generating coal onto a conveyor belt that then leads to the PTG’s. 
  • Long before I get to my 2nd or 3rd PTG, the coal generation has exceeded storage space and there’s plenty of coal for all the PTG’s.
  • It takes about 3 PTG’s to fuel the max capacity of 2 unaltered T1 lasers. (30 vs 32).   Until you build a second smelter, or an autoexcavator, you don’t even approach the halfway point of a single laser.
  • In this case, rather than send power to the coal extractor via laser, I just added a PTG right there.  This was the second vein of coal (having exhausted the 10-coal courtesy seam that the easy level gives you), and it was only 13-15 conveyors away from the base.


That’s all I have time to share at the moment.

I wanted to make an actual log of the first few hours of gameplay – like “what task was I trying to achieve” and how quickly I could achieve it – however, I have run out of time, so that level of documentation will have to wait.  What I can say is that the tasks changed very quickly, every 5-10 minutes.  Besides, this is version 1.14e, which is far from the finished version, so the task list will likely change a lot in the future.

I am still super-excited about this game, and I eagerly await the next drop (bombs!!!??) and the eventual mayhem when mobs become antagonistic.  (I hate camo-spiders already.  They scare the goobers out of me. sneaking like that.  Worse than creepers)

Fortresscraft Evolved

I have been playing a game called “Fortresscraft Evolved”, an early access (developer still working on it) game that my coworker Mike mentioned at lunch the other day.  I really enjoyed Minecraft, so I decided to give it a try.

It has given me an entirely new build order to investigate.   And, there’s a lot of “routing” to think about.   I’m loving it.  (Note, I’m specifically playing survival mode)

There’s a ton of tutorials out there.  I’m not going to do a tutorial.  But I am going to mention a bunch of things that I learned about, to calculate (for myself) an optimal build order.   Granted, “optimal” really means “suited to my liking”, and granted, the furthest I’ve gotten in the game is to automate coal retrieval, but, this is where my thoughts are at.

Here were my most recent questions:

Extractor Priority

You start off with 3 extractors, but there are 4 initial ores to think about – Coal, Tin, Copper, Iron.   Which one to ignore?

At first, this question was complicated by me not knowing about super dig.  (link,  scroll down to “The Extractor”).    Given superdig, where you convert 1 energy for 1 dig (run out of energy fast) for a x% possible resource gain, I can quickly get about 40-50 ores out of a vein with the power that my suit holds.

This means that ore extractors are more for having a “passive” gathering strategy – power dumped in now, yields ores later, that you can go pick up – and in the long term a more efficient one (more ore gets salvaged, less destroyed)

To determine what I want, I choose my end goal:  I want to

  • automate getting coal from the coal vein to the furnace to generate power.  (2 storage hoppers, and 40-50 conveyor belts)
  • put a storage hopper by each extractor (tin, copper, iron = 3 storage hoppers)
  • build an extra extractor so we have an extractor on each vein (1 extractor)

I could also assign a bonus goal of automating delivery of tin, copper, iron to the smelter – I think for that I’d need 200-300 conveyor belts, and +2 storage hoppers (one for holding the ore, one for holding the bars).  I’ll also need a bunch more torches.  And some suit upgrades.   Here’s the spreadsheet I put together:


So, it looks like Coal, Tin and Iron should should get your initial extractors; and then Copper when you build one for it later.    This is all prior to the search for Lithium, which I’ll make a separate spreadsheet for later, if I get that far.

* Note: this list is already out of date.  Watching the author play, turns out that PTG’s are better at power generation than CPH’s, so I should really add a PTG to the above list.

Ore Discovery

Unlike Minecraft, this game has an Ore pinger/scanner.  Problem (for now) is that it either pings (a) Unknown ores, or (b) Known Ores.   Once you discover an ore, to find a second vein of that kind of ore becomes problematical – too many positives.  The solution suggested online was, when searching for a new ore, ONLY research it after you have found a LARGE vein.    Note that you will probably find things in this order:

a) Snow, Rock, Dirt, Leaves, Trees, Stone
b) Coal, Tin, Copper, Rubble
c) Deep Stone  (heh.  Nice one, DJ – pisses me off every time)
d) Iron.

Vertical Navigation / Getting to the Ores

My first attempt, I started building the standard “stairs” down to get to an ore.  It took a while.   I did not know about the grappling hook.  Which might get nerfed in the future.

Second attempt was to build an elevator shaft, but have a ledge at the top, so that I could grapple my way out of the shaft.    I would strategically place lights so that if I’m facing a light, that means it’s the way out.    However, I was being pretty at things, and that took a while.

Third attempt, I used super dig (ctrl-right) and zoom (Z) to my advantage

  • Do not dig straight down unless there was a ceiling above me that I could grapple back up to.  Instead, try to dig at an angle.
  • After locating an sizable vein of an ore, either super-dig, or hold down the dig key, and just dig towards that ore, not being pretty about it.  The idea is to be able to run/fall down to the ore.
  • Build a “wall” at the entrance of the hole to grapple back up to.
  • On subsequent visits to the ore, clean out annoying blocks and add in some lights on the way.
  • Make it pretty when doing conveyor belts.
  • Use a hill as a natural backdrop to grapple back up to.

It also appears that as you are falling, you can still control your fall using WASD.   Watching the main developer DjArcas play on twitch, he builds these large chevron beams (probably using build-to-me Ctrl-Left) that he somehow jumps down onto (without missing).   (If you watch the episode from 10/25/2014, at about 2h:30m or so, he’s building things / starting this world out)

If you are lucky enough to find a large cavern, dude, You’re in luck. 


Ok, enough for this blog post.   I am enjoying the game, its got a nice build order story and some nice layout challenges for laying out conveyors and power and stuff.    Recommend playing, I’ve gotten a good 10 hours of play out of it so far (and I think its $9 or so).