Monday, September 27, 2010

Star Maps

It's really common for star maps to be in 2D. I think this is unfortunate, so I'd like to talk about making the transition to a 3D star map.

The difficulty in a 3D star map is that the human mind really tends to think of surfaces rather than freefloating objects. Just look at how difficult it is to make out what is going on when looking down on scaffolding: how many levels high is it? Which slats are on which levels? This is a problem that many games are beginning to encounter as they try to build very high (tall) levels. Mirror's edge has some examples, as does Prince of Persia: it's easy to lose track of what is "beneath" you, even though you passed through a few moments ago. Which part of the level is that, down there?

And those games have it easy, because at least they're working with surfaces. A star map is just points of light.

There are several things we can do to ease the problems.

One is to introduce surface-like elements, including things like radial disks around certain stars, and trade routes that have broad, flat surfaces. It's critical to keep these things to a size that can be easily extrapolated, so you can tell the distance. Having a disk around a star that grows based on population makes it impossible to use that disk to determine what z-level the star is on. If the disk is always the same size, though, we can guess where the star is by looking at the perspective-induced difference is size.

Having a flat "z-surface" with "raised lines" is pretty common in games. This is descended from old submarine sims. I find this to be a pretty poor solution, only slightly better than no marks at all. A single flat surface with no relation to any of the actual points of light isn't a very useful surface, so the surfaces should integrate the stars.

Gently sliding the camera into position rather than simply "popping" into place is also somewhat useful, as it gives parallax information. This only works until the user switches screens due to the way we process visuals, so it might be useful to slide the camera into place every single time the user switches screens, even if the galactic camera has no reason to have moved. Even a tiny motion is sufficient to give parallax.

Keeping the same "up" and "north" is also useful. It's tempting to let the player control the pitch and yaw of the camera, since it's a 3D world and your instincts are based around flight sims and FPS games. But in actuality the only control the player needs is zoom: always keeping the same up, down, north, south, east, and west means that the players will be able to memorize the location of stars using the same faculties they use to memorize the location of the door in their room, an icon in their desktop, the shift stick in their car. Humans are bad at rotational pattern recognition, and there's no gameplay reason to allow rotation.

All of these will help, but they have the fundamental problem that they're still representing freefloating dots and rails rather than surfaces. It might be worthwhile to create surfaces instead. We can, for example, build a number of surfaces into the star region, and stars have to be on a surface. Due to the vertical requirements, the best solution is probably thick tubes or large freefloating objects instead of a terrain-like surface.

You will have problem with opacity, though: how will you see stars on the opposite side of an object, or occluded by an object? On the plus side, your travel routes could be inherently linked to the topology, making it feel like more than just a visual aide.

This brings up the problem of opacity in general. Stars are not the only things in space. Things like nebulae are often important tactical considerations, but rendering them is difficult to do without mucking up the display: large opaque blobs will hide everything inside them or on the other side. Also, since they are arbitrarily sized and shaped, it can be very hard to determine where in space they actually are.

National borders have the same problem: they are a 3D perimeter of arbitrary size and shape. How do you draw them so they don't confuse the viewer or obscure other important things? Transparency might seem like the answer, but in fact it just makes things even muddier.

I don't know if there's a perfect solution, but I'm playing with two solutions.

One uses the "stars on surface" approach as mentioned above, except that the "surface" is automatically generated to include all stars not part of your nation/reach. This essentially puts your nation inside a bubble. This has a lot of downsides, though. It requires that you have "flight sim" controls due to opacity issues, which in turn means that if your nation is larger than about a dozen stars, you start losing track and thinking of them as "those stars" rather than individual stars.

The other idea is the "panned opacity". I think of this like radar: the opaque walls of nebula and borders are drawn, but only in a transitory thin slice as the "scanner" travels. This seems to work okay, but it feels kind of "foggy".

None of this is necessary if you have a surfaced-based space, though: you can just color the always-visible surfaces the color of their owners.

Another "solution" is to simply radically downplay the importance of the 3D star map to the player. The AI can take advantage of that 3D space to build an interesting world, but the player's game takes place in a small enough region that he can't get lost. Also, if the player is an avatar instead of a nation, the player will have an easier time of it because they won't have to remember where every star is and what they are doing, just two or three.

What are your opinions on 3D star maps?

Sunday, September 26, 2010

Video and Details

Here's a YouTube video of ChinaSim and the new toy that can actually be seen in video. (As you'll see, ChinaSim is basically impossible to see in video.)


Anyway, one thing the sharp-eyed among you will notice is that the new toy has some distinct weaknesses, one of which is that the trade routes don't tend to run along rivers/coasts. That's not ideal, but I'm just showing the basics, so I didn't bother to refine it. Ideally, the contours of the land play a huge role in what cities can reach which cities: cities on the same river can trade with each other, and cities on a coast can reach a wide range of cities also on the coast. Mountains are hard to cross, and so on. The new sim has some aspects of that, but they weren't turned up enough since I didn't spend any time polishing it.

Another thing that you may have missed is that the ChinaSim cities modify the landscape, while the new toy cities don't. There are two reasons for this.

ChinaSim cities build a lot of stuff. They build farms and mines and such. When I originally built it, the idea was to be almost identical to something like Civilization: a resource-based building game. However, that stuff seems very minor in comparison to trade routes, so I left it out.

ChinaSim cities also chop down forests to bolster their economy. This is fairly realistic: even relatively early societies happily chopped down every tree they could find. It also serves as a handy limiter: when you're out of trees, you're out of an economic free ride. When your population outgrows the wilderness, you have to survive on your trade routes.

It's invisible, but ChinaSim also has a fertility rating for the land, which drains over time. This was implemented specifically to get large, flourishing civilizations to collapse, Fertile Crescent Style.

Those things can be added to the new toy, but even without them, sufficiently large nations tend to tear themselves apart into many smaller, independent nations. So there's no need to engineer a mass famine: the world will never consolidate (or never for long).

There are tons of things I could do with the new sim if I wanted to spend more time on it. One is to replace the per-pixel border claims with regional border claims. I want to split the map into regional blocks of maybe 8-30 pixels in area, split along natural boundaries such as slopes, rivers, and so on. With per-pixel claiming, the nations spend a lot of processor power just thinking about what to claim to what extent (hence the halfassed blotchy look you see in the video). With a regional claiming style, that could be eased and made more realistic.

While I've focused on computer algorithms that automatically generate a world, there are plenty of worlds that are not generated in that way. But hand-drawn worlds have many of the same features, and a game where the player is involved in building the world also has the same features.

Anyway, if you want any implementation details, comment here and I'll provide them.

Thursday, September 16, 2010

Spatial Play

Recently I've been talking about using transportation routes to define a world's civilizations, but I've had a hard time talking about why the play is deep. So I'm going to make a post about the fundamentals of constructive spatial play. IE, things like Sim City, rather than things like Halo.

Normally, a space is defined in terms of two basic principles: how easy a point in space is to cross, and what resources are available from a point in space.

For example, in Civilization you have plains tiles, which are easy to cross. Forest tiles are harder to cross (and give a combat bonus). Mountain tiles are impossible (or very difficult) to cross, as are water tiles. However, as time progresses, you learn to cross water tiles using boats - first shore tiles, then deep sea tiles. Later, flying units can also cross mountains.

This carves up the world into "slices" of land, and civilizations in different slices will have some time before they manage to cross over. Normally, the game Civilization downplays this by having technologies advance so fast that by the time you've finished exploring your starting zone, you have the transportation to move into the neighboring zones. Similarly, in space faring games, your range usually expands faster than you can colonize the stars you're currently limited to. A game where the land "slices" remain separate for longer would appeal to me, as it creates a chunky "settle-explore-settle-explore" feel. But I'm getting distracted.

The other half of a map are the resources available. Normally, the more construction-intensive a game is, the wider the variety of resources. If a game is combat-tactical instead, the resources are much more limited. This is because tactical games (such as Starcraft) lean far more heavily on the way space is carved up. While a Starcraft map won't be explicitly broken into zones, it will have many areas that are difficult to cross, creating an unusual topology that makes you have to think about exactly how you should proceed. Tactical games tend to focus on having a complex topology, rather than actually slicing up space into discrete areas.

Construction-centered games focus more on resources, and slice space up with simplistic abandon on the side. Games like Civilization don't simply feature food, work, and money as resources: they actively feature more than a dozen resource types including gems, whales, tribal villages, coffee... spacefaring games (four-X games) work similarly, with each planet varying by size, inhabitability, gravity, and half a dozen different fundamental resource types, quite separate from things like ruins, natives, and so on.

Okay, now let's work out some basic play models.

Both the tactical and the construction games work on the same fundamental idea: you stake out control over the valuable regions, you use them to expand your capabilities, and you defend them. In tactical games, the topology of the land plays a vital role, while in construction games it is the resources that tend to be more important. This is hardly and either-or, though: it's a sliding scale that varies not just between different games, but between different plays of the same game.

For example, in Starcraft you'll want to gain rapid control over your mining spots, even though they are not often topologically valuable. In Civilization, you may want to clamp down on a particular path specifically because your enemy will come through it, even though there are no resources to take advantage of.

Both kinds of game are about controlling specific points in space - a game of territory. The complexity comes when someone else is jockeying for position as well. Your territories bump up against each other. There is often a little bit of bumping, and then a war where each side attempts to strike deep into the other person's territory. There is no mixing - even the most advanced Civilization game doesn't really go any further than "allowing his troops to pass through your land", which is not really a fundamental part of play.

Now, if you use a transport-based system, things get a bit different. In a transport system, the resources on the land are probably of much less importance. Instead, what matters are the routes built to connect various points. The points themselves probably only have value based on their access to the kinds of spaces that are conducive to building routes. IE, probably rivers and oceans.

The fundamental difference between this kind of situation and the above situation is that it isn't about controlling land, it's about controlling movement. Nearly all economic strength comes from your trade routes - they're the most important thing to build. Please note that there doesn't even have to be any kind of specific goods traveling the route or anything: in most situations, just having a route and "traffic" is enough to do the sim. Generally, the further away the two tips are, the more valuable the route. And the busier the route, the more valuable the route.

Connections are a factor you can't forget, either. If A->B->C, then C should be getting some traffic from A, via B. Generally, this calculation is where the AI comes into play: it determines what percent of the traffic to send through to C instead of claiming for itself, and it determines the taxes on those goods. In the end, this resolves to a single percent: B keeps a specific percent for itself, C gets the rest of the economic boost. If B is part of the same nation, it may very well choose to let all of the traffic through. If B-town is part of a different nation, they may claim 100% unless C-burg's nation has some sort of treaty about it. Of course, B-town's flourishing economy will affect it's B->C route independently of A-ville. In terms of in-game flavor, C-burg will still get some of A-ville's products, but from B-town traders instead of direct.

This isn't really very complex, but as you can see, it starts to lead to a very different kind of play.

You can go to war. You can march down the roads into B-town and conquer them. But in the process, you'll probably destroy their economy, radically diminishing their ability to trade with you. With the trade routes not bringing in the traffic, you have just injured yourself by conquering the enemy.

Perhaps forcing B-town to send all of A-ville's trade straight through to C-burg will more than offset it, though. Or perhaps you should invade a city that is not actively trading with you. Or maybe you just want to claim that the river is yours, so you can tax the water trade on it (or benefit from whatever value that terrain has, in games where there are resources on the world map).

There are many factors: what makes a good target for conquest is no longer a matter of how rich and undefended they are, but whether conquering them makes any damn sense. Your neighbor is not automatically your enemy: the borders are not iron walls which nothing crosses.

The political game flourishes as well. For example, marrying one of your nobility to one of B-town's nobility is a good excuse to negotiate a more favorable trade status. B-town will send through a higher percentage of the goods from A-ville if you agree to bulk up the B->C trade road to prevent bandits and promote trade speed. If you're playing with cultural drift/unification, marrying will also bring the cultures closer together, or perhaps even inject your culture into their city without having much of their culture injected into yours.

What I'm trying to say is this: a resource-centric game is all about extermination. A trade/travel-centric game is all about interacting.

Games like Civilization have tried to add more and more cultural/trade stuff into their games with every generation. But they are missing the most crucial factor: they are still thinking in terms of controlling locations. They should be thinking in terms of controlling travel.

Sim City understands this to some extent, as roads and other means of travel are central to defining your city. However, if you control every road, there's not very much complexity in the roads themselves. Their only real purpose is to make sure that the traffic values don't get too high.

So, that's my commentary on constructive spacial play. What do you think?

Tuesday, September 14, 2010

Economies and World Building

I just got into a spirited discussion about economies in world-building (either for a game or just as a setting). The discussion revolved around what factors are important - food, energy, building materials, etc, etc. I quickly derailed it into a pages-long argument for transportation being the only thing that really matters.

This post is pretty much a technical description of why I say that, and what my experiences have been. If you're not into world-building, skip this.

When I'm world building, regardless of technological level, the first thing I think of is transport. How do goods and information get from one place to another?

Some of the people arguing against my position take the position that, at least in high-tech environments, transportation is cheap enough to disregard. However, regardless of price, transportation is what enables the growth of economies. All economic centers are also transportation hubs. This is a symbiotic rather than a causal relationship: a stronger economy promotes more import and export, and more import and export promotes a stronger economy. This is not simply a function of infrastructure, either: it's a fundamental matter of how humans think and plan.

Having built many worlds with this philosophy, I can say that it allows you to quickly and fluidly generate a dense and real-seeming set of nations and cities, regardless of technological level or what economic rules you have underlying the simulation. This is because almost everything about a city and nation is heavily influenced by how many transport routes they have running to/through them, and how open/closed/taxed those routes are.

Things like war, disease, and the spread of culture all happen along transport routes, all of which are marked by a size denoting their max load. Size is not length: it's the amount that can be transported in a time unit, which includes not just the actual road/river/spacelane in question, but also the docks on the tips. Safety can be assumed to be a function of size. Things like strife and war can also be fairly reasonably simulated using nothing but transport lines to determine how nations feel about each other, as long as those transport lines include a rating not just of size, but also of taxation/closedness.

Example: it's ancient times, farming's just been invented, and we use a random seeding system to create tiny little villages. After that, everything is determined by the trade routes. Rivers and coasts are easy to transport along since you only have to build some docks, and roads can be built if you take an economic hit for the initial investment. Not a certain amount of money, but a decrease in your "economic rank".

Speaking from experience trying to simulate a China-like environment, what we find is pretty realistic. Cities rise up on rivers and deltas and coastlines. A network of roads springs up as well, but inland cities never get very far. Not because they lack resources, but because cities on rivers and oceans have a strong head-start by then and dominate the route-building game.

In late game, cities will pop up on land routes simply because the land route is there. This, too, is realistic. Add in a random assortment of disasters that can damage trade routes, and you get a pretty reasonable feeling of organic complexity.

Adding some political acumen to the game works flawlessly, and you can see the borders form and wars start... based almost entirely on the idea of jockeying for transport hubs and routes. A second layer of restricting transport along certain routes or to certain countries further extends this political spectrum and, at this point, it becomes close to realistic. Adding in a dash of mutating culture and you have something that can pass muster with ease.

Of course, this can all be done manually, as well. I find most people manually building worlds end up thinking in terms of transportation, anyway.

A high-tech example: you have FTL drive and are all about building colonies on planets. You rank various planets with a basic "economic value". It's not even important whether the value is food-based, ore-based, or scientific-oddity-based.

The cost transporting world-to-world within a star system is low and flat, the cost for transport between star systems is per light year. All transport must be along defined "routes", but defining a route is cheap, consisting of building a landing dock.

With these simple rules and a completely random star/planet layout, you will quickly find a dense web of trade routes that ends up almost identical to the one in our primitive version. The biggest difference is that we're now working in 3D rather than 2D. The difference is subtle at the moment, but if we add in the "upper layers" of the simulation to get political, the 3D world makes for some very odd political maneuvers.

If we add in wormholes for very cheap long-range transport, wormhole star systems become the most valuable, and almost instantly become massive centers of commerce: just like you'd expect, when you "cheat", you win.

Let's turn around and say that you don't need to define routes: any route is fine. This is actually unrealistic, since established trade routes are more than just a landing bay at each end. An established route is important for insuring company longevity, so companies would naturally start to form specific trade routes even in the absence of any physical need to. It's the nature of trade.

But ignoring that, even when treating every shipment with its own independent path-finding, we still end up with trade routes as they follow the same best path every time. The differences are actually pretty minor, although they grow more extreme as the simulation continues if you continue to disregard things like policing routes, taxing/banning trade, and so on.

Another factor that can be fun to include would be information transport routes. This is especially fun if the information transport system is fundamentally different from the physical transport system, ending up with a complicated "two-map" set of trade routes. Either way, it's a lot of fun if we presume that economies are two-stage: initially, goods are what matters, and the physical trade routes are stressed. As the economy grows past a certain point, goods plateau or even begin to decrease in importance and information creation/transport rapidly grows more and more important (exponentially). Info transport and creation can also be the primary source of technological and cultural innovation.

ANYWAY, this post is all about my pet peeve, so it was a bit dull. The basic lesson is: if you ignore transport in your world-building, you are ignoring a major source of depth.

What's your experience?