DEADSOFTWARE

no more old-styled map structured; sadly, most triggers aren't working; also, save...
[d2df-sdl.git] / src / game / g_triggers.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_triggers;
19 interface
21 uses
22 MAPDEF, e_graphics, g_basic, g_sound,
23 BinEditor, xdynrec;
25 type
26 TActivator = record
27 UID: Word;
28 TimeOut: Word;
29 end;
30 TTrigger = record
31 ID: DWORD;
32 ClientID: DWORD;
33 TriggerType: Byte;
34 X, Y: Integer;
35 Width, Height: Word;
36 Enabled: Boolean;
37 ActivateType: Byte;
38 Keys: Byte;
39 TexturePanel: Integer;
40 TexturePanelType: Word;
42 TimeOut: Word;
43 ActivateUID: Word;
44 Activators: array of TActivator;
45 PlayerCollide: Boolean;
46 DoorTime: Integer;
47 PressTime: Integer;
48 PressCount: Integer;
49 SoundPlayCount: Integer;
50 Sound: TPlayableSound;
51 AutoSpawn: Boolean;
52 SpawnCooldown: Integer;
53 SpawnedCount: Integer;
54 ShotPanelType: Word;
55 ShotPanelTime: Integer;
56 ShotSightTime: Integer;
57 ShotSightTimeout: Integer;
58 ShotSightTarget: Word;
59 ShotSightTargetN: Word;
60 ShotAmmoCount: Word;
61 ShotReloadTime: Integer;
63 trigShotPanelId: Integer;
64 trigPanelId: Integer;
66 //TrigData: TTriggerData;
67 trigData: TDynRecord; // triggerdata; owned by trigger
68 end;
70 function g_Triggers_Create(Trigger: TTrigger): DWORD;
71 procedure g_Triggers_Update();
72 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
73 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
74 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
75 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
76 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
77 procedure g_Triggers_OpenAll();
78 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
79 procedure g_Triggers_Free();
80 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
81 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
83 function tr_Message(MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
85 function tr_CloseDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
86 function tr_OpenDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
87 procedure tr_CloseTrap(PanelID: Integer; NoSound: Boolean; d2d: Boolean);
88 function tr_SetLift(PanelID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
90 function tr_Teleport(ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
91 function tr_Push(ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
93 procedure tr_MakeEffect(X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
94 function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
96 var
97 gTriggerClientID: Integer = 0;
98 gTriggers: array of TTrigger;
99 gSecretsCount: Integer = 0;
100 gMonstersSpawned: array of LongInt = nil;
102 implementation
104 uses
105 g_player, g_map, Math, g_gfx, g_game, g_textures,
106 g_console, g_monsters, g_items, g_phys, g_weapons,
107 wadreader, g_main, SysUtils, e_log, g_language,
108 g_options, g_net, g_netmsg, utils;
110 const
111 TRIGGER_SIGNATURE = $52475254; // 'TRGR'
112 TRAP_DAMAGE = 1000;
114 function FindTrigger(): DWORD;
115 var
116 i: Integer;
117 begin
118 if gTriggers <> nil then
119 for i := 0 to High(gTriggers) do
120 if gTriggers[i].TriggerType = TRIGGER_NONE then
121 begin
122 Result := i;
123 Exit;
124 end;
126 if gTriggers = nil then
127 begin
128 SetLength(gTriggers, 8);
129 Result := 0;
130 end
131 else
132 begin
133 Result := High(gTriggers) + 1;
134 SetLength(gTriggers, Length(gTriggers) + 8);
135 end;
136 end;
138 function tr_CloseDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
139 var
140 a, b, c: Integer;
141 begin
142 Result := False;
144 if PanelID = -1 then Exit;
146 if not d2d then
147 begin
148 with gWalls[PanelID] do
149 begin
150 if g_CollidePlayer(X, Y, Width, Height) or
151 g_Mons_IsAnyAliveAt(X, Y, Width, Height) then Exit;
153 if not Enabled then
154 begin
155 if not NoSound then
156 begin
157 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
158 if g_Game_IsServer and g_Game_IsNet then
159 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
160 end;
161 g_Map_EnableWall(PanelID);
162 Result := True;
163 end;
164 end;
165 end
166 else
167 begin
168 if gDoorMap = nil then Exit;
170 c := -1;
171 for a := 0 to High(gDoorMap) do
172 begin
173 for b := 0 to High(gDoorMap[a]) do
174 if gDoorMap[a, b] = DWORD(PanelID) then
175 begin
176 c := a;
177 Break;
178 end;
180 if c <> -1 then Break;
181 end;
182 if c = -1 then Exit;
184 for b := 0 to High(gDoorMap[c]) do
185 with gWalls[gDoorMap[c, b]] do
186 begin
187 if g_CollidePlayer(X, Y, Width, Height) or
188 g_Mons_IsAnyAliveAt(X, Y, Width, Height) then Exit;
189 end;
191 if not NoSound then
192 for b := 0 to High(gDoorMap[c]) do
193 if not gWalls[gDoorMap[c, b]].Enabled then
194 begin
195 with gWalls[PanelID] do
196 begin
197 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
198 if g_Game_IsServer and g_Game_IsNet then
199 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
200 end;
201 Break;
202 end;
204 for b := 0 to High(gDoorMap[c]) do
205 if not gWalls[gDoorMap[c, b]].Enabled then
206 begin
207 g_Map_EnableWall(gDoorMap[c, b]);
208 Result := True;
209 end;
210 end;
211 end;
213 procedure tr_CloseTrap(PanelID: Integer; NoSound: Boolean; d2d: Boolean);
214 var
215 a, b, c: Integer;
216 wx, wy, wh, ww: Integer;
218 function monsDamage (mon: TMonster): Boolean;
219 begin
220 result := false; // don't stop
221 if g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
222 end;
224 begin
225 if PanelID = -1 then Exit;
227 if not d2d then
228 begin
229 with gWalls[PanelID] do
230 begin
231 if (not NoSound) and (not Enabled) then
232 begin
233 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
234 if g_Game_IsServer and g_Game_IsNet then
235 MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
236 end;
237 end;
239 wx := gWalls[PanelID].X;
240 wy := gWalls[PanelID].Y;
241 ww := gWalls[PanelID].Width;
242 wh := gWalls[PanelID].Height;
244 with gWalls[PanelID] do
245 begin
246 if gPlayers <> nil then
247 for a := 0 to High(gPlayers) do
248 if (gPlayers[a] <> nil) and gPlayers[a].Live and
249 gPlayers[a].Collide(X, Y, Width, Height) then
250 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
252 //g_Mons_ForEach(monsDamage);
253 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
255 if not Enabled then g_Map_EnableWall(PanelID);
256 end;
257 end
258 else
259 begin
260 if gDoorMap = nil then Exit;
262 c := -1;
263 for a := 0 to High(gDoorMap) do
264 begin
265 for b := 0 to High(gDoorMap[a]) do
266 begin
267 if gDoorMap[a, b] = DWORD(PanelID) then
268 begin
269 c := a;
270 Break;
271 end;
272 end;
274 if c <> -1 then Break;
275 end;
276 if c = -1 then Exit;
278 if not NoSound then
279 begin
280 for b := 0 to High(gDoorMap[c]) do
281 begin
282 if not gWalls[gDoorMap[c, b]].Enabled then
283 begin
284 with gWalls[PanelID] do
285 begin
286 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
287 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
288 end;
289 Break;
290 end;
291 end;
292 end;
294 for b := 0 to High(gDoorMap[c]) do
295 begin
296 wx := gWalls[gDoorMap[c, b]].X;
297 wy := gWalls[gDoorMap[c, b]].Y;
298 ww := gWalls[gDoorMap[c, b]].Width;
299 wh := gWalls[gDoorMap[c, b]].Height;
301 with gWalls[gDoorMap[c, b]] do
302 begin
303 if gPlayers <> nil then
304 for a := 0 to High(gPlayers) do
305 if (gPlayers[a] <> nil) and gPlayers[a].Live and
306 gPlayers[a].Collide(X, Y, Width, Height) then
307 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
309 //g_Mons_ForEach(monsDamage);
310 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
311 (*
312 if gMonsters <> nil then
313 for a := 0 to High(gMonsters) do
314 if (gMonsters[a] <> nil) and gMonsters[a].Live and
315 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
316 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
317 *)
319 if not Enabled then g_Map_EnableWall(gDoorMap[c, b]);
320 end;
321 end;
322 end;
323 end;
325 function tr_OpenDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
326 var
327 a, b, c: Integer;
328 begin
329 Result := False;
331 if PanelID = -1 then Exit;
333 if not d2d then
334 begin
335 with gWalls[PanelID] do
336 if Enabled then
337 begin
338 if not NoSound then
339 begin
340 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
341 if g_Game_IsServer and g_Game_IsNet then
342 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
343 end;
344 g_Map_DisableWall(PanelID);
345 Result := True;
346 end;
347 end
348 else
349 begin
350 if gDoorMap = nil then Exit;
352 c := -1;
353 for a := 0 to High(gDoorMap) do
354 begin
355 for b := 0 to High(gDoorMap[a]) do
356 if gDoorMap[a, b] = DWORD(PanelID) then
357 begin
358 c := a;
359 Break;
360 end;
362 if c <> -1 then Break;
363 end;
364 if c = -1 then Exit;
366 if not NoSound then
367 for b := 0 to High(gDoorMap[c]) do
368 if gWalls[gDoorMap[c, b]].Enabled then
369 begin
370 with gWalls[PanelID] do
371 begin
372 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
373 if g_Game_IsServer and g_Game_IsNet then
374 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
375 end;
376 Break;
377 end;
379 for b := 0 to High(gDoorMap[c]) do
380 if gWalls[gDoorMap[c, b]].Enabled then
381 begin
382 g_Map_DisableWall(gDoorMap[c, b]);
383 Result := True;
384 end;
385 end;
386 end;
388 function tr_SetLift(PanelID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
389 var
390 a, b, c, t: Integer;
391 begin
392 t := 0;
393 Result := False;
395 if PanelID = -1 then Exit;
397 if (gLifts[PanelID].PanelType = PANEL_LIFTUP) or
398 (gLifts[PanelID].PanelType = PANEL_LIFTDOWN) then
399 case d of
400 0: t := 0;
401 1: t := 1;
402 else t := IfThen(gLifts[PanelID].LiftType = 1, 0, 1);
403 end
404 else if (gLifts[PanelID].PanelType = PANEL_LIFTLEFT) or
405 (gLifts[PanelID].PanelType = PANEL_LIFTRIGHT) then
406 case d of
407 0: t := 2;
408 1: t := 3;
409 else t := IfThen(gLifts[PanelID].LiftType = 2, 3, 2);
410 end;
412 if not d2d then
413 begin
414 with gLifts[PanelID] do
415 if LiftType <> t then
416 begin
417 g_Map_SetLift(PanelID, t);
419 {if not NoSound then
420 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);}
421 Result := True;
422 end;
423 end
424 else // Êàê â D2d
425 begin
426 if gLiftMap = nil then Exit;
428 c := -1;
429 for a := 0 to High(gLiftMap) do
430 begin
431 for b := 0 to High(gLiftMap[a]) do
432 if gLiftMap[a, b] = DWORD(PanelID) then
433 begin
434 c := a;
435 Break;
436 end;
438 if c <> -1 then Break;
439 end;
440 if c = -1 then Exit;
442 {if not NoSound then
443 for b := 0 to High(gLiftMap[c]) do
444 if gLifts[gLiftMap[c, b]].LiftType <> t then
445 begin
446 with gLifts[PanelID] do
447 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
448 Break;
449 end;}
451 for b := 0 to High(gLiftMap[c]) do
452 with gLifts[gLiftMap[c, b]] do
453 if LiftType <> t then
454 begin
455 g_Map_SetLift(gLiftMap[c, b], t);
457 Result := True;
458 end;
459 end;
460 end;
462 function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
463 var
464 snd: string;
465 Projectile: Boolean;
466 TextureID: DWORD;
467 Anim: TAnimation;
468 begin
469 Result := -1;
470 TextureID := DWORD(-1);
471 snd := 'SOUND_WEAPON_FIREROCKET';
472 Projectile := True;
473 case ShotType of
474 TRIGGER_SHOT_PISTOL:
475 begin
476 g_Weapon_pistol(wx, wy, dx, dy, 0, True);
477 snd := 'SOUND_WEAPON_FIREPISTOL';
478 Projectile := False;
479 if ShotSound then
480 begin
481 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
482 if g_Game_IsNet then
483 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
484 end;
485 end;
487 TRIGGER_SHOT_BULLET:
488 begin
489 g_Weapon_mgun(wx, wy, dx, dy, 0, True);
490 if gSoundEffectsDF then snd := 'SOUND_WEAPON_FIRECGUN'
491 else snd := 'SOUND_WEAPON_FIREPISTOL';
492 Projectile := False;
493 if ShotSound then
494 begin
495 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
496 if g_Game_IsNet then
497 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
498 end;
499 end;
501 TRIGGER_SHOT_SHOTGUN:
502 begin
503 g_Weapon_Shotgun(wx, wy, dx, dy, 0, True);
504 snd := 'SOUND_WEAPON_FIRESHOTGUN';
505 Projectile := False;
506 if ShotSound then
507 begin
508 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
509 if g_Game_IsNet then
510 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL2);
511 end;
512 end;
514 TRIGGER_SHOT_SSG:
515 begin
516 g_Weapon_DShotgun(wx, wy, dx, dy, 0, True);
517 snd := 'SOUND_WEAPON_FIRESHOTGUN2';
518 Projectile := False;
519 if ShotSound then
520 begin
521 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
522 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
523 if g_Game_IsNet then
524 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL3);
525 end;
526 end;
528 TRIGGER_SHOT_IMP:
529 begin
530 g_Weapon_ball1(wx, wy, dx, dy, 0, -1, True);
531 snd := 'SOUND_WEAPON_FIREBALL';
532 end;
534 TRIGGER_SHOT_PLASMA:
535 begin
536 g_Weapon_Plasma(wx, wy, dx, dy, 0, -1, True);
537 snd := 'SOUND_WEAPON_FIREPLASMA';
538 end;
540 TRIGGER_SHOT_SPIDER:
541 begin
542 g_Weapon_aplasma(wx, wy, dx, dy, 0, -1, True);
543 snd := 'SOUND_WEAPON_FIREPLASMA';
544 end;
546 TRIGGER_SHOT_CACO:
547 begin
548 g_Weapon_ball2(wx, wy, dx, dy, 0, -1, True);
549 snd := 'SOUND_WEAPON_FIREBALL';
550 end;
552 TRIGGER_SHOT_BARON:
553 begin
554 g_Weapon_ball7(wx, wy, dx, dy, 0, -1, True);
555 snd := 'SOUND_WEAPON_FIREBALL';
556 end;
558 TRIGGER_SHOT_MANCUB:
559 begin
560 g_Weapon_manfire(wx, wy, dx, dy, 0, -1, True);
561 snd := 'SOUND_WEAPON_FIREBALL';
562 end;
564 TRIGGER_SHOT_REV:
565 begin
566 g_Weapon_revf(wx, wy, dx, dy, 0, ShotTarget, -1, True);
567 snd := 'SOUND_WEAPON_FIREREV';
568 end;
570 TRIGGER_SHOT_ROCKET:
571 begin
572 g_Weapon_Rocket(wx, wy, dx, dy, 0, -1, True);
573 snd := 'SOUND_WEAPON_FIREROCKET';
574 end;
576 TRIGGER_SHOT_BFG:
577 begin
578 g_Weapon_BFGShot(wx, wy, dx, dy, 0, -1, True);
579 snd := 'SOUND_WEAPON_FIREBFG';
580 end;
582 TRIGGER_SHOT_EXPL:
583 begin
584 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
585 begin
586 Anim := TAnimation.Create(TextureID, False, 6);
587 Anim.Blending := False;
588 g_GFX_OnceAnim(wx-64, wy-64, Anim);
589 Anim.Free();
590 end;
591 Projectile := False;
592 g_Weapon_Explode(wx, wy, 60, 0);
593 snd := 'SOUND_WEAPON_EXPLODEROCKET';
594 end;
596 TRIGGER_SHOT_BFGEXPL:
597 begin
598 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
599 begin
600 Anim := TAnimation.Create(TextureID, False, 6);
601 Anim.Blending := False;
602 g_GFX_OnceAnim(wx-64, wy-64, Anim);
603 Anim.Free();
604 end;
605 Projectile := False;
606 g_Weapon_BFG9000(wx, wy, 0);
607 snd := 'SOUND_WEAPON_EXPLODEBFG';
608 end;
610 else exit;
611 end;
613 if g_Game_IsNet and g_Game_IsServer then
614 case ShotType of
615 TRIGGER_SHOT_EXPL:
616 MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_EXPLODE);
617 TRIGGER_SHOT_BFGEXPL:
618 MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_BFGEXPL);
619 else
620 begin
621 if Projectile then
622 MH_SEND_CreateShot(LastShotID);
623 if ShotSound then
624 MH_SEND_Sound(wx, wy, snd);
625 end;
626 end;
628 if ShotSound then
629 g_Sound_PlayExAt(snd, wx, wy);
631 if Projectile then
632 Result := LastShotID;
633 end;
635 procedure MakeShot(var Trigger: TTrigger; wx, wy, dx, dy: Integer; TargetUID: Word);
636 begin
637 with Trigger do
638 if (trigData.trigShotAmmo = 0) or
639 ((trigData.trigShotAmmo > 0) and (ShotAmmoCount > 0)) then
640 begin
641 if (trigShotPanelID <> -1) and (ShotPanelTime = 0) then
642 begin
643 g_Map_SwitchTexture(ShotPanelType, trigShotPanelID);
644 ShotPanelTime := 4; // òèêîâ íà âñïûøêó âûñòðåëà
645 end;
647 if trigData.trigShotIntSight > 0 then
648 ShotSightTimeout := 180; // ~= 5 ñåêóíä
650 if ShotAmmoCount > 0 then Dec(ShotAmmoCount);
652 dx := dx + Random(trigData.trigShotAccuracy) - Random(trigData.trigShotAccuracy);
653 dy := dy + Random(trigData.trigShotAccuracy) - Random(trigData.trigShotAccuracy);
655 tr_SpawnShot(trigData.trigShotType, wx, wy, dx, dy, trigData.trigShotSound, TargetUID);
656 end
657 else
658 if (trigData.trigShotIntReload > 0) and (ShotReloadTime = 0) then
659 ShotReloadTime := trigData.trigShotIntReload; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
660 end;
662 procedure tr_MakeEffect(X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
663 var
664 FramesID: DWORD;
665 Anim: TAnimation;
666 begin
667 if T = TRIGGER_EFFECT_PARTICLE then
668 case ST of
669 TRIGGER_EFFECT_SLIQUID:
670 begin
671 if (CR = 255) and (CG = 0) and (CB = 0) then
672 g_GFX_SimpleWater(X, Y, 1, VX, VY, 1, 0, 0, 0)
673 else if (CR = 0) and (CG = 255) and (CB = 0) then
674 g_GFX_SimpleWater(X, Y, 1, VX, VY, 2, 0, 0, 0)
675 else if (CR = 0) and (CG = 0) and (CB = 255) then
676 g_GFX_SimpleWater(X, Y, 1, VX, VY, 3, 0, 0, 0)
677 else
678 g_GFX_SimpleWater(X, Y, 1, VX, VY, 0, 0, 0, 0);
679 end;
680 TRIGGER_EFFECT_LLIQUID:
681 g_GFX_SimpleWater(X, Y, 1, VX, VY, 4, CR, CG, CB);
682 TRIGGER_EFFECT_DLIQUID:
683 g_GFX_SimpleWater(X, Y, 1, VX, VY, 5, CR, CG, CB);
684 TRIGGER_EFFECT_BLOOD:
685 g_GFX_Blood(X, Y, 1, VX, VY, 0, 0, CR, CG, CB);
686 TRIGGER_EFFECT_SPARK:
687 g_GFX_Spark(X, Y, 1, GetAngle2(VX, VY), 0, 0);
688 TRIGGER_EFFECT_BUBBLE:
689 g_GFX_Bubbles(X, Y, 1, 0, 0);
690 end;
691 if T = TRIGGER_EFFECT_ANIMATION then
692 case ST of
693 EFFECT_TELEPORT: begin
694 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
695 begin
696 Anim := TAnimation.Create(FramesID, False, 3);
697 if not Silent then
698 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
699 g_GFX_OnceAnim(X-32, Y-32, Anim);
700 Anim.Free();
701 end;
702 if Send and g_Game_IsServer and g_Game_IsNet then
703 MH_SEND_Effect(X, Y, Byte(not Silent), NET_GFX_TELE);
704 end;
705 EFFECT_RESPAWN: begin
706 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
707 begin
708 Anim := TAnimation.Create(FramesID, False, 4);
709 if not Silent then
710 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
711 g_GFX_OnceAnim(X-16, Y-16, Anim);
712 Anim.Free();
713 end;
714 if Send and g_Game_IsServer and g_Game_IsNet then
715 MH_SEND_Effect(X-16, Y-16, Byte(not Silent), NET_GFX_RESPAWN);
716 end;
717 EFFECT_FIRE: begin
718 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
719 begin
720 Anim := TAnimation.Create(FramesID, False, 4);
721 if not Silent then
722 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
723 g_GFX_OnceAnim(X-32, Y-128, Anim);
724 Anim.Free();
725 end;
726 if Send and g_Game_IsServer and g_Game_IsNet then
727 MH_SEND_Effect(X-32, Y-128, Byte(not Silent), NET_GFX_FIRE);
728 end;
729 end;
730 end;
732 function tr_Teleport(ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
733 var
734 p: TPlayer;
735 m: TMonster;
736 begin
737 Result := False;
738 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
739 case g_GetUIDType(ActivateUID) of
740 UID_PLAYER:
741 begin
742 p := g_Player_Get(ActivateUID);
743 if p = nil then
744 Exit;
746 if D2D then
747 begin
748 if p.TeleportTo(TX-(p.Obj.Rect.Width div 2),
749 TY-p.Obj.Rect.Height,
750 Silent,
751 TDir) then
752 Result := True;
753 end
754 else
755 if p.TeleportTo(TX, TY, Silent, TDir) then
756 Result := True;
757 end;
759 UID_MONSTER:
760 begin
761 m := g_Monsters_ByUID(ActivateUID);
762 if m = nil then
763 Exit;
765 if D2D then
766 begin
767 if m.TeleportTo(TX-(m.Obj.Rect.Width div 2),
768 TY-m.Obj.Rect.Height,
769 Silent,
770 TDir) then
771 Result := True;
772 end
773 else
774 if m.TeleportTo(TX, TY, Silent, TDir) then
775 Result := True;
776 end;
777 end;
778 end;
780 function tr_Push(ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
781 var
782 p: TPlayer;
783 m: TMonster;
784 begin
785 Result := True;
786 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
787 case g_GetUIDType(ActivateUID) of
788 UID_PLAYER:
789 begin
790 p := g_Player_Get(ActivateUID);
791 if p = nil then
792 Exit;
794 if ResetVel then
795 begin
796 p.GameVelX := 0;
797 p.GameVelY := 0;
798 p.GameAccelX := 0;
799 p.GameAccelY := 0;
800 end;
802 p.Push(VX, VY);
803 end;
805 UID_MONSTER:
806 begin
807 m := g_Monsters_ByUID(ActivateUID);
808 if m = nil then
809 Exit;
811 if ResetVel then
812 begin
813 m.GameVelX := 0;
814 m.GameVelY := 0;
815 m.GameAccelX := 0;
816 m.GameAccelY := 0;
817 end;
819 m.Push(VX, VY);
820 end;
821 end;
822 end;
824 function tr_Message(MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
825 var
826 msg: string;
827 p: TPlayer;
828 i: Integer;
829 begin
830 Result := True;
831 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
832 msg := b_Text_Format(MText);
833 case MSendTo of
834 0: // activator
835 begin
836 if g_GetUIDType(ActivateUID) = UID_PLAYER then
837 begin
838 if g_Game_IsWatchedPlayer(ActivateUID) then
839 begin
840 if MKind = 0 then
841 g_Console_Add(msg, True)
842 else if MKind = 1 then
843 g_Game_Message(msg, MTime);
844 end
845 else
846 begin
847 p := g_Player_Get(ActivateUID);
848 if g_Game_IsNet and (p.FClientID >= 0) then
849 if MKind = 0 then
850 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, p.FClientID)
851 else if MKind = 1 then
852 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, p.FClientID);
853 end;
854 end;
855 end;
857 1: // activator's team
858 begin
859 if g_GetUIDType(ActivateUID) = UID_PLAYER then
860 begin
861 p := g_Player_Get(ActivateUID);
862 if g_Game_IsWatchedTeam(p.Team) then
863 if MKind = 0 then
864 g_Console_Add(msg, True)
865 else if MKind = 1 then
866 g_Game_Message(msg, MTime);
868 if g_Game_IsNet then
869 begin
870 for i := Low(gPlayers) to High(gPlayers) do
871 if (gPlayers[i].Team = p.Team) and (gPlayers[i].FClientID >= 0) then
872 if MKind = 0 then
873 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
874 else if MKind = 1 then
875 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
876 end;
877 end;
878 end;
880 2: // activator's enemy team
881 begin
882 if g_GetUIDType(ActivateUID) = UID_PLAYER then
883 begin
884 p := g_Player_Get(ActivateUID);
885 if g_Game_IsWatchedTeam(p.Team) then
886 if MKind = 0 then
887 g_Console_Add(msg, True)
888 else if MKind = 1 then
889 g_Game_Message(msg, MTime);
891 if g_Game_IsNet then
892 begin
893 for i := Low(gPlayers) to High(gPlayers) do
894 if (gPlayers[i].Team <> p.Team) and (gPlayers[i].FClientID >= 0) then
895 if MKind = 0 then
896 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
897 else if MKind = 1 then
898 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
899 end;
900 end;
901 end;
903 3: // red team
904 begin
905 if g_Game_IsWatchedTeam(TEAM_RED) then
906 if MKind = 0 then
907 g_Console_Add(msg, True)
908 else if MKind = 1 then
909 g_Game_Message(msg, MTime);
911 if g_Game_IsNet then
912 begin
913 for i := Low(gPlayers) to High(gPlayers) do
914 if (gPlayers[i].Team = TEAM_RED) and (gPlayers[i].FClientID >= 0) then
915 if MKind = 0 then
916 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
917 else if MKind = 1 then
918 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
919 end;
920 end;
922 4: // blue team
923 begin
924 if g_Game_IsWatchedTeam(TEAM_BLUE) then
925 if MKind = 0 then
926 g_Console_Add(msg, True)
927 else if MKind = 1 then
928 g_Game_Message(msg, MTime);
930 if g_Game_IsNet then
931 begin
932 for i := Low(gPlayers) to High(gPlayers) do
933 if (gPlayers[i].Team = TEAM_BLUE) and (gPlayers[i].FClientID >= 0) then
934 if MKind = 0 then
935 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
936 else if MKind = 1 then
937 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
938 end;
939 end;
941 5: // everyone
942 begin
943 if MKind = 0 then
944 g_Console_Add(msg, True)
945 else if MKind = 1 then
946 g_Game_Message(msg, MTime);
948 if g_Game_IsNet then
949 begin
950 if MKind = 0 then
951 MH_SEND_Chat(msg, NET_CHAT_SYSTEM)
952 else if MKind = 1 then
953 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg);
954 end;
955 end;
956 end;
957 end;
959 function tr_ShotAimCheck(var Trigger: TTrigger; Obj: PObj): Boolean;
960 begin
961 result := false;
962 with Trigger do
963 begin
964 if TriggerType <> TRIGGER_SHOT then
965 Exit;
966 Result := (trigData.trigShotAim and TRIGGER_SHOT_AIM_ALLMAP > 0)
967 or g_Obj_Collide(X, Y, Width, Height, Obj);
968 if Result and (trigData.trigShotAim and TRIGGER_SHOT_AIM_TRACE > 0) then
969 Result := g_TraceVector(trigData.trigShotPos.X,
970 trigData.trigShotPos.Y,
971 Obj^.X + Obj^.Rect.X + (Obj^.Rect.Width div 2),
972 Obj^.Y + Obj^.Rect.Y + (Obj^.Rect.Height div 2));
973 end;
974 end;
976 function ActivateTrigger(var Trigger: TTrigger; actType: Byte): Boolean;
977 var
978 animonce: Boolean;
979 p: TPlayer;
980 m: TMonster;
981 idx, k, wx, wy, xd, yd: Integer;
982 iid: LongWord;
983 coolDown: Boolean;
984 pAngle: Real;
985 FramesID: DWORD;
986 Anim: TAnimation;
987 UIDType: Byte;
988 TargetUID: Word;
989 it: PItem;
990 mon: TMonster;
992 function monsShotTarget (mon: TMonster): Boolean;
993 begin
994 result := false; // don't stop
995 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
996 begin
997 xd := mon.GameX + mon.Obj.Rect.Width div 2;
998 yd := mon.GameY + mon.Obj.Rect.Height div 2;
999 TargetUID := mon.UID;
1000 result := true; // stop
1001 end;
1002 end;
1004 function monsShotTargetMonPlr (mon: TMonster): Boolean;
1005 begin
1006 result := false; // don't stop
1007 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1008 begin
1009 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1010 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1011 TargetUID := mon.UID;
1012 result := true; // stop
1013 end;
1014 end;
1016 function monShotTargetPlrMon (mon: TMonster): Boolean;
1017 begin
1018 result := false; // don't stop
1019 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1020 begin
1021 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1022 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1023 TargetUID := mon.UID;
1024 result := true; // stop
1025 end;
1026 end;
1028 begin
1029 Result := False;
1030 if g_Game_IsClient then
1031 Exit;
1033 if not Trigger.Enabled then
1034 Exit;
1035 if (Trigger.TimeOut <> 0) and (actType <> ACTIVATE_CUSTOM) then
1036 Exit;
1037 if gLMSRespawn = LMS_RESPAWN_WARMUP then
1038 Exit;
1040 animonce := False;
1042 coolDown := (actType <> 0);
1044 with Trigger do
1045 begin
1046 case TriggerType of
1047 TRIGGER_EXIT:
1048 begin
1049 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1050 if g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH0');
1051 gExitByTrigger := True;
1052 g_Game_ExitLevel(trigData.trigMapName);
1053 TimeOut := 18;
1054 Result := True;
1056 Exit;
1057 end;
1059 TRIGGER_TELEPORT:
1060 begin
1061 Result := tr_Teleport(ActivateUID,
1062 trigData.trigTargetPoint.X, trigData.trigTargetPoint.Y,
1063 trigData.trigTlpDir, trigData.trigsilent_teleport,
1064 trigData.trigd2d_teleport);
1065 TimeOut := 0;
1066 end;
1068 TRIGGER_OPENDOOR:
1069 begin
1070 Result := tr_OpenDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1071 TimeOut := 0;
1072 end;
1074 TRIGGER_CLOSEDOOR:
1075 begin
1076 Result := tr_CloseDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1077 TimeOut := 0;
1078 end;
1080 TRIGGER_DOOR, TRIGGER_DOOR5:
1081 begin
1082 if trigPanelID <> -1 then
1083 begin
1084 if gWalls[trigPanelID].Enabled then
1085 begin
1086 Result := tr_OpenDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1088 if TriggerType = TRIGGER_DOOR5 then
1089 DoorTime := 180;
1090 end
1091 else
1092 Result := tr_CloseDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1094 if Result then
1095 TimeOut := 18;
1096 end;
1097 end;
1099 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1100 begin
1101 tr_CloseTrap(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1103 if TriggerType = TRIGGER_TRAP then
1104 begin
1105 DoorTime := 40;
1106 TimeOut := 76;
1107 end
1108 else
1109 begin
1110 DoorTime := -1;
1111 TimeOut := 0;
1112 end;
1114 Result := True;
1115 end;
1117 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
1118 begin
1119 PressCount := PressCount + 1;
1121 if PressTime = -1 then
1122 PressTime := trigData.trigWait;
1124 if coolDown then
1125 TimeOut := 18
1126 else
1127 TimeOut := 0;
1128 Result := True;
1129 end;
1131 TRIGGER_SECRET:
1132 if g_GetUIDType(ActivateUID) = UID_PLAYER then
1133 begin
1134 Enabled := False;
1135 Result := True;
1136 if gLMSRespawn = LMS_RESPAWN_NONE then
1137 begin
1138 g_Player_Get(ActivateUID).GetSecret();
1139 Inc(gCoopSecretsFound);
1140 if g_Game_IsNet then MH_SEND_GameStats();
1141 end;
1142 end;
1144 TRIGGER_LIFTUP:
1145 begin
1146 Result := tr_SetLift(trigPanelID, 0, trigData.trigNoSound, trigData.trigd2d_doors);
1147 TimeOut := 0;
1149 if (not trigData.trigNoSound) and Result then begin
1150 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1151 X + (Width div 2),
1152 Y + (Height div 2));
1153 if g_Game_IsServer and g_Game_IsNet then
1154 MH_SEND_Sound(X + (Width div 2),
1155 Y + (Height div 2),
1156 'SOUND_GAME_SWITCH0');
1157 end;
1158 end;
1160 TRIGGER_LIFTDOWN:
1161 begin
1162 Result := tr_SetLift(trigPanelID, 1, trigData.trigNoSound, trigData.trigd2d_doors);
1163 TimeOut := 0;
1165 if (not trigData.trigNoSound) and Result then begin
1166 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1167 X + (Width div 2),
1168 Y + (Height div 2));
1169 if g_Game_IsServer and g_Game_IsNet then
1170 MH_SEND_Sound(X + (Width div 2),
1171 Y + (Height div 2),
1172 'SOUND_GAME_SWITCH0');
1173 end;
1174 end;
1176 TRIGGER_LIFT:
1177 begin
1178 Result := tr_SetLift(trigPanelID, 3, trigData.trigNoSound, trigData.trigd2d_doors);
1180 if Result then
1181 begin
1182 TimeOut := 18;
1184 if (not trigData.trigNoSound) and Result then begin
1185 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1186 X + (Width div 2),
1187 Y + (Height div 2));
1188 if g_Game_IsServer and g_Game_IsNet then
1189 MH_SEND_Sound(X + (Width div 2),
1190 Y + (Height div 2),
1191 'SOUND_GAME_SWITCH0');
1192 end;
1193 end;
1194 end;
1196 TRIGGER_TEXTURE:
1197 begin
1198 if ByteBool(trigData.trigActivateOnce) then
1199 begin
1200 Enabled := False;
1201 TriggerType := TRIGGER_NONE;
1202 end
1203 else
1204 if coolDown then
1205 TimeOut := 6
1206 else
1207 TimeOut := 0;
1209 animonce := trigData.trigAnimOnce;
1210 Result := True;
1211 end;
1213 TRIGGER_SOUND:
1214 begin
1215 if Sound <> nil then
1216 begin
1217 if trigData.trigSoundSwitch and Sound.IsPlaying() then
1218 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1219 Sound.Stop();
1220 SoundPlayCount := 0;
1221 Result := True;
1222 end
1223 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1224 if (trigData.trigPlayCount > 0) or (not Sound.IsPlaying()) then
1225 begin
1226 if trigData.trigPlayCount > 0 then
1227 SoundPlayCount := trigData.trigPlayCount
1228 else // 0 - èãðàåì áåñêîíå÷íî
1229 SoundPlayCount := 1;
1230 Result := True;
1231 end;
1232 if g_Game_IsNet then MH_SEND_TriggerSound(Trigger);
1233 end;
1234 end;
1236 TRIGGER_SPAWNMONSTER:
1237 if (trigData.trigMonType in [MONSTER_DEMON..MONSTER_MAN]) then
1238 begin
1239 Result := False;
1240 if (trigData.trigMonDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1241 begin
1242 AutoSpawn := not AutoSpawn;
1243 SpawnCooldown := 0;
1244 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1245 Result := True;
1246 end;
1248 if ((trigData.trigMonDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1249 or ((trigData.trigMonDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1250 for k := 1 to trigData.trigMonCount do
1251 begin
1252 if (actType = ACTIVATE_CUSTOM) and (trigData.trigMonDelay > 0) then
1253 SpawnCooldown := trigData.trigMonDelay;
1254 if (trigData.trigMonMax > 0) and (SpawnedCount >= trigData.trigMonMax) then
1255 Break;
1257 mon := g_Monsters_Create(trigData.trigMonType,
1258 trigData.trigMonPos.X, trigData.trigMonPos.Y,
1259 TDirection(trigData.trigMonDir), True);
1261 Result := True;
1263 // Çäîðîâüå:
1264 if (trigData.trigMonHealth > 0) then
1265 mon.SetHealth(trigData.trigMonHealth);
1266 // Óñòàíàâëèâàåì ïîâåäåíèå:
1267 mon.MonsterBehaviour := trigData.trigMonBehav;
1268 mon.FNoRespawn := True;
1269 if g_Game_IsNet then
1270 MH_SEND_MonsterSpawn(mon.UID);
1271 // Èäåì èñêàòü öåëü, åñëè íàäî:
1272 if trigData.trigMonActive then
1273 mon.WakeUp();
1275 if trigData.trigMonType <> MONSTER_BARREL then Inc(gTotalMonsters);
1277 if g_Game_IsNet then
1278 begin
1279 SetLength(gMonstersSpawned, Length(gMonstersSpawned)+1);
1280 gMonstersSpawned[High(gMonstersSpawned)] := mon.UID;
1281 end;
1283 if trigData.trigMonMax > 0 then
1284 begin
1285 mon.SpawnTrigger := ID;
1286 Inc(SpawnedCount);
1287 end;
1289 case trigData.trigMonEffect of
1290 EFFECT_TELEPORT: begin
1291 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1292 begin
1293 Anim := TAnimation.Create(FramesID, False, 3);
1294 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1295 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1296 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, Anim);
1297 Anim.Free();
1298 end;
1299 if g_Game_IsServer and g_Game_IsNet then
1300 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1301 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, 1,
1302 NET_GFX_TELE);
1303 end;
1304 EFFECT_RESPAWN: begin
1305 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1306 begin
1307 Anim := TAnimation.Create(FramesID, False, 4);
1308 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1309 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1310 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, Anim);
1311 Anim.Free();
1312 end;
1313 if g_Game_IsServer and g_Game_IsNet then
1314 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1315 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, 1,
1316 NET_GFX_RESPAWN);
1317 end;
1318 EFFECT_FIRE: begin
1319 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1320 begin
1321 Anim := TAnimation.Create(FramesID, False, 4);
1322 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1323 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1324 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, Anim);
1325 Anim.Free();
1326 end;
1327 if g_Game_IsServer and g_Game_IsNet then
1328 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1329 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, 1,
1330 NET_GFX_FIRE);
1331 end;
1332 end;
1333 end;
1334 if g_Game_IsNet then
1335 begin
1336 MH_SEND_GameStats();
1337 MH_SEND_CoopStats();
1338 end;
1340 if coolDown then
1341 TimeOut := 18
1342 else
1343 TimeOut := 0;
1344 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1345 if actType = ACTIVATE_CUSTOM then
1346 Result := False;
1347 end;
1349 TRIGGER_SPAWNITEM:
1350 if (trigData.trigItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX]) then
1351 begin
1352 Result := False;
1353 if (trigData.trigItemDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1354 begin
1355 AutoSpawn := not AutoSpawn;
1356 SpawnCooldown := 0;
1357 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1358 Result := True;
1359 end;
1361 if ((trigData.trigItemDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1362 or ((trigData.trigItemDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1363 if (not trigData.trigItemOnlyDM) or
1364 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1365 for k := 1 to trigData.trigItemCount do
1366 begin
1367 if (actType = ACTIVATE_CUSTOM) and (trigData.trigItemDelay > 0) then
1368 SpawnCooldown := trigData.trigItemDelay;
1369 if (trigData.trigItemMax > 0) and (SpawnedCount >= trigData.trigItemMax) then
1370 Break;
1372 iid := g_Items_Create(trigData.trigItemPos.X, trigData.trigItemPos.Y,
1373 trigData.trigItemType, trigData.trigItemFalls, False, True);
1375 Result := True;
1377 if trigData.trigItemMax > 0 then
1378 begin
1379 it := g_Items_ByIdx(iid);
1380 it.SpawnTrigger := ID;
1381 Inc(SpawnedCount);
1382 end;
1384 case trigData.trigItemEffect of
1385 EFFECT_TELEPORT: begin
1386 it := g_Items_ByIdx(iid);
1387 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1388 begin
1389 Anim := TAnimation.Create(FramesID, False, 3);
1390 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1391 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1392 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, Anim);
1393 Anim.Free();
1394 end;
1395 if g_Game_IsServer and g_Game_IsNet then
1396 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1397 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, 1,
1398 NET_GFX_TELE);
1399 end;
1400 EFFECT_RESPAWN: begin
1401 it := g_Items_ByIdx(iid);
1402 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1403 begin
1404 Anim := TAnimation.Create(FramesID, False, 4);
1405 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1406 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1407 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, Anim);
1408 Anim.Free();
1409 end;
1410 if g_Game_IsServer and g_Game_IsNet then
1411 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1412 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, 1,
1413 NET_GFX_RESPAWN);
1414 end;
1415 EFFECT_FIRE: begin
1416 it := g_Items_ByIdx(iid);
1417 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1418 begin
1419 Anim := TAnimation.Create(FramesID, False, 4);
1420 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1421 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1422 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, Anim);
1423 Anim.Free();
1424 end;
1425 if g_Game_IsServer and g_Game_IsNet then
1426 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1427 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, 1,
1428 NET_GFX_FIRE);
1429 end;
1430 end;
1432 if g_Game_IsNet then
1433 MH_SEND_ItemSpawn(True, iid);
1434 end;
1436 if coolDown then
1437 TimeOut := 18
1438 else
1439 TimeOut := 0;
1440 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1441 if actType = ACTIVATE_CUSTOM then
1442 Result := False;
1443 end;
1445 TRIGGER_MUSIC:
1446 begin
1447 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1448 if (Trigger.trigData.trigMusicName <> '') then
1449 begin
1450 gMusic.SetByName(Trigger.trigData.trigMusicName);
1451 gMusic.SpecPause := True;
1452 gMusic.Play();
1453 end;
1455 if Trigger.trigData.trigMusicAction = 1 then
1456 begin // Âêëþ÷èòü
1457 if gMusic.SpecPause then // Áûëà íà ïàóçå => èãðàòü
1458 gMusic.SpecPause := False
1459 else // Èãðàëà => ñíà÷àëà
1460 gMusic.SetPosition(0);
1461 end
1462 else // Âûêëþ÷èòü
1463 begin
1464 // Ïàóçà:
1465 gMusic.SpecPause := True;
1466 end;
1468 if coolDown then
1469 TimeOut := 36
1470 else
1471 TimeOut := 0;
1472 Result := True;
1473 if g_Game_IsNet then MH_SEND_TriggerMusic;
1474 end;
1476 TRIGGER_PUSH:
1477 begin
1478 pAngle := -DegToRad(trigData.trigPushAngle);
1479 Result := tr_Push(ActivateUID,
1480 Floor(Cos(pAngle)*trigData.trigPushForce),
1481 Floor(Sin(pAngle)*trigData.trigPushForce),
1482 trigData.trigResetVel);
1483 TimeOut := 0;
1484 end;
1486 TRIGGER_SCORE:
1487 begin
1488 Result := False;
1489 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1490 if (trigData.trigScoreAction in [0..1]) and (trigData.trigScoreCount > 0) then
1491 begin
1492 // Ñâîåé èëè ÷óæîé êîìàíäå
1493 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1494 begin
1495 p := g_Player_Get(ActivateUID);
1496 if ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED))
1497 or ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1498 begin
1499 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1501 if trigData.trigScoreCon then
1502 if trigData.trigScoreTeam = 0 then
1503 begin
1504 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1505 if g_Game_IsServer and g_Game_IsNet then
1506 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+r');
1507 end else
1508 begin
1509 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1510 if g_Game_IsServer and g_Game_IsNet then
1511 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+re');
1512 end;
1514 if trigData.trigScoreMsg then
1515 begin
1516 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1517 if g_Game_IsServer and g_Game_IsNet then
1518 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1519 end;
1520 end;
1521 if ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED))
1522 or ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1523 begin
1524 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1526 if trigData.trigScoreCon then
1527 if trigData.trigScoreTeam = 0 then
1528 begin
1529 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1530 if g_Game_IsServer and g_Game_IsNet then
1531 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-r');
1532 end else
1533 begin
1534 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1535 if g_Game_IsServer and g_Game_IsNet then
1536 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-re');
1537 end;
1539 if trigData.trigScoreMsg then
1540 begin
1541 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1542 if g_Game_IsServer and g_Game_IsNet then
1543 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1544 end;
1545 end;
1546 if ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE))
1547 or ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1548 begin
1549 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1551 if trigData.trigScoreCon then
1552 if trigData.trigScoreTeam = 0 then
1553 begin
1554 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1555 if g_Game_IsServer and g_Game_IsNet then
1556 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+b');
1557 end else
1558 begin
1559 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1560 if g_Game_IsServer and g_Game_IsNet then
1561 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+be');
1562 end;
1564 if trigData.trigScoreMsg then
1565 begin
1566 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1567 if g_Game_IsServer and g_Game_IsNet then
1568 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1569 end;
1570 end;
1571 if ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE))
1572 or ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1573 begin
1574 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1576 if trigData.trigScoreCon then
1577 if trigData.trigScoreTeam = 0 then
1578 begin
1579 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1580 if g_Game_IsServer and g_Game_IsNet then
1581 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-b');
1582 end else
1583 begin
1584 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1585 if g_Game_IsServer and g_Game_IsNet then
1586 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-be');
1587 end;
1589 if trigData.trigScoreMsg then
1590 begin
1591 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1592 if g_Game_IsServer and g_Game_IsNet then
1593 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1594 end;
1595 end;
1596 Result := (p.Team = TEAM_RED) or (p.Team = TEAM_BLUE);
1597 end;
1598 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1599 if trigData.trigScoreTeam in [2..3] then
1600 begin
1601 if (trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 2) then
1602 begin
1603 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1605 if trigData.trigScoreCon then
1606 begin
1607 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1608 if g_Game_IsServer and g_Game_IsNet then
1609 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tr');
1610 end;
1612 if trigData.trigScoreMsg then
1613 begin
1614 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1615 if g_Game_IsServer and g_Game_IsNet then
1616 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1617 end;
1618 end;
1619 if (trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 2) then
1620 begin
1621 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1623 if trigData.trigScoreCon then
1624 begin
1625 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1626 if g_Game_IsServer and g_Game_IsNet then
1627 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tr');
1628 end;
1630 if trigData.trigScoreMsg then
1631 begin
1632 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1633 if g_Game_IsServer and g_Game_IsNet then
1634 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1635 end;
1636 end;
1637 if (trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 3) then
1638 begin
1639 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1641 if trigData.trigScoreCon then
1642 begin
1643 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1644 if g_Game_IsServer and g_Game_IsNet then
1645 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tb');
1646 end;
1648 if trigData.trigScoreMsg then
1649 begin
1650 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1651 if g_Game_IsServer and g_Game_IsNet then
1652 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1653 end;
1654 end;
1655 if (trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 3) then
1656 begin
1657 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1659 if trigData.trigScoreCon then
1660 begin
1661 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1662 if g_Game_IsServer and g_Game_IsNet then
1663 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tb');
1664 end;
1666 if trigData.trigScoreMsg then
1667 begin
1668 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1669 if g_Game_IsServer and g_Game_IsNet then
1670 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1671 end;
1672 end;
1673 Result := True;
1674 end;
1675 end;
1676 // Âûèãðûø
1677 if (trigData.trigScoreAction = 2) and (gGameSettings.GoalLimit > 0) then
1678 begin
1679 // Ñâîåé èëè ÷óæîé êîìàíäû
1680 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1681 begin
1682 p := g_Player_Get(ActivateUID);
1683 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED)) // Red Wins
1684 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1685 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1686 begin
1687 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1689 if trigData.trigScoreCon then
1690 if trigData.trigScoreTeam = 0 then
1691 begin
1692 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1693 if g_Game_IsServer and g_Game_IsNet then
1694 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1695 end else
1696 begin
1697 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1698 if g_Game_IsServer and g_Game_IsNet then
1699 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1700 end;
1702 Result := True;
1703 end;
1704 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE)) // Blue Wins
1705 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1706 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1707 begin
1708 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1710 if trigData.trigScoreCon then
1711 if trigData.trigScoreTeam = 0 then
1712 begin
1713 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1714 if g_Game_IsServer and g_Game_IsNet then
1715 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1716 end else
1717 begin
1718 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1719 if g_Game_IsServer and g_Game_IsNet then
1720 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1721 end;
1723 Result := True;
1724 end;
1725 end;
1726 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1727 if trigData.trigScoreTeam in [2..3] then
1728 begin
1729 if trigData.trigScoreTeam = 2 then // Red Wins
1730 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1731 begin
1732 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1733 Result := True;
1734 end;
1735 if trigData.trigScoreTeam = 3 then // Blue Wins
1736 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1737 begin
1738 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1739 Result := True;
1740 end;
1741 end;
1742 end;
1743 // Ïðîèãðûø
1744 if (trigData.trigScoreAction = 3) and (gGameSettings.GoalLimit > 0) then
1745 begin
1746 // Ñâîåé èëè ÷óæîé êîìàíäû
1747 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1748 begin
1749 p := g_Player_Get(ActivateUID);
1750 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE)) // Red Wins
1751 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1752 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1753 begin
1754 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1756 if trigData.trigScoreCon then
1757 if trigData.trigScoreTeam = 0 then
1758 begin
1759 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1760 if g_Game_IsServer and g_Game_IsNet then
1761 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1762 end else
1763 begin
1764 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1765 if g_Game_IsServer and g_Game_IsNet then
1766 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1767 end;
1769 Result := True;
1770 end;
1771 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED)) // Blue Wins
1772 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1773 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1774 begin
1775 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1777 if trigData.trigScoreCon then
1778 if trigData.trigScoreTeam = 0 then
1779 begin
1780 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1781 if g_Game_IsServer and g_Game_IsNet then
1782 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1783 end else
1784 begin
1785 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1786 if g_Game_IsServer and g_Game_IsNet then
1787 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1788 end;
1790 Result := True;
1791 end;
1792 end;
1793 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1794 if trigData.trigScoreTeam in [2..3] then
1795 begin
1796 if trigData.trigScoreTeam = 3 then // Red Wins
1797 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1798 begin
1799 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1800 Result := True;
1801 end;
1802 if trigData.trigScoreTeam = 2 then // Blue Wins
1803 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1804 begin
1805 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1806 Result := True;
1807 end;
1808 end;
1809 end;
1810 if Result then begin
1811 if coolDown then
1812 TimeOut := 18
1813 else
1814 TimeOut := 0;
1815 if g_Game_IsServer and g_Game_IsNet then
1816 MH_SEND_GameStats;
1817 end;
1818 end;
1820 TRIGGER_MESSAGE:
1821 begin
1822 Result := tr_Message(trigData.trigMessageKind, trigData.trigMessageText,
1823 trigData.trigMessageSendTo, trigData.trigMessageTime,
1824 ActivateUID);
1825 TimeOut := 18;
1826 end;
1828 TRIGGER_DAMAGE, TRIGGER_HEALTH:
1829 begin
1830 Result := False;
1831 UIDType := g_GetUIDType(ActivateUID);
1832 if (UIDType = UID_PLAYER) or (UIDType = UID_MONSTER) then
1833 begin
1834 Result := True;
1835 k := -1;
1836 if coolDown then
1837 begin
1838 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1839 for idx := 0 to High(Activators) do
1840 if Activators[idx].UID = ActivateUID then
1841 begin
1842 k := idx;
1843 Break;
1844 end;
1845 if k = -1 then
1846 begin // Âèäèì åãî âïåðâûå
1847 // Çàïîìèíàåì åãî
1848 SetLength(Activators, Length(Activators) + 1);
1849 k := High(Activators);
1850 Activators[k].UID := ActivateUID;
1851 end else
1852 begin // Óæå âèäåëè åãî
1853 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1854 if (trigData.trigDamageInterval = 0) and (Activators[k].TimeOut > 0) then
1855 Activators[k].TimeOut := 65535;
1856 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1857 Result := Activators[k].TimeOut = 0;
1858 end;
1859 end;
1861 if Result then
1862 begin
1863 case UIDType of
1864 UID_PLAYER:
1865 begin
1866 p := g_Player_Get(ActivateUID);
1867 if p = nil then
1868 Exit;
1870 // Íàíîñèì óðîí èãðîêó
1871 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigDamageValue > 0) then
1872 p.Damage(trigData.trigDamageValue, 0, 0, 0, HIT_SOME);
1874 // Ëå÷èì èãðîêà
1875 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigHealValue > 0) then
1876 if p.Heal(trigData.trigHealValue, not trigData.trigHealMax) and (not trigData.trigHealSilent) then
1877 begin
1878 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p.Obj.X, p.Obj.Y);
1879 if g_Game_IsServer and g_Game_IsNet then
1880 MH_SEND_Sound(p.Obj.X, p.Obj.Y, 'SOUND_ITEM_GETITEM');
1881 end;
1882 end;
1884 UID_MONSTER:
1885 begin
1886 m := g_Monsters_ByUID(ActivateUID);
1887 if m = nil then
1888 Exit;
1890 // Íàíîñèì óðîí ìîíñòðó
1891 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigDamageValue > 0) then
1892 m.Damage(trigData.trigDamageValue, 0, 0, 0, HIT_SOME);
1894 // Ëå÷èì ìîíñòðà
1895 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigHealValue > 0) then
1896 if m.Heal(trigData.trigHealValue) and (not trigData.trigHealSilent) then
1897 begin
1898 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m.Obj.X, m.Obj.Y);
1899 if g_Game_IsServer and g_Game_IsNet then
1900 MH_SEND_Sound(m.Obj.X, m.Obj.Y, 'SOUND_ITEM_GETITEM');
1901 end;
1902 end;
1903 end;
1904 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1905 if TriggerType = TRIGGER_DAMAGE then
1906 idx := trigData.trigDamageInterval
1907 else
1908 idx := trigData.trigHealInterval;
1909 if coolDown then
1910 if idx > 0 then
1911 Activators[k].TimeOut := idx
1912 else
1913 Activators[k].TimeOut := 65535;
1914 end;
1915 end;
1916 TimeOut := 0;
1917 end;
1919 TRIGGER_SHOT:
1920 begin
1921 if ShotSightTime > 0 then
1922 Exit;
1924 // put this at the beginning so it doesn't trigger itself
1925 TimeOut := trigData.trigShotWait + 1;
1927 wx := trigData.trigShotPos.X;
1928 wy := trigData.trigShotPos.Y;
1929 pAngle := -DegToRad(trigData.trigShotAngle);
1930 xd := wx + Round(Cos(pAngle) * 32.0);
1931 yd := wy + Round(Sin(pAngle) * 32.0);
1932 TargetUID := 0;
1934 case trigData.trigShotTarget of
1935 TRIGGER_SHOT_TARGET_MON: // monsters
1936 //TODO: accelerate this!
1937 g_Mons_ForEachAlive(monsShotTarget);
1939 TRIGGER_SHOT_TARGET_PLR: // players
1940 if gPlayers <> nil then
1941 for idx := Low(gPlayers) to High(gPlayers) do
1942 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1943 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1944 begin
1945 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1946 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1947 TargetUID := gPlayers[idx].UID;
1948 break;
1949 end;
1951 TRIGGER_SHOT_TARGET_RED: // red team
1952 if gPlayers <> nil then
1953 for idx := Low(gPlayers) to High(gPlayers) do
1954 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1955 (gPlayers[idx].Team = TEAM_RED) and
1956 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1957 begin
1958 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1959 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1960 TargetUID := gPlayers[idx].UID;
1961 break;
1962 end;
1964 TRIGGER_SHOT_TARGET_BLUE: // blue team
1965 if gPlayers <> nil then
1966 for idx := Low(gPlayers) to High(gPlayers) do
1967 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1968 (gPlayers[idx].Team = TEAM_BLUE) and
1969 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1970 begin
1971 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1972 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1973 TargetUID := gPlayers[idx].UID;
1974 break;
1975 end;
1977 TRIGGER_SHOT_TARGET_MONPLR: // monsters then players
1978 begin
1979 //TODO: accelerate this!
1980 g_Mons_ForEachAlive(monsShotTargetMonPlr);
1982 if (TargetUID = 0) and (gPlayers <> nil) then
1983 for idx := Low(gPlayers) to High(gPlayers) do
1984 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1985 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1986 begin
1987 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1988 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1989 TargetUID := gPlayers[idx].UID;
1990 break;
1991 end;
1992 end;
1994 TRIGGER_SHOT_TARGET_PLRMON: // players then monsters
1995 begin
1996 if gPlayers <> nil then
1997 for idx := Low(gPlayers) to High(gPlayers) do
1998 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1999 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2000 begin
2001 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2002 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2003 TargetUID := gPlayers[idx].UID;
2004 break;
2005 end;
2006 if TargetUID = 0 then
2007 begin
2008 //TODO: accelerate this!
2009 g_Mons_ForEachAlive(monShotTargetPlrMon);
2010 end;
2011 end;
2013 else begin
2014 if (trigData.trigShotTarget <> TRIGGER_SHOT_TARGET_NONE) or
2015 (trigData.trigShotType <> TRIGGER_SHOT_REV) then
2016 TargetUID := ActivateUID;
2017 end;
2018 end;
2020 if (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or (TargetUID > 0) or
2021 ((trigData.trigShotTarget > TRIGGER_SHOT_TARGET_NONE) and (TargetUID = 0)) then
2022 begin
2023 Result := True;
2024 if (trigData.trigShotIntSight = 0) or
2025 (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or
2026 (TargetUID = ShotSightTarget) then
2027 MakeShot(Trigger, wx, wy, xd, yd, TargetUID)
2028 else
2029 begin
2030 ShotSightTime := trigData.trigShotIntSight;
2031 ShotSightTargetN := TargetUID;
2032 if trigData.trigShotType = TRIGGER_SHOT_BFG then
2033 begin
2034 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx, wy);
2035 if g_Game_IsNet and g_Game_IsServer then
2036 MH_SEND_Sound(wx, wy, 'SOUND_WEAPON_STARTFIREBFG');
2037 end;
2038 end;
2039 end;
2040 end;
2042 TRIGGER_EFFECT:
2043 begin
2044 idx := trigData.trigFXCount;
2046 while idx > 0 do
2047 begin
2048 case trigData.trigFXPos of
2049 TRIGGER_EFFECT_POS_CENTER:
2050 begin
2051 wx := X + Width div 2;
2052 wy := Y + Height div 2;
2053 end;
2054 TRIGGER_EFFECT_POS_AREA:
2055 begin
2056 wx := X + Random(Width);
2057 wy := Y + Random(Height);
2058 end;
2059 else begin
2060 wx := X + Width div 2;
2061 wy := Y + Height div 2;
2062 end;
2063 end;
2064 xd := trigData.trigFXVelX;
2065 yd := trigData.trigFXVelY;
2066 if trigData.trigFXSpreadL > 0 then xd := xd - Random(trigData.trigFXSpreadL + 1);
2067 if trigData.trigFXSpreadR > 0 then xd := xd + Random(trigData.trigFXSpreadR + 1);
2068 if trigData.trigFXSpreadU > 0 then yd := yd - Random(trigData.trigFXSpreadU + 1);
2069 if trigData.trigFXSpreadD > 0 then yd := yd + Random(trigData.trigFXSpreadD + 1);
2070 tr_MakeEffect(wx, wy, xd, yd,
2071 trigData.trigFXType, trigData.trigFXSubType,
2072 trigData.trigFXColorR, trigData.trigFXColorG, trigData.trigFXColorB, True, False);
2073 Dec(idx);
2074 end;
2075 TimeOut := trigData.trigFXWait;
2076 end;
2077 end;
2078 end;
2080 if Result and (Trigger.TexturePanel <> -1) then
2081 g_Map_SwitchTexture(Trigger.TexturePanelType, Trigger.TexturePanel, IfThen(animonce, 2, 1));
2082 end;
2084 function g_Triggers_Create(Trigger: TTrigger): DWORD;
2085 var
2086 find_id: DWORD;
2087 fn, mapw: String;
2088 begin
2089 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2090 if (Trigger.TriggerType = TRIGGER_EXIT) and
2091 (not LongBool(gGameSettings.Options and GAME_OPTION_ALLOWEXIT)) then
2092 Trigger.TriggerType := TRIGGER_NONE;
2094 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2095 if (Trigger.TriggerType = TRIGGER_SPAWNMONSTER) and
2096 (not LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS)) and
2097 (gGameSettings.GameType <> GT_SINGLE) then
2098 Trigger.TriggerType := TRIGGER_NONE;
2100 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2101 if Trigger.TriggerType = TRIGGER_SECRET then
2102 gSecretsCount := gSecretsCount + 1;
2104 find_id := FindTrigger();
2105 gTriggers[find_id] := Trigger;
2107 with gTriggers[find_id] do
2108 begin
2109 ID := find_id;
2110 // if this type of trigger exists both on the client and on the server
2111 // use an uniform numeration
2112 if Trigger.TriggerType = TRIGGER_SOUND then
2113 begin
2114 Inc(gTriggerClientID);
2115 ClientID := gTriggerClientID;
2116 end
2117 else
2118 ClientID := 0;
2119 TimeOut := 0;
2120 ActivateUID := 0;
2121 PlayerCollide := False;
2122 DoorTime := -1;
2123 PressTime := -1;
2124 PressCount := 0;
2125 SoundPlayCount := 0;
2126 Sound := nil;
2127 AutoSpawn := False;
2128 SpawnCooldown := 0;
2129 SpawnedCount := 0;
2130 end;
2132 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2133 if (Trigger.TriggerType = TRIGGER_SOUND) and
2134 (Trigger.trigData.trigSoundName <> '') then
2135 begin
2136 // Åùå íåò òàêîãî çâóêà:
2137 if not g_Sound_Exists(Trigger.trigData.trigSoundName) then
2138 begin
2139 fn := g_ExtractWadName(Trigger.trigData.trigSoundName);
2141 if fn = '' then
2142 begin // Çâóê â ôàéëå ñ êàðòîé
2143 mapw := g_ExtractWadName(gMapInfo.Map);
2144 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigSoundName);
2145 end
2146 else // Çâóê â îòäåëüíîì ôàéëå
2147 fn := GameDir + '/wads/' + Trigger.trigData.trigSoundName;
2149 if not g_Sound_CreateWADEx(Trigger.trigData.trigSoundName, fn) then
2150 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigSoundName]));
2151 end;
2153 // Ñîçäàåì îáúåêò çâóêà:
2154 with gTriggers[find_id] do
2155 begin
2156 Sound := TPlayableSound.Create();
2157 if not Sound.SetByName(Trigger.trigData.trigSoundName) then
2158 begin
2159 Sound.Free();
2160 Sound := nil;
2161 end;
2162 end;
2163 end;
2165 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2166 if (Trigger.TriggerType = TRIGGER_MUSIC) and
2167 (Trigger.trigData.trigMusicName <> '') then
2168 begin
2169 // Åùå íåò òàêîé ìóçûêè:
2170 if not g_Sound_Exists(Trigger.trigData.trigMusicName) then
2171 begin
2172 fn := g_ExtractWadName(Trigger.trigData.trigMusicName);
2174 if fn = '' then
2175 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2176 mapw := g_ExtractWadName(gMapInfo.Map);
2177 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigMusicName);
2178 end
2179 else // Ìóçûêà â ôàéëå ñ êàðòîé
2180 fn := GameDir+'/wads/'+Trigger.trigData.trigMusicName;
2182 if not g_Sound_CreateWADEx(Trigger.trigData.trigMusicName, fn, True) then
2183 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigMusicName]));
2184 end;
2185 end;
2187 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2188 if Trigger.TriggerType = TRIGGER_SHOT then
2189 with gTriggers[find_id] do
2190 begin
2191 ShotPanelTime := 0;
2192 ShotSightTime := 0;
2193 ShotSightTimeout := 0;
2194 ShotSightTarget := 0;
2195 ShotSightTargetN := 0;
2196 ShotAmmoCount := Trigger.trigData.trigShotAmmo;
2197 ShotReloadTime := 0;
2198 end;
2200 Result := find_id;
2201 end;
2204 // sorry; grid doesn't support recursive queries, so we have to do this
2205 type
2206 TSimpleMonsterList = specialize TSimpleList<TMonster>;
2208 var
2209 tgMonsList: TSimpleMonsterList = nil;
2211 procedure g_Triggers_Update();
2212 var
2213 a, b, i: Integer;
2214 Affected: array of Integer;
2216 function monsNear (mon: TMonster): Boolean;
2217 begin
2218 result := false; // don't stop
2220 gTriggers[a].ActivateUID := mon.UID;
2221 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2223 tgMonsList.append(mon);
2224 end;
2226 var
2227 mon: TMonster;
2228 begin
2229 if (tgMonsList = nil) then tgMonsList := TSimpleMonsterList.Create();
2231 if gTriggers = nil then
2232 Exit;
2233 SetLength(Affected, 0);
2235 for a := 0 to High(gTriggers) do
2236 with gTriggers[a] do
2237 // Åñòü òðèããåð:
2238 if TriggerType <> TRIGGER_NONE then
2239 begin
2240 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè):
2241 if DoorTime > 0 then
2242 DoorTime := DoorTime - 1;
2243 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ:
2244 if PressTime > 0 then
2245 PressTime := PressTime - 1;
2246 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2247 if (TriggerType = TRIGGER_DAMAGE) or (TriggerType = TRIGGER_HEALTH) then
2248 for b := 0 to High(Activators) do
2249 begin
2250 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2251 if Activators[b].TimeOut > 0 then
2252 Dec(Activators[b].TimeOut)
2253 else
2254 Continue;
2255 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2256 if (trigData.trigDamageInterval = 0) and (Activators[b].TimeOut < 65530) then
2257 Activators[b].TimeOut := 0;
2258 end;
2260 // Îáðàáàòûâàåì ñïàâíåðû:
2261 if Enabled and AutoSpawn then
2262 if SpawnCooldown = 0 then
2263 begin
2264 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà:
2265 if (TriggerType = TRIGGER_SPAWNMONSTER) and (trigData.trigMonDelay > 0) then
2266 begin
2267 ActivateUID := 0;
2268 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2269 end;
2270 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò:
2271 if (TriggerType = TRIGGER_SPAWNITEM) and (trigData.trigItemDelay > 0) then
2272 begin
2273 ActivateUID := 0;
2274 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2275 end;
2276 end else // Óìåíüøàåì âðåìÿ îæèäàíèÿ:
2277 Dec(SpawnCooldown);
2279 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü":
2280 if TriggerType = TRIGGER_SHOT then
2281 begin
2282 if ShotPanelTime > 0 then
2283 begin
2284 Dec(ShotPanelTime);
2285 if ShotPanelTime = 0 then
2286 g_Map_SwitchTexture(ShotPanelType, trigShotPanelID);
2287 end;
2288 if ShotSightTime > 0 then
2289 begin
2290 Dec(ShotSightTime);
2291 if ShotSightTime = 0 then
2292 ShotSightTarget := ShotSightTargetN;
2293 end;
2294 if ShotSightTimeout > 0 then
2295 begin
2296 Dec(ShotSightTimeout);
2297 if ShotSightTimeout = 0 then
2298 ShotSightTarget := 0;
2299 end;
2300 if ShotReloadTime > 0 then
2301 begin
2302 Dec(ShotReloadTime);
2303 if ShotReloadTime = 0 then
2304 ShotAmmoCount := trigData.trigShotAmmo;
2305 end;
2306 end;
2308 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì:
2309 if Enabled and (TriggerType = TRIGGER_SOUND) and (Sound <> nil) then
2310 if (SoundPlayCount > 0) and (not Sound.IsPlaying()) then
2311 begin
2312 if trigData.trigPlayCount > 0 then // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2313 SoundPlayCount := SoundPlayCount - 1;
2314 if trigData.trigLocal then
2315 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), trigData.trigVolume/255.0)
2316 else
2317 Sound.PlayPanVolume((trigData.trigPan-127.0)/128.0, trigData.trigVolume/255.0);
2318 if Sound.IsPlaying() and g_Game_IsNet and g_Game_IsServer then
2319 MH_SEND_TriggerSound(gTriggers[a]);
2320 end;
2322 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü:
2323 if (TriggerType = TRIGGER_TRAP) and (DoorTime = 0) and (trigPanelID <> -1) then
2324 begin
2325 tr_OpenDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
2326 DoorTime := -1;
2327 end;
2329 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü:
2330 if (TriggerType = TRIGGER_DOOR5) and (DoorTime = 0) and (trigPanelID <> -1) then
2331 begin
2332 // Óæå çàêðûòà:
2333 if gWalls[trigPanelID].Enabled then
2334 DoorTime := -1
2335 else // Ïîêà îòêðûòà - çàêðûâàåì
2336 if tr_CloseDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors) then
2337 DoorTime := -1;
2338 end;
2340 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2341 if (TriggerType in [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) and
2342 (PressTime = 0) and (PressCount >= trigData.trigCount) then
2343 begin
2344 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2345 PressTime := -1;
2346 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2347 if trigData.trigCount > 0 then
2348 PressCount := PressCount - trigData.trigCount
2349 else
2350 PressCount := 0;
2352 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2353 for b := 0 to High(gTriggers) do
2354 if g_Collide(trigData.trigtX, trigData.trigtY, trigData.trigtWidth, trigData.trigtHeight, gTriggers[b].X, gTriggers[b].Y,
2355 gTriggers[b].Width, gTriggers[b].Height) and
2356 ((b <> a) or (trigData.trigWait > 0)) then
2357 begin // Can be self-activated, if there is Data.Wait
2358 if (not trigData.trigExtRandom) or gTriggers[b].Enabled then
2359 begin
2360 SetLength(Affected, Length(Affected) + 1);
2361 Affected[High(Affected)] := b;
2362 end;
2363 end;
2364 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2365 if (TriggerType = TRIGGER_PRESS) and trigData.trigExtRandom then
2366 begin
2367 if (Length(Affected) > 0) then
2368 begin
2369 b := Affected[Random(Length(Affected))];
2370 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2371 ActivateTrigger(gTriggers[b], 0);
2372 end;
2373 end
2374 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2375 for i := 0 to High(Affected) do
2376 begin
2377 b := Affected[i];
2378 case TriggerType of
2379 TRIGGER_PRESS:
2380 begin
2381 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2382 ActivateTrigger(gTriggers[b], 0);
2383 end;
2384 TRIGGER_ON:
2385 begin
2386 gTriggers[b].Enabled := True;
2387 end;
2388 TRIGGER_OFF:
2389 begin
2390 gTriggers[b].Enabled := False;
2391 gTriggers[b].TimeOut := 0;
2392 if gTriggers[b].AutoSpawn then
2393 begin
2394 gTriggers[b].AutoSpawn := False;
2395 gTriggers[b].SpawnCooldown := 0;
2396 end;
2397 end;
2398 TRIGGER_ONOFF:
2399 begin
2400 gTriggers[b].Enabled := not gTriggers[b].Enabled;
2401 if not gTriggers[b].Enabled then
2402 begin
2403 gTriggers[b].TimeOut := 0;
2404 if gTriggers[b].AutoSpawn then
2405 begin
2406 gTriggers[b].AutoSpawn := False;
2407 gTriggers[b].SpawnCooldown := 0;
2408 end;
2409 end;
2410 end;
2411 end;
2412 end;
2413 SetLength(Affected, 0);
2414 end;
2416 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2417 if TimeOut > 0 then
2418 begin
2419 TimeOut := TimeOut - 1;
2420 Continue; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2421 end;
2423 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2424 if not Enabled then
2425 Continue;
2427 // "Èãðîê áëèçêî":
2428 if ByteBool(ActivateType and ACTIVATE_PLAYERCOLLIDE) and
2429 (TimeOut = 0) then
2430 if gPlayers <> nil then
2431 for b := 0 to High(gPlayers) do
2432 if gPlayers[b] <> nil then
2433 with gPlayers[b] do
2434 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2435 if Live and ((gTriggers[a].Keys and GetKeys) = gTriggers[a].Keys) and
2436 Collide(X, Y, Width, Height) then
2437 begin
2438 gTriggers[a].ActivateUID := UID;
2440 if (gTriggers[a].TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) and
2441 PlayerCollide then
2442 { Don't activate sound/music again if player is here }
2443 else
2444 ActivateTrigger(gTriggers[a], ACTIVATE_PLAYERCOLLIDE);
2445 end;
2447 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2449 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2450 ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2451 (TimeOut = 0) and (Keys = 0) then
2452 begin
2453 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2454 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2455 ActivateType := ActivateType and not (ACTIVATE_MONSTERCOLLIDE or ACTIVATE_NOMONSTER);
2456 gTriggers[a].ActivateUID := 0;
2457 ActivateTrigger(gTriggers[a], 0);
2458 end else
2459 begin
2460 // "Ìîíñòð áëèçêî"
2461 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2462 (TimeOut = 0) and (Keys = 0) then // Åñëè íå íóæíû êëþ÷è
2463 begin
2464 //g_Mons_ForEach(monsNear);
2465 //Alive?!
2466 tgMonsList.reset();
2467 g_Mons_ForEachAt(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height, monsNear);
2468 for mon in tgMonsList do
2469 begin
2470 gTriggers[a].ActivateUID := mon.UID;
2471 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2472 end;
2473 tgMonsList.reset(); // just in case
2474 end;
2476 // "Ìîíñòðîâ íåò"
2477 if ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2478 (TimeOut = 0) and (Keys = 0) then
2479 if not g_Mons_IsAnyAliveAt(X, Y, Width, Height) then
2480 begin
2481 gTriggers[a].ActivateUID := 0;
2482 ActivateTrigger(gTriggers[a], ACTIVATE_NOMONSTER);
2483 end;
2484 end;
2486 PlayerCollide := g_CollidePlayer(X, Y, Width, Height);
2487 end;
2488 end;
2490 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
2491 begin
2492 gTriggers[ID].ActivateUID := ActivateUID;
2493 ActivateTrigger(gTriggers[ID], ActivateType);
2494 end;
2496 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
2497 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
2498 var
2499 a: Integer;
2500 k: Byte;
2501 p: TPlayer;
2502 begin
2503 Result := nil;
2505 if gTriggers = nil then Exit;
2507 case g_GetUIDType(UID) of
2508 UID_GAME: k := 255;
2509 UID_PLAYER:
2510 begin
2511 p := g_Player_Get(UID);
2512 if p <> nil then
2513 k := p.GetKeys
2514 else
2515 k := 0;
2516 end;
2517 else k := 0;
2518 end;
2520 for a := 0 to High(gTriggers) do
2521 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2522 (gTriggers[a].TimeOut = 0) and
2523 (not InDWArray(a, IgnoreList)) and
2524 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2525 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2526 if g_Collide(X, Y, Width, Height,
2527 gTriggers[a].X, gTriggers[a].Y,
2528 gTriggers[a].Width, gTriggers[a].Height) then
2529 begin
2530 gTriggers[a].ActivateUID := UID;
2531 if ActivateTrigger(gTriggers[a], ActivateType) then
2532 begin
2533 SetLength(Result, Length(Result)+1);
2534 Result[High(Result)] := a;
2535 end;
2536 end;
2537 end;
2539 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
2540 var
2541 a: Integer;
2542 k: Byte;
2543 p: TPlayer;
2544 begin
2545 if gTriggers = nil then Exit;
2547 case g_GetUIDType(UID) of
2548 UID_GAME: k := 255;
2549 UID_PLAYER:
2550 begin
2551 p := g_Player_Get(UID);
2552 if p <> nil then
2553 k := p.GetKeys
2554 else
2555 k := 0;
2556 end;
2557 else k := 0;
2558 end;
2560 for a := 0 to High(gTriggers) do
2561 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2562 (gTriggers[a].TimeOut = 0) and
2563 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2564 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2565 if g_CollideLine(x1, y1, x2, y2, gTriggers[a].X, gTriggers[a].Y,
2566 gTriggers[a].Width, gTriggers[a].Height) then
2567 begin
2568 gTriggers[a].ActivateUID := UID;
2569 ActivateTrigger(gTriggers[a], ActivateType);
2570 end;
2571 end;
2573 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
2574 var
2575 a: Integer;
2576 k: Byte;
2577 rsq: Word;
2578 p: TPlayer;
2579 begin
2580 if gTriggers = nil then
2581 Exit;
2583 case g_GetUIDType(UID) of
2584 UID_GAME: k := 255;
2585 UID_PLAYER:
2586 begin
2587 p := g_Player_Get(UID);
2588 if p <> nil then
2589 k := p.GetKeys
2590 else
2591 k := 0;
2592 end;
2593 else k := 0;
2594 end;
2596 rsq := Radius * Radius;
2598 for a := 0 to High(gTriggers) do
2599 if (gTriggers[a].ID <> DWORD(IgnoreTrigger)) and
2600 (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2601 (gTriggers[a].TimeOut = 0) and
2602 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2603 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2604 with gTriggers[a] do
2605 if g_Collide(CX-Radius, CY-Radius, 2*Radius, 2*Radius,
2606 X, Y, Width, Height) then
2607 if ((Sqr(CX-X)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2608 ((Sqr(CX-X-Width)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2609 ((Sqr(CX-X-Width)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2610 ((Sqr(CX-X)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2611 ( (CX > (X-Radius)) and (CX < (X+Width+Radius)) and
2612 (CY > Y) and (CY < (Y+Height)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2613 ( (CY > (Y-Radius)) and (CY < (Y+Height+Radius)) and
2614 (CX > X) and (CX < (X+Width)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2615 begin
2616 ActivateUID := UID;
2617 ActivateTrigger(gTriggers[a], ActivateType);
2618 end;
2619 end;
2621 procedure g_Triggers_OpenAll();
2622 var
2623 a: Integer;
2624 b: Boolean;
2625 begin
2626 if gTriggers = nil then Exit;
2628 b := False;
2629 for a := 0 to High(gTriggers) do
2630 with gTriggers[a] do
2631 if (TriggerType = TRIGGER_OPENDOOR) or
2632 (TriggerType = TRIGGER_DOOR5) or
2633 (TriggerType = TRIGGER_DOOR) then
2634 begin
2635 tr_OpenDoor(trigPanelID, True, trigData.trigd2d_doors);
2636 if TriggerType = TRIGGER_DOOR5 then DoorTime := 180;
2637 b := True;
2638 end;
2640 if b then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2641 end;
2643 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
2644 begin
2645 if (gTriggers <> nil) then
2646 if gTriggers[ID].SpawnedCount > 0 then
2647 Dec(gTriggers[ID].SpawnedCount);
2648 end;
2650 procedure g_Triggers_Free();
2651 var
2652 a: Integer;
2653 begin
2654 for a := 0 to High(gTriggers) do
2655 begin
2656 gTriggers[a].trigData.Free();
2657 if (gTriggers[a].TriggerType = TRIGGER_SOUND) then
2658 begin
2659 if g_Sound_Exists(gTriggers[a].trigData.trigSoundName) then
2660 begin
2661 g_Sound_Delete(gTriggers[a].trigData.trigSoundName);
2662 end;
2663 gTriggers[a].Sound.Free();
2664 end;
2665 if (gTriggers[a].Activators <> nil) then
2666 begin
2667 SetLength(gTriggers[a].Activators, 0);
2668 end;
2669 end;
2671 gTriggers := nil;
2672 gSecretsCount := 0;
2673 SetLength(gMonstersSpawned, 0);
2674 end;
2676 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
2677 var
2678 count, act_count, i, j: Integer;
2679 dw: DWORD;
2680 sg: Single;
2681 b: Boolean;
2682 //p: Pointer;
2683 begin
2684 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ:
2685 count := 0;
2686 if gTriggers <> nil then
2687 for i := 0 to High(gTriggers) do
2688 count := count + 1;
2690 Mem := TBinMemoryWriter.Create((count+1) * 200);
2692 // Êîëè÷åñòâî òðèããåðîâ:
2693 Mem.WriteInt(count);
2695 if count = 0 then
2696 Exit;
2698 for i := 0 to High(gTriggers) do
2699 begin
2700 // Ñèãíàòóðà òðèããåðà:
2701 dw := TRIGGER_SIGNATURE; // 'TRGR'
2702 Mem.WriteDWORD(dw);
2703 // Òèï òðèããåðà:
2704 Mem.WriteByte(gTriggers[i].TriggerType);
2705 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2706 //!!!FIXME!!!
2707 //p := @gTriggers[i].Data;
2708 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2709 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2710 Mem.WriteInt(gTriggers[i].X);
2711 Mem.WriteInt(gTriggers[i].Y);
2712 // Ðàçìåðû:
2713 Mem.WriteWord(gTriggers[i].Width);
2714 Mem.WriteWord(gTriggers[i].Height);
2715 // Âêëþ÷åí ëè òðèããåð:
2716 Mem.WriteBoolean(gTriggers[i].Enabled);
2717 // Òèï àêòèâàöèè òðèããåðà:
2718 Mem.WriteByte(gTriggers[i].ActivateType);
2719 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2720 Mem.WriteByte(gTriggers[i].Keys);
2721 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2722 Mem.WriteInt(gTriggers[i].TexturePanel);
2723 // Òèï ýòîé ïàíåëè:
2724 Mem.WriteWord(gTriggers[i].TexturePanelType);
2725 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2726 Mem.WriteWord(gTriggers[i].TimeOut);
2727 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2728 Mem.WriteWord(gTriggers[i].ActivateUID);
2729 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2730 act_count := Length(gTriggers[i].Activators);
2731 Mem.WriteInt(act_count);
2732 for j := 0 to act_count-1 do
2733 begin
2734 // UID îáúåêòà
2735 Mem.WriteWord(gTriggers[i].Activators[j].UID);
2736 // Âðåìÿ îæèäàíèÿ
2737 Mem.WriteWord(gTriggers[i].Activators[j].TimeOut);
2738 end;
2739 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2740 Mem.WriteBoolean(gTriggers[i].PlayerCollide);
2741 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2742 Mem.WriteInt(gTriggers[i].DoorTime);
2743 // Çàäåðæêà àêòèâàöèè:
2744 Mem.WriteInt(gTriggers[i].PressTime);
2745 // Ñ÷åò÷èê íàæàòèé:
2746 Mem.WriteInt(gTriggers[i].PressCount);
2747 // Ñïàâíåð àêòèâåí:
2748 Mem.WriteBoolean(gTriggers[i].AutoSpawn);
2749 // Çàäåðæêà ñïàâíåðà:
2750 Mem.WriteInt(gTriggers[i].SpawnCooldown);
2751 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2752 Mem.WriteInt(gTriggers[i].SpawnedCount);
2753 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2754 Mem.WriteInt(gTriggers[i].SoundPlayCount);
2755 // Ïðîèãðûâàåòñÿ ëè çâóê?
2756 if gTriggers[i].Sound <> nil then
2757 b := gTriggers[i].Sound.IsPlaying()
2758 else
2759 b := False;
2760 Mem.WriteBoolean(b);
2761 if b then
2762 begin
2763 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2764 dw := gTriggers[i].Sound.GetPosition();
2765 Mem.WriteDWORD(dw);
2766 // Ãðîìêîñòü çâóêà:
2767 sg := gTriggers[i].Sound.GetVolume();
2768 sg := sg / (gSoundLevel/255.0);
2769 Mem.WriteSingle(sg);
2770 // Ñòåðåî ñìåùåíèå çâóêà:
2771 sg := gTriggers[i].Sound.GetPan();
2772 Mem.WriteSingle(sg);
2773 end;
2774 end;
2775 end;
2777 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
2778 var
2779 count, act_count, i, j, a: Integer;
2780 dw: DWORD;
2781 vol, pan: Single;
2782 b: Boolean;
2783 //p: Pointer;
2784 Trig: TTrigger;
2785 begin
2786 if Mem = nil then
2787 Exit;
2789 g_Triggers_Free();
2791 // Êîëè÷åñòâî òðèããåðîâ:
2792 Mem.ReadInt(count);
2794 if count = 0 then
2795 Exit;
2797 for a := 0 to count-1 do
2798 begin
2799 // Ñèãíàòóðà òðèããåðà:
2800 Mem.ReadDWORD(dw);
2801 if dw <> TRIGGER_SIGNATURE then // 'TRGR'
2802 begin
2803 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2804 end;
2805 // Òèï òðèããåðà:
2806 Mem.ReadByte(Trig.TriggerType);
2807 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2808 //!!!FIXME!!!
2810 Mem.ReadMemory(p, dw);
2811 if dw <> SizeOf(TTriggerData) then
2812 begin
2813 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2814 end;
2815 Trig.Data := TTriggerData(p^);
2817 // Ñîçäàåì òðèããåð:
2818 i := g_Triggers_Create(Trig);
2819 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2820 Mem.ReadInt(gTriggers[i].X);
2821 Mem.ReadInt(gTriggers[i].Y);
2822 // Ðàçìåðû:
2823 Mem.ReadWord(gTriggers[i].Width);
2824 Mem.ReadWord(gTriggers[i].Height);
2825 // Âêëþ÷åí ëè òðèããåð:
2826 Mem.ReadBoolean(gTriggers[i].Enabled);
2827 // Òèï àêòèâàöèè òðèããåðà:
2828 Mem.ReadByte(gTriggers[i].ActivateType);
2829 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2830 Mem.ReadByte(gTriggers[i].Keys);
2831 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2832 Mem.ReadInt(gTriggers[i].TexturePanel);
2833 // Òèï ýòîé ïàíåëè:
2834 Mem.ReadWord(gTriggers[i].TexturePanelType);
2835 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2836 Mem.ReadWord(gTriggers[i].TimeOut);
2837 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2838 Mem.ReadWord(gTriggers[i].ActivateUID);
2839 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2840 Mem.ReadInt(act_count);
2841 if act_count > 0 then
2842 begin
2843 SetLength(gTriggers[i].Activators, act_count);
2844 for j := 0 to act_count-1 do
2845 begin
2846 // UID îáúåêòà
2847 Mem.ReadWord(gTriggers[i].Activators[j].UID);
2848 // Âðåìÿ îæèäàíèÿ
2849 Mem.ReadWord(gTriggers[i].Activators[j].TimeOut);
2850 end;
2851 end;
2852 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2853 Mem.ReadBoolean(gTriggers[i].PlayerCollide);
2854 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2855 Mem.ReadInt(gTriggers[i].DoorTime);
2856 // Çàäåðæêà àêòèâàöèè:
2857 Mem.ReadInt(gTriggers[i].PressTime);
2858 // Ñ÷åò÷èê íàæàòèé:
2859 Mem.ReadInt(gTriggers[i].PressCount);
2860 // Ñïàâíåð àêòèâåí:
2861 Mem.ReadBoolean(gTriggers[i].AutoSpawn);
2862 // Çàäåðæêà ñïàâíåðà:
2863 Mem.ReadInt(gTriggers[i].SpawnCooldown);
2864 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2865 Mem.ReadInt(gTriggers[i].SpawnedCount);
2866 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2867 Mem.ReadInt(gTriggers[i].SoundPlayCount);
2868 // Ïðîèãðûâàåòñÿ ëè çâóê?
2869 Mem.ReadBoolean(b);
2870 if b then
2871 begin
2872 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2873 Mem.ReadDWORD(dw);
2874 // Ãðîìêîñòü çâóêà:
2875 Mem.ReadSingle(vol);
2876 // Ñòåðåî ñìåùåíèå çâóêà:
2877 Mem.ReadSingle(pan);
2878 // Çàïóñêàåì çâóê, åñëè åñòü:
2879 if gTriggers[i].Sound <> nil then
2880 begin
2881 gTriggers[i].Sound.PlayPanVolume(pan, vol);
2882 gTriggers[i].Sound.Pause(True);
2883 gTriggers[i].Sound.SetPosition(dw);
2884 end
2885 end;
2886 end;
2887 end;
2889 end.