Saturday, September 4, 2010

Android Attack

A small change of pace ...

In the future we will have handheld devices that resemble an iPad, except that they are not beholden to either Steve Jobs or AT&T. And we will want to know the Mars travel schedule right now, whether or not we can afford a ticket.

To prepare for this future I have started playing around with the Java language and the Android operating system. I've written a number of sim programs in C, some of which are on my static website, but they all have a neolithic user interface that makes them impressively user-hostile. So I have decided to move into the 21st century and play with some sim apps that don't go out of their way to be inconvenient.

Learning to program for mobile devices is a bit odd when I don't even own one, but the alternative was learning either Java for Windows, if there is such a thing, or programming inside a browser, which also seemed odd. Android provides a definite environment, and the Eclipse development tool comes with a nifty Android emulator, which you see in the screenshot.

Because working with modern user interfaces is new to me, that has been the focus of my initial efforts, which you see above. Don't go rushing out to buy an Android phone just yet; as space game apps go this one is both unrealistic and boring. You type in a heading in degrees (on the slide out keyboard, not shown). When you hit ENTER it reports the heading in radians, and positions the spacecraft at the desired angle. The little graphic comes with a Lunar Lander game at the Android development pages.

Hit the Reset button to clear the entry. Hit the Rotate button and the ship does a 360 degree rotation (at a steady rate, no fancy acceleration and deceleration). Error entries - anything non-numerical - cause the image of a wrecked ship to appear. That is the entire functionality of the app.

But the odd thing about a space sim app is that the rocket science is in many ways the easiest part. You don't actually have to design the hardware, after all, and as for the computations, Sir Isaac Newton and the computer processor do the heavy lifting. Providing the information in a way humans can play with it is the more challenging part. This little gizmo is effectively a sort of 'Hello, World' test of basic interface tools, and giving me a first sense of Java code in action.

What I have in mind for now is a solar orbit sim, intended to test the performance of the sorts of midfuture ships that I discuss on this blog. Right now there are no tools out there (that I know of) for modeling steep, fast orbits, and my estimates of travel times are a mix of flat-space approximations and sheer guesswork. The interface, as I picture it, will toggle between a 'pilot' view roughly like this one, and a 'navigation' view showing the orbits. There will also have to be a design-phase screen for entering ship characteristics.

It probably won't challenge FarmVille in the game popularity rankings, but who would have guessed that a farming sim would be a hit? And it will give everyone an opportunity to miss your destination and hurtle on to oblivion, without fuel enough to slow down let alone return to Earth.

Good clean fun for all!


Geoffrey S H said...

An economic "sim" game/ with combat, economic goals and politics would very interesting (somewhat diverging immediatly from your harder-edged pure-sim). Even the most basic of games such as Star-Trek Armarda and Freespace 2 can model some form of neutonian physics in some whay- which is why I am still puzzled as to why so many games and sims still have th notion that craft "float" in space and don't have momentum, not to mention orbital mechanics and hohmann transfers. If naval mechanics can be modeled wit some accuracy, with land and air mechanics being managed in descendeing orders of realism, thenb surely space has been disgracfully neglected? An Imperium Galactica/ Civilisation type game comes to mind.

Timing hohmann convoys to arrive just in time to deliver their goods and thus stay in competition with more local industries... fire off clouds of shrapnel to prevent enemies getting shots at your vulnerable heat radiators... trying to solve the porblems of an economy in space, with the diplomatic complictions that come with it. There is an untapped market out there.

jollyreaper said...

I'd wanted to design an abstracted space combat game along the lines of Star Control which is of course a loving tribute to the very first video game, Space Duel.

By abstracted I mean that it'll be a 2D topdown representation of space. Two ships (for starters) maneuvering in orbit around a planet. Weapons include point-defense lasers, missiles (longer range, can attack targets behind planets), anti-ship nets that act as passive navigational hazards, etc.

My only problem is I suck at programming and wouldn't know where to begin. I'm also not sure how one would implement some of the more complicated controls. Star Control had homing weapons but there was no complication there since there was only one target to shoot, the enemy ship. Some of the more powerful weapons were unguided so the whole ship had to be pointed to fire the weapon. And there were only two weapons for every ship class, primary and secondary. You could take a fleet into the fight but each battle was fought one-on-one. It would have been impossible to do otherwise because you'd be stuck with relying on AI for your own ships.

I'm surprised nobody has come up with an updated version of Star Control, either the original or the sequel. We won't mention the third one.

Jim Baerg said...

Some years ago I wrote a C program for simulating the motion of a solar sail. The code included such things as determining the gravitational acceleration due to all bodies the user includes in the simulation, & adjusting the tilt to maximize the acceleration in a particular direction. However, the user interface is definitely user-hostile.

I could use much of the code for an ion drive sim, whether the drive is powered by solar panels or a nuclear power source. Something that elaborate would be needed to determine travel times for a drive that provides accelerations in the mm/s^2 to a few cm/s^2 range. I expect that would be similar to Hohmann travel times, but would allow smaller mass ratios & so be cheaper.

jnutley said...

I think what Rick is working on is a handy torch-ship calculator. Fill out the form with your destination, fuel load and ISP and get one or more annotated travel times.

The two problems that I suspect torpedo space sims of all kind:

1) Modeling 3d motion is non-trivial and has been computer intensive.

2) long periods of boring travel interrupted by moments of frantic (sometimes terrifying) activity.

-- -- --

I'm also a fan of the concept of an alt history machine on your computer.

Anyone here remember "Race into Space", later "Buzz Aldrin's Race into Space"?

I've also played various versions of Civ and wished I could set up a "War of the Worlds" scenario which included building up both Earth and "Mars" and playing out transit and occasional battles in the space between.

The problem with computer games though, is that they have to balance the opponents to produce the chance that a player can win or loose, and so real modeling, of space or economics or politics, etc eventually takes the hindmost.

So what I'm left wishing for is an alt history builder, a solar system in a box. I'd set up the initial conditions over the weekend, then set things in motion Sunday night, when I came home from work Monday, I'd have a report like a network of possibilities: what were the most likely results, where were the turning points that decided between them (battles, inventions, martyrs, etc). I could review them, pick a subset, and set the machine to build a more detailed work up of my chosen paths. Eventually I'd have a detailed world history, with some pretty (though admittedly generic) graphics and be able to drill down to the events that made it happen with side bars on their details and likelihood (or unlikelihood). Then if I wanted to, I could post the report and my settings to an Alt Hist community, and get comments back on it if it was interesting, and comment on other people's worlds too.

jnutley said...
This comment has been removed by the author.
jollyreaper said...

I love the idea of city builder sims but they usually fall apart in practice. Civ is a good game but you're playing against other civs and it kind of becomes a nightmare to keep up. Sim City is more of a slow-based builder in that there's nobody to compete against except the difficulty of keeping a city going.

Something that we don't tend to see as much of are ant farm games. By that I would compare to civ as the not-ant farm because you're having to make every decision, plan every outcome. An ant farm game would be about you tweaking conditions and seeing what develops from there.

The ultimate ant farm game would be Sim God. You start out with a planet peopled by various stone age tribes. They will develop according to randomly seeded scripts, building empires and technology and falling. If you do nothing but observe, you'll have a fantastically detailed ant farm to enjoy. But what's the best part about having an ant farm? Shaking it up and seeing what happens. That's when you get to be a malign god.

There would be the sandbox mode where all power belongs to you. Game mode would require you to build worship points to do things. You pick a chosen people and give them a set of commandments to follow. The interplay between commandments will show how successful this new religion is. The more adherents you have, the more power you build for performing miracles and smiting enemies.

I suppose that goes a bit beyond the realm of a solar system sim. I've seen games try to do that sort of thing in the past and they just fall on their faces. It's difficult to create a sim like that and have it remain fun and engaging. Usually they just end up turning into tedium.

Teleros said...

@Geoffrey S H:
"which is why I am still puzzled as to why so many games and sims still have th notion that craft "float" in space and don't have momentum"
1. People are used to Star Wars etc. Space fighters that don't duck & swoop are doing it wrong...
2. It's much more complicated for the layman than ones based on (1). If you've ever played the Homeworld games, you give a move order, and your ships start moving, quickly accelerate to their top speed, and then fly along, decellerating briefly at the end. Rather like a car I guess, and very unrealistic for space, but easy to use.

As for making a realistic game, the problem will be matching the physics up with the need for easy gameplay. The Homeworld games I mentioned above are (or can be made to be) fairly good in this regard, although they do still suffer from things like top speeds and have starships swooping around like giant aircraft. Still, you can do a fair bit with the engine if you've the time.

Geoffrey S H said...

Independance War managed it successfully to a degree... as for slow times of transit- a speed-up button should fix that, reverting to normal time just before something happens- Imperium Galatica 2 being a good example here.

Basic manourves and the like I don't see to be too much of a problem. As for disparity of poewr- the total war games, IMO, managed to have unequal nations occasionally competing. Diplomacy and economics are also starting to become very important factors for that series, especially with the release of Empire: Total War.

My basic point is that while it is hard, it shouldn't be impossible to do. If invisible lasers are hard to do, then just an an infrared "visor" in-game to allow you to see them.

Rick said...

Welcome to a new commenter!

As you say, there is a tension between physics and gameplay. A computer takes care of the bookkeeping that makes vector movement so difficult in board wargaming, but it doesn't help with the sheer unfamiliarity, when most gamers just want to dogfight with enemy space fighters, and blow them up.

I seem to recall a discussion at SFConsim-l (and more generally in the gaming world), arguing that there are three basic 'world views' about gaming: simulation, gameplay, and alas I forget the third. :-) My bias is toward simulation, but obviously it is gameplay (and the social element, which might be the third perspective) that sells games.

Tablet devices will lend themselves wonderfully to casual gaming, but also to more serious gaming and simulation, though it will sell a lot less.

Ideally, and in principle, all the Realism [TM] is under the hood, handled by the computer, so that the player gets a cool, intuitive play situation that happens to be realistic.

Milo said...

Re: space physics simulation

What we really need is the ability to calculate the optimal transit between two given orbits, given the spacecraft's parameters (delta-vee and maximum acceleration, or exhaust velocity and mass ratio and maximum thrust, or power density and mass ratio), and the time of departure (along with the ability to calculate optimal and pessimal launch windows).

In the space-travelling future, navigators would have an advanced software suite that can accurately calculate not just the planetary-orbit-to-planetary-orbit transit but also seamlessly integrates the task of leaving a planet's Hill sphere, that allows them to key all sorts of elaborations on the basic plan like "what happens if we try a gravitational slingshot past Jupiter?", that keeps track of small objects and other spacecraft and can predict what mission plans detected spacecraft are likely to attempt given their current heading and (if the craft's performance is approximately known) how much leeway they have to deviate from it, that can plot intercept courses with those spacecraft, etc. Once this package is in common use among commercial spaceliners and ground traffic control, and has become reasonably easy to use, game designers would be able to easily plug the existing library into their games. For now, I'd settle for something with even a fraction of this functionality - or better yet, formulas I can understand that allow me to plug the calculations into my own frontends. The "I can understand" bit means that simplicity trumps accuracy (within limits) and clean formulas are preferable to numeric approximations where possible.

Currently I know how to calculate transits between circular orbits, with given delta-vee but unlimited acceleration, assuming optimal launch windows. (Assuming two-tangent transfers, which I'm not actually 100% sure are optimal.) That's about it. I'm fine with the circular orbit approximation, to keep the formulas simple, but the other limitations have got to go.

It's also important to ask what you're simulating. For an action game, you would need to simulate small scale maneuvers, while for a stragy game, you mainly need to know planet-to-planet courses and intercept courses. Traffic will look very different depending on whether you're simulating planetary orbital maneuvers, interplanetary transits, or deep space encounters. A real space navigation suite would be able to handle all of those, but for beginners, it's probably best to stick with one and model it closely.

Re: history simulation

I'm going to cite emergent complexity again. The challenge is to have a game model that's complex enough to do lots of stuff that neither the player nor the programmer expected. (If the player didn't expect it but the programmer did, then it's just a scripted or semi-scripted plot twist.) This requires modelling things in quite a bit of detail - tricky when the things you're modelling are human behavior!

Milo said...

Re: gamer types

The classification was originally applied to tabletop roleplaying games, where there are claimed to be three types of players:

Simulationists see the goal as portraying a fictional world realistically. They like realistic rules, obeying common sense, and modelling the world in a reasonably accurate and coherent manner (for example, having NPCs play by the same rules as PCs). Realism does not necessarily mean following real-life physics, although in a science fiction game, it tends to be assumed that you should at least have some technobabble explanation for anything that doesn't obey real physics. (Players will happily accept ships moving however you want them to in hyperspace, but if they still don't obey Newtonian physics after exiting hyperspace, people will complain.)

Gamists see the goal as figuring out how to build effective characters and teams to make use of the rules to take on challenges with as few resources as possible, often while earning loot/experience points that reward them with ways to increase their power. They like intricate yet well-balanced rule systems that give them a lot of options to play with, without making it obvious which are best. This doesn't mean they won't pay attention to the story, but they see it as a background element that justifies why their characters are fighting the enemies they're fighting, as opposed to the main focus of the game.

Narrativists see the goal as telling a story about the game's characters. They like rules which provide inspiration and encourage players to do cool stuff, and dislike plot-killer mechanics ("We need to deliver this ring to Mount Doom? Oh, I'll just cast a teleport spell.").

There can, of course, be a certain amount of overlap. If you look hard enough you can probably find something any given pair has in common with each other.

Also I typed this without looking anything up, but since this isn't exactly a highly scientific classification, I doubt any inaccuracies are going to be an issue.

Teleros said...

@ Geoffrey S H:
"My basic point is that while it is hard, it shouldn't be impossible to do. If invisible lasers are hard to do, then just an an infrared "visor" in-game to allow you to see them."
Oh I know, it's just one of those situations where the money's in much softer sci-fi.
On another note, I've been playing and enjoying Empire: Total War recently, but have missed a few things in that game (like, as Britain or the Netherlands, being able to borrow oodles of money rather than rely on the actual economy). Diplomacy was a bit simplistic too, but there we go. Still a good game.

@ Rick:
Thanks for the welcome - I've been reading a few of the other posts here, having discovered the blog via (where else) Atomic Rockets.

I agree with your point on keeping the maths out of sight, although some of that stuff may be good to include in a game. Say right-click an enemy ship to accelerate towards it, decellerate at the proper time automatically, and then attack at optimum firing range. Alt+right-click however will have your ship zip past and do a "drive-by shooting" with a much shorter engagement window - but with the downside that it'll be slowing to a stop waaaay over on the other side of the map. Or include a "radiator capacity" metre for each ship that shows how hot its radiators / heat sinks are - then let players overheat the ship (bad news for the crew of course) in battle if needed. Fog of war could also be handled with a little thought: rather than the usual cloud covering the map though you'd need to work out a means of using it to show players that due to lightspeed lag there are uncertainties in plotting enemy positions, with only a few situations (like fighting around a planet) being a case of "we don't know where they hell they are".

It'd certainly make a change to the old "Unit sight = 6" model that 90-odd % of RTS games use :P .

Milo said...

I don't think lightspeed lag is worth worrying about for a midfuture game... sure, information you get on Earth about ships at Saturn will be a few hours out of date, but how much are those ships going to have moved in those few hours when they're going at anything less than high-end torch speeds? Lightspeed lag will be factored into the weapons accuracy code if someone is crazy enough to try shooting across that distance (although I expect most lasers/particle beams will become ineffective due to diffraction long before they actually stand a significant chance of missing from lightspeed lag), but you're not likely to actually be able to see the uncertainty in the ships' position on the scale the map is shown in. (Ships are likely to be shown as stylized out-of-scale sprites, anyway. Either that, or microscopic dots.)

Anonymous said...

One approach that seems promising for making on a mobile without paying Jobs or suffering the pain that is AppStore on Android is to do it with javascript and the Canvas tag.
The canvas tag is a frame buffer that you can draw and animate stuff with Javascript. The buffer is hardware accelerated and works on all browsers except Internet Explorer.

Android and iOS has spent a lot of effort in accelerating the Javascript execution so performance should be less of a problem.

Safari has support for two and thre fingered swiping/zooming7pitching but I am not sure if Chrome has too, the Canvas tag is in the HTML 5 standard so it shoule eventually be adopted by MS.

DeviantArt has built a PhotoShop 'clone' out of JavaScript and the canvas tag - not suitable for mobile use but it will give you an idea on how powerful Canvas + Javascript is.

Geoffrey S H said...

Random thought: Space Freightor Tycoon.

Elukka said...

I've had that thought!

Rick said...

If the reference is to Railroad Tycoon, I have only the vaguest notion about it, but the idea cries out.

Basically you are talking about implementing the equivalent of Traveller, but with no need to buy into Traveller itself, because the player does not need to know any of the mechanics. At least until an advanced level. It is the basic Adventure Planet trope, 'implemented' in fiction since the Golden Age.

Yes, narrativist is the third leg of the triangle. I should have remembered this, because I'm basically right between simulationist and narrativist. I'm not really a gamer at all, but I have hung around gamers forever, and game systems fascinate me.

You can see it in the sort of economic modeling I do, an implicit framework for a cost system.

nyrath said...


nyrath said...

There is an interesting paper-and-cardboard space sim game in development called High Frontier. It is supposed to come out in October.

Rick said...

Didn't Phil Eklund design the game 'Rocket Flight,' that represented interplanetary movement by orbital energy level rather than literal representation of the orbit?