Monday, February 19, 2018

Cosmoteer 0.13.6 - Explosive Charges, Multiplayer A.I., and more!

Cosmoteer 0.13.6 was released today! This update has a ton of small-to-medium sized features and improvements. Here are some of the most notable:

Explosive Charges

For a while now, Cosmoteer has supported a feature allowing you to self-destruct literally any module on your ship at any time. To be honest, I've always thought this was pretty strange, and in multiplayer it's especially exploitable. So I decided to remove arbitrary self-destruct of individual modules. However, players were using the self-destruct to execute some pretty creative strategies (such as splitting ships into multiple distinct ships), and I didn't want to lose those creative strategies altogether -- I just wanted a way to balance them and make them feel less strange.

Thus, the Explosive Charge was born! The Explosive Charge is a new 1x1 module that can be manually detonated by the player, destroying itself and almost everything else within a small radius around it:

While fairly cheap, the Explosive Charge is still much more expensive than a single structure tile (which is what players would usually use to self-destruct in previous versions) and so you must balance its cost against other modules. Additionally, since the Explosive Charge will also destroy almost everything else around it, you'll need to position it carefully to make sure that its explosion won't damage other important parts of your ship.

A.I. Player in Multiplayer Games

In order to round-out uneven teams in multiplayer or play co-op against the computer, the host of a multiplayer game can now add A.I. players.

These are just like regular players, except that their ships are controlled by the computer. The host is able to select the difficulty level of the A.I. and what ships it will use.

Multiplayer Quality-of-Life Improvements

This update also has a plethora of quality-of-life improvements to make multiplayer more playable and stable.

First of all, the networking code has been significantly optimized and should now have fewer disconnects, fewer server crashes, lower latency, and use less bandwidth. That's a win all-around!

Second, the lobby screen has been revamped to show the details of the selected game, so that you know what kind of game you're joining before you hop in:

Notice that there's also a little latency meter displayed for every game that should give you a rough indication of how laggy the game will be.

Third, due to past problems with spam, this update now limits chat messages in the public lobby to 5 every 50 seconds. You can also mute individual players and ban them altogether from joining your games.

Lastly, this update adds a toggle to the in-game chat that lets you send messages that can be seen by only your teammates, so you can strategize without informing the enemy of your plans!

And More!

This update has a ton more improvements and bug fixes. Check out the full changelog for all the details!

Saturday, January 27, 2018

Cosmoteer 0.13.5 - Improved Multiplayer Stability

Cosmoteer 0.13.5 has been released! This is a minor update that should significantly improve the stability of multiplayer games and also fixes a handful of other bugs. Enjoy!

Sunday, January 21, 2018

Cosmoteer 0.13.4 - Online Multiplayer

Cosmoteer 0.13.4 has been released! The new-and-notable improvements are online multiplayer, increased weapon range, and better ship flight A.I.

Online Multiplayer

Until now, to play multiplayer with someone else you had to either be on the same Local Area Network as them, or send them your I.P. address and have them join your game. This made playing with other people online problematic because the host had to first setup port forwarding on their router (which can be a little complicated for someone who hasn't done it before) and then send everyone else their I.P. address (which can be potentially risky).

But now 0.13.4 adds "online multiplayer", which allows players to play with others online without having to share their I.P. addresses or setup port forwarding. This works thanks to what's called the "Cosmoteer Lobby Server" (or CosmoServer for short), which is a little program that players can connect to and join an online "lobby" where they can then host games and play with anyone else in that lobby, just as if they were on the same LAN. There's currently one official server called "Official U.S. East" (located in New York, NY, USA), but you can also run your own server if you want.

Unlike the servers for most other games, CosmoServer does not actually run any gameplay logic; it merely acts as a communication relay between all the connected players, letting the players themselves run the gameplay logic. The advantages of this approach are that it uses far less CPU than a conventional game server, and even more importantly, it is fully compatible with all mods. (Individual players playing games together must still have the same mods, but those mods do not need to be installed on the server.) The primary disadvantage is that it increases latency (not a huge deal in an RTS-style game like Cosmoteer). And if you know anything about multiplayer game programming, you may think that not running gameplay logic on the server would expose the game to cheating, but this is actually not true thanks to its deterministic lock-step multiplayer implementation.

Increased Weapon Range

Cosmoteer is a game about building pretty much any kind of starship you want, from tiny fighters to huge motherships or anywhere in between. This is great for player creativity, but it turns out to be really hard to design gameplay mechanics that work well for ships of any size. In fact, the single biggest challenge when designing Cosmoteer is figuring out how to deal with the sheer differences in scale between ships.

One of the ways in which scale can be a prickly challenge is when choosing the "range" for each weapon (how far it can shoot). The goal is to pick a range that is close enough so that two ships fighting can both be seen on the screen at the same time (without zooming so far out that you can't tell what's going on) while not so close that it feels like the ships are sumo-wrestling. The big problem here is that the ideal range for small ships is much closer than the ideal range for large ships.

Until now, Cosmoteer has leaned towards picking weapon ranges that are ideal for small ships because that made the game more understandable for new players, but that of course meant that large ships would tend to fight more closely than felt comfortable or intuitive.

But the 0.13.4 update changes that in a way that makes combat between large ships happen at a more ideal range, while still keeping combat between small ships relatively close. This change has two parts:

  1. The range of all weapons has been increased, most by about 50% (the missile launcher being the most notable exception that got a much smaller buff). These increases makes large capital ships choose longer default attack distances.
  2. The range at which a ship will choose to attack (the default attack distance when given an order by the player, and the attack distance when chosen by the A.I.) now depends on the size of the target, such that a closer range will be chosen when attacking smaller targets and a longer range will be chosen when attacking larger targets. This means that two small fighter-sized ships attacking each other will still engage at relatively close range, while two capital ships fighting each other will stand off at longer range. (And if a small, fast ship is attacking a large, slow ship, then the small ship will try to stay at a longer range than the large ship wants, which could give the smaller ship more of an advantage so long as it is fast enough to stay away from the big ship.)
Better Ship Flight A.I.

The last change I want to mention in this post is that the flight A.I. for ships has been improved in several different ways that when combine together should make ships less "dumb" and annoying:
  1. The collision avoidance algorithm has been overhauled (again) to fix a bunch of problems it had when detecting potential collisions and evading them.
  2. When a ship is commanded to attack an enemy from a specific angle, the ship will now approach the enemy straight-on until it reaches attack range and only then attempt to move to the correct angle. This change prevents ships from entering combat facing the wrong direction, which was frustrating for many players.
  3. Lastly, the thruster calculation algorithm now prioritizes lateral thrust 50% more than it does forward/reverse thrust, meaning that ships will now try to eliminate most lateral motion before thrusting forward towards their intended destination. This has the practical effect of preventing most cases where ships would "orbit" around their destination without ever actually arriving at it.

Saturday, January 6, 2018

Cosmoteer 0.13.3 - Bug fixes & restored mod compatibility

Cosmoteer 0.13.3 has been released! When I released 0.13.2, I made a mistake which made many existing mods incompatible with Cosmoteer, much to everyone's dismay. This update restores compatibility with those mods and also fixes a handful of bugs.

Wednesday, January 3, 2018

Cosmoteer 0.13.2 - Miscellaneous Improvements

Cosmoteer 0.13.2 has been released! This is a relatively minor update that fixes bugs, reduces RAM usage, and adds some quality-of-life improvements and modding tools.

The reduction in RAM (and VRAM) usage is largely because Cosmoteer now uses "texture compression" to reduce the size of almost all of the graphics textures by 75%. This saves a couple hundred MB of RAM in the vanilla game, and it makes an enormous impact for some mods: "Abh Mod" for example has gone from using more than 4 GB of ram to around 1.2 GB of RAM.

Most games use texture compression and package already-compressed textures as part of the game installation. But Cosmoteer is a bit different in that it compresses textures on the fly from the raw PNG files during loading. It does this primarily to keep the game very easy to mod (most paint programs are unable to save textures using GPU-compatible texture compression formats, and none can generate the texture atlases that Cosmoteer uses for its ship graphics). The downside is that it takes much longer to compress a texture than it does to load an uncompressed texture, and so after compressing a texture for the first time, Cosmoteer caches the compressed texture on your hard drive and only re-compresses it if the original PNG file has changed.

This update also adds a "Developer Mode" to Cosmoteer, which makes available a number of development tools and features that should hopefully make mods easier and more convenient to create. These tools include a particle effect editor, a planet editor, and the ability to "cheat" by giving yourself money and fuel.

Tuesday, November 28, 2017

Cosmoteer 0.13.1 - Perimeter of Death!

Cosmoteer 0.13.1 has just been released! The majority of changes are bug fixes, but there are still a couple of nice other improvements:

First, this update adds to multiplayer a feature called the "Perimeter of Death". This is a giant circle around the battle area that will quickly damage and destroy any ships that stray outside of it. It is intended to reduce the effectiveness of "kiters" (ships with long-range weapons and lots of thrust that simply stay out of range of enemies) as well as prevent players from simply running away indefinitely.

The other feature is something that a lot of players have been asking for: a "sort" function for the Ship Library. Now, players can sort their ships by name (the default), cost, crew, or date modified.

Sunday, November 12, 2017

Cosmoteer 0.13.0 - Multiplayer!!!

Given the lack of updates for the past couple of months, you'd be forgiven for thinking that I had stopped working on Cosmoteer. Thankfully, you could not be more mistaken!

I've actually been working on one of the biggest new features in the history of Cosmoteer: Multiplayer!

Those of you who have been following Cosmoteer for a really long time probably know that the original prototype versions had support for multiplayer in which players could design ships and battle them with their friends. But I realized that having to support multiplayer was dramatically slowing down the development of Cosmoteer, including development of singleplayer-only features. And so I removed multiplayer support from the game's code, hoping (but not expecting) that one day I would be able to bring it back.

Well, that day has arrived! I am incredibly proud and excited to announce that multiplayer is returning to Cosmoteer!

In this first version, multiplayer is a simple team-versus-team battle of up to 8 players spread across two teams. Each team has a certain amount of money (configured by the host) to spend on a fleet of up to 5 ships per player (or fewer, as configured by the host). Then the game starts and the players control their own ships, attempting to destroy the other team's fleet. The game ends and one team is declared the winner when either the other team's fleet is sufficiently destroyed or the timer runs out.

You can play with anyone on the same LAN (Local Area Network) as you, and you can also play with a friend anywhere else in the world by typing in the host computer's I.P. address. (There is not yet a public online list of games, but I hope to add that soon.)

This is just the beginning! This first version lays the coding foundation for more improvements to come. In the long term, I may add entirely different game modes, such as multiplayer co-op and creative modes. In the near future, I plan to add:
  • A.I. players in multiplayer battles
  • Observers (for streaming tournaments)
  • More than two teams & free-for-all battles
  • Some sort of boundary around the playing area to prevent people from being able to run away indefinitely
  • Limit price per-ship and not just total price per fleet
There's lots more details and plenty of other fixes and improvements in the full changelog.

Technical Implementation

You may be wondering why I've chosen to bring back multiplayer given the fact that I originally removed it because it was slowing down development too much. Wouldn't bringing back multiplayer cause all future development to become a lot slower?

Thankfully, the answer to that is mostly "no", and the reason for that is that I've taken an entirely different approach to implementing the multiplayer code.

The original implementation of the multiplayer code required that every single change in the state of the game (such as a ship firing a weapon, a ship moving a millimeter, a crew person walking a foot, or a bullet hitting an enemy) be synchronized among all players by sending packets over the internet. This was a huge problem for two very important reasons:
  1. In a game as complex as Cosmoteer with potentially dozens of ships and thousands of crew, that's a potentially huge amount data that needs to be transferred over the internet between all the players. We're talking megabytes per second of data for a large battle, which made the game really only playable on LAN or very-high-speed internet connections.
  2. The code for anything that could affect gameplay even in the slightest became way more complicated due to the need to send those aforementioned internet packets. For example, if I wanted a bullet to inflict 1000 damage on an enemy ship, I couldn't just call the TakeDamage(1000) function; I first had to construct a network packet with all the needed information and send it to all other players. This made working on gameplay code far more time-consuming that it would've been without having to send all those packets.
The new multiplayer code uses an entirely different approach that's called "deterministic lockstep". Essentially, this approach requires that two computers running the same version of the game with the same initial battle setup and same player inputs will simulate the game in exactly the same way. (Not even off by a millimeter, or else the butterfly effect will cause bigger and bigger errors until the game desyncs.) There are two big advantages to using deterministic lockstep:
  1. Only player inputs (commands issued to the ship) need to be turned into packets and sent over the internet. Everything else (physics, weapons, damage, etc...) will happen exactly the same way on every computer by virtue of them running completely deterministic game simulations. This saves massively on bandwidth, so much so that Cosmoteer now only uses a few KB of bandwidth per second.
  2. Code that affects gameplay no longer needs to be synchronized using packets sent over the internet, so long as the gameplay code can be written to be 100% deterministic. Writing deterministic gameplay code isn't very hard as long as you know what kinds of things to avoid (primarily code whose outcome could change based on framerate).
There are, however, some important disadvantages to using deterministic lockstep:
  1. The gameplay really does have to be 100% deterministic. 99% deterministic is not good enough. And non-determinism bugs can be very tricky to track down. I have written myself some pretty nice tools for debugging determinism issues, but it still took me several weeks to comb through the whole Cosmoteer codebase and convert everything to be deterministic.
  2. Games that use deterministic lockstep typically have more latency than other types of games. You may notice that when playing multiplayer Cosmoteer (and most RTS games) that there's a small delay after assigning a ship an order and before you see it actually respond. That's because it has to wait for the other computers to receive the order before it can process it. In action games like first-person-shooters, this would be a huge problem, but in slower games like Cosmoteer, it's not a big issue.
  3. Differences in how different CPUs compute floating-point (fractional) numbers can cause an otherwise 100% deterministic simulation to become only 99% deterministic, which due to the butterfly effect will ultimately lead to desyncs. In practice, this means that players running on 64-bit operating systems can't play with players on 32-bit operating systems. (Although there is a mode to force the game into 32-bits so that friends on different operating systems can play with each other.)
While these downsides are significant, none of them are deal-breaking, and are certainly preferable than the problems caused by the original way I implemented the multiplayer code.

All in all, getting multiplayer working again was a pretty huge undertaking -- one that I wasn't even sure I could pull off -- but in the end I think it has proven to be well worth it. And I'm looking forward to playing a ton of Cosmoteer multiplayer as a result!