Dynamic Scenarios

As of Solar Vengeance 5, Build 6, Dynamic Scenarios are supported.  This allows you to program your own behavior into the game the executes on an impulse by impulse basis.  The key to this new, powerful functionality, is overriding the ProcessImpulse method, accessing the SVGame object via the Game property, and modifying the game state by using the Dynamic Scenario methods described here.

Warning: Do not modify any game state without using a Dynamic Scenario (DS) method!  If you do, the changes will not propagate to others in a Multiplayer game.

public virtual void ProcessImpulse(int impulse)
SV5 calls this method in your Scenario on every impulse, for every player in a MultiPlayer game.  It allows you to hook into the game and provide your own behavior.  You can examine the internal game state by using the Game property, which returns an instance of the SVGame class.  This class contains all of the internal state of the game, including lists of StarShip objects (the StarShips property), StarSystem objects (the StarSystems property) and the ability to examine the map (GetTerrain and GetObjectAt methods).  Use Visual Studio Intellisense to examine the various public properties and methods available in the Game object.  If you have questions about how to achieve a desired result, post it to the Silicon Commander Games message board.

Dynamic Scenario Game object Methods

The methods of the SVGame class mentioned below are specially created to be called from your Scenario's ProcessImpulse method.  They allow you to safely change aspects of the game state.  To call one of these methods, use the Game property.

Example:

int randomNumber = Game.DS_Random(1, 100);

public void DS_AdjustShipValues(StarShip ship, int engines, int maxEngines, int value, int maxValue, bool repsectFixedValues)
Adjusts the current, and maximum, engine and primary system values for the specified StarShip.  If respectFixedEngineValues is false, the method even allows you to override the normal fixed engine values of StarShips (such as the E1 Emines) and assign "values" to StarShips that normally don't have them (like Drones).  See the HighEnergy.cs Scenario for an example.

public BlackHole DS_CreateBlackHole(int x, int y, int radius)
Creates a new BlackHole on the map at the specified location.  The "radius" parameter indicates how close StarShips need to get before getting pulled toward the BlackHole.

public void DS_CreateExplosion(int x, int y, int particles, Color startColor, Color endColor, int startDiam, int endDiam, int lifeSpan)
Produces an explosion on the map, and optionally plays an explosion sound.  The explosion is particle-based, and you control the various aspects of it via the parameters.  The number of particles in the explosion is determined by the "particles" parameter.  Each particle will be a random color ranging from "startColor" to "endColor".  Note that you can apply alpha values to "startColor" and "endColor" to get more interesting effects (for example, Color.FromArgb(20, Color.Black) for "startColor" and Color.FromArgb(255,Color.Red) for "endColor".)  Each particle is a random size in pixels between "startDiam" and "endDiam".  The explosion's life span is controlled by the "lifeSpan" parameter, expressed in animation cycles.

public Pulsar DS_CreatePulsar(int x, int y)
Creates a new pulsar on the map.

public StarShip DS_CreateStarShip(int x, int y, Player owner, StarShipType shipType, int engines, int extra, bool cloaked)
Creates a new StarShip on the map at the specified location.

public StarSystem DS_CreateStarSystem(int x, int y, int value, int shields, int scanners, double resources)
Creates a new StarSystem at the specified location with the specified properties.  You can change aspects of the StarSystem further by modifying its properties, such as Name, BonusShipType and BonusValue.

public Wormhole DS_CreateWormhole(int x, int y, int destX, int destY)
Creates a new Wormhole on the map, with the specified location and destination point.

public void DS_DamageStarShip(StarShip ship, int damage)
Inflicts damage to a StarShip in the amount specified in the "damage" parameter.  Will destroy the StarShip if Engines or Primary System falls below zero.  This is the preferred method for reducing a StarShip's strength, although you can also AdjustStarShipValues, and not get the explosive effect.

public void DS_DestroyStarShip(StarShip ship)
Destroys the specified StarShip outright.

public void DS_DisplayMessage(string msg)
Displays a Scenario message on the map the the player will have to clear by clicking an OK button.  You should only call this method on a specific numeric Impulse, or when a specific event occurs that will not be repeated.  Otherwise, the message will continually appear on top of the map.

public void DS_MoveStarShip(StarShip ship, int x, int y)
Causes a StarShip to smoothly move toward the specified destination.

public int DS_Random(int maxValue)
Returns a random integer with the specified maximum value.  Be sure to use only this random number generator within ProcessImpulse.  It uses a specially seeded RNG to ensure that all players in a MultiPlayer game get the same sequence of random numbers and do not wind up out of synch.

public void DS_RelocateObject(SVMapObject svm, int x, int y)
Use this method to re-position an object on the map.  The SVMapObject is the base class for objects that can be found on the map.  The following classes are derived from SVMapObject: StarShip, StarSystem, BlackHole, Wormhole and Pulsar.  You should use this method if you want to reposition an object, rather than changing its location explicitly in your code.

public void DS_RemoveObject(SVMapObject svm)
Removes an object from the map.  SVMapObject is a base class that all map objects descend from, including StarShips, StarSystems, Pulsars, BlackHoles and Wormholes.  So, you can pass any of these objects into this method to remove them from play.

public void DS_SetBlackHoleRadius(BlackHole bh, int radius)
Allows you to dynamically change the radius of a BlackHole.

public void DS_SetTerrain(int x, int y, char terrain)
Allows you to change terrain on the map dynamically.  The current supported terrains are an empty space (' ') for clear terrain, and 'N' for Nebula.

Example

See the Scenario "HighEnergy" for an example of a Dynamic Scenario.  It examines all StarShips, and any of them that are within the central Nebula have a 10% chance per Impulse of having their primary system (Weapons, Scanners, etc.) increased by 1.