Index: /code/branches/campaignHS15/data/levels/Campaign1.oxw
===================================================================
--- /code/branches/campaignHS15/data/levels/Campaign1.oxw	(revision 10765)
+++ /code/branches/campaignHS15/data/levels/Campaign1.oxw	(revision 10766)
@@ -11,5 +11,5 @@
     include("templates/lodInformation.oxt")
 
-    include("templates/spaceshipAssff2.oxt")
+    include("templates/spaceshipAssff.oxt")
     include("templates/spaceshipPirate.oxt")
     include("templates/spaceshipEscort.oxt")
@@ -41,5 +41,28 @@
         waves = 3
         enemies = 5
-        allies = 5
+        allies = 3
+
+        --[[ Coordinates. NOTE: Indexing starts at 1 in lua! Don´t forget to adapt the for loops, too! ]]--
+        cCenter = {0, 0, 0}
+        cSpawn = {0, -50, 0}
+        cUnit = {3000, -2000, 0}
+        cA = {5000, -3000, 0}
+        cB = {-5000, -3000, 0}
+        cC = {0, -2300, 0}
+        dStation = {0, 1, 0}
+        cNewShip = {4100, -2100, 0}
+        cFPSGround = {0, -2300, 1200}
+        dFPSGround = {0, 0, -1}
+        cFPS = {0, -2300, 1201}
+        cField1 = {2500, 400, 0}
+        cField2 = {-2500, 400, 0}
+        cPlanet1 = {15000, 8000, -2000}
+        cPlanet2 = {-1000, -20000, 4000}
+        rAllies = {3000, -2000}         --[[ To be addressed directly, hence r ]]--
+
+        --[[ Function to print Coordinates. Quotes not included! ]]--
+        function printC(coord)
+          print(coord[1] .. [[,]] .. coord[2] .. [[,]] .. coord[3])
+        end
     ?>
 
@@ -50,9 +73,9 @@
     >
 
-    <SpawnPoint name="playerSpawn" team=0 position="0,-50,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
+    <SpawnPoint 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="0,0,0" 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(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"/>
 
     <!--QUEST DEFINITIONS-->
@@ -173,5 +196,5 @@
     </EventMultiTrigger>
 
-    <DistanceTrigger name="reachedA" position="5000,-3000,0" distance=1000 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true />
+    <DistanceTrigger name="reachedA" position="<?lua printC(cA) ?>" distance=1000 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true />
 
     <!-- TODO: find out how to link an event to the COMPLETION of a dock. How is this not possible?? -->
@@ -184,5 +207,5 @@
     </EventMultiTrigger>
 
-    <DistanceTrigger name="joinedUnit" active=false position="3000,-2000,0" distance=100 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true>
+    <DistanceTrigger name="joinedUnit" active=false position="<?lua printC(cUnit) ?>" distance=100 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true>
         <events>
             <activity>
@@ -192,5 +215,5 @@
     </DistanceTrigger>
 
-    <EventMultiTrigger name="wave1" activations="1" stayactive="true" delay=4>
+    <EventMultiTrigger name="wave1" activations="1" delay=4>
         <events>
             <trigger>
@@ -233,6 +256,38 @@
     <?lua end ?>
 
+    <!-- This controls the ally AI controller so it is only active when active enemies are around!
+    TODO: Find a way to control the allies in another case (Multiple controllers are not allowed). -->
+    <EventDispatcher name="allyControllerDispatcher">
+      <targets>
+        <EventTarget target="allyController" />
+      </targets>
+      <events>
+          <activity>
+              <?lua
+              for k = 1, waves, 1 do
+              ?>
+              <Trigger mode=and>
+                  <EventTrigger>
+                      <events>
+                          <trigger>
+                              <EventListener event="wave<?lua print(k) ?>" />
+                          </trigger>
+                      </events>
+                  </EventTrigger>
+                  <EventTrigger invert=true>
+                      <events>
+                          <trigger>
+                              <EventListener event="waveClear<?lua print(k) ?>" />
+                          </trigger>
+                      </events>
+                  </EventTrigger>
+              </Trigger>
+              <?lua end ?>
+          </activity>
+      </events>
+    </EventDispatcher>
+
     <!-- FIXME: This trigger needs fixing, as endMission can only be called by a Pawn Distance Trigger. Herpaderp.
-        Also, the fix proposed in MissionOne does not work anymore... -->
+    Also, the fix proposed in MissionOne does not work anymore... -->
    <EventMultiTrigger name="missionFailed" target="Pawn" stayActive="true" delay=1.5>
        <events>
@@ -383,4 +438,12 @@
     </SimpleNotification>
 
+    <SimpleNotification broadcast="true" message="Howdy Commander! Ready to kick alien ass?">
+        <events>
+            <trigger>
+                <EventListener event="joinedUnit" />
+            </trigger>
+        </events>
+    </SimpleNotification>
+
     <SimpleNotification broadcast="true" message="An enemy wave is approaching the shuttle!">
         <events>
@@ -426,31 +489,31 @@
     <Template name="station">
         <Pawn mass=10000 collisionType=dynamic friction=0.01>
-          <attached>
-            <Model mesh="HydroHarvester.mesh" position="0,0,0" scale=50 />
-            <DistanceTriggerBeacon name="NPC" />
-          </attached>
-          <collisionShapes>
-            <BoxCollisionShape  position="-560,0,0" halfExtents="115,100,245" /><!-- Three lower boxes -->
-            <BoxCollisionShape  position="290,0,-480" halfExtents="115,100,245" yaw=-120 />
-            <BoxCollisionShape  position="290,0,480" halfExtents="115,100,245" yaw=-240 />
-            <BoxCollisionShape  position="-280,0,0" halfExtents="163,50,50" /><!-- Three lower connections -->
-            <BoxCollisionShape  position="140,0,-240" halfExtents="163,50,50" yaw=-120 />
-            <BoxCollisionShape  position="140,0,240" halfExtents="163,50,50" yaw=-240 />
-            <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" /><!-- Upper Tower -->
-            <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" yaw=-120 />
-            <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" yaw=-240 />
-            <BoxCollisionShape  position="0,400,0" halfExtents="43,110,26" yaw=-30 /><!-- Middle one-->
-            <BoxCollisionShape  position="-200,100,0" halfExtents="26,50,43" /><!--Three lower legs -->
-            <BoxCollisionShape  position="100,100,-173" halfExtents="43,50,26" yaw=-30 />
-            <BoxCollisionShape  position="100,100,-173" halfExtents="43,50,26" yaw=30 />
-            <BoxCollisionShape  position="-100,264,0" halfExtents="26,105,43" roll=-49 /><!--Three upper legs -->
-            <BoxCollisionShape  position="50,264,-87" halfExtents="26,105,43" roll=-49 yaw=-120 />
-            <BoxCollisionShape  position="50,264,87" halfExtents="26,105,43" roll=-49 yaw=-240 />
-          </collisionShapes>
-      </Pawn>
+            <attached>
+                <Model mesh="HydroHarvester.mesh" position="0,0,0" scale=50 />
+                <DistanceTriggerBeacon name="NPC" />
+            </attached>
+            <collisionShapes>
+                <BoxCollisionShape  position="-560,0,0" halfExtents="115,100,245" /><!-- Three lower boxes -->
+                <BoxCollisionShape  position="290,0,-480" halfExtents="115,100,245" yaw=-120 />
+                <BoxCollisionShape  position="290,0,480" halfExtents="115,100,245" yaw=-240 />
+                <BoxCollisionShape  position="-280,0,0" halfExtents="163,50,50" /><!-- Three lower connections -->
+                <BoxCollisionShape  position="140,0,-240" halfExtents="163,50,50" yaw=-120 />
+                <BoxCollisionShape  position="140,0,240" halfExtents="163,50,50" yaw=-240 />
+                <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" /><!-- Upper Tower -->
+                <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" yaw=-120 />
+                <BoxCollisionShape  position="0,530,0" halfExtents="172,52,298" yaw=-240 />
+                <BoxCollisionShape  position="0,400,0" halfExtents="43,110,26" yaw=-30 /><!-- Middle one-->
+                <BoxCollisionShape  position="-200,100,0" halfExtents="26,50,43" /><!--Three lower legs -->
+                <BoxCollisionShape  position="100,100,-173" halfExtents="43,50,26" yaw=-30 />
+                <BoxCollisionShape  position="100,100,-173" halfExtents="43,50,26" yaw=30 />
+                <BoxCollisionShape  position="-100,264,0" halfExtents="26,105,43" roll=-49 /><!--Three upper legs -->
+                <BoxCollisionShape  position="50,264,-87" halfExtents="26,105,43" roll=-49 yaw=-120 />
+                <BoxCollisionShape  position="50,264,87" halfExtents="26,105,43" roll=-49 yaw=-240 />
+            </collisionShapes>
+        </Pawn>
     </Template>
 
     <!-- A, Coordinates are approx. (cos(29pi/16), sin(29pi/16), 0)*3000 -->
-    <Pawn name="statA" team=0 radarname="Station A" position="5000,-3000,0" direction="0,1,0" initialhealth=10000 maxhealth=10000>
+    <Pawn name="statA" team=0 radarname="Station A" position="<?lua printC(cA) ?>" direction="<?lua printC(dStation) ?>" initialhealth=10000 maxhealth=10000>
         <templates>
             <Template link="station" />
@@ -479,5 +542,5 @@
 
     <!-- B, Coordinates are approx. (-cos(29pi/16), sin(29pi/16), 0)*3000 -->
-    <Pawn name="statB" team=0 radarname="Station B" position="-5000,-3000,0" direction="0,1,0" initialhealth=10000 maxhealth=10000>
+    <Pawn name="statB" team=0 radarname="Station B" position="<?lua printC(cB) ?>" direction="<?lua printC(dStation) ?>" initialhealth=10000 maxhealth=10000>
         <templates>
             <Template link="station" />
@@ -506,5 +569,5 @@
 
     <!-- C -->
-    <Pawn name="statC" team=0 radarname="Station C" position="0,-2300,0" direction="0,1,0" initialhealth=10000 maxhealth=10000>
+    <Pawn name="statC" team=0 radarname="Station C" position="<?lua printC(cC) ?>" direction="<?lua printC(dStation) ?>" initialhealth=10000 maxhealth=10000>
         <templates>
             <Template link="station" />
@@ -534,27 +597,27 @@
     <!-- New SpaceShip as destination of dock A-->
     <SpaceShip
-        template            = "spaceshipassff2"
-        team                = "0"
-        position            = "4100,-2100,0"
-        orientation         = "-0.14, 0.68, 0.68, 0.223"
-        health              = "400"
-        initialhealth       = "400"
-        maxhealth           = "500"
-        shieldhealth        = "80"
-        initialshieldhealth = "80"
-        maxshieldhealth     = "120"
-        shieldabsorption    = "0.8"
-        reloadrate          = "1"
-        reloadwaittime      = "1"
-        name                = "newSpaceShip"
-        radarname           = "Defender" >
-      <attached>
-        <DockingTarget name="newSpaceShip" />
-        <DistanceTriggerBeacon name="newSpaceShip" />
-      </attached>
+            template            = "spaceshipassff"
+            team                = "0"
+            position            = "<?lua printC(cNewShip) ?>"
+            lookat              = "<?lua printC(cCenter) ?>"
+            health              = "400"
+            initialhealth       = "400"
+            maxhealth           = "500"
+            shieldhealth        = "80"
+            initialshieldhealth = "80"
+            maxshieldhealth     = "120"
+            shieldabsorption    = "0.8"
+            reloadrate          = "1"
+            reloadwaittime      = "1"
+            name                = "newSpaceShip"
+            radarname           = "Defender" >
+        <attached>
+            <DockingTarget name="newSpaceShip" />
+            <DistanceTriggerBeacon name="newSpaceShip" />
+        </attached>
     </SpaceShip>
 
     <!-- FPS Player as destination of dock C-->
-    <FpsPlayer team=0 template = "fps" rotationaxis="0,0,1" radarname = "First Person Player" position = "0,-2300,1201">
+    <FpsPlayer team=0 template = "fps" radarname = "First Person Player" position = "<?lua printC(cFPS) ?>">
         <attached>
             <DockingTarget name="fpsMode" />
@@ -563,10 +626,10 @@
     </FpsPlayer>
 
-    <StaticEntity position="0,-2300,1001" direction="0,0,-1" collisionType=static mass=100000 friction=0.01 >
+    <StaticEntity position="<?lua printC(cFPSGround) ?>" direction="<?lua printC(dFPSGround) ?>" collisionType=static mass=100000 friction=0.01 >
         <attached>
-          <Model position="0,0,0" mesh="crate.mesh" scale3D="80,80,5" />
+            <Model position="0,0,0" mesh="crate.mesh" scale3D="80,80,5" />
         </attached>
         <collisionShapes>
-          <BoxCollisionShape position="0,0,0" halfExtents="400,400,25" />
+            <BoxCollisionShape position="0,0,0" halfExtents="80,80,5" />
         </collisionShapes>
     </StaticEntity>
@@ -576,14 +639,14 @@
     <?lua
         dofile("includes/asteroidField.lua")
-       asteroidField(2500, 400, 0, 20, 30, 2200, 250, 0)
+       asteroidField(cField1[1], cField1[2], cField1[3], 20, 30, 2200, 250, 0)
     ?>
 
     <?lua
         dofile("includes/asteroidField.lua")
-       asteroidField(-2500, 400, 0, 20, 30, 2200, 250, 0)
+       asteroidField(cField2[1], cField2[2], cField2[3], 20, 30, 2200, 250, 0)
     ?>
 
     <Planet
-        position="15000,8000,-2000"
+        position="<?lua printC(cPlanet1) ?>"
         scale="2000"
         collisionType="dynamic"
@@ -611,9 +674,9 @@
     <?lua
         dofile("includes/asteroidField.lua")
-        asteroidBelt(15000, 8000, -2000, 30, 0, 30, 20, 40, 2800, 3000, 200, 1)
+        asteroidBelt(cPlanet1[1], cPlanet1[2], cPlanet1[3], 30, 0, 30, 20, 40, 2800, 3000, 200, 1)
     ?>
 
     <Planet
-        position="-1000,-20000,4000"
+        position="<?lua printC(cPlanet2) ?>"
         scale="3000"
         collisionType="dynamic"
@@ -641,17 +704,17 @@
     <?lua
         dofile("includes/asteroidField.lua")
-        asteroidBelt(-1000, -20000, 4000, 30, 20, 100, 20, 40, 3400, 3700, 400, 1)
-    ?>
-
-    <!-- Allies, 3000,-2000 -->
+        asteroidBelt(cPlanet2[1], cPlanet2[2], cPlanet2[3], 30, 20, 100, 20, 40, 3400, 3700, 400, 1)
+    ?>
+
+    <!-- Allies -->
     <?lua
     for i = 1, allies, 1
     do
-    x = 3000 + math.cos(2*math.pi/5*(i+1))*100
-    y = -2000 + math.sin(2*math.pi/5*(i+1))*100
+    x = rAllies[1] + math.cos(2*math.pi/allies*(i+1))*100
+    y = rAllies[2] + math.sin(2*math.pi/allies*(i+1))*100
     ?>
     <SpaceShip visible=false active=false name="allies<?lua print(k)?>" radarname="Ally" position="<?lua print(x)?>,<?lua print(y)?>,<?lua print(math.pow(-1,i)*100) ?>" lookat="0,0,0" team=0>
         <templates>
-            <Template link="spaceshipassff2" />
+            <Template link="spaceshipassff" />
         </templates>
         <events>
@@ -667,11 +730,6 @@
         </attached>
         <controller>
-            <WaypointPatrolController accuracy=100 name="allyController" alertnessradius=5000 team=0 active=false>
-                <events>
-                    <activity>
-                        <EventListener event="joinedUnit" />
-                    </activity>
-                </events>
-            </WaypointPatrolController>
+            <!-- also see allyControllerDispatcher -->
+            <AIController name="allyController" accuracy=100 team=0 active=false />
         </controller>
     </SpaceShip>
@@ -686,6 +744,6 @@
     for i = 1, enemies, 1
     do
-    x = math.cos(math.pi/(8)*(i+1))*1500
-    y = math.sin(math.pi/(8)*(i+1))*1500
+    x = math.cos(math.pi/(enemies + 3)*(i+1))*1500
+    y = math.sin(math.pi/(enemies + 3)*(i+1))*1500
     ?>
     <SpaceShip visible=false active=false name="attackers<?lua print(k)?>" radarname="Attacker" position="<?lua print(x)?>,<?lua print(y)?>,<?lua print(math.pow(-1,i)*250) ?>" lookat="0,0,0" team=1>
@@ -720,7 +778,6 @@
     <?lua end ?>
 
-
     <!-- Transporter, starting Point is near A, end Point near B, the circle parameters for the waypoints are: Center = (0, -887, 0), r = 2613 -->
-    <SpaceShip position="5000,-3000,0" lookat="-2494, -1667, 0" team=0 name="transporter" radarname="Shuttle">
+    <SpaceShip position="<?lua printC(cA) ?>" lookat="<?lua printC(cB) ?>" team=0 name="transporter" radarname="Shuttle">
         <templates>
             <Template link="spaceshipTransporter" />
@@ -744,5 +801,5 @@
 
                     <!-- Return Point -->
-                    <Billboard position="-5000, -3000, 0" amplitude=1 material="Flares/lensflare" colour="1,1,0.05"/>
+                    <Billboard position="<?lua printC(cB) ?>" amplitude=1 material="Flares/lensflare" colour="1,1,0.05"/>
 
                     <!-- B to A -->
@@ -758,5 +815,5 @@
 
                     <!-- Start Point -->
-                    <Billboard position="5000,-3000,0" amplitude=1 material="Flares/lensflare" colour="1,1,0.05"/>
+                    <Billboard position="<?lua printC(cA) ?>" amplitude=1 material="Flares/lensflare" colour="1,1,0.05"/>
                 </waypoints>
             </WaypointController>
