hedgewars/uTriggers.pas
author unc0rr
Fri, 14 Sep 2007 20:51:40 +0000
changeset 593 1f5e66379a43
parent 589 f382c41f658a
child 594 221ffeb92f30
permissions -rw-r--r--
Triggers proof-of-concept
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     1
(*
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com>
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     4
 *
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     8
 *
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    13
 *
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    17
 *)
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    18
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    19
unit uTriggers;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    20
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    21
interface
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    22
uses SDLh, uConsts;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    23
{$INCLUDE options.inc}
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    24
const trigTurns = $80000001;
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    25
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    26
procedure AddTrigger(id, Ticks: Longword);
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    27
procedure TickTrigger(id: Longword);
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    28
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    29
implementation
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    30
uses uGears, uFloat, uMisc;
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    31
type PTrigger = ^TTrigger;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    32
     TTrigger = record
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    33
                id: Longword;
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    34
                Ticks: Longword;
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    35
                Next: PTrigger;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    36
                end;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    37
var TriggerList: PTrigger = nil;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    38
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    39
procedure AddTrigger(id, Ticks: Longword);
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    40
var tmp: PTrigger;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    41
begin
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    42
if (Ticks = 0) then exit;
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    43
{$IFDEF DEBUGFILE}AddFileLog('Add trigger: ' + inttostr(id));{$ENDIF}
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    44
new(tmp);
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    45
FillChar(tmp^, sizeof(TGear), 0);
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    46
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    47
tmp^.id:= id;
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    48
tmp^.Ticks:= Ticks;
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    49
if TriggerList <> nil then tmp^.Next:= TriggerList;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    50
TriggerList:= tmp
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    51
end;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    52
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    53
procedure TickTriggerT(Trigger: PTrigger);
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    54
begin
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    55
AddGear(1024, -140, gtTarget, 0, _0, _0, 0)
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    56
end;
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    57
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    58
procedure TickTrigger(id: Longword);
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    59
var t, tt: PTrigger;
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    60
begin
593
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    61
t:= TriggerList;
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    62
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    63
while (t <> nil) do
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    64
  begin
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    65
  if t^.id = id then
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    66
    begin
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    67
    tt:= t;
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    68
    dec(t^.Ticks);
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    69
    if (t^.Ticks = 0) then
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    70
       begin
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    71
       TickTriggerT(t);
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    72
       if t = TriggerList then TriggerList:= t^.Next
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    73
                          else tt^.Next:= t^.Next;
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    74
       Dispose(t)
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    75
       end
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    76
       else t:= t^.Next
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    77
    end else t:= t^.Next
1f5e66379a43 Triggers proof-of-concept
unc0rr
parents: 589
diff changeset
    78
  end
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    79
end;
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    80
f382c41f658a Start implementing triggers in engine
unc0rr
parents:
diff changeset
    81
end.