Showing posts with label StarWright. Show all posts
Showing posts with label StarWright. Show all posts

Tuesday, April 12, 2016

StarWright 0.8.0 - User Interface Revamp

Yesterday I released StarWright 0.8.0. The main focus of this release was to greatly improve the user interface (or "user experience" to use the trendy modern term) for designing and constructing ships. This is the culmination of the U.I. work that started with 0.7.1 (the ship "info card" in the corner) and 0.7.2 (the separate repair and crew management U.I.s), which I will also talk about in this post.

Let's back way up first, and talk about the original U.I. for constructing ships: At the beginning of time (StarWright's lifetime, anyway), designing starships was done using a user interface that was completely separate from the gameplay:


You'd hop into the "Builder" and design your ship on a grid. When you were happy with your design and wanted to test it, you'd press the "Save & Test" button, which would switch you to a testing game environment where you could spawn enemy ships to test your ship's combat prowess against.

And then I watched a talk by Bret Victor in which he persuasively argued that user interfaces are hampered when the user makes a choice but the feedback from the user interface about that choice is delayed. I realized that StarWright (called "ShipBuilder" at the time) suffered from the same delay in that the player didn't see the effects of their design changes until they actually hit the "Save & Test" button. This was unlike most other "construction" games such as SimCity in which you can immediately see how placing a building effects things like power, water, and roads. And so I decided to merge the ship editor and gameplay environment into a new environment that I called the "Sandbox":


In this new environment you could add a part to your ship (like a cannon) and very quickly see how that new part interacts with the simulation of your ship as a whole (crew running over to operate it) and any problems that it has (crew can't get any ammo to it). (I wrote about this change more extensively in a blog post from way back in 2012.)

This was a really big improvement! Being able to watch a ship operate as it was designed really made learning the rules of the ship simulation much more intuitive, and players felt like they were making much more informed (and successful) ship design decisions.

Now let's fast forward again by a few years (I had a job, okay?) to late 2015, as I was beginning to ramp development on StarWright back up to full speed. Up to this point, there was no real challenge or economy in the game; it was just a free-form sandbox mode where you could build whatever you want. And while creative/sandbox modes in these kinds of games are great (yes, I plan on keeping the "Creative Mode" forever and ever), my ultimate vision for the game was that the player would start with a small ship, earn money by going on missions and defeating enemy ships, and expand their own ship over time.

But this caused a couple of conflicts with how ships were built:

  • Adding parts to ships needed to cost money, but the player shouldn't be forced to waste money when they accidentally place a part in the wrong location or if they change their mind halfway through an in-progress design.
  • It needed to be easy and convenient for the player to restore a partially-destroyed ship back to its intended design.
My solution to these two problems was to introduce the "Blueprint" mode, which separated a ship's design (i.e., its blueprints) from its current physical condition:


I talk more about the Blueprint mode in another blog post, but to summarize how it solved these two problems:
  • Players would make modifications to the ship's blueprints instead of the ship itself. The player could freely modify the blueprints without being charged any money. Once the player was satisfied with their design, they pressed the big "MAKE IT SO" button on the right, and -- voila! -- their ship was updated to match their blueprint design and the appropriate amount of money was subtracted from their funds. (If you're thinking, "But Walt, wasn't being able to immediately see the results of design changes a good thing? Why get rid of that?", then my only response to you is, I wish you were there to remind me of that in Nov. 2015!)
  • While a ship could take damage and have parts of it completely destroyed, its blueprints would remain unaffected. If the player wanted to repair their ship back to its intended design, they could just open up the Blueprints mode and click "MAKE IT SO" again.
The first problem I realized that blueprints had was with repairing: While it was definitely A Good Thing that players were able to easily repair their ship back to its original state, I quickly discovered that players (including me) would often do the following:
  1. Fight and defeat an enemy, taking some damage and earning some bounty money.
  2. Open up the Blueprint mode and design some awesome additions for their ship.
  3. Realize they can't afford their new awesome design, and so decide to go earn another bounty.
  4. Want to repair their ship, but realize they can't without undoing all their glorious design work!
  5. Get really angry.
And so I decided to add a "Repair" option. When this option was selected, pressing the "MAKE IT SO" button, instead of making your ship's physical condition match its blueprints, would make your ship match how it was the last time you pressed that button.

And this is how it's worked for the past few months. All problems solved?

Of course not:
  • I realized (again) that players were having a harder time designing their ships because they weren't getting immediate feedback from the game simulation on their design changes. Somehow, in my excitement to make Bounty Mode work, I had forgotten that immediate feedback was A Really Good Thing.
  • The "Repair" option next to the "MAKE IT SO" button was both confusing and limiting. Confusing because it was a very important feature that was buried as an option inside the Blueprint mode user interface despite having, literally, nothing to do with blueprints. And limiting because it was an all-or-nothing choice; there was no option to selectively repair only certain parts of your ship.
And so I embarked on my weeks-long journey to fix these two problems...

First up, I decided to dedicate a separate user interface to repairing ships; a U.I. which would be accessed by its own "Repair" button sitting co-equally right next to the "Build" button.

And so I started to work on-- screeeech, halt! ... Nevermind. Instead, I decided to first implement another U.I. feature that I'd been wanting for a while. Even though that feature wasn't really necessary to solve the above problems, its code would be very intertwined with the code for solving the above problems, and it'd take less time to implement it before solving those problems than after. This feature was the Ship Hub:


The general idea behind the Ship Hub was that it'd be the place on the screen where the player would go to interact with their ship in any way. The dark rectangular card shows a silhouette icon of the ship, it's name, and some other basic information. (And the '...' button exposes some lesser-used options that used to be in the super-awkward alt-right-click menu.) Above the informational card would be all the buttons to access various ship features, such as the ship design U.I. and, eventually, repairs and crew. The Ship Hub was released in version 0.7.1.

With the Ship Hub completed and out-of-the-way, I did, finally, implement the new repairing U.I.:


The "Repair Mode" is accessed by clicking the green wrench icon next to the Build button.

The cool thing about Repair Mode is that it shows you exactly which parts are damaged or destroyed with a red wrench icon for damaged parts or a red overlay for missing destroyed parts. Clicking on a damaged or missing part will repair that specific part. Or you can simply click the big "REPAIR ALL" button to fix everything at once!

I'm pretty happy with this new Repair Mode user interface. It's much more easily accessed and prominently displayed, and it is also much more flexible since you can, optionally, pick individual parts to be repaired. Repair Mode was released in version 0.7.2.

Also released in 0.7.2 was a little U.I. for managing your ship's crew:


This shows you your current number of crew relative to the number of crew your ship can carry. And it has three buttons for adjusting the number of crew: The first button adds one crew, the second button fills your ship up to its maximum crew capacity (or as many crew as you can afford to hire), and the third button fires one crew. That's it!

This also wasn't strictly necessary for solving those two big problems, but it was easy to implement and is nice to have. Eventually I plan on having individual crew members with different ranks and abilities, and this user interface will be fleshed out to manage them.

0.7.3 and 0.7.4 were interim bugfix released that I put out while I was working on revamping the user interface for designing ships.

With repairing ships handled via a completely separate interface, I realized that the only major design impediment to letting the player directly add and remove parts from their ship was the risk of them wasting money by making accidental mistakes or backtracking on their design. And then I realized that the only reason this was actually a problem was that removing a part didn't refund the full cost of adding that part in the first place (it refunded 75%). And so I made the decision to refund the player the full original cost when removing a part, and now the player can undo any design change they make without having wasted any money. (I had originally added the 25% "deconstruction" tax as a way to incentivize picking a design and sticking with it, but I think being able to directly modify your ship and freely experiment is worth getting rid of the tax.)

And so with that last design hurdle out-of-the-way, I split ship designing into two separate modes: Direct Edit mode and Blueprint mode...

Blueprint mode
Blueprint mode isn't much changed from how it worked these past few months: You can freely make modifications to your ship's blueprints without regard for cost, and then when you're happy with them, you press the "MAKE IT SO" button. In fact, Blueprint mode has gotten even better, because now it will let you temporarily place blueprints in illegal locations as you plan things out, so long as you fix any problems before clicking "MAKE IT SO".

Direct Edit mode
Direct Edit mode on the other hand is brand new. In this mode you directly add and remove parts to and from your ship, being charged or refunded as you go. (And behind-the-scenes, the blueprints will be kept up-to-date with your changes as well.) It's somewhat more restrictive than Blueprint mode in that you can't make any change that would put your ship into an illegal configuration. But on the flip side, you can see the immediate effects or problems of any changes you make, such as whether crew can access a room or whether a laser cannon has power.

Both modes are accessed by clicking the "Build" button in the lower-left above the ship information card. The Direct Edit mode will be shown by default (although if you prefer Blueprint mode, you can make it the default in the settings), and you can then switch to Blueprint mode by clicking the blue blueprints button that expands out from the build button.

There are some restrictions to when you can use Direct Edit mode that don't apply to Blueprint mode. In particular, you can't use Direct Edit mode during combat or while in debt. In addition, if your ship has any destroyed parts, those parts must be repaired before entering Direct Edit. And if you've made any modifications in blueprint mode, those modifications must be either committed or discarded before returning to Direct Edit mode. (If you open the ship designer and Direct Edit mode is unavailable for any reason, Blueprint mode will be shown instead.) These restrictions are necessary to make sure that you can't make any changes in Direct Edit mode that would break either the Blueprint or Repair modes.

I also took the opportunity to improve the design experience of both Direct Edit and Blueprint modes in some nice ways:
  • While in either Direct Edit or Blueprint modes, the background is dimmed and a build grid is displayed underneath your ship. This should make it easier to eyeball distances and also make it more obvious when you're in design mode instead of being able to control your ship.
  • The cost (or refund) of making any changes to your ship is shown underneath the mouse cursor.
  • The logic that determines where to automatically add doors between parts has been greatly improved, especially when the "Overwrite Existing Parts" option is turned on (as it is now by default). It will no longer remove any doors that didn't actually need to be removed, and it's much smarter and more aggressive about adding doors as new parts are placed. This is the kind of improvement that, if it works well, you won't notice it at all!
  • Adding a Crew's Quarters or Crew's Bunk in Direct Edit mode will, by default, automatically hire crew to go along with it.
  • And lots of other little improvements that you can read about in the version history.
As always, thanks for playing! And please post whatever feedback you have!

Sunday, March 20, 2016

StarWright 0.7.0 - Ion Beams!

Today I released StarWright 0.7.0!

This latest major release adds the 'Ion Beam Emitter' weapon:



The Ion Beam shoots an extremely powerful (and power-hungry) beam of ion energy that will quickly rip holes in enemy ships. It is currently the most powerful weapon in the game in terms of how much damage it can do every second, and it's particularly effective at sawing ships into pieces.

But as powerful as the Ion Beam is, it does have some key weaknesses:

  1. Unlike the other weapons currently in the game, the Ion Beam Emitter is so heavy that it can't be mounted on a turret and thus must be fixed directly to the ship's hull. This means that the ion beam can only shoot in a straight line (as determined by which way the ship is facing), and thus is very difficult to aim with any precision.
  2. Firing the ion beam uses a lot of power very fast. If you want to keep the ion beam active for more than a few seconds, you'll need a lot of power being constantly delivered to it.
  3. Unlike the other weapons, the Ion Beam Emitter is very weakly armored, making it a potential Achilles' heel through which enemy fire can reach the inside of your ship.
  4. While the Ion Beam Emitter is only two spaces wide, it is four spaces deep, three of which cannot be traveled by crew. This may force you to re-think your ship's layout and cause issues with ammo and power delivery to other systems.
Please feel free to download the game and post your feedback!

Tuesday, February 23, 2016

StarWright 0.5.0 - Sounds!

I'm a bit ashamed to say this, but until today no version of StarWright has ever had even a single sound effect. Well it took me a lot longer than I anticipated, but sounds are finally here! (Or should I say hear?) I just released StarWright 0.5.0 which you can download, play, and hear right now!

I had told myself for the longest time that sounds were a lower priority than getting in core gameplay features. I guess that might be true to an extent, but now that I'm playing the game with sounds, I'm really regretting not adding audio months ago, because the game feels much better with sound effects. (And also some accompanying screen-shake effects, which really help to give the sounds some added punch.)

Sound Design


Sounds in StarWright can be grouped broadly into two categories: User interface sounds and gameplay sounds. User interface sounds are easy because they never vary in volume or pitch and always get played whenever the user interacts with the interface. Gameplay sounds on the other hand are much trickier to design and implement because whether they're played, their volume, and sometimes even their pitch depend on what's happening in the gameplay.

Designing gameplay sounds for any game is hard, but StarWright has proven to be by far the hardest sound design challenge I've yet tackled. There are two primary reasons for this challenge:

First, unlike most games where the area that the player can see is relatively constant, in StarWright the scale of the player's view can change dramatically as the player zooms in and out; the player's view can scale from a dozen meters across to a kilometer across or more in a second. What the player hears when zoomed in at 10 meters (the loading of ammo and beeps of controls and charging of lasers) is not what the player should hear at 100 meters (the muted, distant reverb of cannons and thrusters) nor what the player should hear at 1000 meters (the almost-empty yet strangely-beautiful resonance of space).

Many of the more-detailed gameplay sounds (such as beeping controls, loading ammo, and charging weapons) are only audible when zoomed-in near the 10-meter scale; they quickly fade out as the player zooms away. But the louder sounds (such as firing cannons, projectile impacts, and explosions) can be hard at the 100-meter scale as well. However, I wanted these louder sounds to sound more muted and distant when the player is zoomed out, and so each of these sounds is actually authored as two separate sounds; one containing higher-frequency elements that fade out quickly as the player zooms out, and one containing lower-frequency elements that fade out much more slowly. Eventually though, near the 1000-meter scale, no gameplay sounds are audible and the only sound left is the eerie sound of space itself. (Yes, I know space IRL has no sound, but in StarWright it does!)

Sounds don't just fade out as the player zooms out; they also fade out as their point-of-origin moves farther away from the center of the player's view. This works like most games in that more distant sounds are quieter (an enemy shooting you from ten meters away is a lot louder than one shooting at you from a hundred), with the added wrinkle that the distance that a sound can travel increases as the player zooms out the camera. This may seem unnatural, but if the distance didn't scale then the player would either (when zoomed in) be able to hear loudly a lot of sounds from objects they can't see or (when zoomed out) not hear sounds from objects that they can see.

The effect of fading sounds as the player zooms out while simultaneously increasing their audible distance leads to a nice "level of detail" -- that is, when zoomed in, the player hears a relatively small number of higher-pitched, high-details sounds; whereas when zoomed out, the player hears a large number of more muted, less-detailed sounds.

The other big challenge to designing sounds for StarWright is the sheer number of objects that can make sounds. While a typical side-scroller or action game might have a few dozen sound-emitting objects (on screen or near the player) at once, StarWright can have hundreds or even thousands since every weapon, thruster, projectile, explosion, and crew member could be making a sound. And the problem with so many sounds at once (aside from being computationally expensive) is that when they all combine together, too many sounds will start to be like gray noise and the individual details will get lost in the chaos; that's neither pleasant to listen to nor useful information for the player.

My solution is conceptually simple enough: limit the number of gameplay sounds of any single type that can be played at once; the theory being that there should be enough simultaneous sounds that the player won't notice when some don't play while also not having so many sounds that they just create unrecognizable noise.

Gameplay sounds in StarWright can be subdivided into two general groups: One-shot sounds and continuous sounds. One-shot sounds are those that are tied to a particular event happening in the game (such as a cannon firing or a battery being delivered) and are over within a few seconds. Continuous sounds loop indefinitely for as long as some state is true (such as while the control room is powered). The ways in which each of these two groups of sounds is limited differs significantly:

For one-shot sounds, there is a simple limit to the number of sounds of any particular type (such as the sound of the regular cannon firing) that can be played simultaneously. (Usually around 3-5 simultaneous sounds, which seems to be about the point at which players will stop noticing when some don't play.) When a one-shot sound is about to be played, the game checks how many other sounds of the same type are playing, and if the maximum number is already reached, it simply doesn't play the sound.

Continuous sounds are a bit more complicated. Any particular type of continuous sound is typically limited to only 1 playing at once. But unlike one-shot sounds, once the limit is reached, any additional continuous sounds will increase the volume of the currently-playing sound. For example, two thruster rumble sounds playing at 0.5 volume will get combined into one thruster rumble sound playing at 1.0 volume.

Sound Implementation


One of the biggest reasons that it took me so long to release 0.5.0 is that I almost completely rewrote my audio-playing code.

StarWright is based on the same codebase that I originally created for my game Tanky-Tank almost a decade ago. At the time, the best API for playing sounds on Windows was DirectSound. However, in the many years since, DirectSound has been obsoleted by the much-more-modern and well-maintained XAudio2 (and on newer systems, DirectSound is actually emulated on top of XAudio2).

When I started working on sounds for StarWright, I started with my old DirectSound-based code, but I quickly ran into some nasty race conditions that would cause crashes in the above-discussed sound-limiting code. These race conditions were going to be very difficult if not impossible to work around, and so I chose to spend a few days rewriting all of my audio code to use XAudio2 instead of DirectSound.

This rewrite went relatively smoothly, except that I found a few bugs in SharpDX, the C#-language DirectX wrapper I use. I spent at least a day tracking down and then fixing those bugs in SharpDX. (But on the bright side, I had my first-ever GitHub pull request accepted to fix those bugs!)

Screen Shake!


The greatest lesson I've learned in my years as a game developer is that every game is made better by adding screen shake!

While this may be a bit of an exaggeration, it's true enough for StarWright.

You may notice while playing that a lot of explosions and firing sounds are accompanied by a subtle (or not-so-subtle) screen shake effect. They started as kind of a silly experiment but they really added a great sense of weight and power to the louder, more explosion-y sounds. When you get hit by a Large Cannon, it feels quite impactful, and a lot of that has to do with the accompanying screen shake.

Screen shakes work a lot like sounds in the sense that they get weaker as the player zooms out or as the origin gets farther from the center of the screen. (And yes, that distance-to-center is scaled by the zoom, just like sounds.) But unlike sounds, there is only one type of screen shake, and so the magnitudes of all the currently-in-effect screen shakes get added together to determine the final amount by which the screen is actually shaking.

Saturday, January 16, 2016

StarWright 0.4.0 - Laser Blasters!

Today I released version 0.4.0 of StarWright. The big feature of this release is a new weapon: the Small Laser Blaster!

The Small Laser Blaster is an energy weapon that fires pulses of raw energy. Unlike the cannons, the laser blaster draws its power from plasma batteries instead of using ammo that has to be manufactured elsewhere. Compared to the cannons, the laser blaster deals less damage but has a higher rate of fire and is considerably more accurate. Its rounds also cannot penetrate inside enemy ships, unlike the cannons, making it more effective at destroying perimeter systems than interior systems.


Related to the addition of laser blasters, the player now starts with a new class of ship, which I dubbed the Model-1. The Model-1 is a bit smaller than the previous starting-ship, and instead of having two Regular Cannons it has two Small Laser Blasters. I made this change to reduce the number of game mechanics that the player has to learn and understand at the beginning of the game; laser blasters use no ammo, and so the player only has to understand the power mechanic instead of both the power and ammo mechanics. Also, because laser blasters are more accurate than the cannons, new players will be frustrated less by missed shots.


I have also made some major balance & pacing adjustments in this release. First of all, the damage dealt by all weapons has been greatly increased (cannons do more than twice as much damage); a change I made to increase the pace of combat, which I felt was feeling sluggish. Also, the thrusters and the Ammo Factory both use power much more rapidly, which, combined with the power-consuming new laser blasters, makes balancing power usage and providing sufficient reactors & power supplies much more important.

Go ahead and download it now! I welcome all of your feedback!

Monday, January 11, 2016

StarWright 0.3.0 - New Art!

Which much relief, I've finally released version 0.3.0 of StarWright! (Which you can download here.) This release contains a handful of balance changes and, much more exciting, completely revamped art for the ship interiors.

The new art is much more detailed and attractive than the old "art" (which was really just quick "programmer art" sketches). Most of it is even animated! While I don't consider this art to be "final" and I intend to eventually have it replaced by a professional artist, I think it's good enough for (what is currently) a free game. Even so, I welcome your feedback on it if you have any!

Here's a (rather rough) gameplay video featuring the new art:


And a handful of screenshots as well:





Sunday, December 6, 2015

StarWright 0.2.0 series

Since I last posted, I have released not one, not two, but nine new builds of StarWright!

Most of these updates have been to fix bugs that people have found. (Indeed, the game is feeling *much* more stable than 0.1.0 did; there are, literally, no known bugs right now.)

One of those nine new builds was 0.2.0, which includes not just bug fixes but also a handful of other improvements. Here's a summary of the juiciest bits:

  • When a part is destroyed, it no longer spawns one structure piece occupying the entire area of the destroyed part. It now spawns one structure piece per tile, each of which can be destroyed individually. This looks better than stretching the structure graphic over the entire area of the original part, and it feels less weird as well. It also paves the way for some future features I want to add that relate to being able to watch a ship build to your specifications rather than it updating instantly.
  • Probably the biggest usability issue of the previous versions was that, in order to target a specific part of an enemy ship, you had to hold the alt key while right-clicking on the part you wanted to target. This was not intuitive, and the only way you could figure it out was either accidentally or reading the online bullet points that substitute for not having a manual. So now you no longer have to hold the 'alt' key to target a specific part. Simply right-click to target an enemy ship, and then right-click again on a specific part to target that part.
  • In order to destroy an enemy ship in the regular Bounty mode, you now only have to destroy its Reactor instead of both the Reactor and Control Room. I think that it was confusing having to destroy both, and players have told me that they find the reactor a more naturally explosive target. Plus, only having to destroy the reactor makes taking out the control room first a more interesting decision.

There's tons more changes and fixes, almost all of which I list in the patch notes.

I'll leave you with this screenshot of one of my favorite ships I've made:


Tuesday, November 24, 2015

StarWright 0.1.0 - Bounties & Blueprints!

At long last (more than a year and a half!) I finally have a brand-new version of StarWright available for you to download and (hopefully!) enjoy, and it's a doozy of an update: StarWright 0.1.0. I consider this the first "non-prototype" version of the game, since it now has some amount of actual challenge and progression.

The changelog lists most of the improvements since the last prototype version, but I'll outline here the biggest new features...

The first big feature is what I call Bounty Mode. Just start up the game and hit the New Game button. You'll start the game with a small ship just like this one:


You start the game with 5000 credits, which if you want you can immediately use to make some upgrades to your ship, though you won't be able to afford much more than a cannon and another couple crew.

In order to earn more credits, you'll need to fight and defeat enemy ships. They're listed under the BOUNTIES in the top-right along with the reward for defeating each ship, and there will also be an arrow pointing in the direction of any enemy ship off-screen. Many of the bounties you may see will be too difficult to defeat without upgrading your ship first.

Once you defeat an enemy ship (specifically, by destroying its Control Room and Reactor), you'll earn a substantial credit reward, which you should use to repair any damage to your ship and, if you have any credits left over, make further improvements to your ship such as adding more cannons, thrusters, and crew.

In order to make upgrades to your ship (or even repair it), you'll utilize the other big feature: Blueprints. Click on the "Blueprints" button in the bottom-left corner, and you'll be presented with a U.I. that looks something like this:


(This screenshot is from much later in the game after the playing has already upgraded their ship many times.)

When this U.I. is displayed, you're not actually modifying your ship itself; you're modifying its blueprints. The cool thing about blueprints is that you can edit and tweak them as much as you want at no cost, only paying the required credits once you're actually happy with your design and want to commit to it. And the other cool thing about blueprints is that, if your ship takes damage and has parts of it destroyed, the blueprints are unaffected, making it easy to restore your ship to its intended design.

When you're satisfied with your design and want to commit to it, simply press the MAKE IT SO button in the bottom right. As long as you have enough credits, your ship will be updated to match the blueprints, and the required funds will be deducted from your account.

Once you've upgraded your ship, you can fly off and attempt to defeat one of the enemy bounties:


Simply right-click on the enemy ship to attack it. Hold the alt key and right-click on a specific part of an enemy ship to concentrate fire on that specific part. (I recommend usually taking out the weapons and ammo supplies first, unless its Control Room or Reactor is especially vulnerable.)

The enemy ships will try their best to shoot you from their best side and will occasionally maneuver to hit you from another position. If you disarm them, then they'll try to run away, so you may want to consider taking out their engines or Control Room to prevent that.

And lastly, we have to say a sad goodbye to an old feature that I have decided to remove to make developing the rest of the game easier.... Goodbye, multiplayer. :(  I removed multiplayer because its presence was making the game's code far more complicated than it otherwise would be and was greatly slowing down the development of the primary singleplayer mode of play. It's possible that some sort of multiplayer "my ship versus your ship" mode will return in the future, but for now I've decided to remove multiplayer from StarWright.

Please feel free to download the game. I welcome all of your feedback!

Friday, April 18, 2014

Procedurally Generated Starships in StarWright

I've been working on the main singleplayer (& co-op) "explorable universe" mode for StarWright. This mode is still a ways off, but in the meantime I'd like to share something with you that I think is pretty neat: the "random starship generator" that the singleplayer mode will use to generate an unlimited variety of enemy starships for you to fight. (You can play with these procedurally-generated starships in the "sandbox" mode of the latest version of StarWright.)

Here's a screenshot of just one of the practically-unlimited number of starships that the game can generate:


This is a fully-functional and heavily-armed starship, complete with thrusters, weapons, a cockpit, a reactor, ammo storage, power storage, and crew's quarters.

On the left you can see (click on the screenshot to get a bigger view) a user interface that gives a great amount of power and control over the underlying algorithm that generates the starships. I've included it in these screenshots to help you understand the underlying algorithm.

At a high level, the algorithm works by creating a starship in "stages", which you can see listed on the left with names like "Shape", "Fill Gaps", and "Cockpit". The algorithm starts at the top of the list and processes each stage in sequence. Each stage adds to what was generated by the previous stages, except for of course the first stage which starts from scratch.

Let's walk through each stage in sequence so we can see how the ship gets created stage-by-stage:

Stage 1: "Shape"


In the above screenshot, I've turned off all of the stages except for the very first: the "Shape" stage. On the right you see what the ship looks like (in this case a rough outline of a ship composed entirely of empty "corridor" tiles), and on the left you can see that I've expanded the user interface for this "Shape" stage to give a better view of the inner-workings of this stage.

The sole purpose of this stage is to give a rough outline to the general shape of the ship. Most subsequent stages will obey the shape given by this stage and only place additional parts ("part" being my technical term for discrete rooms, systems, and corridor/armor tiles) within this outline.

The "Shape" stage is actually unlike all the later stages in that it itself is comprised of some number of "shape modules". You can almost think of a shape module as a "brush" from a paint program such as Photoshop in that it defines a "shape" of 1x1 corridor tiles to add to the ship. The two shape modules you can see here are "CircleModule" (which places a blocky circle-like shape of tiles) and "RectangleModule" (which places a rectangular area of tiles).

The "Shape" stage adds somewhere between "MinModules" and "MaxModules" number of random modules (in this case it's always 8 modules), where the chance of any given module being added is determined by its "RandomWeight". Once the modules are chosen, the stage then joins them together in a random configuration and "paints" the resulting shape as corridor tiles.

Stage 2: "Fill Gaps"



Notice that the result of the first stage left some small gaps and rough edges in the ship. The purpose of this second stage is to fill in those gaps and "even out" the rough edges to give the ship a more solid appearance. While the desire to have ships appear more solid is largely an aesthetic preference (it's perfectly legal to have a ship with holes in it), it does make it easier for the later stages to place new rooms and systems inside the ship. For other styles of ships I may choose to leave out this stage entirely, or even replace it with a stage that carves away bits of the ship in order to make it appear more "stick-like".

The actual logic behind this stage is pretty simple: It simply looks at each empty tile, checks to see if it's surrounded on 2 or more sides by tiles no more than "ScanRange" units away, and if so, fills that empty tile in with another corridor tile. Then it repeats itself (up to "Iterations" number of times) to fill in any more tiles that are newly-eligible to be filled.

Stages 3 & 4: "Cockpit" and "Reactor"



The two most important rooms/systems on any starship are the cockpit and the reactor, so we add those before we add any others. While both the cockpit and the reactor have their own stages, the actual logic of the stages are very similar, so I'll talk about them both at once.

Each of these stages works by iterating through every possible location for the cockpit or reactor and picking the single "best" location for it.

The only difference between the Cockpit and the Reactor stages are in how they define "best". You can see in the user interface that each stage defines a "PlacementStrategy" that is used to determine the best location.

The cockpit uses a "Protected" placement strategy, which simply means that the "best" location for the cockpit is the one that is farthest from the perimeter of the ship. This makes sense since the actual location of the cockpit doesn't affect how well the ship functions, and so we just want to place it in the most difficult-to-destroy location possible.

The reactor uses a "Centralized" placement strategy, which simply means that the reactor will be placed as close to the ship's center of mass as possible. This makes sense since the reactor is most effective when it's in a relatively central and accessible location.

As you can see here, the "best" locations for the cockpit and reactor are often very close or even overlapping. In that case, the cockpit's location preference gets priority simply by virtue of being before the reactor in the list of stages. This explains why the reactor in the above screenshot is somewhat offset from the ship's actual center of mass -- the reactor couldn't be placed in the ideal location because the cockpit was already there, and so it picked the next-best location.

Stages 5 & 6: "Cockpit Armor" and "Reactor Armor":



Since the cockpit and reactor are so important, its usually a good idea to surround them with added protection in the form of armor tiles. These two stages do just that by each finding a part of a specific type and then surrounding that part with one or more layers of armor tiles.

But as you can see in the above screenshot, these stages will usually leave gaps and paths around the parts that they are protecting so that access by the crew to any room or section of the ship isn't cut off. The logic that handles this is crucial to how this and almost every other stage works, so let's talk about...

Path Contiguity Checking

Before any stage picks a location for a new part, it first does what I call a "path contiguity check", which essentially asks the question, "If I place a part here, will I be forcing crew to go too far out of their way to get around me?"

To perform this check, the stage picks any open tile adjacent to the proposed location, and does a quick Dijkstra search to each of the other adjacent tiles. As long as the search finds a path to each other tile no longer than, for example, 5 tiles, then the path contiguity check it considered a success and the part is allowed to be placed there. But if the path fails, then adding a new part to that location would either force the crew to go too far out of their way or would cut off a path entirely, and so the stage will exclude that possible location when deciding where a new part should go.

We can see the practical implications of this check in the above screenshot for stages 5 & 6. Look at, for example, the gap in the armor directly underneath the cockpit where the cockpit's door is located. The "Cockpit Armor" stage didn't place an armor tile there because doing so would have cut off access from the surrounding corridor tiles to the cockpit itself. And the corridor running between the cockpit and the reactor exists because adding an armor tile there would have forced crew to walk all the way around both the cockpit and the reactor to get to the other side.

Stage 7: "Thrusters"



After the Cockpit and Reactor are placed, along with their surrounding armor, the thrusters are placed. There are three sizes of thrusters (small, medium, and big), and this stage is responsible for placing all three.

If you take a look at the U.I. for this stage above, you can see that each size of thruster has a different "score" (1 for small, 2 for medium, and 4 for large), and the stage as a whole can place between 35-45 points worth of thrusters. In addition each size of thruster has a different random "weight", meaning that about 1/6 of the thrusters will be small, 2/6 will be medium, and 3/6 will be large.

The directions of the thrusters are also weighted randomly, so that 5/8 are placed pointing backwards and 1/8 are pointing in each of the other three directions.

Aside from those random weights, there is currently no additional logic (besides randomness) to determine where the thrusters are placed. Even so, randomly-generated ships usually have reasonably well-balanced thruster placements simply by virtue of random probabilities.

Stage 8: "Weapons"



The placement of weapons works almost identically to the placement of thrusters, but with different sizes, scores, and random distributions. (In this case, there are only two sizes of weapons, and their rotations are distributed more evenly around the ship while still favoring weapons that face forward.)

The one algorithmic difference between thrusters and weapons is that, when choosing a location for a weapon, the algorithm will choose the location that is farthest away from the center of the ship in the direction that the weapon is facing.

Stage 9: "Exterior Armor"


Once all the exterior systems (weapons and armor) are placed, a single layer of armor is placed around the perimeter of the ship on any tiles that are already occupied by a weapon or thruster, so long as placing an armor tile there will not block and crew paths according to the above "Path Contiguity Checking" algorithm.

Stages 10 & 11: "Ammo Supplies" and "Power Storage"


Next, Ammo Supply and Power Storage parts are placed. In this case, between 2-3 ammo supplies and 1-2 power supplies are added to the ship.

The algorithm that places these parts attempts to place them in locations that are nearby as many ammo-consuming or power-consuming parts as possible. In the case of ammo supplies, the algorithm will attempt to place them near as many weapons as possible, so long as those weapons aren't already near other ammo supplies. And in the case of power supplies, it places them near thrusters and ammo supplies (which use power to create ammo), so long as those thrusters and ammo supplies aren't near other power supplies or the reactor.

Stage 12: "Crew"


Finally, crew's quarters and bunk rooms are placed in the remaining empty areas. Their placement is completely random, except that the algorithm tries to line up the edges of the rooms if possible, which tends to cause crew's quarters and bunks to be placed adjacent to each other.

Stage 13: "Fill With Armor"


Once all of the crucial rooms and systems have been placed, the almost-final step is to fill any remaining space with armor tiles, because having armor throughout a ship makes it generally harder to destroy.

In order accomplish this, every single empty tile is scanned using the above "Path Contiguity Checking" algorithm to determine whether placing armor there will block any crew paths. If no crew paths will be blocked, then an armor tile is placed.

The neat side-effect of placing armor in this way is that corridors, like the ones you see above, are naturally "created" as a simple by-product not placing armor in locations that would block crew paths!

Stage 14: "Add Extra Doors"


The one final-final step is to place any extra doors in locations that would make crew access significantly more convenient. This is accomplished by scanning every wall location where a door could be placed (but isn't already there) and doing a path search from one side of the wall to the other. If the resulting path is over a certain distance (in this case 10 tiles), then a door is placed to make the path shorter.

In the above screenshot, I can only spot one additional door that was added -- in this case, on the right side of the medium-sized thruster on the bottom of the ship.

Sunday, September 1, 2013

StarWright build 2013.09.01

No major new StarWright news, other than that I have just posted a new build of the game that shows off the starship designer, ship combat, and multiplayer!

Download it from here: http://starwright.waltdestler.com/

Sunday, June 16, 2013

StarWright - Power

Over the past couple of weeks I implemented one of the last remaining starship simulation mechanics that I had planned to create. This mechanic has to do with providing power to all the various ship systems.

The power mechanic works very similarly to the existing ammo mechanic. If you don't recall, the purpose of the ammo mechanic is to require the player to carefully balance weapons (which consume ammo) with ammo supplies. The closer the ammo supply is to a weapon, the faster the ammo can be delivered, and the faster the weapon can shoot, so the player has to think carefully about where they place weapons and ammo supplies relative to each other. While I've found that this mechanic is successful in giving greater depth to the design of small, localized areas of ships, it adds little depth to the overall design of larger ships since ammo rarely needs to be transported more than short distances.

The power mechanic is intended to complement the ammo mechanic by providing greater depth to the overall design of larger ships. Power works similarly to ammo in that many ship systems (currently thrusters, ammo supplies, and the cockpit) require power to operate. And just like ammo, power "batteries" (for lack of a better word) must be hand-delivered by the ship's crew to the systems that need power. But power is different from ammo in the distance that batteries travel, the rate at which batteries are consumed, and the cost of creating batteries. Ammo is consumed very quickly during combat, but ammo typically travels only short distances, since ammo supplies are cheap enough that any well-designed ship will have one for every few weapons. Producing batteries, on the other hand, is extremely expensive due to the very high dollar cost of the "reactor core", a new ship part that produces batteries. The reactor core is so expensive that most any medium-size ship will only have one. Thankfully, power-consuming systems need fresh batteries fairly infrequently, so the potentially longer distances between the power core and power-consuming systems is not as big a deal as it would be for ammo. However, the distance that power has to travel is still a major consideration when designing a ship, so choosing a relatively central and protected location for the reactor core and keeping traffic congestion low is very important.

Here's a screenshot showing a power core and glowing batteries being carried to some nearby systems:


As I mentioned above, the ammo supply now requires power to operate. You can see the new redesigned ammo supply and thruster artwork in the above screenshot, which clearly shows how many batteries the thrusters and ammo supplies have remaining. Since producing ammo now requires power, power is now the most important resource on any ship. Without it all your systems will eventually become non-functional.

Reactor cores are very expensive, but they can produce an unlimited amount of power. Sometimes when designing a ship, you may find it beneficial to have a closer source of batteries, but you don't want the huge added expensive of another reactor core. The compromise solution is a "battery storage" which can be seen in this screenshot:


A battery storage room does not itself produce batteries, but it can store up to 15 batteries in case of an urgent spike in local demand for power. When all 15 batteries are used up, then any additional batteries must come directly from the reactor core, or the battery storage must be re-filled from the reactor.

If you think it's weird that power must be carried by hand instead of over wires, then I admit you're right. This is a design decision where I have deliberately compromised realism for the sake of deeper ship design and a more transparent simulation. The ship design is deeper because batteries make large-scale ship design decisions and corridor layouts more meaningful. And the simulation is more transparent and understandable because, rather than having some abstracted representation or numbers for power levels, you can actually see how power travels throughout the ship as it is being carried around by the crew.

Saturday, May 11, 2013

StarWright - Doors, Doors, Doors

Recently I finished an artistic revamp to StarWright's visuals. One of the most important improvements is the addition of a separate layer of walls that is rendered above the crew on the ship. This gave the feeling of actually viewing a cross-sectional floor plan of the ship, which was sorely missing in earlier versions. But the one big oddity with that revamp was that the crew could still walk between the walls, which was definitely weird.

Now, finally, ships in StarWright have walls that crew can't move through, and of course by necessity, doors in the walls!


The player may place those white double-sliding doors in any legal wall locations (some are blocked). Once a wall has a door in it, crew may freely move through the wall. As in a lot of space fiction (Star Trek in particular), when a crew member walks up to a door, the door will automatically slide open to let them through.

From a technical standpoint, implementing doors and walls was much trickier than you might initially suspect, for a handful of reasons:

  • The pathfinding system was previously unaware of the presence of walls between rooms, and making it "wall-aware" required a significant retrofit.
  • The pathfinding system previously assumed that the entire ship was contiguous -- that is, it assumed that it was possible to get from any location of the ship to any other location of the ship. Additional fixes were required to remove this assumption.
  • I didn't want to have to update every wall sprite with every possible door location, because that would have added many times as many wall sprites. Instead, I had to devise a way for the doors to "replace" the particular section of wall that they occupy, but no other parts of the wall. To do this, I render a rectangle representing the door sprites to a special off-screen "stencil" buffer. Then when I render the walls themselves, ever pixel of the wall gets checked against that stencil buffer to make sure there's no door at that pixel.
  • Every door sprite has animations to open and close as crew walk through. Unfortunately, doing potentially hundreds of simultaneous sprite animations on the CPU can be slow, so instead I devised a special vertex shader to handle the sprite animation on the GPU. When an animation is triggered, such as the door is opened or closed, the CPU sends the vertex shader the information it needs to render the door animation, and then the CPU never has to worry about the animation again until a new animation is triggered.

Saturday, May 4, 2013

StarWright Logo

I made a logo for StarWright using the in-game ship editor, mostly just to show off how flexible the ship editor is.


Tuesday, April 23, 2013

StarWright - Better Art

I've been working for a while to revamp most of the ship art in StarWright. While I'm certainly no great artist, or even a good one, this new art is definitely much better than before, primarily because it gives the sense that you're looking into a cross-section of a ship as the people run around inside. This was a feeling that was missing from the old art, and the game is much better for having that feeling.


A key part of the new art is having clearly visible walls that separate the various rooms. There are no doors yet, but when crew walk from room to room they walk underneath the walls, which gives a much better sense that they're inside the ship.

The new art is not just aesthetic, though. It serves some practical purposes too. The lighting color lets you know at-a-glance what kinds of systems you're looking at, even when zoomed out (red for weapons, orange for thrusters, tan for hallways and crew). The presence or not of colored lighting also indicates whether that room is operational (a dark gray cannon tells you that it doesn't have any crew operating it). And the number of ammo bullets loaded into a cannon tells you how many bullets that cannon needs to fire.

Sunday, February 24, 2013

StarWright - Micro Commands

"Micro commands" are special commands for power players that allow players to micromanage the behavior of their ship's crew and systems. The only current use for micro commands is to command your ship's weapons to focus-fire on a specific part of an enemy ship.


A micro command to focus-fire on an enemy ship's part is issued by holding the alt key and right-clicking on the enemy part. Additional micro commands can be queued up by holding shift in addition to alt while right-clicking.

Monday, February 18, 2013

StarWright - Better Commands

Players have for a while now been able to give both move commands and attack commands to ships, but until now haven't been able to queue up multiple commands or tweak commands already-given. These two new features really help make commands more flexible and useful.

Queuing up multiple commands to be executed in sequence is easy. Simply give the first command and then hold the shift key while giving each additional command. It looks like this:


Adjusting an already-queued command is also pretty easy. While holding shift, rotator and mover widgets will be displayed. Simply click and drag on one of the four arrows to rotate the ship, or click and drag the center widget to move the ship.


This also of course works for attack commands too. Clicking and dragging the center widget will adjust the distance and direction of attack. Clicking and dragging one of the four arrows allows you to choose what flank your ship will fire from, which was previously not able to be manually set.


Sunday, December 23, 2012

StarWright - A Slicker Sandbox

A few posts ago I talked about the new "modeless sandbox" user interface. It was nice because it didn't require the player to manually switch modes between building ships and playing the game. Unfortunately, as I pointed out at the time, having on the screen at the same time the full U.I. for everything you might want to do made the screen feel quite crowded, and it has become apparent to me that, unless I reorganize the user interface for the sandbox, it will only continue to become more and more crowded.

What I'm presenting here is what I think is a visually clean, usable compromise between not having modes and not having everything on the screen at once.

You could certainly argue that what I've done here has simply re-introduced distinct modes (and added 2 more), and from a strict word-definition standpoint you'd be right. (You could also rightly say that I never really eliminated modes entirely in the first place. You'd be right there too.)

But the new mode interface is different from the old mode interface in presentation, organization, and efficiency. I steal shamelessly from games like Sim City and software like Photoshop that organize tools into a handful of high-level categories and then show the individual tools in the category once the player opens the category. So in a sense, these new modes feel just like tools in Sim City or photoshop. And this re-categorization really allowed me to minimize the amount of U.I. on the screen during normal play, which keeps the game from feeling claustrophobic.

In the screenshot below there are four buttons stacked vertically on the left, each activating a single "category" or "mode". The first button, highlighted below, is the default mode. It's called the Command Tool, but it serves exactly the same purpose as the Play mode did previously -- when selected, you can click on and command ships like normal. As the default tool, clicking the right mouse button while using any other tool will return you to the command tool. This is an important feature borrowed from the modeless sandbox version, because it eliminates half the nuisance of switching modes.


In this next screenshot, the Build Tool is selected. While selected, a sub-menu is displayed from which the specific desired part can be selected. While the Build Tool is selected, it works just like the old Build mode from the original sandbox U.I.


Here I show a brand new tool, the Ships Tool. In prior versions of the sandbox, if you wanted to add a previously-designed ship into the sandbox, you had to open the Ship menu, click the Load button, and then select the ship from a dialog. In this new version, all of the previously-saved ships are put into the Ships Tool. Simply select the Ships Tool, select the ship you want to add, and click where you want it to go.


And lastly we have the Doodads Tool. Right now the only objects it contains are the asteroids, but eventually it could contain other objects such as worm holes, salvageable resources, or gas fields.


Friday, December 21, 2012

StarWright - Multiplayer! (and saved games too!)

WOW, it has been a very long time since I last posted about StarWright! To a great extent my new job has been keeping me quite busy, but also I've been working on the biggest new feature yet...



Multiplayer.

Adding multiplayer play to StarWright has been a huge task, as anyone who has ever added multiplayer networking to a previously-singleplayer game can tell you. Every core mechanic of the game, from damage and destruction to crew pathfinding to command and control, had to be overhauled to be multiplayer-capable. Add to this the creation of a custom UDP communications protocol and a programming library for "remote procedure call", both of which are critical to the multiplayer capabilities of StarWright.

To make matters even more difficult, my belief is that ever single mode of play in StarWright should be multiplayer-capable. That even includes the sandbox mode, which is the only real way to play the game right now. Making the sandbox multiplayer-capable as well meant that all the systems related to designing ships, such as adding and removing ships, adding and removing parts, and undo/redo, had to work over the network as well.

Oh yeah, I also want other players to be able to drop in and out of the game whenever they want. No pre-game lobbies, except for certain kinds of competitive matches. The host just starts a game, checks a box allowing other players to join, and then other players can hop right in. This means that the host computer must be able to send the entire current state of the game whenever a new player joins, which is its own big system unto itself.

On the bright side, sending the state of the game to another player essentially amounts to creating a save file of the game and sending it to the other player. So even though drop-in-anytime was a big feature to implement, I basically got a save-game feature almost for free. The code that handles networked state sending is about 95% shared with the code that handles game saving, even though networked state sending and game saving write the data to different formats (networked state sending uses a compact binary format to reduce bandwidth usage, while game saving uses a custom text format which is more tolerant of game version changes). This is thanks to a robust multi-format serialization library that I developed for my game engine, Halfling.

Sunday, November 18, 2012

StarWright - Self Destruct!

Starships blowing themselves up in slow motion is pretty cool.

Friday, August 24, 2012

StarWright - Weapon Ammunition

As in the original prototype, weapons now require ammunition in order to fire. Each weapon can store a small amount of ammunition for itself, but once it runs out, additional ammunition must be delivered by the ship's crew. Individual crew hand-carry ammo bullets from a nearby ammo supply to the weapon.


Notice how in the above screenshot, some of the crew are carrying ammo to the weapons.

The purpose of this mechanic is to further emphasis the importance and role of the crew on the ship, and to make designing a ship for maximum crew efficiency a priority. If the closest ammo supply is too far from the weapon, then the weapon won't be able to fire as often. It will also be important to prevent narrow corridors from getting congested with too much foot traffic. Wider corridors and/or more ammo supplies may help if foot traffic becomes an issue.

Friday, June 29, 2012

StarWright - Attacking

For a very long time it has been possible to command a ship to move to a particular destination by right-clicking into empty space, but there has been no way to command a ship to approach and attack another ship. That has now changed!


This screenshot probably requires a bit of explanation:
  • In their simplest form, attack commands are very simple to use and work almost exactly like move commands. Simply left-click on one of your own ships, and then right-click on an enemy ship to command your own ship to fly to the enemy ship and attack it. The computer will automatically determine the ideal distance from the enemy ship as well as the ideal flank to attack from (that is, whether to fire from the bow, stern, port, or starboard sides of your ship). A red circle will display the distance from the enemy ship, and a red ghost of your ship will show you exactly where your ship will station itself relative to the enemy ship.
  • As an advanced "power player" feature, it is also possible to right-click on an enemy ship and then, without releasing the right mouse button, drag away from the enemy ship. Doing so allows you to adjust both the attack distance and the direction to attack from. Thin red lines show which weapons can hit the enemy ship. The screenshot above shows an in-progress right-click-and-drag away from an enemy ship.
It is currently not possible to manually adjust which flank your ship will fire from. This feature is hopefully coming soon.