Pre-Order the Game!

Desura Digital Distribution

Tuesday, February 7, 2012

Technology Scripts

Warning, this post will be highly technical and is not for the faint of heart!

My goal is to make the technology very flexible in the game. In order to do this, I need to create a consistent scripting system that all technologies can share. So a shield technology will share the same system as a beam weapon for example.

I realized that I can't have one script that handles both input from user and particle/ship effects. If I were to fire a laser cannon 10 times, and the delay between them is not enough for one to fade out before firing another, how should the script handle that? So I will split the scripting system into three parts:

The technology script
The particle script
The effect script

I will explain what each of those does, starting with the technology script. This is the backbone of the whole system, it handles input from the user, as well as collision checking/detection. It also determines the target crosshair size - For example, if it's an engine or teleporter, it would return the ship's size resulting in the current ship's size for target movement. If it's an weapon, it would return 1, as a normal crosshair. If it's an effect such as auto-repair, it would return 0, no crosshair.

Why the collision checking/detection? Let's say that you have an shield technology with a range of 1 (about 1 grid cell around your ship). Anything that overlaps this (including ships and weapons) will trigger collision handling. So if a shield technology is triggered, it would call "DoCollision" and reduce the item's damage by a specified value. However, it's not limited for shields. One example is that you have an anti-missile equipment, and it have a range of 4. Missiles entering this range would trigger the anti-missile's "DoCollision" which in turn fires a weapon at the missile. Or if you have a repulsing weapon, it will automatically trigger and spawns a repulsing beam at the target ship, pushing it away.

Most items won't have collision, so they'll have range of -1, meaning no collision at all. Armor will have collision of 0, meaning that it's triggered first before hitting the components in the ship. But what if you want to add an technology that absorbs some of the damage and converts it into energy for the reactor or a weapon? Then you'd put range of 0, moving it up into the "armor" position therby triggering the "DoCollision". Any remaining damage will be distributed among the internal components, including armor and shield. So if no damage reaches -1 range, no components are damaged. The order of DoCollision processing are done using the order of components in the ship. So if you put an item that converts part of the damage into energy above the armor, that item will be processed first, otherwise the armor will be processed first before that item. It don't affect how much damage actually hits the ship, because all of the range 0 components will be processed before reaching the -1 range

Now, the particle script. This will handle the "visual effects" and data of weapons, shields, and any other non-ship graphics. It is called from the technology script, and expires after a certain time period. For example, if I have an laser cannon, and I fires it at a ship, the game would call the Laser technology script's "DoAction()" and it would spawn a "Laser Particle" with values passed in. The game will draw and update all particles simultaneously. So if a laser beam hits a ship's shield, that shield script would spawn a "shield particle" that's basically just eye candy to indicate that it hit the shield, and both shield and laser would be drawn at the same time.

Each particle will be a separate instance, so if you fire 5 bullets at a ship, each bullet are handled individually. A particle script also handles the updating, so if a particle moves in an oscillating fashion (wave weapon for example), it would update the position of the particle. So you could create a weapon that fires a "blinking" bullet that phases out and teleports to the other side of the map using the script's update functionality. It also handles collision, so if it impacts something, it will call 'OnHit' function. If it's a fragmentation weapon, it would spawn 10 "shrapnel" particles in random directions.

Now finally, the last script: Effect scripts. This is different from particles in that it's for ships. It handles the visual effects for ships, as well as other data related to the ship. Let's use a couple of examples to illustrate:

If you have a teleporter item, activating it when clicking on a position will spawn "StartTeleport" effect that adds the visual effect of the ship fading out or disappearing. When the StartTeleport expires, it spawns "EndTeleport" which handles the "fading in" or re-appearing of the ship, as well as moving the ship to that position.

Another example would be cloaking. It would use a particular shader to make it partially invisible to the owner, and completely invisible for others. It does not change the ship's position or anything.

Last example, if you have a statis weapon, and you hit a ship with it, it would spawn a "Statis" effect on that ship, rendering it frozen and unable to perform any actions.

So in sum:
Technology Script - Handles input from users/AI, handles collisions, can spawn particles or effects
Particle Script - Manages one particle (beam, shield, etc), and handles that particle's position, collision and visual effect - can spawn other particles or effects.
Effect Script - Manages one effect (frozen, cloaking, etc), can spawn other effects.

I think this will be a very robust system allowing people to create very creative technologies. The only limitations would be the memory and speed of the computer handling the game :) If limitations are encountered in the future, I will look into expanding the functionality. The goal is to not write a specific functionality for just one item in the game itself, but to have that supported through the script system.

In a unrelated topic, I've submitted my game to Desura for review last night, and am now awaiting their response. I will let you know as soon as I find out the result!

1 comment:

  1. Good luck! And the tech script system sounds great.

    ReplyDelete