author | unc0rr |
Sat, 22 Sep 2007 17:04:28 +0000 | |
changeset 610 | 9b5a6200f667 |
parent 595 | 5ee863f2f568 |
child 613 | e8cf72d0e0f7 |
permissions | -rw-r--r-- |
589 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
19 |
unit uTriggers; |
|
20 |
||
21 |
interface |
|
22 |
uses SDLh, uConsts; |
|
23 |
{$INCLUDE options.inc} |
|
593 | 24 |
const trigTurns = $80000001; |
589 | 25 |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
26 |
type TTrigAction = (taSpawnGear); |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
27 |
|
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
28 |
procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword); |
593 | 29 |
procedure TickTrigger(id: Longword); |
589 | 30 |
|
31 |
implementation |
|
610 | 32 |
uses uGears, uFloat, uMisc, uWorld; |
589 | 33 |
type PTrigger = ^TTrigger; |
34 |
TTrigger = record |
|
35 |
id: Longword; |
|
593 | 36 |
Ticks: Longword; |
594 | 37 |
Lives: Longword; |
38 |
TicksPerLife: LongWord; |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
39 |
Action: TTrigAction; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
40 |
X, Y: LongInt; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
41 |
SpawnGearType: TGearType; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
42 |
SpawnGearTriggerId: Longword; |
589 | 43 |
Next: PTrigger; |
44 |
end; |
|
45 |
var TriggerList: PTrigger = nil; |
|
46 |
||
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
47 |
procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword); |
589 | 48 |
var tmp: PTrigger; |
49 |
begin |
|
594 | 50 |
if (Ticks = 0) or (Lives = 0) then exit; |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
51 |
{$IFDEF DEBUGFILE}AddFileLog('Add spawner trigger: ' + inttostr(id) + ', gear triggers ' + inttostr(GearTriggerId));{$ENDIF} |
589 | 52 |
new(tmp); |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
53 |
FillChar(tmp^, sizeof(TTrigger), 0); |
589 | 54 |
|
55 |
tmp^.id:= id; |
|
593 | 56 |
tmp^.Ticks:= Ticks; |
594 | 57 |
tmp^.TicksPerLife:= Ticks; |
58 |
tmp^.Lives:= Lives; |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
59 |
tmp^.Action:= taSpawnGear; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
60 |
tmp^.X:= X; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
61 |
tmp^.Y:= Y; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
62 |
tmp^.SpawnGearType:= GearType; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
63 |
tmp^.SpawnGearTriggerId:= GearTriggerId; |
589 | 64 |
if TriggerList <> nil then tmp^.Next:= TriggerList; |
65 |
TriggerList:= tmp |
|
66 |
end; |
|
67 |
||
593 | 68 |
procedure TickTriggerT(Trigger: PTrigger); |
69 |
begin |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
70 |
with Trigger^ do |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
71 |
case Action of |
610 | 72 |
taSpawnGear: begin |
73 |
FollowGear:= AddGear(X, Y, SpawnGearType, 0, _0, _0, 0); |
|
74 |
FollowGear^.TriggerId:= SpawnGearTriggerId |
|
75 |
end |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
76 |
end |
593 | 77 |
end; |
78 |
||
79 |
procedure TickTrigger(id: Longword); |
|
594 | 80 |
var t, pt, nt: PTrigger; |
589 | 81 |
begin |
593 | 82 |
t:= TriggerList; |
594 | 83 |
pt:= nil; |
593 | 84 |
|
85 |
while (t <> nil) do |
|
86 |
begin |
|
594 | 87 |
nt:= t^.Next; |
88 |
if (t^.id = id) then |
|
593 | 89 |
begin |
90 |
dec(t^.Ticks); |
|
91 |
if (t^.Ticks = 0) then |
|
92 |
begin |
|
93 |
TickTriggerT(t); |
|
594 | 94 |
dec(t^.Lives); |
95 |
t^.Ticks:= t^.TicksPerLife; |
|
96 |
if (t^.Lives = 0) then |
|
97 |
begin |
|
98 |
if t = TriggerList then TriggerList:= nt |
|
99 |
else pt^.Next:= nt; |
|
100 |
Dispose(t) |
|
101 |
end |
|
593 | 102 |
end |
594 | 103 |
end; |
104 |
pt:= t; |
|
105 |
t:= nt |
|
593 | 106 |
end |
589 | 107 |
end; |
108 |
||
109 |
end. |