1 (* Copyright (C) DooM 2D:Forever Developers
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.
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.
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/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 MAPDEF
, e_graphics
, g_basic
, g_sound
,
41 TexturePanelGUID
: Integer;
42 TexturePanelType
: Word;
46 Activators
: array of TActivator
;
47 PlayerCollide
: Boolean;
51 SoundPlayCount
: Integer;
52 Sound
: TPlayableSound
;
54 SpawnCooldown
: Integer;
55 SpawnedCount
: Integer;
57 ShotPanelTime
: Integer;
58 ShotSightTime
: Integer;
59 ShotSightTimeout
: Integer;
60 ShotSightTarget
: Word;
61 ShotSightTargetN
: Word;
63 ShotReloadTime
: Integer;
65 mapId
: AnsiString; // trigger id, from map
66 mapIndex
: Integer; // index in fields['trigger'], used in save/load
67 trigPanelGUID
: Integer;
69 //TrigData: TTriggerData;
70 trigData
: TDynRecord
; // triggerdata; owned by trigger
73 function trigCenter (): TDFPoint
; inline;
76 property trigShotPanelGUID
: Integer read trigPanelGUID write trigPanelGUID
;
79 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
80 procedure g_Triggers_Update();
81 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
82 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
83 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
84 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
85 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
86 procedure g_Triggers_OpenAll();
87 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
88 procedure g_Triggers_Free();
89 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
90 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
94 gTriggerClientID
: Integer = 0;
95 gTriggers
: array of TTrigger
;
96 gSecretsCount
: Integer = 0;
97 gMonstersSpawned
: array of LongInt = nil;
104 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
105 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
106 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
107 g_options
, g_net
, g_netmsg
, utils
, xparser
;
110 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
114 function TTrigger
.trigCenter (): TDFPoint
; inline;
116 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
120 function FindTrigger (): DWORD
;
124 for i
:= 0 to High(gTriggers
) do
126 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
129 if (gTriggers
= nil) then
131 SetLength(gTriggers
, 8);
136 result
:= Length(gTriggers
);
137 SetLength(gTriggers
, result
+8);
138 for i
:= result
to High(gTriggers
) do gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
143 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
150 pan
:= g_Map_PanelByGUID(PanelGUID
);
151 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
152 PanelID
:= pan
.arrIdx
;
156 with gWalls
[PanelID
] do
158 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
163 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
164 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
166 g_Map_EnableWallGUID(PanelGUID
);
173 if (gDoorMap
= nil) then exit
;
176 for a
:= 0 to High(gDoorMap
) do
178 for b
:= 0 to High(gDoorMap
[a
]) do
180 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
186 if (c
<> -1) then break
;
188 if (c
= -1) then exit
;
190 for b
:= 0 to High(gDoorMap
[c
]) do
192 with gWalls
[gDoorMap
[c
, b
]] do
194 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
200 for b
:= 0 to High(gDoorMap
[c
]) do
202 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
204 with gWalls
[PanelID
] do
206 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
207 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
214 for b
:= 0 to High(gDoorMap
[c
]) do
216 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
218 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
226 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
229 wx
, wy
, wh
, ww
: Integer;
233 function monsDamage (mon
: TMonster
): Boolean;
235 result
:= false; // don't stop
236 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
240 pan
:= g_Map_PanelByGUID(PanelGUID
);
244 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
248 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
251 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
252 PanelID
:= pan
.arrIdx
;
256 with gWalls
[PanelID
] do
258 if (not NoSound
) and (not Enabled
) then
260 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
261 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
265 wx
:= gWalls
[PanelID
].X
;
266 wy
:= gWalls
[PanelID
].Y
;
267 ww
:= gWalls
[PanelID
].Width
;
268 wh
:= gWalls
[PanelID
].Height
;
270 with gWalls
[PanelID
] do
272 if gPlayers
<> nil then
274 for a
:= 0 to High(gPlayers
) do
276 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
278 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
283 //g_Mons_ForEach(monsDamage);
284 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
286 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
291 if (gDoorMap
= nil) then exit
;
294 for a
:= 0 to High(gDoorMap
) do
296 for b
:= 0 to High(gDoorMap
[a
]) do
298 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
304 if (c
<> -1) then break
;
306 if (c
= -1) then exit
;
310 for b
:= 0 to High(gDoorMap
[c
]) do
312 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
314 with gWalls
[PanelID
] do
316 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
317 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
324 for b
:= 0 to High(gDoorMap
[c
]) do
326 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
327 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
328 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
329 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
331 with gWalls
[gDoorMap
[c
, b
]] do
333 if gPlayers
<> nil then
335 for a
:= 0 to High(gPlayers
) do
337 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
339 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
344 //g_Mons_ForEach(monsDamage);
345 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
347 if gMonsters <> nil then
348 for a := 0 to High(gMonsters) do
349 if (gMonsters[a] <> nil) and gMonsters[a].alive and
350 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
351 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
354 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
361 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
368 pan
:= g_Map_PanelByGUID(PanelGUID
);
369 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
370 PanelID
:= pan
.arrIdx
;
374 with gWalls
[PanelID
] do
380 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
381 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
383 g_Map_DisableWallGUID(PanelGUID
);
390 if (gDoorMap
= nil) then exit
;
393 for a
:= 0 to High(gDoorMap
) do
395 for b
:= 0 to High(gDoorMap
[a
]) do
397 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
403 if (c
<> -1) then break
;
405 if (c
= -1) then exit
;
409 for b
:= 0 to High(gDoorMap
[c
]) do
411 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
413 with gWalls
[PanelID
] do
415 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
416 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
423 for b
:= 0 to High(gDoorMap
[c
]) do
425 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
427 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
435 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
443 pan
:= g_Map_PanelByGUID(PanelGUID
);
444 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
445 PanelID
:= pan
.arrIdx
;
447 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
452 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
455 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
460 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
466 with gLifts
[PanelID
] do
468 if (LiftType
<> t
) then
470 g_Map_SetLiftGUID(PanelGUID
, t
); //???
471 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
478 if (gLiftMap
= nil) then exit
;
481 for a
:= 0 to High(gLiftMap
) do
483 for b
:= 0 to High(gLiftMap
[a
]) do
485 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
491 if (c
<> -1) then break
;
493 if (c
= -1) then exit
;
496 for b := 0 to High(gLiftMap[c]) do
497 if gLifts[gLiftMap[c, b]].LiftType <> t then
499 with gLifts[PanelID] do
500 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
504 for b
:= 0 to High(gLiftMap
[c
]) do
506 with gLifts
[gLiftMap
[c
, b
]] do
508 if (LiftType
<> t
) then
510 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
519 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
527 TextureID
:= DWORD(-1);
528 snd
:= 'SOUND_WEAPON_FIREROCKET';
534 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
535 snd
:= 'SOUND_WEAPON_FIREPISTOL';
539 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
540 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
546 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
547 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
548 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
552 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
553 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
557 TRIGGER_SHOT_SHOTGUN
:
559 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
560 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
564 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
565 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
571 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
572 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
576 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
577 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
578 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
584 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
585 snd
:= 'SOUND_WEAPON_FIREBALL';
590 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
591 snd
:= 'SOUND_WEAPON_FIREPLASMA';
596 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
597 snd
:= 'SOUND_WEAPON_FIREPLASMA';
602 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
603 snd
:= 'SOUND_WEAPON_FIREBALL';
608 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
609 snd
:= 'SOUND_WEAPON_FIREBALL';
614 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
615 snd
:= 'SOUND_WEAPON_FIREBALL';
620 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
621 snd
:= 'SOUND_WEAPON_FIREREV';
626 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
627 snd
:= 'SOUND_WEAPON_FIREROCKET';
632 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
633 snd
:= 'SOUND_WEAPON_FIREBFG';
638 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
640 Anim
:= TAnimation
.Create(TextureID
, False, 6);
641 Anim
.Blending
:= False;
642 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
646 g_Weapon_Explode(wx
, wy
, 60, 0);
647 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
650 TRIGGER_SHOT_BFGEXPL
:
652 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
654 Anim
:= TAnimation
.Create(TextureID
, False, 6);
655 Anim
.Blending
:= False;
656 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
660 g_Weapon_BFG9000(wx
, wy
, 0);
661 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
667 if g_Game_IsNet
and g_Game_IsServer
then
670 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
671 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
674 if Projectile
then MH_SEND_CreateShot(LastShotID
);
675 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
680 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
682 if Projectile
then Result
:= LastShotID
;
686 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
690 if (trigData
.trigAmmo
= 0) or ((trigData
.trigAmmo
> 0) and (ShotAmmoCount
> 0)) then
692 if (trigShotPanelGUID
<> -1) and (ShotPanelTime
= 0) then
694 g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
695 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
698 if (trigData
.trigSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
700 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
702 dx
+= Random(trigData
.trigAccuracy
)-Random(trigData
.trigAccuracy
);
703 dy
+= Random(trigData
.trigAccuracy
)-Random(trigData
.trigAccuracy
);
705 tr_SpawnShot(trigData
.trigShotType
, wx
, wy
, dx
, dy
, not trigData
.trigQuiet
, TargetUID
);
709 if (trigData
.trigReload
> 0) and (ShotReloadTime
= 0) then
711 ShotReloadTime
:= trigData
.trigReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
718 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
723 if T
= TRIGGER_EFFECT_PARTICLE
then
726 TRIGGER_EFFECT_SLIQUID
:
728 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
729 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
730 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
731 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
733 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
734 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
735 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
736 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
737 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
741 if T
= TRIGGER_EFFECT_ANIMATION
then
744 EFFECT_TELEPORT
: begin
745 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
747 Anim
:= TAnimation
.Create(FramesID
, False, 3);
748 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
749 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
752 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
754 EFFECT_RESPAWN
: begin
755 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
757 Anim
:= TAnimation
.Create(FramesID
, False, 4);
758 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
759 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
762 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
765 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
767 Anim
:= TAnimation
.Create(FramesID
, False, 4);
768 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
769 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
772 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
779 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
785 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
786 case g_GetUIDType(ActivateUID
) of
789 p
:= g_Player_Get(ActivateUID
);
790 if p
= nil then Exit
;
793 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
797 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
802 m
:= g_Monsters_ByUID(ActivateUID
);
803 if m
= nil then Exit
;
806 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
810 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
817 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
823 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
824 case g_GetUIDType(ActivateUID
) of
827 p
:= g_Player_Get(ActivateUID
);
828 if p
= nil then Exit
;
843 m
:= g_Monsters_ByUID(ActivateUID
);
844 if m
= nil then Exit
;
860 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
867 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
868 msg
:= b_Text_Format(MText
);
870 TRIGGER_MESSAGE_DEST_ME
: // activator
872 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
874 if g_Game_IsWatchedPlayer(ActivateUID
) then
876 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
877 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
881 p
:= g_Player_Get(ActivateUID
);
882 if g_Game_IsNet
and (p
.FClientID
>= 0) then
884 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
885 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
891 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
893 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
895 p
:= g_Player_Get(ActivateUID
);
896 if g_Game_IsWatchedTeam(p
.Team
) then
898 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
899 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
904 for i
:= Low(gPlayers
) to High(gPlayers
) do
906 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
908 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
909 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
916 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
918 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
920 p
:= g_Player_Get(ActivateUID
);
921 if g_Game_IsWatchedTeam(p
.Team
) then
923 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
924 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
929 for i
:= Low(gPlayers
) to High(gPlayers
) do
931 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
933 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
934 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
941 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
943 if g_Game_IsWatchedTeam(TEAM_RED
) then
945 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
946 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
951 for i
:= Low(gPlayers
) to High(gPlayers
) do
953 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
955 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
956 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
962 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
964 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
966 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
967 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
972 for i
:= Low(gPlayers
) to High(gPlayers
) do
974 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
976 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
977 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
983 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
985 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
986 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
990 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
991 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
998 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1003 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1004 result
:= (trigData
.trigAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1005 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1006 if result
and (trigData
.trigAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1008 result
:= g_TraceVector(trigData
.trigTX
, trigData
.trigTY
,
1009 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1010 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1016 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1022 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1033 function monsShotTarget (mon
: TMonster
): Boolean;
1035 result
:= false; // don't stop
1036 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1038 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1039 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1040 TargetUID
:= mon
.UID
;
1041 result
:= true; // stop
1045 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1047 result
:= false; // don't stop
1048 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1050 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1051 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1052 TargetUID
:= mon
.UID
;
1053 result
:= true; // stop
1057 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1059 result
:= false; // don't stop
1060 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1062 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1063 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1064 TargetUID
:= mon
.UID
;
1065 result
:= true; // stop
1071 if g_Game_IsClient
then exit
;
1073 if not Trigger
.Enabled
then exit
;
1074 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1075 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then exit
;
1079 coolDown
:= (actType
<> 0);
1086 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1087 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1088 gExitByTrigger
:= True;
1089 g_Game_ExitLevel(trigData
.trigMap
);
1098 Result
:= tr_Teleport(ActivateUID
,
1099 trigData
.trigTarget
.X
, trigData
.trigTarget
.Y
,
1100 trigData
.trigDirection
, trigData
.trigSilent
,
1107 Result
:= tr_OpenDoor(trigPanelGUID
, trigData
.trigSilent
, trigData
.trigD2d
);
1113 Result
:= tr_CloseDoor(trigPanelGUID
, trigData
.trigSilent
, trigData
.trigD2d
);
1117 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1119 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1120 if (pan
<> nil) and pan
.isGWall
then
1122 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1124 result
:= tr_OpenDoor(trigPanelGUID
, trigData
.trigSilent
, trigData
.trigD2d
);
1125 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1129 result
:= tr_CloseDoor(trigPanelGUID
, trigData
.trigSilent
, trigData
.trigD2d
);
1132 if result
then TimeOut
:= 18;
1136 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1138 tr_CloseTrap(trigPanelGUID
, trigData
.trigSilent
, trigData
.trigD2d
);
1140 if TriggerType
= TRIGGER_TRAP
then
1154 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1157 if PressTime
= -1 then PressTime
:= trigData
.trigWait
;
1158 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1163 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1167 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1169 g_Player_Get(ActivateUID
).GetSecret();
1170 Inc(gCoopSecretsFound
);
1171 if g_Game_IsNet
then MH_SEND_GameStats();
1177 Result
:= tr_SetLift(trigPanelGUID
, 0, trigData
.trigSilent
, trigData
.trigD2d
);
1180 if (not trigData
.trigSilent
) and Result
then begin
1181 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1183 Y
+ (Height
div 2));
1184 if g_Game_IsServer
and g_Game_IsNet
then
1185 MH_SEND_Sound(X
+ (Width
div 2),
1187 'SOUND_GAME_SWITCH0');
1193 Result
:= tr_SetLift(trigPanelGUID
, 1, trigData
.trigSilent
, trigData
.trigD2d
);
1196 if (not trigData
.trigSilent
) and Result
then begin
1197 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1199 Y
+ (Height
div 2));
1200 if g_Game_IsServer
and g_Game_IsNet
then
1201 MH_SEND_Sound(X
+ (Width
div 2),
1203 'SOUND_GAME_SWITCH0');
1209 Result
:= tr_SetLift(trigPanelGUID
, 3, trigData
.trigSilent
, trigData
.trigD2d
);
1215 if (not trigData
.trigSilent
) and Result
then begin
1216 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1218 Y
+ (Height
div 2));
1219 if g_Game_IsServer
and g_Game_IsNet
then
1220 MH_SEND_Sound(X
+ (Width
div 2),
1222 'SOUND_GAME_SWITCH0');
1229 if trigData
.trigActivateOnce
then
1232 TriggerType
:= TRIGGER_NONE
;
1240 animonce
:= trigData
.trigAnimateOnce
;
1246 if Sound
<> nil then
1248 if trigData
.trigSoundSwitch
and Sound
.IsPlaying() then
1249 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1251 SoundPlayCount
:= 0;
1254 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1255 if (trigData
.trigPlayCount
> 0) or (not Sound
.IsPlaying()) then
1257 if trigData
.trigPlayCount
> 0 then
1258 SoundPlayCount
:= trigData
.trigPlayCount
1259 else // 0 - èãðàåì áåñêîíå÷íî
1260 SoundPlayCount
:= 1;
1263 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1267 TRIGGER_SPAWNMONSTER
:
1268 if (trigData
.trigSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1271 if (trigData
.trigDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1273 AutoSpawn
:= not AutoSpawn
;
1275 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1279 if ((trigData
.trigDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1280 or ((trigData
.trigDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1281 for k
:= 1 to trigData
.trigMonsCount
do
1283 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigDelay
> 0) then
1284 SpawnCooldown
:= trigData
.trigDelay
;
1285 if (trigData
.trigMax
> 0) and (SpawnedCount
>= trigData
.trigMax
) then
1288 mon
:= g_Monsters_Create(trigData
.trigSpawnMonsType
,
1289 trigData
.trigTX
, trigData
.trigTY
,
1290 TDirection(trigData
.trigDirection
), True);
1295 if (trigData
.trigHealth
> 0) then
1296 mon
.SetHealth(trigData
.trigHealth
);
1297 // Óñòàíàâëèâàåì ïîâåäåíèå:
1298 mon
.MonsterBehaviour
:= trigData
.trigBehaviour
;
1299 mon
.FNoRespawn
:= True;
1300 if g_Game_IsNet
then
1301 MH_SEND_MonsterSpawn(mon
.UID
);
1302 // Èäåì èñêàòü öåëü, åñëè íàäî:
1303 if trigData
.trigActive
then
1306 if trigData
.trigSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1308 if g_Game_IsNet
then
1310 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1311 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1314 if trigData
.trigMax
> 0 then
1316 mon
.SpawnTrigger
:= ID
;
1320 case trigData
.trigEffect
of
1321 EFFECT_TELEPORT
: begin
1322 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1324 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1325 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigTX
, trigData
.trigTY
);
1326 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1327 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1330 if g_Game_IsServer
and g_Game_IsNet
then
1331 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1332 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1335 EFFECT_RESPAWN
: begin
1336 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1338 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1339 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigTX
, trigData
.trigTY
);
1340 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1341 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1344 if g_Game_IsServer
and g_Game_IsNet
then
1345 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1346 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1350 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1352 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1353 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigTX
, trigData
.trigTY
);
1354 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1355 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1358 if g_Game_IsServer
and g_Game_IsNet
then
1359 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1360 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1365 if g_Game_IsNet
then
1367 MH_SEND_GameStats();
1368 MH_SEND_CoopStats();
1375 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1376 if actType
= ACTIVATE_CUSTOM
then
1381 if (trigData
.trigSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1384 if (trigData
.trigDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1386 AutoSpawn
:= not AutoSpawn
;
1388 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1392 if ((trigData
.trigDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1393 or ((trigData
.trigDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1394 if (not trigData
.trigDmonly
) or
1395 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1396 for k
:= 1 to trigData
.trigItemCount
do
1398 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigDelay
> 0) then
1399 SpawnCooldown
:= trigData
.trigDelay
;
1400 if (trigData
.trigMax
> 0) and (SpawnedCount
>= trigData
.trigMax
) then
1403 iid
:= g_Items_Create(trigData
.trigTX
, trigData
.trigTY
,
1404 trigData
.trigSpawnItemType
, trigData
.trigGravity
, False, True);
1408 if trigData
.trigMax
> 0 then
1410 it
:= g_Items_ByIdx(iid
);
1411 it
.SpawnTrigger
:= ID
;
1415 case trigData
.trigEffect
of
1416 EFFECT_TELEPORT
: begin
1417 it
:= g_Items_ByIdx(iid
);
1418 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1420 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1421 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigTX
, trigData
.trigTY
);
1422 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1423 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1426 if g_Game_IsServer
and g_Game_IsNet
then
1427 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1428 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1431 EFFECT_RESPAWN
: begin
1432 it
:= g_Items_ByIdx(iid
);
1433 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1435 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1436 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigTX
, trigData
.trigTY
);
1437 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1438 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1441 if g_Game_IsServer
and g_Game_IsNet
then
1442 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1443 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1447 it
:= g_Items_ByIdx(iid
);
1448 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1450 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1451 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigTX
, trigData
.trigTY
);
1452 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1453 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1456 if g_Game_IsServer
and g_Game_IsNet
then
1457 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1458 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1463 if g_Game_IsNet
then
1464 MH_SEND_ItemSpawn(True, iid
);
1471 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1472 if actType
= ACTIVATE_CUSTOM
then
1478 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1479 if (Trigger
.trigData
.trigMusicName
<> '') then
1481 gMusic
.SetByName(Trigger
.trigData
.trigMusicName
);
1482 gMusic
.SpecPause
:= True;
1486 case Trigger
.trigData
.trigMusicAction
of
1487 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1488 gMusic
.SpecPause
:= True; // Ïàóçà
1489 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1490 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1491 gMusic
.SpecPause
:= False
1492 else // Èãðàëà => ñíà÷àëà
1493 gMusic
.SetPosition(0);
1501 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1506 pAngle
:= -DegToRad(trigData
.trigAngle
);
1507 Result
:= tr_Push(ActivateUID
,
1508 Floor(Cos(pAngle
)*trigData
.trigForce
),
1509 Floor(Sin(pAngle
)*trigData
.trigForce
),
1510 trigData
.trigResetVelocity
);
1517 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1518 if (trigData
.trigScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (trigData
.trigScoreCount
> 0) then
1520 // Ñâîåé èëè ÷óæîé êîìàíäå
1521 if (trigData
.trigScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1523 p
:= g_Player_Get(ActivateUID
);
1524 if ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1525 or ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1527 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1529 if trigData
.trigScoreCon
then
1531 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1533 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1534 if g_Game_IsServer
and g_Game_IsNet
then
1535 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+r');
1538 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1539 if g_Game_IsServer
and g_Game_IsNet
then
1540 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+re');
1544 if trigData
.trigScoreMsg
then
1546 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1547 if g_Game_IsServer
and g_Game_IsNet
then
1548 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1551 if ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1552 or ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1554 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1556 if trigData
.trigScoreCon
then
1558 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1560 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1561 if g_Game_IsServer
and g_Game_IsNet
then
1562 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-r');
1565 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1566 if g_Game_IsServer
and g_Game_IsNet
then
1567 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-re');
1571 if trigData
.trigScoreMsg
then
1573 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1574 if g_Game_IsServer
and g_Game_IsNet
then
1575 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1578 if ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1579 or ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1581 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1583 if trigData
.trigScoreCon
then
1585 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1587 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1588 if g_Game_IsServer
and g_Game_IsNet
then
1589 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+b');
1592 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1593 if g_Game_IsServer
and g_Game_IsNet
then
1594 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+be');
1598 if trigData
.trigScoreMsg
then
1600 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1601 if g_Game_IsServer
and g_Game_IsNet
then
1602 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1605 if ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1606 or ((trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1608 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1610 if trigData
.trigScoreCon
then
1612 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1614 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1615 if g_Game_IsServer
and g_Game_IsNet
then
1616 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-b');
1619 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1620 if g_Game_IsServer
and g_Game_IsNet
then
1621 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-be');
1625 if trigData
.trigScoreMsg
then
1627 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1628 if g_Game_IsServer
and g_Game_IsNet
then
1629 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1632 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1634 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1635 if trigData
.trigScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1637 if (trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1639 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1641 if trigData
.trigScoreCon
then
1643 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1644 if g_Game_IsServer
and g_Game_IsNet
then
1645 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tr');
1648 if trigData
.trigScoreMsg
then
1650 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1651 if g_Game_IsServer
and g_Game_IsNet
then
1652 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1655 if (trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1657 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1659 if trigData
.trigScoreCon
then
1661 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1662 if g_Game_IsServer
and g_Game_IsNet
then
1663 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tr');
1666 if trigData
.trigScoreMsg
then
1668 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1669 if g_Game_IsServer
and g_Game_IsNet
then
1670 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1673 if (trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1675 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1677 if trigData
.trigScoreCon
then
1679 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1680 if g_Game_IsServer
and g_Game_IsNet
then
1681 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tb');
1684 if trigData
.trigScoreMsg
then
1686 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1687 if g_Game_IsServer
and g_Game_IsNet
then
1688 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1691 if (trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1693 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1695 if trigData
.trigScoreCon
then
1697 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1698 if g_Game_IsServer
and g_Game_IsNet
then
1699 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tb');
1702 if trigData
.trigScoreMsg
then
1704 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1705 if g_Game_IsServer
and g_Game_IsNet
then
1706 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1713 if (trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1715 // Ñâîåé èëè ÷óæîé êîìàíäû
1716 if (trigData
.trigScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1718 p
:= g_Player_Get(ActivateUID
);
1719 if ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1720 or ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1722 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1724 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1726 if trigData
.trigScoreCon
then
1728 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1730 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1731 if g_Game_IsServer
and g_Game_IsNet
then
1732 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1735 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1736 if g_Game_IsServer
and g_Game_IsNet
then
1737 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1744 if ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1745 or ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1747 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1749 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1751 if trigData
.trigScoreCon
then
1753 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1755 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1756 if g_Game_IsServer
and g_Game_IsNet
then
1757 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1760 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1761 if g_Game_IsServer
and g_Game_IsNet
then
1762 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1770 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1771 if trigData
.trigScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1773 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1775 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1777 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1781 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1783 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1785 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1792 if (trigData
.trigScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1794 // Ñâîåé èëè ÷óæîé êîìàíäû
1795 if (trigData
.trigScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1797 p
:= g_Player_Get(ActivateUID
);
1798 if ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1799 or ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1800 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1802 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1804 if trigData
.trigScoreCon
then
1805 if trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1807 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1808 if g_Game_IsServer
and g_Game_IsNet
then
1809 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1812 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1813 if g_Game_IsServer
and g_Game_IsNet
then
1814 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1819 if ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
1820 or ((trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1821 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1823 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1825 if trigData
.trigScoreCon
then
1826 if trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1828 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1829 if g_Game_IsServer
and g_Game_IsNet
then
1830 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1833 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1834 if g_Game_IsServer
and g_Game_IsNet
then
1835 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1841 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1842 if trigData
.trigScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
1844 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
1846 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1848 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1852 if (trigData
.trigScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
1854 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1856 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1862 if Result
then begin
1867 if g_Game_IsServer
and g_Game_IsNet
then
1874 Result
:= tr_Message(trigData
.trigKind
, trigData
.trigText
,
1875 trigData
.trigMsgDest
, trigData
.trigMsgTime
,
1880 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1883 UIDType
:= g_GetUIDType(ActivateUID
);
1884 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1890 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1891 for idx
:= 0 to High(Activators
) do
1892 if Activators
[idx
].UID
= ActivateUID
then
1898 begin // Âèäèì åãî âïåðâûå
1900 SetLength(Activators
, Length(Activators
) + 1);
1901 k
:= High(Activators
);
1902 Activators
[k
].UID
:= ActivateUID
;
1904 begin // Óæå âèäåëè åãî
1905 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1906 if (trigData
.trigInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
1907 Activators
[k
].TimeOut
:= 65535;
1908 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1909 Result
:= Activators
[k
].TimeOut
= 0;
1918 p
:= g_Player_Get(ActivateUID
);
1922 // Íàíîñèì óðîí èãðîêó
1923 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigAmount
> 0) then
1924 p
.Damage(trigData
.trigAmount
, 0, 0, 0, HIT_SOME
);
1927 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigAmount
> 0) then
1928 if p
.Heal(trigData
.trigAmount
, not trigData
.trigHealMax
) and (not trigData
.trigSilent
) then
1930 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
1931 if g_Game_IsServer
and g_Game_IsNet
then
1932 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1938 m
:= g_Monsters_ByUID(ActivateUID
);
1942 // Íàíîñèì óðîí ìîíñòðó
1943 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigAmount
> 0) then
1944 m
.Damage(trigData
.trigAmount
, 0, 0, 0, HIT_SOME
);
1947 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigAmount
> 0) then
1948 if m
.Heal(trigData
.trigAmount
) and (not trigData
.trigSilent
) then
1950 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
1951 if g_Game_IsServer
and g_Game_IsNet
then
1952 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1956 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1957 idx
:= trigData
.trigInterval
;
1960 Activators
[k
].TimeOut
:= idx
1962 Activators
[k
].TimeOut
:= 65535;
1970 if ShotSightTime
> 0 then
1973 // put this at the beginning so it doesn't trigger itself
1974 TimeOut
:= trigData
.trigWait
+ 1;
1976 wx
:= trigData
.trigTX
;
1977 wy
:= trigData
.trigTY
;
1978 pAngle
:= -DegToRad(trigData
.trigAngle
);
1979 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
1980 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
1983 case trigData
.trigShotTarget
of
1984 TRIGGER_SHOT_TARGET_MON
: // monsters
1985 //TODO: accelerate this!
1986 g_Mons_ForEachAlive(monsShotTarget
);
1988 TRIGGER_SHOT_TARGET_PLR
: // players
1989 if gPlayers
<> nil then
1990 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1991 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
1992 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1994 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1995 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1996 TargetUID
:= gPlayers
[idx
].UID
;
2000 TRIGGER_SHOT_TARGET_RED
: // red team
2001 if gPlayers
<> nil then
2002 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2003 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2004 (gPlayers
[idx
].Team
= TEAM_RED
) and
2005 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2007 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2008 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2009 TargetUID
:= gPlayers
[idx
].UID
;
2013 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2014 if gPlayers
<> nil then
2015 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2016 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2017 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2018 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2020 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2021 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2022 TargetUID
:= gPlayers
[idx
].UID
;
2026 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2028 //TODO: accelerate this!
2029 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2031 if (TargetUID
= 0) and (gPlayers
<> nil) then
2032 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2033 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2034 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2036 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2037 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2038 TargetUID
:= gPlayers
[idx
].UID
;
2043 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2045 if gPlayers
<> nil then
2046 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2047 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2048 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2050 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2051 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2052 TargetUID
:= gPlayers
[idx
].UID
;
2055 if TargetUID
= 0 then
2057 //TODO: accelerate this!
2058 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2063 if (trigData
.trigShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2064 (trigData
.trigShotType
<> TRIGGER_SHOT_REV
) then
2065 TargetUID
:= ActivateUID
;
2069 if (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2070 ((trigData
.trigShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2073 if (trigData
.trigSight
= 0) or
2074 (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2075 (TargetUID
= ShotSightTarget
) then
2076 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2079 ShotSightTime
:= trigData
.trigSight
;
2080 ShotSightTargetN
:= TargetUID
;
2081 if trigData
.trigShotType
= TRIGGER_SHOT_BFG
then
2083 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2084 if g_Game_IsNet
and g_Game_IsServer
then
2085 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2093 idx
:= trigData
.trigFXCount
;
2097 case trigData
.trigFXPos
of
2098 TRIGGER_EFFECT_POS_CENTER
:
2100 wx
:= X
+ Width
div 2;
2101 wy
:= Y
+ Height
div 2;
2103 TRIGGER_EFFECT_POS_AREA
:
2105 wx
:= X
+ Random(Width
);
2106 wy
:= Y
+ Random(Height
);
2109 wx
:= X
+ Width
div 2;
2110 wy
:= Y
+ Height
div 2;
2113 xd
:= trigData
.trigVelX
;
2114 yd
:= trigData
.trigVelY
;
2115 if trigData
.trigSpreadL
> 0 then xd
-= Random(trigData
.trigSpreadL
+1);
2116 if trigData
.trigSpreadR
> 0 then xd
+= Random(trigData
.trigSpreadR
+1);
2117 if trigData
.trigSpreadU
> 0 then yd
-= Random(trigData
.trigSpreadU
+1);
2118 if trigData
.trigSpreadD
> 0 then yd
+= Random(trigData
.trigSpreadD
+1);
2119 tr_MakeEffect(wx
, wy
, xd
, yd
,
2120 trigData
.trigFXType
, trigData
.trigFXSubType
,
2121 trigData
.trigFXRed
, trigData
.trigFXGreen
, trigData
.trigFXBlue
, True, False);
2124 TimeOut
:= trigData
.trigWait
;
2129 if Result
{and (Trigger.TexturePanel <> -1)} then
2131 g_Map_SwitchTextureGUID(Trigger
.TexturePanelType
, Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2136 function g_Triggers_CreateWithMapIndex (Trigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2138 triggers
: TDynField
;
2140 triggers
:= gCurrentMap
['trigger'];
2141 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2142 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2143 Trigger
.trigData
:= triggers
.itemAt
[mapidx
];
2144 if (Trigger
.trigData
= nil) then raise Exception
.Create('LOAD: internal error in trigger loader');
2145 Trigger
.mapId
:= Trigger
.trigData
.id
;
2146 Trigger
.mapIndex
:= mapidx
;
2147 if (Trigger
.trigData
.trigRec
<> nil) then
2149 Trigger
.trigData
:= Trigger
.trigData
.trigRec
.clone({Trigger.trigData.headerRec}nil);
2153 Trigger
.trigData
:= nil;
2155 result
:= g_Triggers_Create(Trigger
, arridx
);
2159 function g_Triggers_Create(Trigger
: TTrigger
; forceInternalIndex
: Integer=-1): DWORD
;
2162 fn
, mapw
: AnsiString;
2165 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2166 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2167 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2168 Trigger
.TriggerType
:= TRIGGER_NONE
;
2170 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2171 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2172 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2173 (gGameSettings
.GameType
<> GT_SINGLE
) then
2174 Trigger
.TriggerType
:= TRIGGER_NONE
;
2176 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2177 if Trigger
.TriggerType
= TRIGGER_SECRET
then
2178 gSecretsCount
:= gSecretsCount
+ 1;
2180 if (forceInternalIndex
< 0) then
2182 find_id
:= FindTrigger();
2186 olen
:= Length(gTriggers
);
2187 if (forceInternalIndex
>= olen
) then
2189 SetLength(gTriggers
, forceInternalIndex
+1);
2190 for f
:= olen
to High(gTriggers
) do gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2192 find_id
:= DWORD(forceInternalIndex
);
2194 gTriggers
[find_id
] := Trigger
;
2196 //e_LogWritefln('created trigger with map index %s, findid=%s (%s)', [Trigger.mapIndex, find_id, Trigger.mapId]);
2199 writeln('trigger #', find_id, ': pos=(', Trigger.x, ',', Trigger.y, ')-(', Trigger.width, 'x', Trigger.height, ')',
2200 '; TexturePanel=', Trigger.TexturePanel,
2201 '; TexturePanelType=', Trigger.TexturePanelType,
2202 '; ShotPanelType=', Trigger.ShotPanelType,
2203 '; TriggerType=', Trigger.TriggerType,
2204 '; ActivateType=', Trigger.ActivateType,
2205 '; Keys=', Trigger.Keys,
2206 '; trigPanelId=', Trigger.trigPanelId,
2207 '; trigShotPanelId=', Trigger.trigShotPanelId
2211 with gTriggers
[find_id
] do
2214 // if this type of trigger exists both on the client and on the server
2215 // use an uniform numeration
2216 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2218 Inc(gTriggerClientID
);
2219 ClientID
:= gTriggerClientID
;
2225 PlayerCollide
:= False;
2229 SoundPlayCount
:= 0;
2236 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2237 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and
2238 (Trigger
.trigData
.trigSoundName
<> '') then
2240 // Åùå íåò òàêîãî çâóêà:
2241 if not g_Sound_Exists(Trigger
.trigData
.trigSoundName
) then
2243 fn
:= g_ExtractWadName(Trigger
.trigData
.trigSoundName
);
2246 begin // Çâóê â ôàéëå ñ êàðòîé
2247 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2248 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigSoundName
);
2250 else // Çâóê â îòäåëüíîì ôàéëå
2251 fn
:= GameDir
+ '/wads/' + Trigger
.trigData
.trigSoundName
;
2253 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigSoundName
, fn
) then
2254 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigSoundName
]));
2257 // Ñîçäàåì îáúåêò çâóêà:
2258 with gTriggers
[find_id
] do
2260 Sound
:= TPlayableSound
.Create();
2261 if not Sound
.SetByName(Trigger
.trigData
.trigSoundName
) then
2269 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2270 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and
2271 (Trigger
.trigData
.trigMusicName
<> '') then
2273 // Åùå íåò òàêîé ìóçûêè:
2274 if not g_Sound_Exists(Trigger
.trigData
.trigMusicName
) then
2276 fn
:= g_ExtractWadName(Trigger
.trigData
.trigMusicName
);
2279 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2280 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2281 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigMusicName
);
2283 else // Ìóçûêà â ôàéëå ñ êàðòîé
2284 fn
:= GameDir
+'/wads/'+Trigger
.trigData
.trigMusicName
;
2286 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigMusicName
, fn
, True) then
2287 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigMusicName
]));
2291 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2292 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2293 with gTriggers
[find_id
] do
2297 ShotSightTimeout
:= 0;
2298 ShotSightTarget
:= 0;
2299 ShotSightTargetN
:= 0;
2300 ShotAmmoCount
:= Trigger
.trigData
.trigAmmo
;
2301 ShotReloadTime
:= 0;
2308 // sorry; grid doesn't support recursive queries, so we have to do this
2310 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2313 tgMonsList
: TSimpleMonsterList
= nil;
2315 procedure g_Triggers_Update();
2318 Affected
: array of Integer;
2320 function monsNear (mon
: TMonster
): Boolean;
2322 result
:= false; // don't stop
2324 gTriggers[a].ActivateUID := mon.UID;
2325 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2327 tgMonsList
.append(mon
);
2334 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2336 if gTriggers
= nil then
2338 SetLength(Affected
, 0);
2340 for a
:= 0 to High(gTriggers
) do
2341 with gTriggers
[a
] do
2343 if TriggerType
<> TRIGGER_NONE
then
2345 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2346 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2347 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2348 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2349 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2350 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2352 for b
:= 0 to High(Activators
) do
2354 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2355 if Activators
[b
].TimeOut
> 0 then
2357 Dec(Activators
[b
].TimeOut
);
2363 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2364 if (trigData
.trigInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2368 // Îáðàáàòûâàåì ñïàâíåðû
2369 if Enabled
and AutoSpawn
then
2371 if SpawnCooldown
= 0 then
2373 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2374 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (trigData
.trigDelay
> 0) then
2377 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2379 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2380 if (TriggerType
= TRIGGER_SPAWNITEM
) and (trigData
.trigDelay
> 0) then
2383 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2388 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2393 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2394 if TriggerType
= TRIGGER_SHOT
then
2396 if ShotPanelTime
> 0 then
2399 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID(ShotPanelType
, trigShotPanelGUID
);
2401 if ShotSightTime
> 0 then
2404 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2406 if ShotSightTimeout
> 0 then
2408 Dec(ShotSightTimeout
);
2409 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2411 if ShotReloadTime
> 0 then
2413 Dec(ShotReloadTime
);
2414 if ShotReloadTime
= 0 then ShotAmmoCount
:= trigData
.trigAmmo
;
2418 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2419 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2421 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2423 if trigData
.trigPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2424 if trigData
.trigLocal
then
2426 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), trigData
.trigVolume
/255.0);
2430 Sound
.PlayPanVolume((trigData
.trigPan
-127.0)/128.0, trigData
.trigVolume
/255.0);
2432 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2436 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2437 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2439 tr_OpenDoor(trigPanelGUID
, trigData
.trigSilent
, trigData
.trigD2d
);
2443 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2444 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2446 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2447 if (pan
<> nil) and pan
.isGWall
then
2450 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2456 // Ïîêà îòêðûòà - çàêðûâàåì
2457 if tr_CloseDoor(trigPanelGUID
, trigData
.trigSilent
, trigData
.trigD2d
) then DoorTime
:= -1;
2462 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2463 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2464 (PressTime
= 0) and (PressCount
>= trigData
.trigPressCount
) then
2466 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2468 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2469 if trigData
.trigPressCount
> 0 then PressCount
-= trigData
.trigPressCount
else PressCount
:= 0;
2471 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2472 for b
:= 0 to High(gTriggers
) do
2474 if g_Collide(trigData
.trigtX
, trigData
.trigtY
, trigData
.trigtWidth
, trigData
.trigtHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2475 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2476 ((b
<> a
) or (trigData
.trigWait
> 0)) then
2477 begin // Can be self-activated, if there is Data.Wait
2478 if (not trigData
.trigExtRandom
) or gTriggers
[b
].Enabled
then
2480 SetLength(Affected
, Length(Affected
) + 1);
2481 Affected
[High(Affected
)] := b
;
2487 // if we have panelid, assume that it will switch the moving platform
2488 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2489 if (pan
<> nil) then
2492 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2493 TRIGGER_ON
: pan
.movingActive
:= true;
2494 TRIGGER_OFF
: pan
.movingActive
:= false;
2495 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2499 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2500 if (TriggerType
= TRIGGER_PRESS
) and trigData
.trigExtRandom
then
2502 if (Length(Affected
) > 0) then
2504 b
:= Affected
[Random(Length(Affected
))];
2505 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2506 ActivateTrigger(gTriggers
[b
], 0);
2509 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2511 for i
:= 0 to High(Affected
) do
2517 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2518 ActivateTrigger(gTriggers
[b
], 0);
2522 gTriggers
[b
].Enabled
:= True;
2526 gTriggers
[b
].Enabled
:= False;
2527 gTriggers
[b
].TimeOut
:= 0;
2528 if gTriggers
[b
].AutoSpawn
then
2530 gTriggers
[b
].AutoSpawn
:= False;
2531 gTriggers
[b
].SpawnCooldown
:= 0;
2536 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2537 if not gTriggers
[b
].Enabled
then
2539 gTriggers
[b
].TimeOut
:= 0;
2540 if gTriggers
[b
].AutoSpawn
then
2542 gTriggers
[b
].AutoSpawn
:= False;
2543 gTriggers
[b
].SpawnCooldown
:= 0;
2550 SetLength(Affected
, 0);
2553 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2556 TimeOut
:= TimeOut
- 1;
2557 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2560 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2565 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2567 if gPlayers
<> nil then
2568 for b
:= 0 to High(gPlayers
) do
2569 if gPlayers
[b
] <> nil then
2571 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2572 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2573 Collide(X
, Y
, Width
, Height
) then
2575 gTriggers
[a
].ActivateUID
:= UID
;
2577 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2579 { Don't activate sound/music again if player is here }
2581 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2584 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2586 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2587 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2588 (TimeOut
= 0) and (Keys
= 0) then
2590 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2591 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2592 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2593 gTriggers
[a
].ActivateUID
:= 0;
2594 ActivateTrigger(gTriggers
[a
], 0);
2598 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2599 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2601 //g_Mons_ForEach(monsNear);
2604 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2605 for mon
in tgMonsList
do
2607 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2608 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2610 tgMonsList
.reset(); // just in case
2614 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2615 (TimeOut
= 0) and (Keys
= 0) then
2616 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2618 gTriggers
[a
].ActivateUID
:= 0;
2619 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2623 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2627 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2629 if (ID
>= Length(gTriggers
)) then exit
;
2630 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2631 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2634 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2635 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2643 if gTriggers
= nil then Exit
;
2645 case g_GetUIDType(UID
) of
2649 p
:= g_Player_Get(UID
);
2658 for a
:= 0 to High(gTriggers
) do
2659 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2660 (gTriggers
[a
].TimeOut
= 0) and
2661 (not InDWArray(a
, IgnoreList
)) and
2662 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2663 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2664 if g_Collide(X
, Y
, Width
, Height
,
2665 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2666 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2668 gTriggers
[a
].ActivateUID
:= UID
;
2669 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2671 SetLength(Result
, Length(Result
)+1);
2672 Result
[High(Result
)] := a
;
2677 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2683 if gTriggers
= nil then Exit
;
2685 case g_GetUIDType(UID
) of
2689 p
:= g_Player_Get(UID
);
2698 for a
:= 0 to High(gTriggers
) do
2699 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2700 (gTriggers
[a
].TimeOut
= 0) and
2701 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2702 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2703 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2704 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2706 gTriggers
[a
].ActivateUID
:= UID
;
2707 ActivateTrigger(gTriggers
[a
], ActivateType
);
2711 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2718 if gTriggers
= nil then
2721 case g_GetUIDType(UID
) of
2725 p
:= g_Player_Get(UID
);
2734 rsq
:= Radius
* Radius
;
2736 for a
:= 0 to High(gTriggers
) do
2737 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
2738 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2739 (gTriggers
[a
].TimeOut
= 0) and
2740 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2741 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2742 with gTriggers
[a
] do
2743 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
2744 X
, Y
, Width
, Height
) then
2745 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2746 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2747 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2748 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2749 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
2750 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2751 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
2752 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2755 ActivateTrigger(gTriggers
[a
], ActivateType
);
2759 procedure g_Triggers_OpenAll();
2764 if gTriggers
= nil then Exit
;
2767 for a
:= 0 to High(gTriggers
) do
2769 with gTriggers
[a
] do
2771 if (TriggerType
= TRIGGER_OPENDOOR
) or
2772 (TriggerType
= TRIGGER_DOOR5
) or
2773 (TriggerType
= TRIGGER_DOOR
) then
2775 tr_OpenDoor(trigPanelGUID
, True, trigData
.trigD2d
);
2776 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2782 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2785 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2787 if (gTriggers
<> nil) then
2788 if gTriggers
[ID
].SpawnedCount
> 0 then
2789 Dec(gTriggers
[ID
].SpawnedCount
);
2792 procedure g_Triggers_Free();
2796 for a
:= 0 to High(gTriggers
) do
2798 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
2800 if g_Sound_Exists(gTriggers
[a
].trigData
.trigSoundName
) then
2802 g_Sound_Delete(gTriggers
[a
].trigData
.trigSoundName
);
2804 gTriggers
[a
].Sound
.Free();
2806 if (gTriggers
[a
].Activators
<> nil) then
2808 SetLength(gTriggers
[a
].Activators
, 0);
2810 gTriggers
[a
].trigData
.Free();
2815 SetLength(gMonstersSpawned
, 0);
2818 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2820 count
, act_count
, i
, j
: Integer;
2825 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2826 count
:= Length(gTriggers
);
2828 Mem
:= TBinMemoryWriter
.Create((count
+1) * 200);
2830 // Êîëè÷åñòâî òðèããåðîâ:
2831 Mem
.WriteInt(count
);
2833 //e_LogWritefln('saving %s triggers (count=%s)', [Length(gTriggers), count]);
2835 if count
= 0 then exit
;
2837 for i
:= 0 to High(gTriggers
) do
2839 // Ñèãíàòóðà òðèããåðà:
2840 dw
:= TRIGGER_SIGNATURE
; // 'TRGX'
2843 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2844 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2845 // Ñïåöèàëüíûå äàííûå òðèããåðà: äà â æîïó, ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2846 //e_LogWritefln('=== trigger #%s saved ===', [gTriggers[i].mapIndex]);
2847 Mem
.WriteInt(gTriggers
[i
].mapIndex
);
2848 //p := @gTriggers[i].Data;
2849 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2850 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2851 Mem
.WriteInt(gTriggers
[i
].X
);
2852 Mem
.WriteInt(gTriggers
[i
].Y
);
2854 Mem
.WriteWord(gTriggers
[i
].Width
);
2855 Mem
.WriteWord(gTriggers
[i
].Height
);
2856 // Âêëþ÷åí ëè òðèããåð:
2857 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
2858 // Òèï àêòèâàöèè òðèããåðà:
2859 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
2860 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2861 Mem
.WriteByte(gTriggers
[i
].Keys
);
2862 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2863 Mem
.WriteInt(gTriggers
[i
].TexturePanelGUID
);
2865 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
2866 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2867 Mem
.WriteInt(gTriggers
[i
].trigPanelGUID
);
2868 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2869 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
2870 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2871 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
2872 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2873 act_count
:= Length(gTriggers
[i
].Activators
);
2874 Mem
.WriteInt(act_count
);
2875 for j
:= 0 to act_count
-1 do
2878 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2880 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2882 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2883 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2884 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2885 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2886 // Çàäåðæêà àêòèâàöèè:
2887 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2889 Mem
.WriteInt(gTriggers
[i
].PressCount
);
2891 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
2892 // Çàäåðæêà ñïàâíåðà:
2893 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
2894 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2895 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
2896 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2897 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
2898 // Ïðîèãðûâàåòñÿ ëè çâóê?
2899 if gTriggers
[i
].Sound
<> nil then
2900 b
:= gTriggers
[i
].Sound
.IsPlaying()
2903 Mem
.WriteBoolean(b
);
2906 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2907 dw
:= gTriggers
[i
].Sound
.GetPosition();
2910 sg
:= gTriggers
[i
].Sound
.GetVolume();
2911 sg
:= sg
/ (gSoundLevel
/255.0);
2912 Mem
.WriteSingle(sg
);
2913 // Ñòåðåî ñìåùåíèå çâóêà:
2914 sg
:= gTriggers
[i
].Sound
.GetPan();
2915 Mem
.WriteSingle(sg
);
2920 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
2922 count
, act_count
, i
, j
, a
: Integer;
2929 //tw: TStrTextWriter;
2936 // Êîëè÷åñòâî òðèããåðîâ:
2939 if (count
= 0) then exit
;
2941 for a
:= 0 to count
-1 do
2943 // Ñèãíàòóðà òðèããåðà:
2945 if (dw
<> TRIGGER_SIGNATURE
) then // 'TRGX'
2947 raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2950 Mem
.ReadByte(Trig
.TriggerType
);
2951 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2952 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
2953 Mem
.ReadInt(mapIndex
);
2956 Mem.ReadMemory(p, dw);
2957 if dw <> SizeOf(TTriggerData) then
2959 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2961 Trig.Data := TTriggerData(p^);
2964 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
2966 if (gTriggers[i].trigData <> nil) then
2968 tw := TStrTextWriter.Create();
2970 gTriggers[i].trigData.writeTo(tw);
2971 e_LogWritefln('=== trigger #%s loaded ==='#10'%s'#10'---', [mapIndex, tw.str]);
2977 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2978 Mem
.ReadInt(gTriggers
[i
].X
);
2979 Mem
.ReadInt(gTriggers
[i
].Y
);
2981 Mem
.ReadWord(gTriggers
[i
].Width
);
2982 Mem
.ReadWord(gTriggers
[i
].Height
);
2983 // Âêëþ÷åí ëè òðèããåð:
2984 Mem
.ReadBoolean(gTriggers
[i
].Enabled
);
2985 // Òèï àêòèâàöèè òðèããåðà:
2986 Mem
.ReadByte(gTriggers
[i
].ActivateType
);
2987 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2988 Mem
.ReadByte(gTriggers
[i
].Keys
);
2989 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2990 Mem
.ReadInt(gTriggers
[i
].TexturePanelGUID
);
2992 Mem
.ReadWord(gTriggers
[i
].TexturePanelType
);
2993 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2994 Mem
.ReadInt(gTriggers
[i
].trigPanelGUID
);
2995 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2996 Mem
.ReadWord(gTriggers
[i
].TimeOut
);
2997 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2998 Mem
.ReadWord(gTriggers
[i
].ActivateUID
);
2999 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
3000 Mem
.ReadInt(act_count
);
3001 if act_count
> 0 then
3003 SetLength(gTriggers
[i
].Activators
, act_count
);
3004 for j
:= 0 to act_count
-1 do
3007 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
3009 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
3012 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
3013 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
3014 // Âðåìÿ äî çàêðûòèÿ äâåðè:
3015 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
3016 // Çàäåðæêà àêòèâàöèè:
3017 Mem
.ReadInt(gTriggers
[i
].PressTime
);
3019 Mem
.ReadInt(gTriggers
[i
].PressCount
);
3021 Mem
.ReadBoolean(gTriggers
[i
].AutoSpawn
);
3022 // Çàäåðæêà ñïàâíåðà:
3023 Mem
.ReadInt(gTriggers
[i
].SpawnCooldown
);
3024 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3025 Mem
.ReadInt(gTriggers
[i
].SpawnedCount
);
3026 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3027 Mem
.ReadInt(gTriggers
[i
].SoundPlayCount
);
3028 // Ïðîèãðûâàåòñÿ ëè çâóê?
3032 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3035 Mem
.ReadSingle(vol
);
3036 // Ñòåðåî ñìåùåíèå çâóêà:
3037 Mem
.ReadSingle(pan
);
3038 // Çàïóñêàåì çâóê, åñëè åñòü:
3039 if gTriggers
[i
].Sound
<> nil then
3041 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3042 gTriggers
[i
].Sound
.Pause(True);
3043 gTriggers
[i
].Sound
.SetPosition(dw
);