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;
66 function g_Triggers_Create(Trigger
: TTrigger
): DWORD
;
67 procedure g_Triggers_Update();
68 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
69 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
70 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
71 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
72 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
73 procedure g_Triggers_OpenAll();
74 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
75 procedure g_Triggers_Free();
76 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
77 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
79 function tr_Message(MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
81 function tr_CloseDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
82 function tr_OpenDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
83 procedure tr_CloseTrap(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean);
84 function tr_SetLift(PanelID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
86 function tr_Teleport(ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
87 function tr_Push(ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
89 procedure tr_MakeEffect(X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
90 function tr_SpawnShot(ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
93 gTriggerClientID
: Integer = 0;
94 gTriggers
: array of TTrigger
;
95 gSecretsCount
: Integer = 0;
96 gMonstersSpawned
: array of LongInt = nil;
101 g_player
, g_map
, Math
, g_gfx
, g_game
, g_textures
,
102 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
103 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
104 g_options
, g_net
, g_netmsg
, utils
;
107 TRIGGER_SIGNATURE
= $52475254; // 'TRGR'
110 function FindTrigger(): DWORD
;
114 if gTriggers
<> nil then
115 for i
:= 0 to High(gTriggers
) do
116 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then
122 if gTriggers
= nil then
124 SetLength(gTriggers
, 8);
129 Result
:= High(gTriggers
) + 1;
130 SetLength(gTriggers
, Length(gTriggers
) + 8);
134 function tr_CloseDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
140 if PanelID
= -1 then Exit
;
144 with gWalls
[PanelID
] do
146 if g_CollidePlayer(X
, Y
, Width
, Height
) or
147 g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
153 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
154 if g_Game_IsServer
and g_Game_IsNet
then
155 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
157 g_Map_EnableWall(PanelID
);
164 if gDoorMap
= nil then Exit
;
167 for a
:= 0 to High(gDoorMap
) do
169 for b
:= 0 to High(gDoorMap
[a
]) do
170 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
176 if c
<> -1 then Break
;
180 for b
:= 0 to High(gDoorMap
[c
]) do
181 with gWalls
[gDoorMap
[c
, b
]] do
183 if g_CollidePlayer(X
, Y
, Width
, Height
) or
184 g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
188 for b
:= 0 to High(gDoorMap
[c
]) do
189 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
191 with gWalls
[PanelID
] do
193 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
194 if g_Game_IsServer
and g_Game_IsNet
then
195 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
200 for b
:= 0 to High(gDoorMap
[c
]) do
201 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
203 g_Map_EnableWall(gDoorMap
[c
, b
]);
209 procedure tr_CloseTrap(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean);
212 wx
, wy
, wh
, ww
: Integer;
214 function monsDamage (mon
: TMonster
): Boolean;
216 result
:= false; // don't stop
217 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
221 if PanelID
= -1 then Exit
;
225 with gWalls
[PanelID
] do
227 if (not NoSound
) and (not Enabled
) then
229 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
230 if g_Game_IsServer
and g_Game_IsNet
then
231 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
235 wx
:= gWalls
[PanelID
].X
;
236 wy
:= gWalls
[PanelID
].Y
;
237 ww
:= gWalls
[PanelID
].Width
;
238 wh
:= gWalls
[PanelID
].Height
;
240 with gWalls
[PanelID
] do
242 if gPlayers
<> nil then
243 for a
:= 0 to High(gPlayers
) do
244 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and
245 gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
246 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
248 //g_Mons_ForEach(monsDamage);
249 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
251 if not Enabled
then g_Map_EnableWall(PanelID
);
256 if gDoorMap
= nil then Exit
;
259 for a
:= 0 to High(gDoorMap
) do
261 for b
:= 0 to High(gDoorMap
[a
]) do
263 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
270 if c
<> -1 then Break
;
276 for b
:= 0 to High(gDoorMap
[c
]) do
278 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
280 with gWalls
[PanelID
] do
282 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
283 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
290 for b
:= 0 to High(gDoorMap
[c
]) do
292 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
293 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
294 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
295 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
297 with gWalls
[gDoorMap
[c
, b
]] do
299 if gPlayers
<> nil then
300 for a
:= 0 to High(gPlayers
) do
301 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and
302 gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
303 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
305 //g_Mons_ForEach(monsDamage);
306 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
308 if gMonsters <> nil then
309 for a := 0 to High(gMonsters) do
310 if (gMonsters[a] <> nil) and gMonsters[a].Live and
311 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
312 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
315 if not Enabled
then g_Map_EnableWall(gDoorMap
[c
, b
]);
321 function tr_OpenDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
327 if PanelID
= -1 then Exit
;
331 with gWalls
[PanelID
] do
336 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
337 if g_Game_IsServer
and g_Game_IsNet
then
338 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
340 g_Map_DisableWall(PanelID
);
346 if gDoorMap
= nil then Exit
;
349 for a
:= 0 to High(gDoorMap
) do
351 for b
:= 0 to High(gDoorMap
[a
]) do
352 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
358 if c
<> -1 then Break
;
363 for b
:= 0 to High(gDoorMap
[c
]) do
364 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
366 with gWalls
[PanelID
] do
368 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
369 if g_Game_IsServer
and g_Game_IsNet
then
370 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
375 for b
:= 0 to High(gDoorMap
[c
]) do
376 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
378 g_Map_DisableWall(gDoorMap
[c
, b
]);
384 function tr_SetLift(PanelID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
391 if PanelID
= -1 then Exit
;
393 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or
394 (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
398 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
400 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or
401 (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
405 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
410 with gLifts
[PanelID
] do
411 if LiftType
<> t
then
413 g_Map_SetLift(PanelID
, t
);
416 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);}
422 if gLiftMap
= nil then Exit
;
425 for a
:= 0 to High(gLiftMap
) do
427 for b
:= 0 to High(gLiftMap
[a
]) do
428 if gLiftMap
[a
, b
] = DWORD(PanelID
) then
434 if c
<> -1 then Break
;
439 for b := 0 to High(gLiftMap[c]) do
440 if gLifts[gLiftMap[c, b]].LiftType <> t then
442 with gLifts[PanelID] do
443 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
447 for b
:= 0 to High(gLiftMap
[c
]) do
448 with gLifts
[gLiftMap
[c
, b
]] do
449 if LiftType
<> t
then
451 g_Map_SetLift(gLiftMap
[c
, b
], t
);
458 function tr_SpawnShot(ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
466 TextureID
:= DWORD(-1);
467 snd
:= 'SOUND_WEAPON_FIREROCKET';
472 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
473 snd
:= 'SOUND_WEAPON_FIREPISTOL';
477 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
479 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
485 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
486 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
487 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
491 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
493 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
497 TRIGGER_SHOT_SHOTGUN
:
499 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
500 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
504 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
506 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
512 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
513 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
517 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
518 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
520 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
526 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
527 snd
:= 'SOUND_WEAPON_FIREBALL';
532 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
533 snd
:= 'SOUND_WEAPON_FIREPLASMA';
538 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
539 snd
:= 'SOUND_WEAPON_FIREPLASMA';
544 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
545 snd
:= 'SOUND_WEAPON_FIREBALL';
550 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
551 snd
:= 'SOUND_WEAPON_FIREBALL';
556 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
557 snd
:= 'SOUND_WEAPON_FIREBALL';
562 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
563 snd
:= 'SOUND_WEAPON_FIREREV';
568 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
569 snd
:= 'SOUND_WEAPON_FIREROCKET';
574 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
575 snd
:= 'SOUND_WEAPON_FIREBFG';
580 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
582 Anim
:= TAnimation
.Create(TextureID
, False, 6);
583 Anim
.Blending
:= False;
584 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
588 g_Weapon_Explode(wx
, wy
, 60, 0);
589 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
592 TRIGGER_SHOT_BFGEXPL
:
594 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
596 Anim
:= TAnimation
.Create(TextureID
, False, 6);
597 Anim
.Blending
:= False;
598 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
602 g_Weapon_BFG9000(wx
, wy
, 0);
603 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
609 if g_Game_IsNet
and g_Game_IsServer
then
612 MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
613 TRIGGER_SHOT_BFGEXPL
:
614 MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
618 MH_SEND_CreateShot(LastShotID
);
620 MH_SEND_Sound(wx
, wy
, snd
);
625 g_Sound_PlayExAt(snd
, wx
, wy
);
628 Result
:= LastShotID
;
631 procedure MakeShot(var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
634 if (Data
.ShotAmmo
= 0) or
635 ((Data
.ShotAmmo
> 0) and (ShotAmmoCount
> 0)) then
637 if (Data
.ShotPanelID
<> -1) and (ShotPanelTime
= 0) then
639 g_Map_SwitchTexture(ShotPanelType
, Data
.ShotPanelID
);
640 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
643 if Data
.ShotIntSight
> 0 then
644 ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
646 if ShotAmmoCount
> 0 then Dec(ShotAmmoCount
);
648 dx
:= dx
+ Random(Data
.ShotAccuracy
) - Random(Data
.ShotAccuracy
);
649 dy
:= dy
+ Random(Data
.ShotAccuracy
) - Random(Data
.ShotAccuracy
);
651 tr_SpawnShot(Data
.ShotType
, wx
, wy
, dx
, dy
, Data
.ShotSound
, TargetUID
);
654 if (Data
.ShotIntReload
> 0) and (ShotReloadTime
= 0) then
655 ShotReloadTime
:= Data
.ShotIntReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
658 procedure tr_MakeEffect(X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
663 if T
= TRIGGER_EFFECT_PARTICLE
then
665 TRIGGER_EFFECT_SLIQUID
:
667 if (CR
= 255) and (CG
= 0) and (CB
= 0) then
668 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
669 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then
670 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
671 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then
672 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
674 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
676 TRIGGER_EFFECT_LLIQUID
:
677 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
678 TRIGGER_EFFECT_DLIQUID
:
679 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
680 TRIGGER_EFFECT_BLOOD
:
681 g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
682 TRIGGER_EFFECT_SPARK
:
683 g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
684 TRIGGER_EFFECT_BUBBLE
:
685 g_GFX_Bubbles(X
, Y
, 1, 0, 0);
687 if T
= TRIGGER_EFFECT_ANIMATION
then
689 EFFECT_TELEPORT
: begin
690 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
692 Anim
:= TAnimation
.Create(FramesID
, False, 3);
694 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
695 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
698 if Send
and g_Game_IsServer
and g_Game_IsNet
then
699 MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
701 EFFECT_RESPAWN
: begin
702 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
704 Anim
:= TAnimation
.Create(FramesID
, False, 4);
706 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
707 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
710 if Send
and g_Game_IsServer
and g_Game_IsNet
then
711 MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
714 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
716 Anim
:= TAnimation
.Create(FramesID
, False, 4);
718 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
719 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
722 if Send
and g_Game_IsServer
and g_Game_IsNet
then
723 MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
728 function tr_Teleport(ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
734 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
735 case g_GetUIDType(ActivateUID
) of
738 p
:= g_Player_Get(ActivateUID
);
744 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2),
745 TY
-p
.Obj
.Rect
.Height
,
751 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then
757 m
:= g_Monsters_ByUID(ActivateUID
);
763 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2),
764 TY
-m
.Obj
.Rect
.Height
,
770 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then
776 function tr_Push(ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
782 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
783 case g_GetUIDType(ActivateUID
) of
786 p
:= g_Player_Get(ActivateUID
);
803 m
:= g_Monsters_ByUID(ActivateUID
);
820 function tr_Message(MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
827 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
828 msg
:= b_Text_Format(MText
);
832 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
834 if g_Game_IsWatchedPlayer(ActivateUID
) then
837 g_Console_Add(msg
, True)
838 else if MKind
= 1 then
839 g_Game_Message(msg
, MTime
);
843 p
:= g_Player_Get(ActivateUID
);
844 if g_Game_IsNet
and (p
.FClientID
>= 0) then
846 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
847 else if MKind
= 1 then
848 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
853 1: // activator's team
855 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
857 p
:= g_Player_Get(ActivateUID
);
858 if g_Game_IsWatchedTeam(p
.Team
) then
860 g_Console_Add(msg
, True)
861 else if MKind
= 1 then
862 g_Game_Message(msg
, MTime
);
866 for i
:= Low(gPlayers
) to High(gPlayers
) do
867 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
869 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
870 else if MKind
= 1 then
871 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
876 2: // activator's enemy team
878 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
880 p
:= g_Player_Get(ActivateUID
);
881 if g_Game_IsWatchedTeam(p
.Team
) then
883 g_Console_Add(msg
, True)
884 else if MKind
= 1 then
885 g_Game_Message(msg
, MTime
);
889 for i
:= Low(gPlayers
) to High(gPlayers
) do
890 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
892 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
893 else if MKind
= 1 then
894 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
901 if g_Game_IsWatchedTeam(TEAM_RED
) then
903 g_Console_Add(msg
, True)
904 else if MKind
= 1 then
905 g_Game_Message(msg
, MTime
);
909 for i
:= Low(gPlayers
) to High(gPlayers
) do
910 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
912 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
913 else if MKind
= 1 then
914 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
920 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
922 g_Console_Add(msg
, True)
923 else if MKind
= 1 then
924 g_Game_Message(msg
, MTime
);
928 for i
:= Low(gPlayers
) to High(gPlayers
) do
929 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
931 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
932 else if MKind
= 1 then
933 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
940 g_Console_Add(msg
, True)
941 else if MKind
= 1 then
942 g_Game_Message(msg
, MTime
);
947 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
948 else if MKind
= 1 then
949 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
955 function tr_ShotAimCheck(var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
960 if TriggerType
<> TRIGGER_SHOT
then
962 Result
:= (Data
.ShotAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
963 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
964 if Result
and (Data
.ShotAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
965 Result
:= g_TraceVector(Data
.ShotPos
.X
,
967 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
968 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
972 function ActivateTrigger(var Trigger
: TTrigger
; actType
: Byte): Boolean;
977 idx
, k
, wx
, wy
, xd
, yd
: Integer;
988 function monsShotTarget (mon
: TMonster
): Boolean;
990 result
:= false; // don't stop
991 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
993 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
994 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
995 TargetUID
:= mon
.UID
;
996 result
:= true; // stop
1000 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1002 result
:= false; // don't stop
1003 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1005 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1006 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1007 TargetUID
:= mon
.UID
;
1008 result
:= true; // stop
1012 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1014 result
:= false; // don't stop
1015 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1017 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1018 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1019 TargetUID
:= mon
.UID
;
1020 result
:= true; // stop
1026 if g_Game_IsClient
then
1029 if not Trigger
.Enabled
then
1031 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1033 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
1038 coolDown
:= (actType
<> 0);
1045 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1046 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1047 gExitByTrigger
:= True;
1048 g_Game_ExitLevel(Data
.MapName
);
1057 Result
:= tr_Teleport(ActivateUID
,
1058 Data
.TargetPoint
.X
, Data
.TargetPoint
.Y
,
1059 Data
.TlpDir
, Data
.silent_teleport
,
1066 Result
:= tr_OpenDoor(Data
.PanelID
, Data
.NoSound
, Data
.d2d_doors
);
1072 Result
:= tr_CloseDoor(Data
.PanelID
, Data
.NoSound
, Data
.d2d_doors
);
1076 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1078 if Data
.PanelID
<> -1 then
1080 if gWalls
[Data
.PanelID
].Enabled
then
1082 Result
:= tr_OpenDoor(Data
.PanelID
, Data
.NoSound
, Data
.d2d_doors
);
1084 if TriggerType
= TRIGGER_DOOR5
then
1088 Result
:= tr_CloseDoor(Data
.PanelID
, Data
.NoSound
, Data
.d2d_doors
);
1095 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1097 tr_CloseTrap(Data
.PanelID
, Data
.NoSound
, Data
.d2d_doors
);
1099 if TriggerType
= TRIGGER_TRAP
then
1113 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1115 PressCount
:= PressCount
+ 1;
1117 if PressTime
= -1 then
1118 PressTime
:= Data
.Wait
;
1128 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1132 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1134 g_Player_Get(ActivateUID
).GetSecret();
1135 Inc(gCoopSecretsFound
);
1136 if g_Game_IsNet
then MH_SEND_GameStats();
1142 Result
:= tr_SetLift(Data
.PanelID
, 0, Data
.NoSound
, Data
.d2d_doors
);
1145 if (not Data
.NoSound
) and Result
then begin
1146 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1148 Y
+ (Height
div 2));
1149 if g_Game_IsServer
and g_Game_IsNet
then
1150 MH_SEND_Sound(X
+ (Width
div 2),
1152 'SOUND_GAME_SWITCH0');
1158 Result
:= tr_SetLift(Data
.PanelID
, 1, Data
.NoSound
, Data
.d2d_doors
);
1161 if (not Data
.NoSound
) and Result
then begin
1162 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1164 Y
+ (Height
div 2));
1165 if g_Game_IsServer
and g_Game_IsNet
then
1166 MH_SEND_Sound(X
+ (Width
div 2),
1168 'SOUND_GAME_SWITCH0');
1174 Result
:= tr_SetLift(Data
.PanelID
, 3, Data
.NoSound
, Data
.d2d_doors
);
1180 if (not Data
.NoSound
) 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');
1194 if ByteBool(Data
.ActivateOnce
) then
1197 TriggerType
:= TRIGGER_NONE
;
1205 animonce
:= Data
.AnimOnce
;
1211 if Sound
<> nil then
1213 if Data
.SoundSwitch
and Sound
.IsPlaying() then
1214 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1216 SoundPlayCount
:= 0;
1219 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1220 if (Data
.PlayCount
> 0) or (not Sound
.IsPlaying()) then
1222 if Data
.PlayCount
> 0 then
1223 SoundPlayCount
:= Data
.PlayCount
1224 else // 0 - èãðàåì áåñêîíå÷íî
1225 SoundPlayCount
:= 1;
1228 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1232 TRIGGER_SPAWNMONSTER
:
1233 if (Data
.MonType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1236 if (Data
.MonDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1238 AutoSpawn
:= not AutoSpawn
;
1240 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1244 if ((Data
.MonDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1245 or ((Data
.MonDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1246 for k
:= 1 to Data
.MonCount
do
1248 if (actType
= ACTIVATE_CUSTOM
) and (Data
.MonDelay
> 0) then
1249 SpawnCooldown
:= Data
.MonDelay
;
1250 if (Data
.MonMax
> 0) and (SpawnedCount
>= Data
.MonMax
) then
1253 mon
:= g_Monsters_Create(Data
.MonType
,
1254 Data
.MonPos
.X
, Data
.MonPos
.Y
,
1255 TDirection(Data
.MonDir
), True);
1260 if (Data
.MonHealth
> 0) then
1261 mon
.SetHealth(Data
.MonHealth
);
1262 // Óñòàíàâëèâàåì ïîâåäåíèå:
1263 mon
.MonsterBehaviour
:= Data
.MonBehav
;
1264 mon
.FNoRespawn
:= True;
1265 if g_Game_IsNet
then
1266 MH_SEND_MonsterSpawn(mon
.UID
);
1267 // Èäåì èñêàòü öåëü, åñëè íàäî:
1268 if Data
.MonActive
then
1271 if Data
.MonType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1273 if g_Game_IsNet
then
1275 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1276 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1279 if Data
.MonMax
> 0 then
1281 mon
.SpawnTrigger
:= ID
;
1285 case Data
.MonEffect
of
1286 EFFECT_TELEPORT
: begin
1287 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1289 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1290 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', Data
.MonPos
.X
, Data
.MonPos
.Y
);
1291 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1292 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1295 if g_Game_IsServer
and g_Game_IsNet
then
1296 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1297 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1300 EFFECT_RESPAWN
: begin
1301 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1303 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1304 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', Data
.MonPos
.X
, Data
.MonPos
.Y
);
1305 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1306 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1309 if g_Game_IsServer
and g_Game_IsNet
then
1310 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1311 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1315 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1317 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1318 g_Sound_PlayExAt('SOUND_FIRE', Data
.MonPos
.X
, Data
.MonPos
.Y
);
1319 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1320 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1323 if g_Game_IsServer
and g_Game_IsNet
then
1324 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1325 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1330 if g_Game_IsNet
then
1332 MH_SEND_GameStats();
1333 MH_SEND_CoopStats();
1340 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1341 if actType
= ACTIVATE_CUSTOM
then
1346 if (Data
.ItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1349 if (Data
.ItemDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1351 AutoSpawn
:= not AutoSpawn
;
1353 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1357 if ((Data
.ItemDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1358 or ((Data
.ItemDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1359 if (not Data
.ItemOnlyDM
) or
1360 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1361 for k
:= 1 to Data
.ItemCount
do
1363 if (actType
= ACTIVATE_CUSTOM
) and (Data
.ItemDelay
> 0) then
1364 SpawnCooldown
:= Data
.ItemDelay
;
1365 if (Data
.ItemMax
> 0) and (SpawnedCount
>= Data
.ItemMax
) then
1368 iid
:= g_Items_Create(Data
.ItemPos
.X
, Data
.ItemPos
.Y
,
1369 Data
.ItemType
, Data
.ItemFalls
, False, True);
1373 if Data
.ItemMax
> 0 then
1375 it
:= g_Items_ByIdx(iid
);
1376 it
.SpawnTrigger
:= ID
;
1380 case Data
.ItemEffect
of
1381 EFFECT_TELEPORT
: begin
1382 it
:= g_Items_ByIdx(iid
);
1383 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1385 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1386 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', Data
.ItemPos
.X
, Data
.ItemPos
.Y
);
1387 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1388 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1391 if g_Game_IsServer
and g_Game_IsNet
then
1392 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1393 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1396 EFFECT_RESPAWN
: begin
1397 it
:= g_Items_ByIdx(iid
);
1398 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1400 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1401 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', Data
.ItemPos
.X
, Data
.ItemPos
.Y
);
1402 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1403 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1406 if g_Game_IsServer
and g_Game_IsNet
then
1407 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1408 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1412 it
:= g_Items_ByIdx(iid
);
1413 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1415 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1416 g_Sound_PlayExAt('SOUND_FIRE', Data
.ItemPos
.X
, Data
.ItemPos
.Y
);
1417 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1418 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1421 if g_Game_IsServer
and g_Game_IsNet
then
1422 MH_SEND_Effect(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
-128, 1,
1428 if g_Game_IsNet
then
1429 MH_SEND_ItemSpawn(True, iid
);
1436 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1437 if actType
= ACTIVATE_CUSTOM
then
1443 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1444 if (Trigger
.Data
.MusicName
<> '') then
1446 gMusic
.SetByName(Trigger
.Data
.MusicName
);
1447 gMusic
.SpecPause
:= True;
1451 if Trigger
.Data
.MusicAction
= 1 then
1453 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1454 gMusic
.SpecPause
:= False
1455 else // Èãðàëà => ñíà÷àëà
1456 gMusic
.SetPosition(0);
1461 gMusic
.SpecPause
:= True;
1469 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1474 pAngle
:= -DegToRad(Data
.PushAngle
);
1475 Result
:= tr_Push(ActivateUID
,
1476 Floor(Cos(pAngle
)*Data
.PushForce
),
1477 Floor(Sin(pAngle
)*Data
.PushForce
),
1485 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1486 if (Data
.ScoreAction
in [0..1]) and (Data
.ScoreCount
> 0) then
1488 // Ñâîåé èëè ÷óæîé êîìàíäå
1489 if (Data
.ScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1491 p
:= g_Player_Get(ActivateUID
);
1492 if ((Data
.ScoreAction
= 0) and (Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1493 or ((Data
.ScoreAction
= 0) and (Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1495 Inc(gTeamStat
[TEAM_RED
].Goals
, Data
.ScoreCount
); // Red Scores
1497 if Data
.ScoreCon
then
1498 if Data
.ScoreTeam
= 0 then
1500 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1501 if g_Game_IsServer
and g_Game_IsNet
then
1502 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '+r');
1505 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1506 if g_Game_IsServer
and g_Game_IsNet
then
1507 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '+re');
1510 if Data
.ScoreMsg
then
1512 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1513 if g_Game_IsServer
and g_Game_IsNet
then
1514 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1517 if ((Data
.ScoreAction
= 1) and (Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1518 or ((Data
.ScoreAction
= 1) and (Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1520 Dec(gTeamStat
[TEAM_RED
].Goals
, Data
.ScoreCount
); // Red Fouls
1522 if Data
.ScoreCon
then
1523 if Data
.ScoreTeam
= 0 then
1525 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1526 if g_Game_IsServer
and g_Game_IsNet
then
1527 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '-r');
1530 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1531 if g_Game_IsServer
and g_Game_IsNet
then
1532 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '-re');
1535 if Data
.ScoreMsg
then
1537 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1538 if g_Game_IsServer
and g_Game_IsNet
then
1539 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1542 if ((Data
.ScoreAction
= 0) and (Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1543 or ((Data
.ScoreAction
= 0) and (Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1545 Inc(gTeamStat
[TEAM_BLUE
].Goals
, Data
.ScoreCount
); // Blue Scores
1547 if Data
.ScoreCon
then
1548 if Data
.ScoreTeam
= 0 then
1550 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1551 if g_Game_IsServer
and g_Game_IsNet
then
1552 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '+b');
1555 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1556 if g_Game_IsServer
and g_Game_IsNet
then
1557 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '+be');
1560 if Data
.ScoreMsg
then
1562 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1563 if g_Game_IsServer
and g_Game_IsNet
then
1564 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1567 if ((Data
.ScoreAction
= 1) and (Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1568 or ((Data
.ScoreAction
= 1) and (Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1570 Dec(gTeamStat
[TEAM_BLUE
].Goals
, Data
.ScoreCount
); // Blue Fouls
1572 if Data
.ScoreCon
then
1573 if Data
.ScoreTeam
= 0 then
1575 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1576 if g_Game_IsServer
and g_Game_IsNet
then
1577 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '-b');
1580 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, Data
.ScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1581 if g_Game_IsServer
and g_Game_IsNet
then
1582 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (Data
.ScoreCount
shl 16), '-be');
1585 if Data
.ScoreMsg
then
1587 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1588 if g_Game_IsServer
and g_Game_IsNet
then
1589 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1592 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1594 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1595 if Data
.ScoreTeam
in [2..3] then
1597 if (Data
.ScoreAction
= 0) and (Data
.ScoreTeam
= 2) then
1599 Inc(gTeamStat
[TEAM_RED
].Goals
, Data
.ScoreCount
); // Red Scores
1601 if Data
.ScoreCon
then
1603 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], Data
.ScoreCount
]), True);
1604 if g_Game_IsServer
and g_Game_IsNet
then
1605 MH_SEND_GameEvent(NET_EV_SCORE
, Data
.ScoreCount
shl 16, '+tr');
1608 if Data
.ScoreMsg
then
1610 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1611 if g_Game_IsServer
and g_Game_IsNet
then
1612 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1615 if (Data
.ScoreAction
= 1) and (Data
.ScoreTeam
= 2) then
1617 Dec(gTeamStat
[TEAM_RED
].Goals
, Data
.ScoreCount
); // Red Fouls
1619 if Data
.ScoreCon
then
1621 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], Data
.ScoreCount
]), True);
1622 if g_Game_IsServer
and g_Game_IsNet
then
1623 MH_SEND_GameEvent(NET_EV_SCORE
, Data
.ScoreCount
shl 16, '-tr');
1626 if Data
.ScoreMsg
then
1628 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1629 if g_Game_IsServer
and g_Game_IsNet
then
1630 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1633 if (Data
.ScoreAction
= 0) and (Data
.ScoreTeam
= 3) then
1635 Inc(gTeamStat
[TEAM_BLUE
].Goals
, Data
.ScoreCount
); // Blue Scores
1637 if Data
.ScoreCon
then
1639 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], Data
.ScoreCount
]), True);
1640 if g_Game_IsServer
and g_Game_IsNet
then
1641 MH_SEND_GameEvent(NET_EV_SCORE
, Data
.ScoreCount
shl 16, '+tb');
1644 if Data
.ScoreMsg
then
1646 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1647 if g_Game_IsServer
and g_Game_IsNet
then
1648 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1651 if (Data
.ScoreAction
= 1) and (Data
.ScoreTeam
= 3) then
1653 Dec(gTeamStat
[TEAM_BLUE
].Goals
, Data
.ScoreCount
); // Blue Fouls
1655 if Data
.ScoreCon
then
1657 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], Data
.ScoreCount
]), True);
1658 if g_Game_IsServer
and g_Game_IsNet
then
1659 MH_SEND_GameEvent(NET_EV_SCORE
, Data
.ScoreCount
shl 16, '-tb');
1662 if Data
.ScoreMsg
then
1664 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1665 if g_Game_IsServer
and g_Game_IsNet
then
1666 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1673 if (Data
.ScoreAction
= 2) and (gGameSettings
.GoalLimit
> 0) then
1675 // Ñâîåé èëè ÷óæîé êîìàíäû
1676 if (Data
.ScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1678 p
:= g_Player_Get(ActivateUID
);
1679 if ((Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Red Wins
1680 or ((Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1681 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1683 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1685 if Data
.ScoreCon
then
1686 if Data
.ScoreTeam
= 0 then
1688 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1689 if g_Game_IsServer
and g_Game_IsNet
then
1690 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1693 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1694 if g_Game_IsServer
and g_Game_IsNet
then
1695 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1700 if ((Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1701 or ((Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1702 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1704 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1706 if Data
.ScoreCon
then
1707 if Data
.ScoreTeam
= 0 then
1709 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1710 if g_Game_IsServer
and g_Game_IsNet
then
1711 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1714 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1715 if g_Game_IsServer
and g_Game_IsNet
then
1716 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1722 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1723 if Data
.ScoreTeam
in [2..3] then
1725 if Data
.ScoreTeam
= 2 then // Red Wins
1726 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1728 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1731 if Data
.ScoreTeam
= 3 then // Blue Wins
1732 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1734 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1740 if (Data
.ScoreAction
= 3) and (gGameSettings
.GoalLimit
> 0) then
1742 // Ñâîåé èëè ÷óæîé êîìàíäû
1743 if (Data
.ScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1745 p
:= g_Player_Get(ActivateUID
);
1746 if ((Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1747 or ((Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1748 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1750 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1752 if Data
.ScoreCon
then
1753 if Data
.ScoreTeam
= 0 then
1755 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1756 if g_Game_IsServer
and g_Game_IsNet
then
1757 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1760 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1761 if g_Game_IsServer
and g_Game_IsNet
then
1762 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1767 if ((Data
.ScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Blue Wins
1768 or ((Data
.ScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1769 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1771 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1773 if Data
.ScoreCon
then
1774 if Data
.ScoreTeam
= 0 then
1776 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1777 if g_Game_IsServer
and g_Game_IsNet
then
1778 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1781 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1782 if g_Game_IsServer
and g_Game_IsNet
then
1783 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1789 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1790 if Data
.ScoreTeam
in [2..3] then
1792 if Data
.ScoreTeam
= 3 then // Red Wins
1793 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1795 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1798 if Data
.ScoreTeam
= 2 then // Blue Wins
1799 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1801 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1806 if Result
then begin
1811 if g_Game_IsServer
and g_Game_IsNet
then
1818 Result
:= tr_Message(Data
.MessageKind
, Data
.MessageText
,
1819 Data
.MessageSendTo
, Data
.MessageTime
,
1824 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1827 UIDType
:= g_GetUIDType(ActivateUID
);
1828 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1834 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1835 for idx
:= 0 to High(Activators
) do
1836 if Activators
[idx
].UID
= ActivateUID
then
1842 begin // Âèäèì åãî âïåðâûå
1844 SetLength(Activators
, Length(Activators
) + 1);
1845 k
:= High(Activators
);
1846 Activators
[k
].UID
:= ActivateUID
;
1848 begin // Óæå âèäåëè åãî
1849 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1850 if (Data
.DamageInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
1851 Activators
[k
].TimeOut
:= 65535;
1852 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1853 Result
:= Activators
[k
].TimeOut
= 0;
1862 p
:= g_Player_Get(ActivateUID
);
1866 // Íàíîñèì óðîí èãðîêó
1867 if (TriggerType
= TRIGGER_DAMAGE
) and (Data
.DamageValue
> 0) then
1868 p
.Damage(Data
.DamageValue
, 0, 0, 0, HIT_SOME
);
1871 if (TriggerType
= TRIGGER_HEALTH
) and (Data
.HealValue
> 0) then
1872 if p
.Heal(Data
.HealValue
, not Data
.HealMax
) and (not Data
.HealSilent
) then
1874 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
1875 if g_Game_IsServer
and g_Game_IsNet
then
1876 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1882 m
:= g_Monsters_ByUID(ActivateUID
);
1886 // Íàíîñèì óðîí ìîíñòðó
1887 if (TriggerType
= TRIGGER_DAMAGE
) and (Data
.DamageValue
> 0) then
1888 m
.Damage(Data
.DamageValue
, 0, 0, 0, HIT_SOME
);
1891 if (TriggerType
= TRIGGER_HEALTH
) and (Data
.HealValue
> 0) then
1892 if m
.Heal(Data
.HealValue
) and (not Data
.HealSilent
) then
1894 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
1895 if g_Game_IsServer
and g_Game_IsNet
then
1896 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1900 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1901 if TriggerType
= TRIGGER_DAMAGE
then
1902 idx
:= Data
.DamageInterval
1904 idx
:= Data
.HealInterval
;
1907 Activators
[k
].TimeOut
:= idx
1909 Activators
[k
].TimeOut
:= 65535;
1917 if ShotSightTime
> 0 then
1920 // put this at the beginning so it doesn't trigger itself
1921 TimeOut
:= Data
.ShotWait
+ 1;
1923 wx
:= Data
.ShotPos
.X
;
1924 wy
:= Data
.ShotPos
.Y
;
1925 pAngle
:= -DegToRad(Data
.ShotAngle
);
1926 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
1927 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
1930 case Data
.ShotTarget
of
1931 TRIGGER_SHOT_TARGET_MON
: // monsters
1932 //TODO: accelerate this!
1933 g_Mons_ForEachAlive(monsShotTarget
);
1935 TRIGGER_SHOT_TARGET_PLR
: // players
1936 if gPlayers
<> nil then
1937 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1938 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1939 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1941 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1942 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1943 TargetUID
:= gPlayers
[idx
].UID
;
1947 TRIGGER_SHOT_TARGET_RED
: // red team
1948 if gPlayers
<> nil then
1949 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1950 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1951 (gPlayers
[idx
].Team
= TEAM_RED
) and
1952 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1954 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1955 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1956 TargetUID
:= gPlayers
[idx
].UID
;
1960 TRIGGER_SHOT_TARGET_BLUE
: // blue team
1961 if gPlayers
<> nil then
1962 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1963 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1964 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
1965 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1967 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1968 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1969 TargetUID
:= gPlayers
[idx
].UID
;
1973 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
1975 //TODO: accelerate this!
1976 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
1978 if (TargetUID
= 0) and (gPlayers
<> nil) then
1979 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1980 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1981 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1983 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1984 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1985 TargetUID
:= gPlayers
[idx
].UID
;
1990 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
1992 if gPlayers
<> nil then
1993 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1994 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1995 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1997 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1998 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1999 TargetUID
:= gPlayers
[idx
].UID
;
2002 if TargetUID
= 0 then
2004 //TODO: accelerate this!
2005 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2010 if (Data
.ShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2011 (Data
.ShotType
<> TRIGGER_SHOT_REV
) then
2012 TargetUID
:= ActivateUID
;
2016 if (Data
.ShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2017 ((Data
.ShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2020 if (Data
.ShotIntSight
= 0) or
2021 (Data
.ShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2022 (TargetUID
= ShotSightTarget
) then
2023 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2026 ShotSightTime
:= Data
.ShotIntSight
;
2027 ShotSightTargetN
:= TargetUID
;
2028 if Data
.ShotType
= TRIGGER_SHOT_BFG
then
2030 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2031 if g_Game_IsNet
and g_Game_IsServer
then
2032 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2040 idx
:= Data
.FXCount
;
2045 TRIGGER_EFFECT_POS_CENTER
:
2047 wx
:= X
+ Width
div 2;
2048 wy
:= Y
+ Height
div 2;
2050 TRIGGER_EFFECT_POS_AREA
:
2052 wx
:= X
+ Random(Width
);
2053 wy
:= Y
+ Random(Height
);
2056 wx
:= X
+ Width
div 2;
2057 wy
:= Y
+ Height
div 2;
2062 if Data
.FXSpreadL
> 0 then xd
:= xd
- Random(Data
.FXSpreadL
+ 1);
2063 if Data
.FXSpreadR
> 0 then xd
:= xd
+ Random(Data
.FXSpreadR
+ 1);
2064 if Data
.FXSpreadU
> 0 then yd
:= yd
- Random(Data
.FXSpreadU
+ 1);
2065 if Data
.FXSpreadD
> 0 then yd
:= yd
+ Random(Data
.FXSpreadD
+ 1);
2066 tr_MakeEffect(wx
, wy
, xd
, yd
,
2067 Data
.FXType
, Data
.FXSubType
,
2068 Data
.FXColorR
, Data
.FXColorG
, Data
.FXColorB
, True, False);
2071 TimeOut
:= Data
.FXWait
;
2076 if Result
and (Trigger
.TexturePanel
<> -1) then
2077 g_Map_SwitchTexture(Trigger
.TexturePanelType
, Trigger
.TexturePanel
, IfThen(animonce
, 2, 1));
2080 function g_Triggers_Create(Trigger
: TTrigger
): DWORD
;
2085 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2086 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2087 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2088 Trigger
.TriggerType
:= TRIGGER_NONE
;
2090 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2091 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2092 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2093 (gGameSettings
.GameType
<> GT_SINGLE
) then
2094 Trigger
.TriggerType
:= TRIGGER_NONE
;
2096 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2097 if Trigger
.TriggerType
= TRIGGER_SECRET
then
2098 gSecretsCount
:= gSecretsCount
+ 1;
2100 find_id
:= FindTrigger();
2101 gTriggers
[find_id
] := Trigger
;
2103 with gTriggers
[find_id
] do
2106 // if this type of trigger exists both on the client and on the server
2107 // use an uniform numeration
2108 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2110 Inc(gTriggerClientID
);
2111 ClientID
:= gTriggerClientID
;
2117 PlayerCollide
:= False;
2121 SoundPlayCount
:= 0;
2128 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2129 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and
2130 (Trigger
.Data
.SoundName
<> '') then
2132 // Åùå íåò òàêîãî çâóêà:
2133 if not g_Sound_Exists(Trigger
.Data
.SoundName
) then
2135 fn
:= g_ExtractWadName(Trigger
.Data
.SoundName
);
2138 begin // Çâóê â ôàéëå ñ êàðòîé
2139 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2140 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.Data
.SoundName
);
2142 else // Çâóê â îòäåëüíîì ôàéëå
2143 fn
:= GameDir
+ '/wads/' + Trigger
.Data
.SoundName
;
2145 if not g_Sound_CreateWADEx(Trigger
.Data
.SoundName
, fn
) then
2146 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.Data
.SoundName
]));
2149 // Ñîçäàåì îáúåêò çâóêà:
2150 with gTriggers
[find_id
] do
2152 Sound
:= TPlayableSound
.Create();
2153 if not Sound
.SetByName(Trigger
.Data
.SoundName
) then
2161 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2162 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and
2163 (Trigger
.Data
.MusicName
<> '') then
2165 // Åùå íåò òàêîé ìóçûêè:
2166 if not g_Sound_Exists(Trigger
.Data
.MusicName
) then
2168 fn
:= g_ExtractWadName(Trigger
.Data
.MusicName
);
2171 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2172 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2173 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.Data
.MusicName
);
2175 else // Ìóçûêà â ôàéëå ñ êàðòîé
2176 fn
:= GameDir
+'/wads/'+Trigger
.Data
.MusicName
;
2178 if not g_Sound_CreateWADEx(Trigger
.Data
.MusicName
, fn
, True) then
2179 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.Data
.MusicName
]));
2183 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2184 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2185 with gTriggers
[find_id
] do
2189 ShotSightTimeout
:= 0;
2190 ShotSightTarget
:= 0;
2191 ShotSightTargetN
:= 0;
2192 ShotAmmoCount
:= Trigger
.Data
.ShotAmmo
;
2193 ShotReloadTime
:= 0;
2200 // sorry; grid doesn't support recursive queries, so we have to do this
2202 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2205 tgMonsList
: TSimpleMonsterList
= nil;
2207 procedure g_Triggers_Update();
2210 Affected
: array of Integer;
2212 function monsNear (mon
: TMonster
): Boolean;
2214 result
:= false; // don't stop
2216 gTriggers[a].ActivateUID := mon.UID;
2217 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2219 tgMonsList
.append(mon
);
2225 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2227 if gTriggers
= nil then
2229 SetLength(Affected
, 0);
2231 for a
:= 0 to High(gTriggers
) do
2232 with gTriggers
[a
] do
2234 if TriggerType
<> TRIGGER_NONE
then
2236 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè):
2237 if DoorTime
> 0 then
2238 DoorTime
:= DoorTime
- 1;
2239 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ:
2240 if PressTime
> 0 then
2241 PressTime
:= PressTime
- 1;
2242 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2243 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2244 for b
:= 0 to High(Activators
) do
2246 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2247 if Activators
[b
].TimeOut
> 0 then
2248 Dec(Activators
[b
].TimeOut
)
2251 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2252 if (Data
.DamageInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then
2253 Activators
[b
].TimeOut
:= 0;
2256 // Îáðàáàòûâàåì ñïàâíåðû:
2257 if Enabled
and AutoSpawn
then
2258 if SpawnCooldown
= 0 then
2260 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà:
2261 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (Data
.MonDelay
> 0) then
2264 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2266 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò:
2267 if (TriggerType
= TRIGGER_SPAWNITEM
) and (Data
.ItemDelay
> 0) then
2270 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2272 end else // Óìåíüøàåì âðåìÿ îæèäàíèÿ:
2275 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü":
2276 if TriggerType
= TRIGGER_SHOT
then
2278 if ShotPanelTime
> 0 then
2281 if ShotPanelTime
= 0 then
2282 g_Map_SwitchTexture(ShotPanelType
, Data
.ShotPanelID
);
2284 if ShotSightTime
> 0 then
2287 if ShotSightTime
= 0 then
2288 ShotSightTarget
:= ShotSightTargetN
;
2290 if ShotSightTimeout
> 0 then
2292 Dec(ShotSightTimeout
);
2293 if ShotSightTimeout
= 0 then
2294 ShotSightTarget
:= 0;
2296 if ShotReloadTime
> 0 then
2298 Dec(ShotReloadTime
);
2299 if ShotReloadTime
= 0 then
2300 ShotAmmoCount
:= Data
.ShotAmmo
;
2304 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì:
2305 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2306 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2308 if Data
.PlayCount
> 0 then // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2309 SoundPlayCount
:= SoundPlayCount
- 1;
2311 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0)
2313 Sound
.PlayPanVolume((Data
.Pan
-127.0)/128.0, Data
.Volume
/255.0);
2314 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then
2315 MH_SEND_TriggerSound(gTriggers
[a
]);
2318 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü:
2319 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (Data
.PanelID
<> -1) then
2321 tr_OpenDoor(Data
.PanelID
, Data
.NoSound
, Data
.d2d_doors
);
2325 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü:
2326 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (Data
.PanelID
<> -1) then
2329 if gWalls
[Data
.PanelID
].Enabled
then
2331 else // Ïîêà îòêðûòà - çàêðûâàåì
2332 if tr_CloseDoor(Data
.PanelID
, Data
.NoSound
, Data
.d2d_doors
) then
2336 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2337 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2338 (PressTime
= 0) and (PressCount
>= Data
.Count
) then
2340 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2342 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2343 if Data
.Count
> 0 then
2344 PressCount
:= PressCount
- Data
.Count
2348 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2349 for b
:= 0 to High(gTriggers
) do
2350 if g_Collide(Data
.tX
, Data
.tY
, Data
.tWidth
, Data
.tHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2351 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2352 ((b
<> a
) or (Data
.Wait
> 0)) then
2353 begin // Can be self-activated, if there is Data.Wait
2354 if (not Data
.ExtRandom
) or gTriggers
[b
].Enabled
then
2356 SetLength(Affected
, Length(Affected
) + 1);
2357 Affected
[High(Affected
)] := b
;
2360 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2361 if (TriggerType
= TRIGGER_PRESS
) and Data
.ExtRandom
then
2363 if (Length(Affected
) > 0) then
2365 b
:= Affected
[Random(Length(Affected
))];
2366 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2367 ActivateTrigger(gTriggers
[b
], 0);
2370 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2371 for i
:= 0 to High(Affected
) do
2377 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2378 ActivateTrigger(gTriggers
[b
], 0);
2382 gTriggers
[b
].Enabled
:= True;
2386 gTriggers
[b
].Enabled
:= False;
2387 gTriggers
[b
].TimeOut
:= 0;
2388 if gTriggers
[b
].AutoSpawn
then
2390 gTriggers
[b
].AutoSpawn
:= False;
2391 gTriggers
[b
].SpawnCooldown
:= 0;
2396 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2397 if not gTriggers
[b
].Enabled
then
2399 gTriggers
[b
].TimeOut
:= 0;
2400 if gTriggers
[b
].AutoSpawn
then
2402 gTriggers
[b
].AutoSpawn
:= False;
2403 gTriggers
[b
].SpawnCooldown
:= 0;
2409 SetLength(Affected
, 0);
2412 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2415 TimeOut
:= TimeOut
- 1;
2416 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2419 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2424 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2426 if gPlayers
<> nil then
2427 for b
:= 0 to High(gPlayers
) do
2428 if gPlayers
[b
] <> nil then
2430 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2431 if Live
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2432 Collide(X
, Y
, Width
, Height
) then
2434 gTriggers
[a
].ActivateUID
:= UID
;
2436 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2438 { Don't activate sound/music again if player is here }
2440 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2443 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2445 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2446 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2447 (TimeOut
= 0) and (Keys
= 0) then
2449 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2450 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2451 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2452 gTriggers
[a
].ActivateUID
:= 0;
2453 ActivateTrigger(gTriggers
[a
], 0);
2457 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2458 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2460 //g_Mons_ForEach(monsNear);
2463 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2464 for mon
in tgMonsList
do
2466 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2467 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2469 tgMonsList
.reset(); // just in case
2473 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2474 (TimeOut
= 0) and (Keys
= 0) then
2475 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2477 gTriggers
[a
].ActivateUID
:= 0;
2478 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2482 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2486 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2488 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2489 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2492 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2493 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2501 if gTriggers
= nil then Exit
;
2503 case g_GetUIDType(UID
) of
2507 p
:= g_Player_Get(UID
);
2516 for a
:= 0 to High(gTriggers
) do
2517 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2518 (gTriggers
[a
].TimeOut
= 0) and
2519 (not InDWArray(a
, IgnoreList
)) and
2520 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2521 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2522 if g_Collide(X
, Y
, Width
, Height
,
2523 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2524 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2526 gTriggers
[a
].ActivateUID
:= UID
;
2527 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2529 SetLength(Result
, Length(Result
)+1);
2530 Result
[High(Result
)] := a
;
2535 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2541 if gTriggers
= nil then Exit
;
2543 case g_GetUIDType(UID
) of
2547 p
:= g_Player_Get(UID
);
2556 for a
:= 0 to High(gTriggers
) do
2557 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2558 (gTriggers
[a
].TimeOut
= 0) and
2559 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2560 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2561 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2562 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2564 gTriggers
[a
].ActivateUID
:= UID
;
2565 ActivateTrigger(gTriggers
[a
], ActivateType
);
2569 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2576 if gTriggers
= nil then
2579 case g_GetUIDType(UID
) of
2583 p
:= g_Player_Get(UID
);
2592 rsq
:= Radius
* Radius
;
2594 for a
:= 0 to High(gTriggers
) do
2595 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
2596 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2597 (gTriggers
[a
].TimeOut
= 0) and
2598 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2599 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2600 with gTriggers
[a
] do
2601 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
2602 X
, Y
, Width
, Height
) then
2603 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2604 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2605 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2606 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2607 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
2608 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2609 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
2610 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2613 ActivateTrigger(gTriggers
[a
], ActivateType
);
2617 procedure g_Triggers_OpenAll();
2622 if gTriggers
= nil then Exit
;
2625 for a
:= 0 to High(gTriggers
) do
2626 with gTriggers
[a
] do
2627 if (TriggerType
= TRIGGER_OPENDOOR
) or
2628 (TriggerType
= TRIGGER_DOOR5
) or
2629 (TriggerType
= TRIGGER_DOOR
) then
2631 tr_OpenDoor(Data
.PanelID
, True, Data
.d2d_doors
);
2632 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2636 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2639 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2641 if (gTriggers
<> nil) then
2642 if gTriggers
[ID
].SpawnedCount
> 0 then
2643 Dec(gTriggers
[ID
].SpawnedCount
);
2646 procedure g_Triggers_Free();
2650 if gTriggers
<> nil then
2651 for a
:= 0 to High(gTriggers
) do
2653 if gTriggers
[a
].TriggerType
= TRIGGER_SOUND
then
2655 if g_Sound_Exists(gTriggers
[a
].Data
.SoundName
) then
2656 g_Sound_Delete(gTriggers
[a
].Data
.SoundName
);
2658 gTriggers
[a
].Sound
.Free();
2660 if gTriggers
[a
].Activators
<> nil then
2661 SetLength(gTriggers
[a
].Activators
, 0);
2666 SetLength(gMonstersSpawned
, 0);
2669 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2671 count
, act_count
, i
, j
: Integer;
2677 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ:
2679 if gTriggers
<> nil then
2680 for i
:= 0 to High(gTriggers
) do
2683 Mem
:= TBinMemoryWriter
.Create((count
+1) * 200);
2685 // Êîëè÷åñòâî òðèããåðîâ:
2686 Mem
.WriteInt(count
);
2691 for i
:= 0 to High(gTriggers
) do
2693 // Ñèãíàòóðà òðèããåðà:
2694 dw
:= TRIGGER_SIGNATURE
; // 'TRGR'
2697 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2698 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2699 p
:= @gTriggers
[i
].Data
;
2700 Mem
.WriteMemory(p
, SizeOf(TTriggerData
));
2701 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2702 Mem
.WriteInt(gTriggers
[i
].X
);
2703 Mem
.WriteInt(gTriggers
[i
].Y
);
2705 Mem
.WriteWord(gTriggers
[i
].Width
);
2706 Mem
.WriteWord(gTriggers
[i
].Height
);
2707 // Âêëþ÷åí ëè òðèããåð:
2708 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
2709 // Òèï àêòèâàöèè òðèããåðà:
2710 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
2711 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2712 Mem
.WriteByte(gTriggers
[i
].Keys
);
2713 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2714 Mem
.WriteInt(gTriggers
[i
].TexturePanel
);
2716 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
2717 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2718 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
2719 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2720 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
2721 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2722 act_count
:= Length(gTriggers
[i
].Activators
);
2723 Mem
.WriteInt(act_count
);
2724 for j
:= 0 to act_count
-1 do
2727 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2729 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2731 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2732 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2733 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2734 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2735 // Çàäåðæêà àêòèâàöèè:
2736 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2738 Mem
.WriteInt(gTriggers
[i
].PressCount
);
2740 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
2741 // Çàäåðæêà ñïàâíåðà:
2742 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
2743 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2744 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
2745 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2746 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
2747 // Ïðîèãðûâàåòñÿ ëè çâóê?
2748 if gTriggers
[i
].Sound
<> nil then
2749 b
:= gTriggers
[i
].Sound
.IsPlaying()
2752 Mem
.WriteBoolean(b
);
2755 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2756 dw
:= gTriggers
[i
].Sound
.GetPosition();
2759 sg
:= gTriggers
[i
].Sound
.GetVolume();
2760 sg
:= sg
/ (gSoundLevel
/255.0);
2761 Mem
.WriteSingle(sg
);
2762 // Ñòåðåî ñìåùåíèå çâóêà:
2763 sg
:= gTriggers
[i
].Sound
.GetPan();
2764 Mem
.WriteSingle(sg
);
2769 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
2771 count
, act_count
, i
, j
, a
: Integer;
2783 // Êîëè÷åñòâî òðèããåðîâ:
2789 for a
:= 0 to count
-1 do
2791 // Ñèãíàòóðà òðèããåðà:
2793 if dw
<> TRIGGER_SIGNATURE
then // 'TRGR'
2795 raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2798 Mem
.ReadByte(Trig
.TriggerType
);
2799 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2800 Mem
.ReadMemory(p
, dw
);
2801 if dw
<> SizeOf(TTriggerData
) then
2803 raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2805 Trig
.Data
:= TTriggerData(p
^);
2807 i
:= g_Triggers_Create(Trig
);
2808 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2809 Mem
.ReadInt(gTriggers
[i
].X
);
2810 Mem
.ReadInt(gTriggers
[i
].Y
);
2812 Mem
.ReadWord(gTriggers
[i
].Width
);
2813 Mem
.ReadWord(gTriggers
[i
].Height
);
2814 // Âêëþ÷åí ëè òðèããåð:
2815 Mem
.ReadBoolean(gTriggers
[i
].Enabled
);
2816 // Òèï àêòèâàöèè òðèããåðà:
2817 Mem
.ReadByte(gTriggers
[i
].ActivateType
);
2818 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2819 Mem
.ReadByte(gTriggers
[i
].Keys
);
2820 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2821 Mem
.ReadInt(gTriggers
[i
].TexturePanel
);
2823 Mem
.ReadWord(gTriggers
[i
].TexturePanelType
);
2824 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2825 Mem
.ReadWord(gTriggers
[i
].TimeOut
);
2826 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2827 Mem
.ReadWord(gTriggers
[i
].ActivateUID
);
2828 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2829 Mem
.ReadInt(act_count
);
2830 if act_count
> 0 then
2832 SetLength(gTriggers
[i
].Activators
, act_count
);
2833 for j
:= 0 to act_count
-1 do
2836 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
2838 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2841 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2842 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
2843 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2844 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
2845 // Çàäåðæêà àêòèâàöèè:
2846 Mem
.ReadInt(gTriggers
[i
].PressTime
);
2848 Mem
.ReadInt(gTriggers
[i
].PressCount
);
2850 Mem
.ReadBoolean(gTriggers
[i
].AutoSpawn
);
2851 // Çàäåðæêà ñïàâíåðà:
2852 Mem
.ReadInt(gTriggers
[i
].SpawnCooldown
);
2853 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2854 Mem
.ReadInt(gTriggers
[i
].SpawnedCount
);
2855 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2856 Mem
.ReadInt(gTriggers
[i
].SoundPlayCount
);
2857 // Ïðîèãðûâàåòñÿ ëè çâóê?
2861 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2864 Mem
.ReadSingle(vol
);
2865 // Ñòåðåî ñìåùåíèå çâóêà:
2866 Mem
.ReadSingle(pan
);
2867 // Çàïóñêàåì çâóê, åñëè åñòü:
2868 if gTriggers
[i
].Sound
<> nil then
2870 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
2871 gTriggers
[i
].Sound
.Pause(True);
2872 gTriggers
[i
].Sound
.SetPosition(dw
);