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
,
39 TexturePanel
: Integer;
40 TexturePanelType
: Word;
44 Activators
: array of TActivator
;
45 PlayerCollide
: Boolean;
49 SoundPlayCount
: Integer;
50 Sound
: TPlayableSound
;
52 SpawnCooldown
: Integer;
53 SpawnedCount
: Integer;
55 ShotPanelTime
: Integer;
56 ShotSightTime
: Integer;
57 ShotSightTimeout
: Integer;
58 ShotSightTarget
: Word;
59 ShotSightTargetN
: Word;
61 ShotReloadTime
: Integer;
63 trigShotPanelId
: Integer;
66 //TrigData: TTriggerData;
67 trigData
: TDynRecord
; // triggerdata; owned by trigger
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;
97 gTriggerClientID
: Integer = 0;
98 gTriggers
: array of TTrigger
;
99 gSecretsCount
: Integer = 0;
100 gMonstersSpawned
: array of LongInt = nil;
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
;
111 TRIGGER_SIGNATURE
= $52475254; // 'TRGR'
114 function FindTrigger(): DWORD
;
118 if gTriggers
<> nil then
119 for i
:= 0 to High(gTriggers
) do
120 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then
126 if gTriggers
= nil then
128 SetLength(gTriggers
, 8);
133 Result
:= High(gTriggers
) + 1;
134 SetLength(gTriggers
, Length(gTriggers
) + 8);
138 function tr_CloseDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
144 if PanelID
= -1 then Exit
;
148 with gWalls
[PanelID
] do
150 if g_CollidePlayer(X
, Y
, Width
, Height
) or
151 g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
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');
161 g_Map_EnableWall(PanelID
);
168 if gDoorMap
= nil then Exit
;
171 for a
:= 0 to High(gDoorMap
) do
173 for b
:= 0 to High(gDoorMap
[a
]) do
174 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
180 if c
<> -1 then Break
;
184 for b
:= 0 to High(gDoorMap
[c
]) do
185 with gWalls
[gDoorMap
[c
, b
]] do
187 if g_CollidePlayer(X
, Y
, Width
, Height
) or
188 g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
192 for b
:= 0 to High(gDoorMap
[c
]) do
193 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
195 with gWalls
[PanelID
] do
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');
204 for b
:= 0 to High(gDoorMap
[c
]) do
205 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
207 g_Map_EnableWall(gDoorMap
[c
, b
]);
213 procedure tr_CloseTrap(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean);
216 wx
, wy
, wh
, ww
: Integer;
218 function monsDamage (mon
: TMonster
): Boolean;
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
);
225 if PanelID
= -1 then Exit
;
229 with gWalls
[PanelID
] do
231 if (not NoSound
) and (not Enabled
) then
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');
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
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
);
260 if gDoorMap
= nil then Exit
;
263 for a
:= 0 to High(gDoorMap
) do
265 for b
:= 0 to High(gDoorMap
[a
]) do
267 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
274 if c
<> -1 then Break
;
280 for b
:= 0 to High(gDoorMap
[c
]) do
282 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
284 with gWalls
[PanelID
] do
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');
294 for b
:= 0 to High(gDoorMap
[c
]) do
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
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
);
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);
319 if not Enabled
then g_Map_EnableWall(gDoorMap
[c
, b
]);
325 function tr_OpenDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
331 if PanelID
= -1 then Exit
;
335 with gWalls
[PanelID
] do
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');
344 g_Map_DisableWall(PanelID
);
350 if gDoorMap
= nil then Exit
;
353 for a
:= 0 to High(gDoorMap
) do
355 for b
:= 0 to High(gDoorMap
[a
]) do
356 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
362 if c
<> -1 then Break
;
367 for b
:= 0 to High(gDoorMap
[c
]) do
368 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
370 with gWalls
[PanelID
] do
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');
379 for b
:= 0 to High(gDoorMap
[c
]) do
380 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
382 g_Map_DisableWall(gDoorMap
[c
, b
]);
388 function tr_SetLift(PanelID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
395 if PanelID
= -1 then Exit
;
397 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or
398 (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
402 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
404 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or
405 (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
409 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
414 with gLifts
[PanelID
] do
415 if LiftType
<> t
then
417 g_Map_SetLift(PanelID
, t
);
420 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);}
426 if gLiftMap
= nil then Exit
;
429 for a
:= 0 to High(gLiftMap
) do
431 for b
:= 0 to High(gLiftMap
[a
]) do
432 if gLiftMap
[a
, b
] = DWORD(PanelID
) then
438 if c
<> -1 then Break
;
443 for b := 0 to High(gLiftMap[c]) do
444 if gLifts[gLiftMap[c, b]].LiftType <> t then
446 with gLifts[PanelID] do
447 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
451 for b
:= 0 to High(gLiftMap
[c
]) do
452 with gLifts
[gLiftMap
[c
, b
]] do
453 if LiftType
<> t
then
455 g_Map_SetLift(gLiftMap
[c
, b
], t
);
462 function tr_SpawnShot(ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
470 TextureID
:= DWORD(-1);
471 snd
:= 'SOUND_WEAPON_FIREROCKET';
476 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
477 snd
:= 'SOUND_WEAPON_FIREPISTOL';
481 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
483 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
489 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
490 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
491 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
495 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
497 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
501 TRIGGER_SHOT_SHOTGUN
:
503 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
504 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
508 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
510 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
516 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
517 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
521 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
522 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
524 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
530 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
531 snd
:= 'SOUND_WEAPON_FIREBALL';
536 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
537 snd
:= 'SOUND_WEAPON_FIREPLASMA';
542 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
543 snd
:= 'SOUND_WEAPON_FIREPLASMA';
548 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
549 snd
:= 'SOUND_WEAPON_FIREBALL';
554 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
555 snd
:= 'SOUND_WEAPON_FIREBALL';
560 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
561 snd
:= 'SOUND_WEAPON_FIREBALL';
566 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
567 snd
:= 'SOUND_WEAPON_FIREREV';
572 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
573 snd
:= 'SOUND_WEAPON_FIREROCKET';
578 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
579 snd
:= 'SOUND_WEAPON_FIREBFG';
584 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
586 Anim
:= TAnimation
.Create(TextureID
, False, 6);
587 Anim
.Blending
:= False;
588 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
592 g_Weapon_Explode(wx
, wy
, 60, 0);
593 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
596 TRIGGER_SHOT_BFGEXPL
:
598 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
600 Anim
:= TAnimation
.Create(TextureID
, False, 6);
601 Anim
.Blending
:= False;
602 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
606 g_Weapon_BFG9000(wx
, wy
, 0);
607 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
613 if g_Game_IsNet
and g_Game_IsServer
then
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
);
622 MH_SEND_CreateShot(LastShotID
);
624 MH_SEND_Sound(wx
, wy
, snd
);
629 g_Sound_PlayExAt(snd
, wx
, wy
);
632 Result
:= LastShotID
;
635 procedure MakeShot(var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
638 if (trigData
.trigShotAmmo
= 0) or
639 ((trigData
.trigShotAmmo
> 0) and (ShotAmmoCount
> 0)) then
641 if (trigShotPanelID
<> -1) and (ShotPanelTime
= 0) then
643 g_Map_SwitchTexture(ShotPanelType
, trigShotPanelID
);
644 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
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
);
658 if (trigData
.trigShotIntReload
> 0) and (ShotReloadTime
= 0) then
659 ShotReloadTime
:= trigData
.trigShotIntReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
662 procedure tr_MakeEffect(X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
667 if T
= TRIGGER_EFFECT_PARTICLE
then
669 TRIGGER_EFFECT_SLIQUID
:
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)
678 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
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);
691 if T
= TRIGGER_EFFECT_ANIMATION
then
693 EFFECT_TELEPORT
: begin
694 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
696 Anim
:= TAnimation
.Create(FramesID
, False, 3);
698 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
699 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
702 if Send
and g_Game_IsServer
and g_Game_IsNet
then
703 MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
705 EFFECT_RESPAWN
: begin
706 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
708 Anim
:= TAnimation
.Create(FramesID
, False, 4);
710 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
711 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
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
);
718 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
720 Anim
:= TAnimation
.Create(FramesID
, False, 4);
722 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
723 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
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
);
732 function tr_Teleport(ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
738 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
739 case g_GetUIDType(ActivateUID
) of
742 p
:= g_Player_Get(ActivateUID
);
748 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2),
749 TY
-p
.Obj
.Rect
.Height
,
755 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then
761 m
:= g_Monsters_ByUID(ActivateUID
);
767 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2),
768 TY
-m
.Obj
.Rect
.Height
,
774 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then
780 function tr_Push(ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
786 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
787 case g_GetUIDType(ActivateUID
) of
790 p
:= g_Player_Get(ActivateUID
);
807 m
:= g_Monsters_ByUID(ActivateUID
);
824 function tr_Message(MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
831 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
832 msg
:= b_Text_Format(MText
);
836 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
838 if g_Game_IsWatchedPlayer(ActivateUID
) then
841 g_Console_Add(msg
, True)
842 else if MKind
= 1 then
843 g_Game_Message(msg
, MTime
);
847 p
:= g_Player_Get(ActivateUID
);
848 if g_Game_IsNet
and (p
.FClientID
>= 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
);
857 1: // activator's team
859 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
861 p
:= g_Player_Get(ActivateUID
);
862 if g_Game_IsWatchedTeam(p
.Team
) then
864 g_Console_Add(msg
, True)
865 else if MKind
= 1 then
866 g_Game_Message(msg
, MTime
);
870 for i
:= Low(gPlayers
) to High(gPlayers
) do
871 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 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
);
880 2: // activator's enemy team
882 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
884 p
:= g_Player_Get(ActivateUID
);
885 if g_Game_IsWatchedTeam(p
.Team
) then
887 g_Console_Add(msg
, True)
888 else if MKind
= 1 then
889 g_Game_Message(msg
, MTime
);
893 for i
:= Low(gPlayers
) to High(gPlayers
) do
894 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 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
);
905 if g_Game_IsWatchedTeam(TEAM_RED
) then
907 g_Console_Add(msg
, True)
908 else if MKind
= 1 then
909 g_Game_Message(msg
, MTime
);
913 for i
:= Low(gPlayers
) to High(gPlayers
) do
914 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 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
);
924 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
926 g_Console_Add(msg
, True)
927 else if MKind
= 1 then
928 g_Game_Message(msg
, MTime
);
932 for i
:= Low(gPlayers
) to High(gPlayers
) do
933 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 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
);
944 g_Console_Add(msg
, True)
945 else if MKind
= 1 then
946 g_Game_Message(msg
, MTime
);
951 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
952 else if MKind
= 1 then
953 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
959 function tr_ShotAimCheck(var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
964 if TriggerType
<> TRIGGER_SHOT
then
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));
976 function ActivateTrigger(var Trigger
: TTrigger
; actType
: Byte): Boolean;
981 idx
, k
, wx
, wy
, xd
, yd
: Integer;
992 function monsShotTarget (mon
: TMonster
): Boolean;
994 result
:= false; // don't stop
995 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
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
1004 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1006 result
:= false; // don't stop
1007 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
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
1016 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1018 result
:= false; // don't stop
1019 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
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
1030 if g_Game_IsClient
then
1033 if not Trigger
.Enabled
then
1035 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1037 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
1042 coolDown
:= (actType
<> 0);
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
);
1061 Result
:= tr_Teleport(ActivateUID
,
1062 trigData
.trigTargetPoint
.X
, trigData
.trigTargetPoint
.Y
,
1063 trigData
.trigTlpDir
, trigData
.trigsilent_teleport
,
1064 trigData
.trigd2d_teleport
);
1070 Result
:= tr_OpenDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1076 Result
:= tr_CloseDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1080 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1082 if trigPanelID
<> -1 then
1084 if gWalls
[trigPanelID
].Enabled
then
1086 Result
:= tr_OpenDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1088 if TriggerType
= TRIGGER_DOOR5
then
1092 Result
:= tr_CloseDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1099 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1101 tr_CloseTrap(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1103 if TriggerType
= TRIGGER_TRAP
then
1117 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1119 PressCount
:= PressCount
+ 1;
1121 if PressTime
= -1 then
1122 PressTime
:= trigData
.trigWait
;
1132 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1136 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1138 g_Player_Get(ActivateUID
).GetSecret();
1139 Inc(gCoopSecretsFound
);
1140 if g_Game_IsNet
then MH_SEND_GameStats();
1146 Result
:= tr_SetLift(trigPanelID
, 0, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1149 if (not trigData
.trigNoSound
) and Result
then begin
1150 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1152 Y
+ (Height
div 2));
1153 if g_Game_IsServer
and g_Game_IsNet
then
1154 MH_SEND_Sound(X
+ (Width
div 2),
1156 'SOUND_GAME_SWITCH0');
1162 Result
:= tr_SetLift(trigPanelID
, 1, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1165 if (not trigData
.trigNoSound
) and Result
then begin
1166 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1168 Y
+ (Height
div 2));
1169 if g_Game_IsServer
and g_Game_IsNet
then
1170 MH_SEND_Sound(X
+ (Width
div 2),
1172 'SOUND_GAME_SWITCH0');
1178 Result
:= tr_SetLift(trigPanelID
, 3, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1184 if (not trigData
.trigNoSound
) and Result
then begin
1185 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1187 Y
+ (Height
div 2));
1188 if g_Game_IsServer
and g_Game_IsNet
then
1189 MH_SEND_Sound(X
+ (Width
div 2),
1191 'SOUND_GAME_SWITCH0');
1198 if ByteBool(trigData
.trigActivateOnce
) then
1201 TriggerType
:= TRIGGER_NONE
;
1209 animonce
:= trigData
.trigAnimOnce
;
1215 if Sound
<> nil then
1217 if trigData
.trigSoundSwitch
and Sound
.IsPlaying() then
1218 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1220 SoundPlayCount
:= 0;
1223 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1224 if (trigData
.trigPlayCount
> 0) or (not Sound
.IsPlaying()) then
1226 if trigData
.trigPlayCount
> 0 then
1227 SoundPlayCount
:= trigData
.trigPlayCount
1228 else // 0 - èãðàåì áåñêîíå÷íî
1229 SoundPlayCount
:= 1;
1232 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1236 TRIGGER_SPAWNMONSTER
:
1237 if (trigData
.trigMonType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1240 if (trigData
.trigMonDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1242 AutoSpawn
:= not AutoSpawn
;
1244 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
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
1252 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigMonDelay
> 0) then
1253 SpawnCooldown
:= trigData
.trigMonDelay
;
1254 if (trigData
.trigMonMax
> 0) and (SpawnedCount
>= trigData
.trigMonMax
) then
1257 mon
:= g_Monsters_Create(trigData
.trigMonType
,
1258 trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
,
1259 TDirection(trigData
.trigMonDir
), True);
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
1275 if trigData
.trigMonType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1277 if g_Game_IsNet
then
1279 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1280 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1283 if trigData
.trigMonMax
> 0 then
1285 mon
.SpawnTrigger
:= ID
;
1289 case trigData
.trigMonEffect
of
1290 EFFECT_TELEPORT
: begin
1291 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
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
);
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,
1304 EFFECT_RESPAWN
: begin
1305 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
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
);
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,
1319 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
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
);
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,
1334 if g_Game_IsNet
then
1336 MH_SEND_GameStats();
1337 MH_SEND_CoopStats();
1344 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1345 if actType
= ACTIVATE_CUSTOM
then
1350 if (trigData
.trigItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1353 if (trigData
.trigItemDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1355 AutoSpawn
:= not AutoSpawn
;
1357 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
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
1367 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigItemDelay
> 0) then
1368 SpawnCooldown
:= trigData
.trigItemDelay
;
1369 if (trigData
.trigItemMax
> 0) and (SpawnedCount
>= trigData
.trigItemMax
) then
1372 iid
:= g_Items_Create(trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
,
1373 trigData
.trigItemType
, trigData
.trigItemFalls
, False, True);
1377 if trigData
.trigItemMax
> 0 then
1379 it
:= g_Items_ByIdx(iid
);
1380 it
.SpawnTrigger
:= ID
;
1384 case trigData
.trigItemEffect
of
1385 EFFECT_TELEPORT
: begin
1386 it
:= g_Items_ByIdx(iid
);
1387 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
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
);
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,
1400 EFFECT_RESPAWN
: begin
1401 it
:= g_Items_ByIdx(iid
);
1402 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
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
);
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,
1416 it
:= g_Items_ByIdx(iid
);
1417 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
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
);
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,
1432 if g_Game_IsNet
then
1433 MH_SEND_ItemSpawn(True, iid
);
1440 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1441 if actType
= ACTIVATE_CUSTOM
then
1447 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1448 if (Trigger
.trigData
.trigMusicName
<> '') then
1450 gMusic
.SetByName(Trigger
.trigData
.trigMusicName
);
1451 gMusic
.SpecPause
:= True;
1455 if Trigger
.trigData
.trigMusicAction
= 1 then
1457 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1458 gMusic
.SpecPause
:= False
1459 else // Èãðàëà => ñíà÷àëà
1460 gMusic
.SetPosition(0);
1465 gMusic
.SpecPause
:= True;
1473 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
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
);
1489 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1490 if (trigData
.trigScoreAction
in [0..1]) and (trigData
.trigScoreCount
> 0) then
1492 // Ñâîåé èëè ÷óæîé êîìàíäå
1493 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
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
1499 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1501 if trigData
.trigScoreCon
then
1502 if trigData
.trigScoreTeam
= 0 then
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');
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');
1514 if trigData
.trigScoreMsg
then
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
);
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
1524 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1526 if trigData
.trigScoreCon
then
1527 if trigData
.trigScoreTeam
= 0 then
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');
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');
1539 if trigData
.trigScoreMsg
then
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
);
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
1549 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1551 if trigData
.trigScoreCon
then
1552 if trigData
.trigScoreTeam
= 0 then
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');
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');
1564 if trigData
.trigScoreMsg
then
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
);
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
1574 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1576 if trigData
.trigScoreCon
then
1577 if trigData
.trigScoreTeam
= 0 then
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');
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');
1589 if trigData
.trigScoreMsg
then
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
);
1596 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1598 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1599 if trigData
.trigScoreTeam
in [2..3] then
1601 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 2) then
1603 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1605 if trigData
.trigScoreCon
then
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');
1612 if trigData
.trigScoreMsg
then
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
);
1619 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 2) then
1621 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1623 if trigData
.trigScoreCon
then
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');
1630 if trigData
.trigScoreMsg
then
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
);
1637 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 3) then
1639 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1641 if trigData
.trigScoreCon
then
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');
1648 if trigData
.trigScoreMsg
then
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
);
1655 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 3) then
1657 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1659 if trigData
.trigScoreCon
then
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');
1666 if trigData
.trigScoreMsg
then
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
);
1677 if (trigData
.trigScoreAction
= 2) and (gGameSettings
.GoalLimit
> 0) then
1679 // Ñâîåé èëè ÷óæîé êîìàíäû
1680 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
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
1687 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1689 if trigData
.trigScoreCon
then
1690 if trigData
.trigScoreTeam
= 0 then
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');
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');
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
1708 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1710 if trigData
.trigScoreCon
then
1711 if trigData
.trigScoreTeam
= 0 then
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');
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');
1726 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1727 if trigData
.trigScoreTeam
in [2..3] then
1729 if trigData
.trigScoreTeam
= 2 then // Red Wins
1730 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1732 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1735 if trigData
.trigScoreTeam
= 3 then // Blue Wins
1736 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1738 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1744 if (trigData
.trigScoreAction
= 3) and (gGameSettings
.GoalLimit
> 0) then
1746 // Ñâîåé èëè ÷óæîé êîìàíäû
1747 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
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
1754 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1756 if trigData
.trigScoreCon
then
1757 if trigData
.trigScoreTeam
= 0 then
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');
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');
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
1775 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1777 if trigData
.trigScoreCon
then
1778 if trigData
.trigScoreTeam
= 0 then
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');
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');
1793 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1794 if trigData
.trigScoreTeam
in [2..3] then
1796 if trigData
.trigScoreTeam
= 3 then // Red Wins
1797 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1799 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1802 if trigData
.trigScoreTeam
= 2 then // Blue Wins
1803 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1805 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1810 if Result
then begin
1815 if g_Game_IsServer
and g_Game_IsNet
then
1822 Result
:= tr_Message(trigData
.trigMessageKind
, trigData
.trigMessageText
,
1823 trigData
.trigMessageSendTo
, trigData
.trigMessageTime
,
1828 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1831 UIDType
:= g_GetUIDType(ActivateUID
);
1832 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1838 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1839 for idx
:= 0 to High(Activators
) do
1840 if Activators
[idx
].UID
= ActivateUID
then
1846 begin // Âèäèì åãî âïåðâûå
1848 SetLength(Activators
, Length(Activators
) + 1);
1849 k
:= High(Activators
);
1850 Activators
[k
].UID
:= ActivateUID
;
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;
1866 p
:= g_Player_Get(ActivateUID
);
1870 // Íàíîñèì óðîí èãðîêó
1871 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1872 p
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1875 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1876 if p
.Heal(trigData
.trigHealValue
, not trigData
.trigHealMax
) and (not trigData
.trigHealSilent
) then
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');
1886 m
:= g_Monsters_ByUID(ActivateUID
);
1890 // Íàíîñèì óðîí ìîíñòðó
1891 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1892 m
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1895 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1896 if m
.Heal(trigData
.trigHealValue
) and (not trigData
.trigHealSilent
) then
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');
1904 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1905 if TriggerType
= TRIGGER_DAMAGE
then
1906 idx
:= trigData
.trigDamageInterval
1908 idx
:= trigData
.trigHealInterval
;
1911 Activators
[k
].TimeOut
:= idx
1913 Activators
[k
].TimeOut
:= 65535;
1921 if ShotSightTime
> 0 then
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);
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
1945 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1946 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1947 TargetUID
:= gPlayers
[idx
].UID
;
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
1958 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1959 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1960 TargetUID
:= gPlayers
[idx
].UID
;
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
1971 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1972 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1973 TargetUID
:= gPlayers
[idx
].UID
;
1977 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
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
1987 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1988 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1989 TargetUID
:= gPlayers
[idx
].UID
;
1994 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
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
2001 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2002 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2003 TargetUID
:= gPlayers
[idx
].UID
;
2006 if TargetUID
= 0 then
2008 //TODO: accelerate this!
2009 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2014 if (trigData
.trigShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2015 (trigData
.trigShotType
<> TRIGGER_SHOT_REV
) then
2016 TargetUID
:= ActivateUID
;
2020 if (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2021 ((trigData
.trigShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
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
)
2030 ShotSightTime
:= trigData
.trigShotIntSight
;
2031 ShotSightTargetN
:= TargetUID
;
2032 if trigData
.trigShotType
= TRIGGER_SHOT_BFG
then
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');
2044 idx
:= trigData
.trigFXCount
;
2048 case trigData
.trigFXPos
of
2049 TRIGGER_EFFECT_POS_CENTER
:
2051 wx
:= X
+ Width
div 2;
2052 wy
:= Y
+ Height
div 2;
2054 TRIGGER_EFFECT_POS_AREA
:
2056 wx
:= X
+ Random(Width
);
2057 wy
:= Y
+ Random(Height
);
2060 wx
:= X
+ Width
div 2;
2061 wy
:= Y
+ Height
div 2;
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);
2075 TimeOut
:= trigData
.trigFXWait
;
2080 if Result
and (Trigger
.TexturePanel
<> -1) then
2081 g_Map_SwitchTexture(Trigger
.TexturePanelType
, Trigger
.TexturePanel
, IfThen(animonce
, 2, 1));
2084 function g_Triggers_Create(Trigger
: TTrigger
): DWORD
;
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
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
2114 Inc(gTriggerClientID
);
2115 ClientID
:= gTriggerClientID
;
2121 PlayerCollide
:= False;
2125 SoundPlayCount
:= 0;
2132 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2133 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and
2134 (Trigger
.trigData
.trigSoundName
<> '') then
2136 // Åùå íåò òàêîãî çâóêà:
2137 if not g_Sound_Exists(Trigger
.trigData
.trigSoundName
) then
2139 fn
:= g_ExtractWadName(Trigger
.trigData
.trigSoundName
);
2142 begin // Çâóê â ôàéëå ñ êàðòîé
2143 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2144 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigSoundName
);
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
]));
2153 // Ñîçäàåì îáúåêò çâóêà:
2154 with gTriggers
[find_id
] do
2156 Sound
:= TPlayableSound
.Create();
2157 if not Sound
.SetByName(Trigger
.trigData
.trigSoundName
) then
2165 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2166 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and
2167 (Trigger
.trigData
.trigMusicName
<> '') then
2169 // Åùå íåò òàêîé ìóçûêè:
2170 if not g_Sound_Exists(Trigger
.trigData
.trigMusicName
) then
2172 fn
:= g_ExtractWadName(Trigger
.trigData
.trigMusicName
);
2175 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2176 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2177 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigMusicName
);
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
]));
2187 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2188 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2189 with gTriggers
[find_id
] do
2193 ShotSightTimeout
:= 0;
2194 ShotSightTarget
:= 0;
2195 ShotSightTargetN
:= 0;
2196 ShotAmmoCount
:= Trigger
.trigData
.trigShotAmmo
;
2197 ShotReloadTime
:= 0;
2204 // sorry; grid doesn't support recursive queries, so we have to do this
2206 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2209 tgMonsList
: TSimpleMonsterList
= nil;
2211 procedure g_Triggers_Update();
2214 Affected
: array of Integer;
2216 function monsNear (mon
: TMonster
): Boolean;
2218 result
:= false; // don't stop
2220 gTriggers[a].ActivateUID := mon.UID;
2221 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2223 tgMonsList
.append(mon
);
2229 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2231 if gTriggers
= nil then
2233 SetLength(Affected
, 0);
2235 for a
:= 0 to High(gTriggers
) do
2236 with gTriggers
[a
] do
2238 if TriggerType
<> TRIGGER_NONE
then
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
2250 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2251 if Activators
[b
].TimeOut
> 0 then
2252 Dec(Activators
[b
].TimeOut
)
2255 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2256 if (trigData
.trigDamageInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then
2257 Activators
[b
].TimeOut
:= 0;
2260 // Îáðàáàòûâàåì ñïàâíåðû:
2261 if Enabled
and AutoSpawn
then
2262 if SpawnCooldown
= 0 then
2264 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà:
2265 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (trigData
.trigMonDelay
> 0) then
2268 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2270 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò:
2271 if (TriggerType
= TRIGGER_SPAWNITEM
) and (trigData
.trigItemDelay
> 0) then
2274 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2276 end else // Óìåíüøàåì âðåìÿ îæèäàíèÿ:
2279 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü":
2280 if TriggerType
= TRIGGER_SHOT
then
2282 if ShotPanelTime
> 0 then
2285 if ShotPanelTime
= 0 then
2286 g_Map_SwitchTexture(ShotPanelType
, trigShotPanelID
);
2288 if ShotSightTime
> 0 then
2291 if ShotSightTime
= 0 then
2292 ShotSightTarget
:= ShotSightTargetN
;
2294 if ShotSightTimeout
> 0 then
2296 Dec(ShotSightTimeout
);
2297 if ShotSightTimeout
= 0 then
2298 ShotSightTarget
:= 0;
2300 if ShotReloadTime
> 0 then
2302 Dec(ShotReloadTime
);
2303 if ShotReloadTime
= 0 then
2304 ShotAmmoCount
:= trigData
.trigShotAmmo
;
2308 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì:
2309 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2310 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
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)
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
]);
2322 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü:
2323 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (trigPanelID
<> -1) then
2325 tr_OpenDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
2329 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü:
2330 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (trigPanelID
<> -1) then
2333 if gWalls
[trigPanelID
].Enabled
then
2335 else // Ïîêà îòêðûòà - çàêðûâàåì
2336 if tr_CloseDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
) then
2340 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2341 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2342 (PressTime
= 0) and (PressCount
>= trigData
.trigCount
) then
2344 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2346 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2347 if trigData
.trigCount
> 0 then
2348 PressCount
:= PressCount
- trigData
.trigCount
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
2360 SetLength(Affected
, Length(Affected
) + 1);
2361 Affected
[High(Affected
)] := b
;
2364 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2365 if (TriggerType
= TRIGGER_PRESS
) and trigData
.trigExtRandom
then
2367 if (Length(Affected
) > 0) then
2369 b
:= Affected
[Random(Length(Affected
))];
2370 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2371 ActivateTrigger(gTriggers
[b
], 0);
2374 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2375 for i
:= 0 to High(Affected
) do
2381 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2382 ActivateTrigger(gTriggers
[b
], 0);
2386 gTriggers
[b
].Enabled
:= True;
2390 gTriggers
[b
].Enabled
:= False;
2391 gTriggers
[b
].TimeOut
:= 0;
2392 if gTriggers
[b
].AutoSpawn
then
2394 gTriggers
[b
].AutoSpawn
:= False;
2395 gTriggers
[b
].SpawnCooldown
:= 0;
2400 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2401 if not gTriggers
[b
].Enabled
then
2403 gTriggers
[b
].TimeOut
:= 0;
2404 if gTriggers
[b
].AutoSpawn
then
2406 gTriggers
[b
].AutoSpawn
:= False;
2407 gTriggers
[b
].SpawnCooldown
:= 0;
2413 SetLength(Affected
, 0);
2416 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2419 TimeOut
:= TimeOut
- 1;
2420 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2423 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2428 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2430 if gPlayers
<> nil then
2431 for b
:= 0 to High(gPlayers
) do
2432 if gPlayers
[b
] <> nil then
2434 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2435 if Live
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2436 Collide(X
, Y
, Width
, Height
) then
2438 gTriggers
[a
].ActivateUID
:= UID
;
2440 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2442 { Don't activate sound/music again if player is here }
2444 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
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
2453 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2454 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2455 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2456 gTriggers
[a
].ActivateUID
:= 0;
2457 ActivateTrigger(gTriggers
[a
], 0);
2461 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2462 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2464 //g_Mons_ForEach(monsNear);
2467 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2468 for mon
in tgMonsList
do
2470 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2471 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2473 tgMonsList
.reset(); // just in case
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
2481 gTriggers
[a
].ActivateUID
:= 0;
2482 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2486 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2490 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2492 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2493 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2496 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2497 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2505 if gTriggers
= nil then Exit
;
2507 case g_GetUIDType(UID
) of
2511 p
:= g_Player_Get(UID
);
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
2530 gTriggers
[a
].ActivateUID
:= UID
;
2531 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2533 SetLength(Result
, Length(Result
)+1);
2534 Result
[High(Result
)] := a
;
2539 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2545 if gTriggers
= nil then Exit
;
2547 case g_GetUIDType(UID
) of
2551 p
:= g_Player_Get(UID
);
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
2568 gTriggers
[a
].ActivateUID
:= UID
;
2569 ActivateTrigger(gTriggers
[a
], ActivateType
);
2573 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2580 if gTriggers
= nil then
2583 case g_GetUIDType(UID
) of
2587 p
:= g_Player_Get(UID
);
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 // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2617 ActivateTrigger(gTriggers
[a
], ActivateType
);
2621 procedure g_Triggers_OpenAll();
2626 if gTriggers
= nil then Exit
;
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
2635 tr_OpenDoor(trigPanelID
, True, trigData
.trigd2d_doors
);
2636 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2640 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2643 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2645 if (gTriggers
<> nil) then
2646 if gTriggers
[ID
].SpawnedCount
> 0 then
2647 Dec(gTriggers
[ID
].SpawnedCount
);
2650 procedure g_Triggers_Free();
2654 for a
:= 0 to High(gTriggers
) do
2656 gTriggers
[a
].trigData
.Free();
2657 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
2659 if g_Sound_Exists(gTriggers
[a
].trigData
.trigSoundName
) then
2661 g_Sound_Delete(gTriggers
[a
].trigData
.trigSoundName
);
2663 gTriggers
[a
].Sound
.Free();
2665 if (gTriggers
[a
].Activators
<> nil) then
2667 SetLength(gTriggers
[a
].Activators
, 0);
2673 SetLength(gMonstersSpawned
, 0);
2676 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2678 count
, act_count
, i
, j
: Integer;
2684 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ:
2686 if gTriggers
<> nil then
2687 for i
:= 0 to High(gTriggers
) do
2690 Mem
:= TBinMemoryWriter
.Create((count
+1) * 200);
2692 // Êîëè÷åñòâî òðèããåðîâ:
2693 Mem
.WriteInt(count
);
2698 for i
:= 0 to High(gTriggers
) do
2700 // Ñèãíàòóðà òðèããåðà:
2701 dw
:= TRIGGER_SIGNATURE
; // 'TRGR'
2704 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2705 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2707 //p := @gTriggers[i].Data;
2708 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2709 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2710 Mem
.WriteInt(gTriggers
[i
].X
);
2711 Mem
.WriteInt(gTriggers
[i
].Y
);
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
);
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
2735 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2737 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2739 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2740 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2741 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2742 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2743 // Çàäåðæêà àêòèâàöèè:
2744 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2746 Mem
.WriteInt(gTriggers
[i
].PressCount
);
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()
2760 Mem
.WriteBoolean(b
);
2763 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2764 dw
:= gTriggers
[i
].Sound
.GetPosition();
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
);
2777 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
2779 count
, act_count
, i
, j
, a
: Integer;
2791 // Êîëè÷åñòâî òðèããåðîâ:
2797 for a
:= 0 to count
-1 do
2799 // Ñèãíàòóðà òðèããåðà:
2801 if dw
<> TRIGGER_SIGNATURE
then // 'TRGR'
2803 raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2806 Mem
.ReadByte(Trig
.TriggerType
);
2807 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2810 Mem.ReadMemory(p, dw);
2811 if dw <> SizeOf(TTriggerData) then
2813 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2815 Trig.Data := TTriggerData(p^);
2818 i
:= g_Triggers_Create(Trig
);
2819 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2820 Mem
.ReadInt(gTriggers
[i
].X
);
2821 Mem
.ReadInt(gTriggers
[i
].Y
);
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
);
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
2843 SetLength(gTriggers
[i
].Activators
, act_count
);
2844 for j
:= 0 to act_count
-1 do
2847 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
2849 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2852 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2853 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
2854 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2855 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
2856 // Çàäåðæêà àêòèâàöèè:
2857 Mem
.ReadInt(gTriggers
[i
].PressTime
);
2859 Mem
.ReadInt(gTriggers
[i
].PressCount
);
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 // Ïðîèãðûâàåòñÿ ëè çâóê?
2872 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2875 Mem
.ReadSingle(vol
);
2876 // Ñòåðåî ñìåùåíèå çâóêà:
2877 Mem
.ReadSingle(pan
);
2878 // Çàïóñêàåì çâóê, åñëè åñòü:
2879 if gTriggers
[i
].Sound
<> nil then
2881 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
2882 gTriggers
[i
].Sound
.Pause(True);
2883 gTriggers
[i
].Sound
.SetPosition(dw
);