- Add 'Mission Fail' trigger type
authorunc0rr
Sun, 30 Sep 2007 13:36:32 +0000
changeset 615 b646b3c43369
parent 614 0e04504bc140
child 616 00928b3cf505
- Add 'Mission Fail' trigger type - Some improvements to triggers code
hedgewars/CCHandlers.inc
hedgewars/uConsts.pas
hedgewars/uTriggers.pas
share/hedgewars/Data/Trainings/001_Shotgun.txt
--- a/hedgewars/CCHandlers.inc	Sat Sep 29 16:39:21 2007 +0000
+++ b/hedgewars/CCHandlers.inc	Sun Sep 30 13:36:32 2007 +0000
@@ -467,34 +467,37 @@
 end;
 
 procedure chAddTrigger(var s: shortstring);
-var ttype, gt, geartrig, Ticks, Lives: LongWord;
-    X, Y: LongInt;
+const MAXPARAMS = 16;
+var params: array[0..Pred(MAXPARAMS)] of Longword;
+    i: LongInt;
     c: char;
     tmp: shortstring;
 begin
 c:= s[1];
 Delete(s, 1, 1);
+
+i:= 0;
+while (i < MAXPARAMS) and
+      (Length(s) > 0) do
+    begin
+    SplitBySpace(s, tmp);
+    val(s, params[i]);
+    s:= tmp;
+    inc(i)
+    end;
+
 case c of
   's': begin // sTYPE TICKS LIVES GEARTYPE X Y GEARTRIGGER
-       SplitBySpace(s, tmp);
-       val(s, ttype);
-       SplitBySpace(tmp, s);
-       val(tmp, Ticks);
-       SplitBySpace(s, tmp);
-       val(s, Lives);
-       SplitBySpace(tmp, s);
-       val(tmp, gt);
-       SplitBySpace(s, tmp);
-       val(s, X);
-       SplitBySpace(tmp, s);
-       val(tmp, Y);
-       SplitBySpace(s, tmp);
-       val(s, geartrig);
-       AddTriggerSpawner(ttype, Ticks, Lives, X, Y, TGearType(gt), geartrig);
+       TryDo(i = 7, errmsgWrongNumber, true);
+       AddTriggerSpawner(params[0], params[1], params[2], TGearType(params[3]), params[4], params[5], params[6]);
        end;
   'C': begin
-       val(s, ttype);
-       AddTriggerSuccess(ttype);
+       TryDo(i = 3, errmsgWrongNumber, true);
+       AddTriggerSuccess(params[0], params[1], params[2]);
+       end;
+  'F': begin
+       TryDo(i = 3, errmsgWrongNumber, true);
+       AddTriggerFail(params[0], params[1], params[2]);
        end;
   end
 end;
--- a/hedgewars/uConsts.pas	Sat Sep 29 16:39:21 2007 +0000
+++ b/hedgewars/uConsts.pas	Sun Sep 30 13:36:32 2007 +0000
@@ -91,6 +91,7 @@
       errmsgUnknownVariable = 'Unknown variable';
       errmsgIncorrectUse    = 'Incorrect use';
       errmsgShouldntRun     = 'This program shouldn''t be run manually';
+      errmsgWrongNumber     = 'Wrong parameters number';
 
       msgLoading           = 'Loading ';
       msgOK                = 'ok';
--- a/hedgewars/uTriggers.pas	Sat Sep 29 16:39:21 2007 +0000
+++ b/hedgewars/uTriggers.pas	Sun Sep 30 13:36:32 2007 +0000
@@ -23,10 +23,11 @@
 {$INCLUDE options.inc}
 const trigTurns = $80000001;
 
-type TTrigAction = (taSpawnGear, taSuccessFinish);
+type TTrigAction = (taSpawnGear, taSuccessFinish, taFailFinish);
 
-procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword);
-procedure AddTriggerSuccess(tId: Longword);
+procedure AddTriggerSpawner(id, Ticks, Lives: Longword; GearType: TGearType; X, Y: LongInt; GearTriggerId: Longword);
+procedure AddTriggerSuccess(id, Ticks, Lives: Longword);
+procedure AddTriggerFail(id, Ticks, Lives: Longword);
 procedure TickTrigger(id: Longword);
 
 implementation
@@ -45,27 +46,28 @@
                 end;
 var TriggerList: PTrigger = nil;
 
-function AddTrigger: PTrigger;
+function AddTrigger(id, Ticks, Lives: Longword): PTrigger;
 var tmp: PTrigger;
 begin
 new(tmp);
 FillChar(tmp^, sizeof(TTrigger), 0);
+
+tmp^.id:= id;
+tmp^.Ticks:= Ticks;
+tmp^.TicksPerLife:= Ticks;
+tmp^.Lives:= Lives;
+
 if TriggerList <> nil then tmp^.Next:= TriggerList;
 TriggerList:= tmp;
 AddTrigger:= tmp
 end;
 
-procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword);
+procedure AddTriggerSpawner(id, Ticks, Lives: Longword; GearType: TGearType; X, Y: LongInt; GearTriggerId: Longword);
 var tmp: PTrigger;
 begin
 if (Ticks = 0) or (Lives = 0) then exit;
-{$IFDEF DEBUGFILE}AddFileLog('Add spawner trigger: ' + inttostr(id) + ', gear triggers  ' + inttostr(GearTriggerId));{$ENDIF}
 
-tmp:= AddTrigger;
-tmp^.id:= id;
-tmp^.Ticks:= Ticks;
-tmp^.TicksPerLife:= Ticks;
-tmp^.Lives:= Lives;
+tmp:= AddTrigger(id, Ticks, Lives);
 tmp^.Action:= taSpawnGear;
 tmp^.X:= X;
 tmp^.Y:= Y;
@@ -73,19 +75,21 @@
 tmp^.SpawnGearTriggerId:= GearTriggerId
 end;
 
-procedure AddTriggerSuccess(tId: Longword);
+procedure AddTriggerSuccess(id, Ticks, Lives: Longword);
 begin
-with AddTrigger^ do
-     begin
-     id:= tId;
-     Ticks:= 1;
-     TicksPerLife:= 1;
+with AddTrigger(id, Ticks, Lives)^ do
      Action:= taSuccessFinish
-     end
+end;
+
+procedure AddTriggerFail(id, Ticks, Lives: Longword);
+begin
+with AddTrigger(id, Ticks, Lives)^ do
+     Action:= taFailFinish
 end;
 
 procedure TickTriggerT(Trigger: PTrigger);
 begin
+{$IFDEF DEBUGFILE}AddFileLog('Tick trigger (type: ' + inttostr(LongWord(Trigger^.Action)) + ')');{$ENDIF}
 with Trigger^ do
   case Action of
      taSpawnGear: begin
@@ -94,6 +98,9 @@
                   end;
  taSuccessFinish: begin
                   GameState:= gsExit
+                  end;
+    taFailFinish: begin
+                  GameState:= gsExit
                   end
   end
 end;
@@ -117,9 +124,17 @@
        t^.Ticks:= t^.TicksPerLife;
        if (t^.Lives = 0) then
           begin
-          if t = TriggerList then TriggerList:= nt
-                             else pt^.Next:= nt;
-          Dispose(t)
+          if t = TriggerList then
+             begin
+             TriggerList:= nt;
+             Dispose(t)
+             end
+          else
+             begin
+             pt^.Next:= nt;
+             Dispose(t);
+             t:= pt
+             end
           end
        end
     end;
--- a/share/hedgewars/Data/Trainings/001_Shotgun.txt	Sat Sep 29 16:39:21 2007 +0000
+++ b/share/hedgewars/Data/Trainings/001_Shotgun.txt	Sun Sep 30 13:36:32 2007 +0000
@@ -1,4 +1,4 @@
-seed none
+seed 0
 $gmflags 268435458
 $turntime 60000
 $casefreq 0
@@ -14,4 +14,5 @@
 addtrig s4 1 1 33 1450 275 5
 addtrig s5 1 1 33 220 535 6
 addtrig s6 1 1 33 1410 505 7
-addtrig C7
+addtrig C7 1 1
+addtrig F2147483649 2 1