TCFH helicopters
NEWSTHE GAMESCREENSHOTSFAQPRESSABOUT USEXTRAS
Tech FXHaiku Kaiju ReviewDesktop WallpaperSend Us Your Screams!Monster Personality Quiz
GETTING TECHNICAL
You may have seen Ray Harryhausen credited with Technical Effects (meaning special effects) for his amazing stop-motion animation in movies like Mighty Joe Young, It Came From Beneath The Sea, and The Beast From 20,000 Fathoms. Well, this column isn't really about special effects, just technical game details and behind-the-scenes programming stuff that we thought you might find interesting. We'll be updating it regularly, or whenever Lars thinks of something.

12/18/03: THE ONE ABOUT ARTIFICIAL INTELLIGENCE

ONIONS HAVE LAYERS. OGRES HAVE LAYERS. AI HAS LAYERS.
The AI system in TCFH is broken up into several layers, which follows a basic command and control hierarchy and simulates some aspects of a real world chain of command, including coordination, breakdown, imperfect information, and propagation delay.

At the top, there's a high level strategic layer, which makes decisions about overall strategy, what units & weapons to dispatch, etc. and basically tries to play as a human opponent might.* It deals with the overall goals, like "win the game". Goals are broken down into smaller and more specific chunks until they can be distilled to a simple yes/no decision or linear value.

For example, "win the game" breaks down into "how?". "Kill the monster" would be one answer ( but not necessarily the only one -"drive the monster away" or "starve the monster" might also be valid strategies). OK, so now we know we want to kill the monster...how? "Attack it with weapons and units" is again the obvious (but not only) answer. What weapons should I use? Those that would be most effective and cause the least collateral damage, of course. OK, how do we know what weapons are most effective? Take a look at each available weapon choice and compare it to what we currently know about the monster's weaknesses, factor in some range, accuracy, and damage modifiers, carrying unit's mobility and strength, maybe some considerations for cost and risk of collateral damage. Give it a resulting net score. Comparing all the weapons, you have your optimal weapon choice based on your weightings and current priorities.

Once the basic goals have been broken down into some concrete algorithms and formulas, more complexity and randomness can be added so the results are interesting and unpredictable. Applying some hysteresis and fuzzy logic in the decision making are also probably good ideas. Of course, tweaking and tuning those weights and factors is pretty important to a smart AI, but that's why God invented .ini files.

Beneath the strategic layer there's a tactical layer, where individual units manage their own actions. Units are issued broad orders like "attack your current target!" (which is usually - but not always - the monster) and they have to figure out how to best do that. They have to get in range and firing position, pick their weapon(s), aim, shoot, evade if in immediate danger, etc. Things like pathfinding, checking the hazard map, checking line of sight to target, following roads, etc. are all done at this level of AI. Generally units follow their orders until that order is complete or expired, and then request a new order from the strategic AI, which must coordinate actions between large units and making decisions about best places to attack from, what's important to defend, etc.

Some units also have a middle layer of command and control providing some extra coordination as well, like soldiers following orders from their squad leader, moving in formation or getting permission to open fire (while their squad leader gets orders from the strategic AI). If a squad leader is killed, morale and organization in the squad collapse and the remaining members start acting independently, but also more chaotically.

CHEATING IN THE RIGHT WAYS
Off on the side of the military chain of command is the high level civilian AI system, which is responsible for maintaining population levels, directing traffic, and managing the city simulation. For example, it's responsible for making sure people are near the monster and not wandering the unseen portions of the map. The city is very large, and there are often 2000 people or more on a single screen. If the city was really that densely populated all over, that would be hundreds of thousands of people, all taking up CPU time and affecting nothing of significance. That would be wasteful, since you only see 0.5% of them at any given time. Instead I cheat (gasp!) and maintain an active dense population only around the monster. The rest of the city is, in reality, a ghost town.

Likewise, while cars do exist everywhere at once, cars that are offscreen drive at a much reduced level so they don't tax the CPU. Buildings stop animating when they're not visible. A good part of AI programming is cheating in the right ways. Anyway, so there's a civilian manager that's shuffling things around in the city behind the scenes to give the player an impression of a fully populated huge city even though he can only see a small window of it at any one time. Military and special units, and effects like fire or radiation are processed completely at all times, no matter where they are, because there are fewer of them and they have a bigger impact on the gameplay - so those aren't fudged.

* this would be the part controlled by the human player, if and when we expand the game to let the player play the human side.

-- Lars

PREVIOUS ARTICLES:

delicious popcorn© 2004 Octopus Motor
They Came From Hollywood is a registered trademark of Octopus Motor
red hot zeppelins