author | unc0rr |
Sat, 29 Sep 2007 16:39:21 +0000 | |
changeset 614 | 0e04504bc140 |
parent 613 | e8cf72d0e0f7 |
child 615 | b646b3c43369 |
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 |
|
613 | 26 |
type TTrigAction = (taSpawnGear, taSuccessFinish); |
595
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); |
613 | 29 |
procedure AddTriggerSuccess(tId: Longword); |
593 | 30 |
procedure TickTrigger(id: Longword); |
589 | 31 |
|
32 |
implementation |
|
610 | 33 |
uses uGears, uFloat, uMisc, uWorld; |
589 | 34 |
type PTrigger = ^TTrigger; |
35 |
TTrigger = record |
|
36 |
id: Longword; |
|
593 | 37 |
Ticks: Longword; |
594 | 38 |
Lives: Longword; |
39 |
TicksPerLife: LongWord; |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
40 |
Action: TTrigAction; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
41 |
X, Y: LongInt; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
42 |
SpawnGearType: TGearType; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
43 |
SpawnGearTriggerId: Longword; |
589 | 44 |
Next: PTrigger; |
45 |
end; |
|
46 |
var TriggerList: PTrigger = nil; |
|
47 |
||
613 | 48 |
function AddTrigger: PTrigger; |
49 |
var tmp: PTrigger; |
|
50 |
begin |
|
51 |
new(tmp); |
|
52 |
FillChar(tmp^, sizeof(TTrigger), 0); |
|
53 |
if TriggerList <> nil then tmp^.Next:= TriggerList; |
|
54 |
TriggerList:= tmp; |
|
55 |
AddTrigger:= tmp |
|
56 |
end; |
|
57 |
||
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
58 |
procedure AddTriggerSpawner(id, Ticks, Lives: Longword; X, Y: LongInt; GearType: TGearType; GearTriggerId: Longword); |
589 | 59 |
var tmp: PTrigger; |
60 |
begin |
|
594 | 61 |
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
|
62 |
{$IFDEF DEBUGFILE}AddFileLog('Add spawner trigger: ' + inttostr(id) + ', gear triggers ' + inttostr(GearTriggerId));{$ENDIF} |
589 | 63 |
|
613 | 64 |
tmp:= AddTrigger; |
589 | 65 |
tmp^.id:= id; |
593 | 66 |
tmp^.Ticks:= Ticks; |
594 | 67 |
tmp^.TicksPerLife:= Ticks; |
68 |
tmp^.Lives:= Lives; |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
69 |
tmp^.Action:= taSpawnGear; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
70 |
tmp^.X:= X; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
71 |
tmp^.Y:= Y; |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
72 |
tmp^.SpawnGearType:= GearType; |
613 | 73 |
tmp^.SpawnGearTriggerId:= GearTriggerId |
74 |
end; |
|
75 |
||
76 |
procedure AddTriggerSuccess(tId: Longword); |
|
77 |
begin |
|
78 |
with AddTrigger^ do |
|
79 |
begin |
|
80 |
id:= tId; |
|
81 |
Ticks:= 1; |
|
82 |
TicksPerLife:= 1; |
|
83 |
Action:= taSuccessFinish |
|
84 |
end |
|
589 | 85 |
end; |
86 |
||
593 | 87 |
procedure TickTriggerT(Trigger: PTrigger); |
88 |
begin |
|
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
89 |
with Trigger^ do |
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
90 |
case Action of |
610 | 91 |
taSpawnGear: begin |
92 |
FollowGear:= AddGear(X, Y, SpawnGearType, 0, _0, _0, 0); |
|
93 |
FollowGear^.TriggerId:= SpawnGearTriggerId |
|
613 | 94 |
end; |
95 |
taSuccessFinish: begin |
|
96 |
GameState:= gsExit |
|
610 | 97 |
end |
595
5ee863f2f568
Triggers PoC: targets are spawned right after the previous damaged
unc0rr
parents:
594
diff
changeset
|
98 |
end |
593 | 99 |
end; |
100 |
||
101 |
procedure TickTrigger(id: Longword); |
|
594 | 102 |
var t, pt, nt: PTrigger; |
589 | 103 |
begin |
593 | 104 |
t:= TriggerList; |
594 | 105 |
pt:= nil; |
593 | 106 |
|
107 |
while (t <> nil) do |
|
108 |
begin |
|
594 | 109 |
nt:= t^.Next; |
110 |
if (t^.id = id) then |
|
593 | 111 |
begin |
112 |
dec(t^.Ticks); |
|
113 |
if (t^.Ticks = 0) then |
|
114 |
begin |
|
115 |
TickTriggerT(t); |
|
594 | 116 |
dec(t^.Lives); |
117 |
t^.Ticks:= t^.TicksPerLife; |
|
118 |
if (t^.Lives = 0) then |
|
119 |
begin |
|
120 |
if t = TriggerList then TriggerList:= nt |
|
121 |
else pt^.Next:= nt; |
|
122 |
Dispose(t) |
|
123 |
end |
|
593 | 124 |
end |
594 | 125 |
end; |
126 |
pt:= t; |
|
127 |
t:= nt |
|
593 | 128 |
end |
589 | 129 |
end; |
130 |
||
131 |
end. |