Index: /code/branches/campaignHS15/data/levels/Campaign1.oxw
===================================================================
--- /code/branches/campaignHS15/data/levels/Campaign1.oxw	(revision 10688)
+++ /code/branches/campaignHS15/data/levels/Campaign1.oxw	(revision 10689)
@@ -28,14 +28,20 @@
     <?lua include("includes/notifications.oxi") ?>
     <NotificationQueueCEGUI
-      name="narrative"
-      targets="simpleNotification"
-      size=3
-      displayTime=3.9
-      position="0.15, 0, 0.1, 0"
-      fontSize="23"
-      fontColor="0.3, 1, 0.2, 0.8"
-      alignment="HorzCentred"
-      displaySize="0.7, 0, 0, 0"
-      />
+        name="narrative"
+        targets="simpleNotification"
+        size=3
+        displayTime=3.9
+        position="0.15, 0, 0.1, 0"
+        fontSize="23"
+        fontColor="0.3, 1, 0.2, 0.8"
+        alignment="HorzCentred"
+        displaySize="0.7, 0, 0, 0"
+    />
+
+    <!-- GLOBAL LUA VARIABLES -->
+    <?lua
+        waves = 3
+        enemies = 5
+    ?>
 
     <Scene
@@ -44,5 +50,5 @@
     >
 
-    <SpawnPoint name="PlayerSpawn" team=1 position="0,-50,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff2 />
+    <SpawnPoint name="playerSpawn" team=1 position="0,-50,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff2 />
 
     <WorldAmbientSound source="Earth.ogg" looping="true" playOnLoad="true" />
@@ -58,8 +64,11 @@
         </hints>
         <complete-effects>
+            <!-- Quest 2 not made as of yet
             <AddQuest questId="quest2" />
             <AddQuest questId="quest2.1" />
             <AddQuest questId="quest2.2" />
             <AddQuest questId="quest2.3" />
+            -->
+            <AddQuest questId="quest3" />
         </complete-effects>
     </GlobalQuest>
@@ -153,5 +162,7 @@
         _spawntrigger
         _reachedA
-        _wave<1|2|3>
+        _wave<k>
+        _killedEnemy<k>.<i>
+        _waveClear<k>
     -->
 
@@ -159,8 +170,70 @@
         <events>
             <trigger>
-                <EventListener event="PlayerSpawn" />
+                <EventListener event="playerSpawn" />
             </trigger>
         </events>
     </EventMultiTrigger>
+
+    <DistanceTrigger name="reachedA" position="2494,-1667,0" distance=200 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true />
+
+    <EventMultiTrigger name="wave1" activations="1" stayactive="true" >
+        <events>
+            <trigger>
+                <EventListener event="reachedA" />
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+
+    <!-- Recursive helper function for the end-of-wave events. F*ck the event system, seriously. -->
+    <?lua
+    function enemyTriggerRecursor(i, k)
+    if i > 0 then
+    return [[
+    <EventTrigger name=killedEnemy]] .. k .. [[.]] .. i .. [[ activations=1 stayactive=true delay=0.1>
+        <events>
+            <trigger>
+                <EventListener event=attackers]] .. k .. [[ />
+            </trigger>
+        </events>
+        ]] .. enemyTriggerRecursor(i-1, k) .. [[
+    </EventTrigger>
+    ]]
+    else return ""
+    end
+    end
+    ?>
+    <!-- Actual recursive Event(s) for the respective waves. -->
+    <?lua
+    for k = 1, waves, 1
+    do
+    print(enemyTriggerRecursor(enemies,k))
+    ?>
+    <EventMultiTrigger name="waveClear<?lua print(k) ?>" delay=4.0>
+        <events>
+            <trigger>
+                <EventListener event="killedEnemy<?lua print(k .. [[.]] .. enemies) ?>" />
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+    <?lua end ?>
+
+    <!-- This trigger needs fixing, as endMission can only be called by a Pawn Distance Trigger. Herpaderp -->
+    <EventMultiTrigger name="missionFailed" target="Pawn" stayActive="true" delay=1.5>
+        <events>
+            <trigger>
+                <EventListener event="transporter" />
+            </trigger>
+        </events>
+    </EventMultiTrigger>
+
+    <Script code="Mission endMission fail" onLoad="false" times="1">
+        <events>
+            <trigger>
+                <EventListener event="missionFailed" />
+            </trigger>
+        </events>
+    </Script>
+
+    <!--QUEST EFFECT BEACONS -->
 
     <QuestEffectBeacon times=1>
@@ -175,13 +248,25 @@
     </QuestEffectBeacon>
 
-    <DistanceTrigger name="reachedA" position="2494,-1667,0" distance=200 target="SpaceShip" beaconMode="exclude" targetname="NPC" stayactive=true />
-
-    <EventMultiTrigger name="wave1">
-        <events>
-            <trigger>
+    <QuestEffectBeacon times=1>
+        <effects>
+            <CompleteQuest questId="quest1" />
+        </effects>
+        <events>
+            <execute>
                 <EventListener event="reachedA" />
-            </trigger>
-        </events>
-    </EventMultiTrigger>
+            </execute>
+        </events>
+    </QuestEffectBeacon>
+
+    <QuestEffectBeacon times=1>
+        <effects>
+            <CompleteQuest questId="quest3" />
+        </effects>
+        <events>
+            <execute>
+                <EventListener event="waveClear1" />
+            </execute>
+        </events>
+    </QuestEffectBeacon>
 
     <!--NOTIFICATIONS -->
@@ -211,4 +296,22 @@
                 <EventListener event="attackers2" />
                 <EventListener event="attackers3" />
+            </trigger>
+        </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="Phew, that was close! Well done, Commmander.">
+        <events>
+            <trigger>
+                <EventListener event="waveClear1" />
+                <EventListener event="waveClear2" />
+                <EventListener event="waveClear3" />
+            </trigger>
+        </events>
+    </SimpleNotification>
+
+    <SimpleNotification broadcast="true" message="It's over... we failed. Retreat!">
+        <events>
+            <trigger>
+                <EventListener event="missionFailed" />
             </trigger>
         </events>
@@ -251,10 +354,8 @@
     <!-- Enemies. Outer loop defines waves, inner loop defines enemies in every wave. -->
     <?lua
-    waves = 5
     for k = 1, waves, 1
     do
     ?>
     <?lua
-    enemies = 5
     for i = 1, enemies, 1
     do
