|
|
(13 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
− | {{parent_link|parent=[[Development]]}}
| + | This page is meant to provide a platform for campaign, mission, and quest & adventure programmers to describe the python scripting mechanisms and merge their ideas and best practices... |
− | ----
| |
− | {{Template:Spoiler}}
| |
| | | |
− | This page is meant to provide a platform for campaign/mission programmers to merge their ideas and best practices...
| + | =Campaigns, Missions, Quests & Adventures= |
| | | |
− | =Python Scripting= | + | ==[[Development:Campaigns|Campaigns]]== |
| + | '''Campaigns''' describe the overall plot in which the player is involved. From the campaigns various missions are given depending on the progress of the universe and its various conditions. |
| | | |
− | ==Scripting Basics==
| + | For more information, head over to [[Development:Campaigns]]. |
| | | |
− | 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.
| + | ==[[Development:Missions|Missions]]== |
| + | '''Missions''' can be nodes of a campaign or independent missions available through fixers or the mission interface. |
| | | |
− | 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.
| + | For mission editing, refer to [[Development:Missions]]. |
| | | |
− | Each script requires at least those 2 elements:
| + | ==[[Development:Quests|Quests and Adventures]]== |
− | * <code>def __init__ (self):</code> - here you initialize your script variables
| + | '''Quests''' are equivalent to '''adventures''' and are independent events that happen in specific systems when the player is there. |
− | * <code>def Execute (self):</code> - 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 <code>data4.x/modules/stub/VS.py</code> and commented in [[HowTo:Edit_Missions:Python:Bindings:Python]]
| + | A description on creating quests can be found in [[Development:Quests]]. |
| | | |
− | ==Getting Objects== | + | =Common References= |
− | {{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:
| + | Python scripting reference for campaigns, missions, and quests. |
− | * <code>self.player = VS.getPlayer()</code> - that's you
| |
− | * <code>self.planet = unit.getUnitByName('Atlantis')</code> - get planet Atlantis
| |
− | * <code>self.station = unit.getUnitByName('MiningBase')</code> - get the mining base
| |
− | * <code>self.vessel= unit.getUnitByName('Ox')</code> - get an Ox ship
| |
− | * <code>self.gf = VS.launch("Charlotte the Harlot","Robin","privateer","unit","default",1,1,(1000,10,3000),'')</code> - 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== | + | ==Explanations== |
− | Once you have referenced the appropriate object, you want to get information about it. Again, some commented examples follow:
| |
− | * <code>self.starttime = VS.GetGameTime()</code> - get the time since the start of the game. This is not the universe time (star date).
| |
− | * <code>self.planet.isDocked(self.player)</code> - verify if the player is docked to the planet. Note that you need to 'read' the meaning from right to left in this case.
| |
− | * <code>self.station.getDistance(self.player)</code> - The distance to the center of an object. Note that when landed on a planet, the distance is the actual planet radius.
| |
− | * <code>vec = self.player.Position()</code> - assign the player's position vector to a variable
| |
| | | |
− | ==Communications== | + | ===[[HowTo:Edit_Missions:Python:Summary|Summary about Python-Vegastrike Class Relationships]]=== |
− | Sending messages through the comm is fairly easy:
| |
− | * <code>VS.IOmessage (0,self.vessel,"all","Hi buddy.")</code> - make the vessel send a message to all through the comm immediately (the first 0) when the script line is executed.
| |
− | * <code>VS.IOmessage (10,self.player,"all","Do I know you?")</code> - makes the player send a public message through the comm 10 seconds after the script line is executed.
| |
| | | |
− | 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.
| + | ===[[HowTo:Edit_Missions:Python:Bindings|Python - Vega Strike Bindings]]=== |
| | | |
− | ==More Topics== | + | ===[[Development:Python:AI Scripts|Python Inheritance with AI Scripts]]=== |
− | {{Fixme}} Improve/expand it.
| |
| | | |
− | ==Flight Groups== | + | ==Implementation References== |
− | 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)
| + | ===[[HowTo:Edit_Missions:Python:Bindings:CPP|VegaStrike C++ Functions Listing]]=== |
| | | |
− | The list of is in C++ (undocumented) but I've decided to look through the code. This should probably go to the wiki sometime
| + | ===[[HowTo:Edit_Missions:Python:Bindings:Python|VegaStrike Python Functions Listing]]=== |
| | | |
− | H,h (help) -- leader of flightgroup requests help.
| + | ===[[Development:Python:Functions|Useful Python Functions]]=== |
− | 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:
| |
− | | |
− | <code><pre>
| |
− | 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()
| |
− | </pre></code>
| |
− | | |
− | 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:
| |
− | <code><pre> <python>
| |
− | from quest_tutorial import Executor, quest_tutorial
| |
− | tmpvar=Executor([quest_tutorial()])
| |
− | </python>
| |
− | </pre></code>
| |
− | | |
− | =Quests, Missions, Campaigns & Adventures=
| |
− | ==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]].
| |
− | {{Fixme}} Improvements/expend it?
| |
| | | |
| =See also= | | =See also= |
− | * [[HowTo:Edit Missions]]
| |
| * [[HowTo:Edit News]] | | * [[HowTo:Edit News]] |
| * [[HowTo:Add Conversations]] | | * [[HowTo:Add Conversations]] |
| | | |
| [[Category:Development|Quests & Campaigns]] | | [[Category:Development|Quests & Campaigns]] |