--- a/hedgewars/CCHandlers.inc Fri Sep 14 20:51:40 2007 +0000
+++ b/hedgewars/CCHandlers.inc Sat Sep 15 10:27:34 2007 +0000
@@ -469,5 +469,5 @@
var t: LongWord;
begin
val(s, t);
-AddTrigger(t, 1)
+AddTrigger(t, 1, 2)
end;
--- a/hedgewars/uTriggers.pas Fri Sep 14 20:51:40 2007 +0000
+++ b/hedgewars/uTriggers.pas Sat Sep 15 10:27:34 2007 +0000
@@ -23,7 +23,7 @@
{$INCLUDE options.inc}
const trigTurns = $80000001;
-procedure AddTrigger(id, Ticks: Longword);
+procedure AddTrigger(id, Ticks, Lives: Longword);
procedure TickTrigger(id: Longword);
implementation
@@ -32,20 +32,24 @@
TTrigger = record
id: Longword;
Ticks: Longword;
+ Lives: Longword;
+ TicksPerLife: LongWord;
Next: PTrigger;
end;
var TriggerList: PTrigger = nil;
-procedure AddTrigger(id, Ticks: Longword);
+procedure AddTrigger(id, Ticks, Lives: Longword);
var tmp: PTrigger;
begin
-if (Ticks = 0) then exit;
+if (Ticks = 0) or (Lives = 0) then exit;
{$IFDEF DEBUGFILE}AddFileLog('Add trigger: ' + inttostr(id));{$ENDIF}
new(tmp);
FillChar(tmp^, sizeof(TGear), 0);
tmp^.id:= id;
tmp^.Ticks:= Ticks;
+tmp^.TicksPerLife:= Ticks;
+tmp^.Lives:= Lives;
if TriggerList <> nil then tmp^.Next:= TriggerList;
TriggerList:= tmp
end;
@@ -56,25 +60,32 @@
end;
procedure TickTrigger(id: Longword);
-var t, tt: PTrigger;
+var t, pt, nt: PTrigger;
begin
t:= TriggerList;
+pt:= nil;
while (t <> nil) do
begin
- if t^.id = id then
+ nt:= t^.Next;
+ if (t^.id = id) then
begin
- tt:= t;
dec(t^.Ticks);
if (t^.Ticks = 0) then
begin
TickTriggerT(t);
- if t = TriggerList then TriggerList:= t^.Next
- else tt^.Next:= t^.Next;
- Dispose(t)
+ dec(t^.Lives);
+ t^.Ticks:= t^.TicksPerLife;
+ if (t^.Lives = 0) then
+ begin
+ if t = TriggerList then TriggerList:= nt
+ else pt^.Next:= nt;
+ Dispose(t)
+ end
end
- else t:= t^.Next
- end else t:= t^.Next
+ end;
+ pt:= t;
+ t:= nt
end
end;