Index: /code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw
===================================================================
--- /code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw	(revision 10886)
+++ /code/branches/campaignHS15/data/levels/shuttleRetaliation.oxw	(revision 10887)
@@ -42,14 +42,24 @@
     <?lua
 
-        units = 1
+        enemies = 4
+        allies = 4
+
+        radSector = 12000
 
         --[[ Coordinates in (y,z,x). NOTE: Indexing starts at 1 in lua! Don´t forget to adapt the for loops, too! ]]--
         cCenter = {0, 0, 0}
-        cSpawn = {-2000, 2000, 2000}
-        cSector = {2000, 2000, 2000}
-        cBeacon = {1500, 1500, 1500}
-
-        cAlly1 = {-100, 0, 0}
-        cEnemy1 = {1000, 0, 0}
+        cSpawn = {1500, -2000, 900}
+        cSector = {-15000, -5500, -9000}
+        cSectorEntry = {-4710, -5500, -2826}
+        cPathToEntry = {{0, -2000, 0}}
+        cBeacon = {-6500, -5500, -4400}
+         cAllyWait = cBeacon
+
+        cAlly = cSpawn
+        cEnemy = {-9600, -5500, -6000}
+
+        rSection= {0, -200, 0}
+        rWingman1 = {0, -100, 100}
+        rWingman2 = {0, -100, -100}
 
         cPlanet1 = {-9000, -8000, 14000}
@@ -65,4 +75,9 @@
         function printC(coord)
           print(coord[1] .. [[,]] .. coord[2] .. [[,]] .. coord[3])
+        end
+
+        --[[ Function to add Coordinates.]]--
+        function addC(coord1, coord2)
+            return {coord1[1]+coord2[1], coord1[2]+coord2[2], coord1[3]+coord2[3]}
         end
     ?>
@@ -74,31 +89,100 @@
     >
 
-    <TeamSpawnPoint name="playerSpawn" team=0 position="<?lua printC(cSpawn) ?>" lookat="<?lua printC(cCenter) ?>" spawnclass=SpaceShip pawndesign=spaceshipescort />
-
     <WorldAmbientSound source="Earth.ogg" looping="true" playOnLoad="true" />
 
-    <Light type=directional position="<?lua printC(cCenter) ?>" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
+    <Light type=directional position="<?lua printC(cSpawn) ?>" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
+
+    <!--SPAWNING-->
+
+    <Template name=commander>
+        <SpaceShip
+            template            = "spaceshipassff"
+            team                = "0"
+            health              = "800"
+            initialhealth       = "800"
+            maxhealth           = "1500"
+            shieldhealth        = "80"
+            initialshieldhealth = "80"
+            maxshieldhealth     = "120"
+            shieldabsorption    = "0.8"
+            reloadrate          = "1"
+            reloadwaittime      = "1"
+            name                = "commander"
+            radarname           = "Commander"
+            >
+            <attached>
+                <DistanceTriggerBeacon name="Commander" />
+            </attached>
+        </SpaceShip>
+    </Template>
+
+    <Template name=ally>
+        <SpaceShip
+            template            = "spaceshipassff"
+            team                = "0"
+            radarname           = "Ally"
+            lookat              = "<?lua printC(cPathToEntry[1]) ?>"
+        >
+            <attached>
+                <DistanceTriggerBeacon name="Ally" />
+            </attached>
+        </SpaceShip>
+    </Template>
+
+    <Template name=enemy>
+        <SpaceShip
+            template            = "spaceshippirate"
+            team                = "1"
+            radarname           = "Invader"
+            lookat              = "<?lua printC(cBeacon) ?>"
+            active              = false
+            visible             = false
+        >
+            <attached>
+                <DistanceTriggerBeacon name="Enemy" />
+            </attached>
+        </SpaceShip>
+    </Template>
+
+    <TeamSpawnPoint active=false name="playerSpawn" team=0 position="<?lua printC(cSpawn) ?>" lookat="<?lua printC(cPathToEntry[1]) ?>" spawnclass=SpaceShip pawndesign=commander>
+        <events>
+            <activity>
+                <EventTrigger invert=true>
+                  <events>
+                    <trigger>
+                      <EventListener event="reachedSector" />
+                    </trigger>
+                  </events>
+                </EventTrigger>
+            </activity>
+        </events>
+    </TeamSpawnPoint>
+
+    <TeamSpawnPoint active=false name="altSpawn" team=0 position="<?lua printC(cBeacon) ?>" lookat="<?lua printC(cSector) ?>" spawnclass=SpaceShip pawndesign=commander>
+        <events>
+            <activity>
+                <EventListener event="reachedSector" />
+            </activity>
+        </events>
+    </TeamSpawnPoint>
 
     <!--QUEST DEFINITIONS-->
 
     <GlobalQuest id="quest1">
-        <QuestDescription title="Enter Sector 5C" description="It is time to retaliate against the aggressors. Get back to Sector 5C to kill every last one of them!" failMessage="" completeMessage="" />
+        <QuestDescription title="Enter Sector 5C" description="It is time to retaliate against the aggressors. Get back to Sector 5C to kill every last one of them! We have you covered with <?lua print(allies) ?> of our finest Divisions. They will guide, help and protect you if necessary." failMessage="" completeMessage="" />
         <hints>
+            <QuestHint id="quest1hint1">
+                <QuestDescription title="Markings" description="We have marked the bounds of Sector 5C in red lights, you can follow the green trail to get there." />
+            </QuestHint>
         </hints>
-        <complete-effects>
-            <AddQuest questId="quest2" />
-        </complete-effects>
     </GlobalQuest>
 
     <GlobalQuest id="quest2">
-        <QuestDescription title="Find them" description="It seems they have hiden themselves, that is, their whole civilization, in fear of retaliation. Our scientists presume some cloaking technology to be in use. Look out for a way to make the aggressors visible!" failMessage="" completeMessage="" />
+        <QuestDescription title="Find them" description="It seems they have hidden themselves, that is, their whole civilization, in fear of retaliation. Our scientists presume some cloaking technology to be in use. Look out for a way to make the aggressors visible!" failMessage="" completeMessage="" />
         <hints>
             <QuestHint id="quest2hint1">
-                <QuestDescription title="The detector beacon" description="Our scientists claim cloaking is generally toggled by a visible Switch called a detector beacon. Try to find a bright light in your Area and approach it" />
+                <QuestDescription title="The detector beacon" description="Our scientists claim cloaking is generally toggled by a visible Switch called a detector beacon. Try to find a bright light in your Area and approach it!" />
             </QuestHint>
         </hints>
-        <complete-effects>
-            <AddQuest questId="quest3" />
-        </complete-effects>
     </GlobalQuest>
 
@@ -109,11 +193,33 @@
         <complete-effects>
             <AddQuest questId="quest4" />
+            <AddQuest questId="quest4.1" />
+            <AddQuest questId="quest4.2" />
+            <AddQuestHint hintId="quest4.1hint1" />
+            <AddQuestHint hintId="quest4.2hint1" />
         </complete-effects>
     </GlobalQuest>
 
     <GlobalQuest id="quest4">
-        <QuestDescription title="Destroy their civilisation" description="You have successfully uncovered their civilization and home planet, and it is much worse than we thought... they came prepared! You have to fight their army to fulfill your mission." failMessage="" completeMessage="" />
+        <QuestDescription title="Do the right thing" description="The aggressors have surrendered and seem to have had good reasons for their actions. Yet they did not talk to us beforehand and tried to kill us. What will you do?" failMessage="" completeMessage="" />
         <hints>
         </hints>
+        <subquests>
+            <GlobalQuest id="quest4.1">
+                <QuestDescription title="> Destroy their civilisation" description="Even if they had reasons, they are still murderers and can not be trusted anymore. This whole thing might even be a setup... We need to kill them and destroy their planet!" failMessage="" completeMessage="" />
+                <hints>
+                    <QuestHint id="quest4.1hint1">
+                        <QuestDescription title="Choosing" description="To make this choice, kill one of the remaining enemy ships. The divisions will follow your decision." />
+                    </QuestHint>
+                </hints>
+            </GlobalQuest>
+            <GlobalQuest id="quest4.2">
+                <QuestDescription title="> Spare them and leave" description="Military tension arising from a missunderstanding is no valid reasoning for a genocide. Nothing is. We should leave and talk this out later." failMessage="" completeMessage="" />
+                <hints>
+                    <QuestHint id="quest4.2hint1">
+                        <QuestDescription title="Choosing" description="To make this choice, fly away from the remaining enemy ships. The divisions will follow your decision." />
+                    </QuestHint>
+                </hints>
+            </GlobalQuest>
+        </subquests>
     </GlobalQuest>
 
@@ -131,10 +237,10 @@
     </EventMultiTrigger>
 
-    <DistanceTrigger name="reachedSector" position="<?lua printC(cSector) ?>" distance=1000 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true />
-
-    <EventMultiTrigger name="hintBeacon">
-        <events>
-            <trigger>
-                <EventTrigger stayactive="true" delay=90 >
+    <DistanceTrigger name="reachedSector" position="<?lua printC(cSector) ?>" distance="<?lua print(radSector) ?>" target="SpaceShip" beaconMode="identify" targetname="Commander" stayactive=true />
+
+    <EventMultiTrigger name="addQuest2">
+        <events>
+            <trigger>
+                <EventTrigger stayactive="true" delay=10 >
                    <events>
                       <trigger>
@@ -147,5 +253,225 @@
     </EventMultiTrigger>
 
-    <DistanceTrigger name="cloakBeacon" position="<?lua printC(cBeacon) ?>" distance=100 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true />
+    <DistanceTrigger name="alliesReachedWait" position="<?lua printC(cAllyWait) ?>" distance="1000" target="SpaceShip" beaconMode="identify" targetname="Ally" stayactive=true />
+
+    <!-- So the allies stall when they reached their position for negociation and don´t fire away... -->
+
+    <EventDispatcher name="allyControllerDispatcher">
+      <targets>
+        <EventTarget target="allyController" />
+      </targets>
+      <events>
+          <activity>
+              <Trigger mode=or>
+                  <EventTrigger invert=true>
+                      <events>
+                          <trigger>
+                              <EventListener event="alliesReachedWait" />
+                          </trigger>
+                      </events>
+                  </EventTrigger>
+                  <EventTrigger>
+                      <events>
+                          <trigger>
+                              <EventListener event="noMercy" />
+                          </trigger>
+                      </events>
+                  </EventTrigger>
+                  <Trigger mode=and>
+                      <EventTrigger>
+                          <events>
+                              <trigger>
+                                  <EventListener event="fightBegun" />
+                              </trigger>
+                          </events>
+                      </EventTrigger>
+                      <EventTrigger invert=true>
+                          <events>
+                              <trigger>
+                                  <EventListener event="oneUnitLeft" />
+                              </trigger>
+                          </events>
+                      </EventTrigger>
+                  </Trigger>
+              </Trigger>
+          </activity>
+      </events>
+    </EventDispatcher>
+
+    <EventMultiTrigger name="hintBeacon">
+        <events>
+            <trigger>
+                <EventTrigger stayactive="true" delay=70 >
+                   <events>
+                      <trigger>
+                         <EventListener event="reachedSector" />
+                      </trigger>
+                   </events>
+                </EventTrigger>
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+
+    <DistanceTrigger name="cloakBeacon" position="<?lua printC(cBeacon) ?>" distance=100 target="SpaceShip" beaconMode="identify" targetname="Commander" stayactive=true />
+
+    <EventMultiTrigger name="fightBegun" stayactive=true>
+        <events>
+            <trigger>
+                <EventTrigger stayactive="true" delay=12>
+                   <events>
+                      <trigger>
+                         <EventListener event="cloakBeacon" />
+                      </trigger>
+                   </events>
+                </EventTrigger>
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+
+    <EventDispatcher name="enemyControllerDispatcher">
+      <targets>
+        <EventTarget target="enemyController" />
+      </targets>
+      <events>
+          <activity>
+              <Trigger mode=and>
+                  <EventTrigger>
+                      <events>
+                          <trigger>
+                              <EventListener event="fightBegun" />
+                          </trigger>
+                      </events>
+                  </EventTrigger>
+                  <EventTrigger invert=true>
+                      <events>
+                          <trigger>
+                              <EventListener event="oneUnitLeft" />
+                          </trigger>
+                      </events>
+                  </EventTrigger>
+              </Trigger>
+          </activity>
+      </events>
+    </EventDispatcher>
+
+    <EventMultiTrigger name="noMercy" stayactive=true>
+        <events>
+            <trigger>
+                    <Trigger mode=or>
+                        <?lua
+                        for i = 1, enemies, 1
+                        do
+                        ?>
+                        <EventTrigger active=false>
+                            <events>
+                                <activity>
+                                    <EventTrigger>
+                                        <events>
+                                            <trigger>
+                                                <EventListener event="oneUnitLeft" />
+                                            </trigger>
+                                        </events>
+                                    </EventTrigger>
+                                </activity>
+                                <trigger>
+                                    <EventListener event="enemy<?lua print(i) ?>" />      <!--TODO: trigger this with something that comes up when an enemy dies WITHOUT breaking the rest -->
+                                </trigger>
+                            </events>
+                        </EventTrigger>
+                        <?lua end ?>
+                    </Trigger>
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+
+    <!-- Recursive helper function for the event at the "end" of a Unit.-->
+    <?lua
+    function enemyTriggerRecursor(i, k)
+    if i > 0 then
+    return [[
+    <EventTrigger name=killedEnemy]] .. ((k-1)*4+i) .. [[ activations=1 stayactive=true delay=0.1>
+        <events>
+            <trigger>
+                <EventListener event=enemy]] .. k .. [[ />
+            </trigger>
+        </events>
+        ]] .. enemyTriggerRecursor(i-1, k) .. [[
+    </EventTrigger>
+    ]]
+    else return ""
+    end
+    end
+    ?>
+    <!-- Actual recursive Event(s) for the respective Units. (packs of 4 Enemies that is!) -->
+    <?lua
+    for k = 1, enemies, 1
+    do
+    print(enemyTriggerRecursor(4,k))
+    ?>
+    <EventMultiTrigger name="unit<?lua print(k) ?>Down" delay=0.1 stayactive=true>
+        <events>
+            <trigger>
+                <EventListener event="killedEnemy<?lua print(k*4) ?>" />
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+    <?lua end ?>
+
+    <EventMultiTrigger name="oneUnitLeft" stayactive=true>
+        <events>
+            <trigger>
+                <Trigger mode=or>
+                    <?lua
+                    for k = 1, enemies, 1
+                    do
+                    ?>
+                        <Trigger mode=and>
+                            <EventTrigger invert=true>
+                                <events>
+                                    <trigger>
+                                        <EventListener event="unit<?lua print(k) ?>Down" />
+                                    </trigger>
+                                </events>
+                            </EventTrigger>
+                            <?lua
+                            for i = 1, enemies, 1
+                            do
+                            if not (i == k) then
+                            ?>
+                            <EventTrigger>
+                                <events>
+                                    <trigger>
+                                        <EventListener event="unit<?lua print(i) ?>Down" />
+                                    </trigger>
+                                </events>
+                            </EventTrigger>
+                            <?lua end end ?>
+                        </Trigger>
+                    <?lua end ?>
+                </Trigger>
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+
+    <EventMultiTrigger name="AllUnitsDown" stayactive=true>
+        <events>
+            <trigger>
+                <Trigger mode=and>
+                    <?lua
+                    for k = 1, enemies, 1
+                    do
+                    ?>
+                    <EventTrigger>
+                        <events>
+                            <trigger>
+                                <EventListener event="unit<?lua print(i) ?>Down" />
+                            </trigger>
+                        </events>
+                    </EventTrigger>
+                    <?lua end ?>
+                </Trigger>
+            </trigger>
+        </events>
+    </EventMultiTrigger>
 
     <!--TODO: Complete the DistanceTriggers for completing/succeeding correctly! -->
@@ -188,4 +514,5 @@
         <effects>
             <AddQuest questId="quest1" />
+            <AddQuestHint HintId="quest1hint1" />
         </effects>
         <events>
@@ -209,5 +536,17 @@
     <QuestEffectBeacon times=1>
         <effects>
-            <AddQuestHint hintId="quest2hint2" />
+            <AddQuest questId="quest2" />
+        </effects>
+        <events>
+            <execute>
+                <EventListener event="addQuest2" />
+            </execute>
+        </events>
+    </QuestEffectBeacon>
+
+    <QuestEffectBeacon times=1>
+        <effects>
+            <AddQuestHint hintId="quest2hint1
+                " />
         </effects>
         <events>
@@ -228,4 +567,40 @@
         </events>
     </QuestEffectBeacon>
+
+    <QuestEffectBeacon times=1>
+        <effects>
+            <AddQuest questId="quest3" />
+        </effects>
+        <events>
+            <execute>
+                <EventListener event="fightBegun" />
+            </execute>
+        </events>
+    </QuestEffectBeacon>
+
+    <QuestEffectBeacon times=1>
+        <effects>
+            <CompleteQuest questId="quest3" />
+        </effects>
+        <events>
+            <execute>
+                <EventListener event="oneUnitLeft" />
+            </execute>
+        </events>
+    </QuestEffectBeacon>
+
+    <!--TODO: Include planet destruction and quitting -->
+
+    <QuestEffectBeacon times=1>
+        <effects>
+            <CompleteQuest questId="quest4" />
+        </effects>
+        <events>
+            <execute>
+                <EventListener event="enemyAllGone" />
+            </execute>
+        </events>
+    </QuestEffectBeacon>
+
 
     <!--NOTIFICATIONS -->
@@ -273,5 +648,5 @@
     </SimpleNotification>
 
-     <SimpleNotification broadcast="true" message="Stick to your objective, Commander. This is war.">
+    <SimpleNotification broadcast="true" message="Stick to your objective, Commander. This is war.">
         <events>
             <trigger>
@@ -287,112 +662,203 @@
     </SimpleNotification>
 
-    <!--SHIPS -->
-
-    <!--Allied units-->
-
-    
-
-    <SpaceShip position="<?lua printC(cAlly1) ?>" lookat="0,0,0" name="leader1">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <DivisionController team=0 formationMode="DIAMOND" action="FIGHT">
-        </DivisionController>
-      </controller>
-    </SpaceShip>
-
-    <SpaceShip position="100 ,0,100" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=0>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-
-    <SpaceShip position="0, -100,0" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=0>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-
-    <SpaceShip position="-100, 0, 100" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <SectionController team=0>
-        </SectionController>
-      </controller>
-    </SpaceShip>
-
-    
-    
-    <!-- Enemy Units -->
-
+    <SimpleNotification broadcast="true" message="Huh?! The sector is empty! where are they hiding?">
+       <events>
+           <trigger>
+               <EventTrigger stayactive="true" delay=2 >
+                  <events>
+                     <trigger>
+                        <EventListener event="reachedSector" />
+                     </trigger>
+                  </events>
+               </EventTrigger>
+           </trigger>
+       </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="They must be cloaking themselves! But we'll figure it out...">
+      <events>
+          <trigger>
+              <EventTrigger stayactive="true" delay=6 >
+                 <events>
+                    <trigger>
+                       <EventListener event="reachedSector" />
+                    </trigger>
+                 </events>
+              </EventTrigger>
+          </trigger>
+      </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Got it! Look out for a bright light and touch it!">
+     <events>
+         <trigger>
+             <EventListener event="addQuest2" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Divisions are standing by, Sir.">
+     <events>
+         <trigger>
+             <EventListener event="alliesReachedWait" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Woah! what the hell! they boobytrapped us!">
+     <events>
+         <trigger>
+             <EventListener event="cloakBeacon" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Greetings, Humans. Are you here to resign to your menace and make amends?">
+     <events>
+         <trigger>
+             <EventTrigger stayactive="true" delay=4 >
+                <events>
+                   <trigger>
+                      <EventListener event="cloakBeacon" />
+                   </trigger>
+                </events>
+             </EventTrigger>
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Menace? What is he on about, General?">
+     <events>
+         <trigger>
+             <EventTrigger stayactive="true" delay=8 >
+                <events>
+                   <trigger>
+                      <EventListener event="cloakBeacon" />
+                   </trigger>
+                </events>
+             </EventTrigger>
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="None of your concern, Commander. Launch the attack!">
+     <events>
+         <trigger>
+             <EventTrigger stayactive="true" delay=12 >
+                <events>
+                   <trigger>
+                      <EventListener event="cloakBeacon" />
+                   </trigger>
+                </events>
+             </EventTrigger>
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Unit 1 down!">
+     <events>
+         <trigger>
+             <EventListener event="unit1Down" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Unit 2 down!">
+     <events>
+         <trigger>
+             <EventListener event="unit2Down" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Unit 3 down!">
+     <events>
+         <trigger>
+             <EventListener event="unit3Down" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Unit 4 down!">
+     <events>
+         <trigger>
+             <EventListener event="unit4Down" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Please! No More! We surrender!">
+     <events>
+         <trigger>
+             <EventListener event="oneUnitLeft" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Well done, Commander. You got rid of the alien scum.">
+     <events>
+         <trigger>
+             <EventListener event="AllUnitsDown" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Roger that, Commander. We kill them.">
+     <events>
+         <trigger>
+             <EventListener event="noMercy" />
+         </trigger>
+     </events>
+    </SimpleNotification>
+
+    <!--ELEMENTS -->
+
+    <!-- Billboard Path to Sector 5C. Height changes in an atan shape -->
 
     <?lua
-    for k = 1, units, 1
+    for i = 1, 11, 1
     do
-    x = math.cos(math.pi/(2*units - 2)*k)*1500
-    y = math.sin(math.pi/(2*units - 2)*k)*1500
+    heightNow = cPathToEntry[1][2] - (cPathToEntry[1][2]-cSectorEntry[2])*(math.atan(-1.6+0.3*i) + 1)/2
+    cBillNow = {(cSectorEntry[1]-cPathToEntry[1][1])*i/12, heightNow, (cSectorEntry[3]-cPathToEntry[1][3])*i/12}
+    cPathToEntry[i+1] = cBillNow
     ?>
-
-    <SpaceShip team=1 position="<?lua printC(cEnemy1) ?>" lookat="0,0,0" name="enemy<?lua print(k) ?>">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <DivisionController team=1 formationMode="DIAMOND" action="FIGHT">
-        </DivisionController>
-      </controller>
-    </SpaceShip>
-
-    <SpaceShip team=1 position="100 ,0,100" lookat="0,0,0" name="enemy<?lua print(k) ?>">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=1>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-
-    <SpaceShip team=1 position="0, -100,0" lookat="0,0,0" name="enemy<?lua print(k) ?>">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <WingmanController team=1>
-        </WingmanController>
-      </controller>
-    </SpaceShip>
-
-    <SpaceShip team=1 position="-100, 0, 100" lookat="0,0,0" name="enemy<?lua print(k) ?>">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <SectionController team=1>
-        </SectionController>
-      </controller>
-    </SpaceShip>
-
+    <Billboard position="<?lua printC(cBillNow) ?>"  scale=2 material="Flares/ringflare" colour="0.2,0.9,0.2"/>
+    <?lua
+    end
+    cPathToEntry[13] = cSectorEntry
+    ?>
+
+    <Billboard position="<?lua printC(cSectorEntry) ?>"  scale=5 material="Flares/ringflare" colour="0.2,0.9,0.2"/>
+
+    <!-- Circular Billboard Ring around Sector 5C -->
+
+    <?lua
+    for i = 1, 64, 1
+    do
+    rBillboard = {math.sin(i*math.pi/32)*radSector, 0, math.cos(i*math.pi/32)*radSector}
+    cBillNow = addC(cSector,rBillboard)
+    ?>
+    <Billboard position="<?lua printC(cBillNow) ?>"  scale=10 material="Flares/lensflare" colour="1,0.2,0.2"/>
     <?lua end ?>
-    
-    <!--ELEMENTS -->
+
+    <!-- Cloaking Beacon -->
+
+    <BlinkingBillboard visible=false active=false scale=2 position="<?lua printC(cBeacon) ?>" material="Flares/lensflare" frequency=1 amplitude=3 colour="0.4,0.4,1">
+        <events>
+            <activity>
+                <EventListener event="addQuest2" />
+            </activity>
+            <visibility>
+                <EventListener event="addQuest2" />
+            </visibility>
+        </events>
+    </BlinkingBillboard>
 
     <!-- Asteroids you have to fly through to get to the EnemyBase -->
-    
+
     <?lua
         dofile("includes/asteroidField.lua")
        asteroidField(cField1[1], cField1[2], cField1[3], 20, 30, 4500, 500, 0)
-    ?>    
+    ?>
 
     <!-- Other Asteroid-Fields -->
@@ -401,5 +867,5 @@
         dofile("includes/asteroidField.lua")
        asteroidField(cField2[1], cField2[2], cField2[3], 20, 30, 4500, 500, 0)
-    ?> 
+    ?>
 
     <!-- Planets -->
@@ -453,6 +919,6 @@
         collisiondamage = 2
         enablecollisiondamage = true
-    visible=true
-    active=true
+        visible=true
+        active=true
       >
       <attached>
@@ -469,5 +935,5 @@
     ?>
 
-    <!-- EnemyPlanet(s) -->
+    <!-- EnemyPlanet -->
 
     <Planet
@@ -487,14 +953,182 @@
         collisiondamage = 2
         enablecollisiondamage = true
-    visible=true
-    active=true
-      >
-      <attached>
-        <ForceField position="0,0,0" mode="sphere" diameter="10000" velocity="-500" />
+        visible=false
+        active=false
+    >
+        <attached>
+           <ForceField position="0,0,0" mode="sphere" diameter="10000" velocity="-500" />
         </attached>
-          <collisionShapes>
+        <events>
+            <activity>
+                <EventListener event="cloakBeacon" />
+            </activity>
+            <visibility>
+                <EventListener event="cloakBeacon" />
+            </visibility>
+        </events>
+        <collisionShapes>
             <SphereCollisionShape radius="5000" position="0,0,0" />
-      </collisionShapes>
+        </collisionShapes>
     </Planet>
+
+    <!-- Pawn that represents the planet during destruction -->
+
+    <Pawn active=false team=1 initialhealth=500 health=500 maxhealth=500 position="<?lua printC(cEnemyBasePlanet) ?>" radarname="Enemy Home Planet" name="enemyPlanet">
+        <events>
+            <activity>
+                <EventListener event="oneUnitLeft" />
+            </activity>
+        </events>
+        <collisionShapes>
+            <SphereCollisionShape radius="6000" position="0,0,0" />
+        </collisionShapes>
+    </Pawn>
+
+    <!--SHIPS -->
+
+    <!--Allied units-->
+
+    <?lua
+    for i = 1, allies, 1
+    do
+    rUnit = {-math.sin(math.pi*((i-1/2)/allies))*125, math.pow(-1,i)*80, math.cos(math.pi*((i-1/2)/allies))*800}
+    cAllyNow = addC(cAlly,rUnit)
+    ?>
+
+    <SpaceShip health=600 initialhealth=600 maxhealth=600 position="<?lua printC(cAllyNow) ?>" name="ally<?lua print(i) ?>.D">
+      <templates>
+        <Template link=ally />
+      </templates>
+      <controller>
+        <DivisionController name="allyController" team=0 formationMode="diamond" spread=100>
+          <actionpoints>
+              <?lua
+              for i = 1, 13, 1
+              do
+              ?>
+              <Actionpoint position="<?lua printC(addC(cPathToEntry[i], rUnit)) ?>" action="fly" />
+              <?lua end ?>
+           </actionpoints>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+
+    <SpaceShip health=600 initialhealth=600 maxhealth=600 position="<?lua printC(addC(cAllyNow,rSection)) ?>" lookat="0,0,0" name="ally<?lua print(i) ?>.S">
+      <templates>
+        <Template link=ally />
+      </templates>
+      <controller>
+        <SectionController name="allyController" team=0>
+        </SectionController>
+      </controller>
+    </SpaceShip>
+
+    <SpaceShip health=600 initialhealth=600 maxhealth=600 position="<?lua printC(addC(cAllyNow,rWingman1)) ?>" lookat="0,0,0" name="ally<?lua print(i) ?>.W1">
+      <templates>
+        <Template link=ally />
+      </templates>
+      <controller>
+        <WingmanController name="allyController" team=0>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+
+    <SpaceShip health=600 initialhealth=600 maxhealth=600 position="<?lua printC(addC(cAllyNow,rWingman2)) ?>" lookat="0,0,0" name="ally<?lua print(i) ?>.W2">
+      <templates>
+        <Template link=ally />
+      </templates>
+      <controller>
+        <WingmanController name="allyController" team=0>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+
+    <?lua end ?>
+
+    <!-- Enemy Units -->
+
+    <?lua
+    for k = 1, enemies, 1
+    do
+    rUnit = {125 -math.sin(math.pi*((k-1/2)/enemies))*200, math.pow(-1,k)*300, math.cos(math.pi*((k-1/2)/enemies))*1000}
+    cEnemyNow = addC(cEnemy,rUnit)
+    ?>
+
+    <SpaceShip health=400 initialhealth=400 maxhealth=400 position="<?lua printC(cEnemyNow) ?>" name="enemy<?lua print(k) ?>">
+      <templates>
+        <Template link=enemy />
+      </templates>
+      <events>
+          <activity>
+              <EventListener event="cloakBeacon" />
+          </activity>
+          <visibility>
+              <EventListener event="cloakBeacon" />
+          </visibility>
+      </events>
+      <controller>
+        <DivisionController name="enemyControll" active=false team=1 formationMode="diamond" spread=100>
+          <actionpoints>
+              <Actionpoint position="<?lua printC(cEnemyNow) ?>" action="fightall" />
+          </actionpoints>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+
+    <SpaceShip health=400 initialhealth=400 maxhealth=400 position="<?lua printC(addC(cEnemyNow,rSection)) ?>" name="enemy<?lua print(k) ?>">
+      <templates>
+        <Template link=enemy />
+      </templates>
+      <events>
+          <activity>
+              <EventListener event="cloakBeacon" />
+          </activity>
+          <visibility>
+              <EventListener event="cloakBeacon" />
+          </visibility>
+      </events>
+      <controller>
+        <SectionController name="enemyControll" active=false team=1>
+        </SectionController>
+      </controller>
+    </SpaceShip>
+
+    <SpaceShip health=400 initialhealth=400 maxhealth=400 position="<?lua printC(addC(cEnemyNow,rWingman1)) ?>" lookat="0,0,0" name="enemy<?lua print(k) ?>">
+      <templates>
+        <Template link=enemy />
+      </templates>
+      <events>
+          <activity>
+              <EventListener event="cloakBeacon" />
+          </activity>
+          <visibility>
+              <EventListener event="cloakBeacon" />
+          </visibility>
+      </events>
+      <controller>
+        <WingmanController name="enemyControll" active=false team=1>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+
+    <SpaceShip health=400 initialhealth=400 maxhealth=400 position="<?lua printC(addC(cEnemyNow,rWingman2)) ?>" name="enemy<?lua print(k) ?>">
+      <templates>
+        <Template link=enemy />
+      </templates>
+      <events>
+          <activity>
+              <EventListener event="cloakBeacon" />
+          </activity>
+          <visibility>
+              <EventListener event="cloakBeacon" />
+          </visibility>
+      </events>
+      <controller>
+        <WingmanController name="enemyControll" active=false team=1>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+
+    <?lua end ?>
 
     </Scene>
