Tying things together

I’ve been working on putting everything together.  Fixing up placeholders like the spawning of ships being unrelated to planet position in LUA, attaching notifications to planetary invasion events, attaching sounds to planet lasers, that sort of thing.  While it’s more fun from a programming point of view to write new things, I think there’s been a fair amount of untapped potential piling up, waiting for me to connect systems already written.

So: Planets now have a defence value which ticks up.  Upon reaching a threshold, a planet destroyer + escorts are launched at the planet’s faction’s favored enemy.  I’ve significantly reduced the range on the planet killing laser and reduced the fear of gravity wells for ships with weak thrust, so planet killers should no longer hover so far outside planet defence range, and less often get pushed out of the solar system by passing planets.  I’ve also upped their thrust some.  I think I might need to start attaching different drag values to different ships- I still want the planet killers to be slow and ponderous, but it’s a pain having them be constantly flirting with getting sucked into gravity wells just to be within laser range.  Giving them more engine power but more drag would solve that problem without also messing with everything else in the game.

Planetary invasions are announced to the player on launch, as are attacks when they arrive.  There will be some sort of a filter for this eventually so the player isn’t so omniscient, but that’s a gameplay issue to sort out at a later time.

I’ve also resolved some issues with invasions targeting the wrong planet.  The difference between 1-based LUA and 0-based C++ indices still apparently gets me sometimes.

And finally, there is now a nice hum attached to the planet killer lasers, and they no longer visually penetrate the planet they’re hitting.  I think lasers are probably my next target for visual revamp.

Posted in State of the Game | Comments Off on Tying things together

Dust

The significant new update is the addition of dust and, in general, an efficient way to track particles floating through space.

It would be an easy problem, if I didn’t require the dust particles to react to external forces. Until now, the dust has all been stationary, and is obviously just a big dust cloud texture at various depths in the -z axis to provide some feedback on ship speed and apparent depth to the view.  But even having dust floating around randomly could be done pretty much exclusively in the shader- a bunch of 1×1 quads with varying Z-axis depths to provide differentiation to the vertex shader, and a uniform giving the current view coordinates.  Pretty much all the work would be done on the shader, which for my purposes makes it effectively free.

But wait, they’d eventually drift off the screen.  And since I’m not tracking the entire universe worth of dust, there wouldn’t be any more dust drifting in from far off the screen to replace it.  If the player just stood still for a few minutes, the screen would clear.  I could have the particles wrap around, but that might be noticeable.  So given a random value stored in the Z vertex and time stored in a uniform, I wrote a shader which would randomly move each particle in some direction for a while, then fade it out, then fade it back in near the original position floating in some other direction.  Since the fades in/outs are randomly distributed through all the particles, I think the trickery should be pretty transparent to the user, and look like a randomly moving cloud of dust.  If I wanted to, I could even assign nearby particles similar “random” values and reduce the amount similar values are split in the shader, to have them float in loose groups, to give the impression of currents.

So this is what I did for a while, and the results were acceptable.

But it’s a trickier problem if I want explosions to have an effect.  They have a permanent effect on particle position, there is no limit on how many there can be, and their timing is important.  It is unclear to me how to create a shader that can handle all of that without being able to store all the position and velocity data between frames.  I suspect that this might be possible with newer versions of OpenGL, but I’d rather not have significantly more demanding system requirements on a 2D game for the sake of nicer dust, and there’s far too much undone to start writing multiple render paths right now.

So the obvious answer is to track it all in C++, where all that information is available and remembering things between frames is not a problem.  Obviously, tracking all the dust in the world is ridiculous, so I’d have a chunk of memory I’d stake out on game load that I would recycle as old particles drop off the screen and new particles get added on.  It would have to extend a little beyond the edges of the screen, so an explosion near the edge wouldn’t reveal undisturbed dust if the view shifted in that direction, but still, pretty much just enough particles to fill the screen.

Each explosion triggers a search through all the particles to figure out who is nearby (since current position is unrelated to starting position, that can’t really be simplified).  Beyond that, it’s simple- add velocity*time to the position, and degrade velocity a bit.  I toyed with the idea of combining them into groups of 100 or so and setting an “untouched” flag on them, to skip all that computation if they haven’t been touched by an explosion, but since that would fail to save much effort when the computer was the busiest- lots of combat going on on screen- it seemed like a waste of time.  I can’t come up with a way to avoid having to think about every particle every frame.

So not only am I doing more work on the CPU than I envisioned when I started thinking about dust, but that shader I worked on is kind of redundant.  But perhaps there is a common solution.  I could dump the detailed background (the one not included in most updates due to size), and replace it with some drifty clouds, powered by the dust shader, only with much larger and many fewer particles.  It would give a kind of nebula effect, and positioned moderately far back in the Z axis, it would be plausible that it is not touched by explosions in the foreground.  And given the additional non-static visual complexity, maybe I could track many fewer particles in the foreground without losing the feeling of space not being boringly empty.

Or perhaps I’m rationalizing a use for the shader because I dislike cutting something that I spent time on.

In any case, I was careful to write all the dust code with a “density” variable, so it will be easy enough to stick a slider on that value and let the player reduce it if it ends up actually having a significant effect on performance when the game is completed.

Posted in State of the Game | Comments Off on Dust

Notifications, save fixes

I have finished the notification system, so important events are now announced to the player.  Currently this includes when a friendly planet launches an attack or when any planet is conquered.  While implementing the ability to save messages, I also noticed and fixed a bug which would duplicate ships if the game was saved multiple times in a row.

There is also a new feature possible to attach to projectiles- either a gravity explosion or implosion.  I think it makes the shockwave weapon feel a little bit more real.

For the next update, I am probably going to add some layers of cloudy nebula-like material to the background to make the background look less flat, and perhaps some floating particles affected by gravity.

Posted in State of the Game | Comments Off on Notifications, save fixes

Significant updates, including increased AI variety

I suspended work on the game for a while, but I’m back, and progress continues, with a substantial list of updates.

Additional player weapons are re-enabled, switch weapons using the mouse wheel. The number keys still work, but may be eliminated in the future. This means the player can no longer control their zoom level. Whether I re-include that depends at least partially on gameplay mechanics, so I’m not going to make that decision now.

I fixed a shader bug in the glow trail shader introduced/exposed by the most recent ATI driver.  It was the second shader I ever wrote and really a learning experience more than anything else, so it very well may have been relying on some undefined behaviour.

The screen is resizable. Right now, it just resizes down to windowed 800×600; I’ll add in the ability to choose resolutions as soon as I write the main game menu.

The player can now claim a planet which is at zero health. Land, bring up the planet interface menu with “E”, and pick “claim planet”. Satellites will behave according to the faction of their planet’s owner, shooting at enemies and ignoring friends.

Fixed a problem with the gravity wall tool not fully restoring all information when loading a game.

Computer controlled ships no longer stack up at the same point in space. They now bounce off each other, creating a much more believable cloud of ships when a lot of them congregate.

LUA can now access the general state of the universe with “getWorldData”, which allows it to access general star and planet data and positions. I’ve also repaired the get/setPlanetData functions, which were apparently mangling data since I added the extraData ability. This was made exceptionally difficult by having a problem which lay at the interface between C++ and LUA. I have resolved to minimize the size of that interface in the future.

Computer controlled ships are now much more flexible. LUA can set three orders- go to a location, follow a ship, or follow a planet. Since targeting is independent of that, “follow a ship” can be used for both “escort a friendly ship” and “attack an enemy ship”, and the same for a planet. Right now, every five seconds, every owned planet locates an enemy planet and launches a planet-destroying laser-armed ship towards it. Since they’re all close together, the ships spawn so fast, the planets don’t bother defending, and the range of that laser is so large in comparison to the defence satellites, the planets all die fairly promptly. Obviously this is just a proof of concept, but it’s a massive step forwards in terms of actually having a game.

To better illustrate the relations between planets, I’ve added more of them. They’ll all look the same until I get some more images from the NASA archives or something similar.

Also fixed is the behaviour of smoke trails at high speeds and low frame rates. Previously the smoke trails would get ahead of the ship if the number of milliseconds between frames was higher than the time granularity of the smoke trail (currently set at 15ms), this is now fixed.

The glow trail shader wouldn’t work at all on nVidia drivers due to a variable type mistake which ATI cards apparently don’t care about. This is fixed.

I’ve added a queue to flash text to the player- proof of concept bound to the “P” key. Major events like planets being conquered or player planets coming under attack will be displayed through this system.

ver24

Posted in State of the Game | Comments Off on Significant updates, including increased AI variety

Where to go from here

After the recent updates, I’ve arrived at the point where I’m making meaningful gameplay decisions every time I design another part of the game, where the decision are no longer obvious- not like the past, with design decisions like “Sound: do I want it?  Yes.”  or “Should I want the AI to accidentally run into planets?  No.”  So I’ve taken some time to consider the current systems, and where I should go from here.  Of course, I had this all planned out when I started, but after the radical course correction away from the music-powered game, all that planning became irrelevant.

The game will split into several somewhat distinct phases, each with a distinct set of play goals, abilities, available equipment, and threat level.

The first phase takes place in relative safety, deep within the civilized core of the human galaxy.  The barrier for player advancement is accumulation of money, which can be used to buy new ships and equipment from the well-established planets.  Money can be earned by killing pirates found further away from the core, or possibly trading between planets.  The possible income rate will have a greater than linear relationship with the player’s power, to make it less of a grind and more of gateway, and encourage risk-taking rather than sticking with safer, low-risk pirate hunting or trading between low-risk planets.  The equipment available for purchase by the player is intended for civilian use, but more advanced ships and equipment are visible, to give the player a goal.  The player is also made aware of a war with aliens happening on the edges of human space.

A possible second path could be the ability to align with the pirates.  This could allow other types of gameplay- destroying trade ships for their cargo, or destroying planet defence ships for a bounty from the pirates.  Higher risk, but the pirates could make more powerful equipment available.

From a technical perspective, the first phase requires a system for generating and selling equipment on planets.  I’ve already got a planet menu, so on inhabited planets, the trade menu will be an offshoot of that.  The equipment available on each planet is defined in universe.xml under each planet’s entry, with a reference to a piece of equipment defined in equipment.xml.  To avoid having to write a lot of this repetitive code by hand, I plan on allowing the definition of a single “quality factor” to individual stars or planets, which will automatically generate the available equipment in universe.xml with a certain degree of randomness.  The equipment itself must have associated quality levels in any case, to determine the equipment loaded on spawned ships.  This value will not be directly visible by the player.

The second phase occurs as the player nears the end of what is available to buy without a military association.  In return for killing aliens, the player will be able to buy military grade equipment available near the warfront.  Money becomes secondary to reputation with the military.  Enemies are armed with more exotic weaponry, and larger battles can take place.  If the hireable/ownable escort ship thing works out, this will be where it first appears.

This phase will also be the player’s first opportunity to take over a planet.  They’ll be restricted to neutral planets only, and they won’t be very high quality, but the possibility of building up a mining system will be available.  Taking a neutral planet will just be a matter of buying a colony ship and escorting it to the planet in question, combat need not arise.

The point of owning planets is manufacturing.  Every planet has a certain finite amount of various resources, which the player can mine to produce ships.  So at this point, the real currency of the game becomes manufacturing resources.  I expect to make mines pretty cheap, but factories expensive, to encourage a network of mining planets supporting a small number of factories, requiring some freighters to move stuff around.

This phase is also where the planetary assault laser first comes into play.  These are large, slow ships which the player can eventually own but not pilot, which are necessary to take over owned planets.  The military and aliens will occasionally spawn one and send it to enemy planets with an escort, and the player will receive a significant reward if they join the fight, probably determined by being within a certain radius at the moment of a successful takeover.  To prevent one side from actually winning, I will probably mark a bunch of warfront planets as valid targets and only ever spawn capture missions to those planets, so they’ll change hands back and forth, but the front won’t really move until the player takes charge.

From a technical perspective, this phase depends on a believable group combat system.  I plan on having a single ship in each group be set to the standard “go to location, fight when enemies are within a radius” AI mode, and the rest are set to go to that ship, breaking off to pursue enemies a short distance when necessary.  Since I want the higher level AI programming to be on the LUA side, I’ll have to expose a fairly large amount of data to make that happen- I plan on making it a single operation per faction across the entire “sector”, where LUA can access the relevant information and store AI changes all at once.  This will hopefully allow me to make the LUA stateless, which I think will simplify things significantly.  I am somewhat concerned about whether the computations could get complex enough that there is a notable hiccup in gameplay when it recomputes everything at once, which could be avoided by having it only do a few ships each frame.

Phase three is marked by the player acquiring a planetary assault laser of their own.  They pick a target, tell the laser ship to go attack it, escort it there, and when the planet drops to 0 health, they can claim it.  The laser ship should be pretty slow, and maybe announce its presence in some way, and take a while to drop the planet to 0 health.  This is both to make taking over planets a riskier and less boring activity, and to give the player a chance to defend when the computer does the same thing.

From a technical perspective, the big thing that must be in place for this part is a system to own additional ships and order them around.  I expect there will be quite a bit of code overlap between this and the map design program- navigating a map, dropping a planet on a point, and entering some data is pretty similar to navigating a map, selecting a planet, and picking an order.

Finally, the player gathers the power to take over territory from the aliens.  With all the resources from taking over the rich planets controlled by the aliens, the new currency for this phase becomes technology- harvesting alien technology allows the player to design their own weapons.  This part is already pretty much built- the projectile system is very generalized, and changing properties of existing weapons or adding new ones is fairly trivial, and can already be done dynamically.

Posted in Design | Comments Off on Where to go from here

Satellites

New this update is the addition of defence satellites.  Their stats are defined in their own XML file, and they’re plugged into the world through universe.xml, in the appropriate planet entry.  They fire on enemies of their home planet’s faction.

They’re currently armed with lasers- adding projectiles to something which will always be operating in a gravity well seems like asking for trouble, especially since shots which miss will probably be sucked onto the planet, where they’ll damage the planet the satellite is there to defend.  They’re currently invincible, though I will probably change that to be a very large health pool which regenerates, since having no way to to remove them from hostile planets would be frustrating, while they should also not be so fragile that the player would have to be going back and re-purchasing them regularly.

Next up, is handling the small things which I’ve been ignoring- dropping in a few more planets, adding the ability to resize the window, re-enabling weapon switching for the player, and adding in a few more planets under enemy control.

Posted in State of the Game | Comments Off on Satellites

Planetary interaction, Lua empowerment

A significant update today-

I’ve retextured the basic projectiles to look more interesting.  I’ve also modified the XML to be able to dynamically load a texture for projectiles instead of requiring an index number to an internal array, so adding new textures for new projectiles is trivial.  I did that for the ships a while ago, but I guess I missed the projectiles.

I’ve added a mouse-over system.  Hover the cursor over a planet, and you see it’s name and faction.  Hover over an enemy ship, and you see it’s name, faction, and a bar for health.  Hover over a star to see it’s name.

I’ve added the ability to claim planets.  It’s just a “claim” button you can bring up with “e” while landed right now, I’m not totally sure how it will work from a gameplay perspective yet.  I don’t think it’s reasonable for the player to be able to run around claiming every unpopulated planet for free, so there will probably be a resource cost, or the player will have to escort a colony ship from an established planet, or something along those lines.

Unclaimed planets spawn an endless stream of ships, just to showcase the new ability for LUA to easily spawn ships on demand.  I’ll tie ship spawning and which faction the ships belong to to the planet’s defence level in the next update.

There’s now a “planet update” function in LUA, called for every planet every half second, to process things like mining, ship spawning, factories, and whatever else planets might do.  Automatically called, timed scripts really extend the power of scripts, so I’ll be adding more in the future.

Lastly, a bar on the lower right indicates the current charge for the gravity tool.

So, for next time:

A planet upgrade menu.  All the mining and factory data is in place, the player just needs an interface to get at it.  The button is there, but is not currently hooked to anything.

A satellite defence system for planets.  The player can’t be expected to be everywhere, so planets will need to be able to fend for themselves to some degree.  Also, taking a hostile planet by force should be a significant undertaking, so it needs to be able to fight back.  It’s probably something the player should only be able to do later on in the game, so I’ll probably have planets be immune to normal attacks, and add some special, expensive tool for sieging planets.

ver21

Posted in Uncategorized | Comments Off on Planetary interaction, Lua empowerment

Saving completed, sound issue sidestepped

Saving functionality is complete.  All ships, projectiles, gravity walls, and of course the player have save and load functions which slot themselves into the relevant XML in the appropriate save directory, and restore themselves appropriately on load.  Which is, I suppose, a fancy way of saying “You can save and load”, but using so few words for such an important thing seems unjust.

Consistent with the theme of keeping the data in a user modifiable format, saves are straight XML.

Also sidestepped is the sound issue.  I’ve included a sort of droning space ship engine effect as a demonstration.  Next up I’ll add some sounds to the weapons.

So, with new abilities come new controls:
Shift+F1 … Shift+F5 save the game in slots 1-5, respectively
F1 … F5 loads the game.

saves

Posted in State of the Game | Comments Off on Saving completed, sound issue sidestepped

Saving: When and where

Saving and loading is the task of the day.  I’m rapidly becoming comfortable with rapidXML (harr) now that I’m using it a lot in a short period of time.

The question in terms of design, though, is save types.  Exactly how much needs to be saved, and at what times should the player be able to save?  Only allowing saves on planets would probably simplify the task, but I’ve decided to just go all out and allow the player to save anywhere.  So, before me is the task of writing save and load functions for every piece of data which can change over the course of the game.  It’s not as bad as I feared, however- the functions I’ve written to wrap around rapidXML have let me turn whole swaths of the task into a sort of copy+paste+change two words+repeat operation.  If C++ supported reflection, I could probably eliminate even that, and automate the process of adding new data types too.  Anyway, since I’m already loading all my data from XML, I’ve settled on a suitable XML structure for most everything, so there’s really not much design or thought required.  The downside of using XML as a save format is that a lot of data is wasted in repetitive formatting in the XML file itself, but I’m sure all that waste will disappear if I compress it, should it ever become a problem.  In any case, keeping save games user-editable is something I might as well keep in until I have a good reason not to.

Posted in Design | Comments Off on Saving: When and where

Planet data: More flexibility

While writing the LUA “planetTick” function, I came to the conclusion that requiring modification of the C++ core to add new kinds of data to planets runs counter to the premise of user modifiability.  So I’ve added an “extra data” child to the planet XML node, which can contain arbitrary keys and values, which are made available to LUA through the getPlanetData function.  New data can be added either through editing the XML or in LUA through the setPlanetData function, and all of this will be stored on save.

Posted in State of the Game | 2 Comments