Difference between revisions of "Development:Quests"
m (→Quests, Missions, Campaigns & Adventures) |
|||
Line 96: | Line 96: | ||
</pre></code> | </pre></code> | ||
− | = | + | =Missions & Campaigns= |
==The first major campaign written (Jenek)== | ==The first major campaign written (Jenek)== | ||
See also the [http://vegastrike.sourceforge.net/forums/viewtopic.php?t=3246 forum thread] (comments & feedback) when this mission was first put into [[SVN]]. | See also the [http://vegastrike.sourceforge.net/forums/viewtopic.php?t=3246 forum thread] (comments & feedback) when this mission was first put into [[SVN]]. |
Revision as of 16:36, 14 April 2008
Development |
This page is meant to provide a platform for campaign/mission programmers to merge their ideas and best practices...
Contents
Python Scripting
Scripting Basics
VS has a lot of different ways of doing one thing. Just pick the most appropriate one for the job. It supports campaigns, missions, independent fixers, quests, etc., all of them having their specific ways of hooking them up into the game.
Quests are run inside of "random_encounters.py". If it returns 1 or True, it will keep going. If it returns 0, False or None (python returns None if you don't say what to return) then the quest will stop Execute()ing and be deleted until you jump into that system again or reload.
Each script requires at least those 2 elements:
-
def __init__ (self):
- here you initialize your script variables -
def Execute (self):
- this part is executed each simulation frame; this is the place for writing the actions of the adventure.
Most of the python bindings (to the c++ engine) are listed in data4.x/modules/stub/VS.py
and commented in HowTo:Edit_Missions:Python:Bindings:Python
Getting Objects
FIXME Improve/expand it.
In the script you will require to reference the objects of the universe. Here are some examples to get you started:
-
self.player = VS.getPlayer()
- that's you -
self.planet = unit.getUnitByName('Atlantis')
- get planet Atlantis -
self.station = unit.getUnitByName('MiningBase')
- get the mining base -
self.vessel= unit.getUnitByName('Ox')
- get an Ox ship -
self.gf = VS.launch("Charlotte the Harlot","Robin","privateer","unit","default",1,1,(1000,10,3000),)
- creates one ship of type "Robin", being of the faction "privateer", at position (1000,10,3000), which will behave like "default" and show up in the HUD as "Charlotte the Harlot"
Getting Properties
Once you have referenced the appropriate object, you want to get information about it. Again, some commented examples follow:
-
self.starttime = VS.GetGameTime()
- get the time since the start of the game. This is not the universe time (star date). -
self.planet.isDocked(self.player)
- verify if the player is docked to the planet. Note that you need to 'read' the meaning from right to left in this case. -
self.station.getDistance(self.player)
- The distance to the center of an object. Note that when landed on a planet, the distance is the actual planet radius. -
vec = self.player.Position()
- assign the player's position vector to a variable
Communications
Sending messages through the comm is fairly easy:
-
VS.IOmessage (0,"Oxen","all","Hi buddy.")
- make the vessel send a message to all through the comm immediately (the first 0) when the script line is executed. -
VS.IOmessage (10,"You","all","Do I know you?")
- makes the player send a public message through the comm 10 seconds after the script line is executed.
You can even set your own color for the messages with a html color code:
-
VS.IOmessage (20,"Oxen","You","#8080FFYou don't remember me?")
- prints the comm message in light blue.-
self.txtColor="#8080FF"
-
VS.IOmessage (30,"Oxen","Privateer",self.txtColor+"I hardly can believe this")
- you can even define a color variable and add it to each line.
-
As far as the communications go, there is a variable in cockpit that holds what the VDU screen shows as possible options. Unfortunately the communications system is not scriptable at the moment.
More Topics
FIXME Improve/expand it.
Flight Groups
You can use "flightgroup directives" to give units specific orders (which is cool if you want to generate two drones and make one blow up another)
The list of is in C++ (undocumented) but I've decided to look through the code. This should probably go to the wiki sometime
H,h (help) -- leader of flightgroup requests help. B,b (break and attack) -- default, everyone attacks like normal A,a (attack target) -- attack their current targets lowercase k -- something undocumented, says something about capships. Probably it's an order to take out capship turrets with priority, or it's a pure bomber order to attack capships and ignore fighters. F,f (flagship?) -- Ship being escorted. I would imagine that it's an order to attack a ship being escorted by the hostile faction. Alternatively, it could be an order to fly in formation. L,l -- undocumented, like F but has complicated formation rules. Could be a shortcut for "Leave" - ships heading out. E,e -- half of this is copy and pasted from L but I have no idea. I'd say it is "escort", escort a designated ship. P,p (protect)-- I want to help out
You can also add a "." to the end to ensure that the unit will not change targets on its own. Also, a capital letter overrides the AI script, and lower case will allow it to be changed.
Unfortunately I don't see any codes for acting like a sitting duck... You could try something like making it target itself, or making it target NULL (which you get by calling the constructor VS.Unit() ) and then using something like "A."
Or, just try doing a "B." and having it target you, and make sure it is friendly... then it might just fly near you.
I believe you can get it to fly places by having it target them and then force it to do unit.setFgDirective("B.") which I think forces it to act like normal and fly to this target.
Mission Testing
In order to speed up the scripting and testing for adventures that are not already Director.Missions, you can create a mission xml file and call the adventure file directly. In order for it to work properly, it must inherit the Director.Mission class *and* call its constructor. Unfortunately quests must inherit from the quest class, so you need to use a wrapper class that takes an instance of a class as an argument:
import Director
class Executor(Director.Mission):
def __init__(self, classesToExecute):
Director.Mission.__init__(self)
self.classes = classesToExecute
def Execute(self):
for c in self.classes:
c.Execute()
This is a very simple class, and it's similar to what privateer.py does. I'm just making it general by passing the list of classes as an argument.
Then, in the mission xml file, you need to call that class by adding the python section:
<python>
from quest_tutorial import Executor, quest_tutorial
tmpvar=Executor([quest_tutorial()])
</python>
Missions & Campaigns
The first major campaign written (Jenek)
See also the forum thread (comments & feedback) when this mission was first put into SVN. FIXME Improvements/expend it?