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
69 property trigShotPanelId
: Integer read trigPanelId write trigPanelId
;
72 function g_Triggers_Create(Trigger
: TTrigger
): DWORD
;
73 procedure g_Triggers_Update();
74 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
75 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
76 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
77 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
78 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
79 procedure g_Triggers_OpenAll();
80 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
81 procedure g_Triggers_Free();
82 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
83 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
85 function tr_Message(MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
87 function tr_CloseDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
88 function tr_OpenDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
89 procedure tr_CloseTrap(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean);
90 function tr_SetLift(PanelID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
92 function tr_Teleport(ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
93 function tr_Push(ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
95 procedure tr_MakeEffect(X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
96 function tr_SpawnShot(ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
99 gTriggerClientID
: Integer = 0;
100 gTriggers
: array of TTrigger
;
101 gSecretsCount
: Integer = 0;
102 gMonstersSpawned
: array of LongInt = nil;
107 g_player
, g_map
, Math
, g_gfx
, g_game
, g_textures
,
108 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
109 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
110 g_options
, g_net
, g_netmsg
, utils
;
113 TRIGGER_SIGNATURE
= $52475254; // 'TRGR'
116 function FindTrigger(): DWORD
;
120 if gTriggers
<> nil then
121 for i
:= 0 to High(gTriggers
) do
122 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then
128 if gTriggers
= nil then
130 SetLength(gTriggers
, 8);
135 Result
:= High(gTriggers
) + 1;
136 SetLength(gTriggers
, Length(gTriggers
) + 8);
140 function tr_CloseDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
146 if PanelID
= -1 then Exit
;
150 with gWalls
[PanelID
] do
152 if g_CollidePlayer(X
, Y
, Width
, Height
) or
153 g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
159 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
160 if g_Game_IsServer
and g_Game_IsNet
then
161 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
163 g_Map_EnableWall(PanelID
);
170 if gDoorMap
= nil then Exit
;
173 for a
:= 0 to High(gDoorMap
) do
175 for b
:= 0 to High(gDoorMap
[a
]) do
176 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
182 if c
<> -1 then Break
;
186 for b
:= 0 to High(gDoorMap
[c
]) do
187 with gWalls
[gDoorMap
[c
, b
]] do
189 if g_CollidePlayer(X
, Y
, Width
, Height
) or
190 g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
194 for b
:= 0 to High(gDoorMap
[c
]) do
195 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
197 with gWalls
[PanelID
] do
199 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
200 if g_Game_IsServer
and g_Game_IsNet
then
201 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
206 for b
:= 0 to High(gDoorMap
[c
]) do
207 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
209 g_Map_EnableWall(gDoorMap
[c
, b
]);
215 procedure tr_CloseTrap(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean);
218 wx
, wy
, wh
, ww
: Integer;
220 function monsDamage (mon
: TMonster
): Boolean;
222 result
:= false; // don't stop
223 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
227 if PanelID
= -1 then Exit
;
231 with gWalls
[PanelID
] do
233 if (not NoSound
) and (not Enabled
) then
235 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
236 if g_Game_IsServer
and g_Game_IsNet
then
237 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
241 wx
:= gWalls
[PanelID
].X
;
242 wy
:= gWalls
[PanelID
].Y
;
243 ww
:= gWalls
[PanelID
].Width
;
244 wh
:= gWalls
[PanelID
].Height
;
246 with gWalls
[PanelID
] do
248 if gPlayers
<> nil then
249 for a
:= 0 to High(gPlayers
) do
250 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and
251 gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
252 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
254 //g_Mons_ForEach(monsDamage);
255 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
257 if not Enabled
then g_Map_EnableWall(PanelID
);
262 if gDoorMap
= nil then Exit
;
265 for a
:= 0 to High(gDoorMap
) do
267 for b
:= 0 to High(gDoorMap
[a
]) do
269 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
276 if c
<> -1 then Break
;
282 for b
:= 0 to High(gDoorMap
[c
]) do
284 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
286 with gWalls
[PanelID
] do
288 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
289 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
296 for b
:= 0 to High(gDoorMap
[c
]) do
298 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
299 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
300 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
301 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
303 with gWalls
[gDoorMap
[c
, b
]] do
305 if gPlayers
<> nil then
306 for a
:= 0 to High(gPlayers
) do
307 if (gPlayers
[a
] <> nil) and gPlayers
[a
].Live
and
308 gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
309 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
311 //g_Mons_ForEach(monsDamage);
312 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
314 if gMonsters <> nil then
315 for a := 0 to High(gMonsters) do
316 if (gMonsters[a] <> nil) and gMonsters[a].Live and
317 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
318 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
321 if not Enabled
then g_Map_EnableWall(gDoorMap
[c
, b
]);
327 function tr_OpenDoor(PanelID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
333 if PanelID
= -1 then Exit
;
337 with gWalls
[PanelID
] do
342 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
343 if g_Game_IsServer
and g_Game_IsNet
then
344 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
346 g_Map_DisableWall(PanelID
);
352 if gDoorMap
= nil then Exit
;
355 for a
:= 0 to High(gDoorMap
) do
357 for b
:= 0 to High(gDoorMap
[a
]) do
358 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
364 if c
<> -1 then Break
;
369 for b
:= 0 to High(gDoorMap
[c
]) do
370 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
372 with gWalls
[PanelID
] do
374 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
375 if g_Game_IsServer
and g_Game_IsNet
then
376 MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
381 for b
:= 0 to High(gDoorMap
[c
]) do
382 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
384 g_Map_DisableWall(gDoorMap
[c
, b
]);
390 function tr_SetLift(PanelID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
397 if PanelID
= -1 then Exit
;
399 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or
400 (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
404 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
406 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or
407 (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
411 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
416 with gLifts
[PanelID
] do
417 if LiftType
<> t
then
419 g_Map_SetLift(PanelID
, t
);
422 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);}
428 if gLiftMap
= nil then Exit
;
431 for a
:= 0 to High(gLiftMap
) do
433 for b
:= 0 to High(gLiftMap
[a
]) do
434 if gLiftMap
[a
, b
] = DWORD(PanelID
) then
440 if c
<> -1 then Break
;
445 for b := 0 to High(gLiftMap[c]) do
446 if gLifts[gLiftMap[c, b]].LiftType <> t then
448 with gLifts[PanelID] do
449 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
453 for b
:= 0 to High(gLiftMap
[c
]) do
454 with gLifts
[gLiftMap
[c
, b
]] do
455 if LiftType
<> t
then
457 g_Map_SetLift(gLiftMap
[c
, b
], t
);
464 function tr_SpawnShot(ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
472 TextureID
:= DWORD(-1);
473 snd
:= 'SOUND_WEAPON_FIREROCKET';
478 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
479 snd
:= 'SOUND_WEAPON_FIREPISTOL';
483 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
485 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
491 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
492 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
493 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
497 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
499 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
503 TRIGGER_SHOT_SHOTGUN
:
505 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
506 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
510 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
512 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
518 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
519 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
523 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
524 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
526 MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
532 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
533 snd
:= 'SOUND_WEAPON_FIREBALL';
538 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
539 snd
:= 'SOUND_WEAPON_FIREPLASMA';
544 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
545 snd
:= 'SOUND_WEAPON_FIREPLASMA';
550 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
551 snd
:= 'SOUND_WEAPON_FIREBALL';
556 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
557 snd
:= 'SOUND_WEAPON_FIREBALL';
562 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
563 snd
:= 'SOUND_WEAPON_FIREBALL';
568 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
569 snd
:= 'SOUND_WEAPON_FIREREV';
574 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
575 snd
:= 'SOUND_WEAPON_FIREROCKET';
580 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
581 snd
:= 'SOUND_WEAPON_FIREBFG';
586 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
588 Anim
:= TAnimation
.Create(TextureID
, False, 6);
589 Anim
.Blending
:= False;
590 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
594 g_Weapon_Explode(wx
, wy
, 60, 0);
595 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
598 TRIGGER_SHOT_BFGEXPL
:
600 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
602 Anim
:= TAnimation
.Create(TextureID
, False, 6);
603 Anim
.Blending
:= False;
604 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
608 g_Weapon_BFG9000(wx
, wy
, 0);
609 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
615 if g_Game_IsNet
and g_Game_IsServer
then
618 MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
619 TRIGGER_SHOT_BFGEXPL
:
620 MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
624 MH_SEND_CreateShot(LastShotID
);
626 MH_SEND_Sound(wx
, wy
, snd
);
631 g_Sound_PlayExAt(snd
, wx
, wy
);
634 Result
:= LastShotID
;
637 procedure MakeShot(var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
640 if (trigData
.trigShotAmmo
= 0) or
641 ((trigData
.trigShotAmmo
> 0) and (ShotAmmoCount
> 0)) then
643 if (trigShotPanelID
<> -1) and (ShotPanelTime
= 0) then
645 g_Map_SwitchTexture(ShotPanelType
, trigShotPanelID
);
646 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
649 if trigData
.trigShotIntSight
> 0 then
650 ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
652 if ShotAmmoCount
> 0 then Dec(ShotAmmoCount
);
654 dx
:= dx
+ Random(trigData
.trigShotAccuracy
) - Random(trigData
.trigShotAccuracy
);
655 dy
:= dy
+ Random(trigData
.trigShotAccuracy
) - Random(trigData
.trigShotAccuracy
);
657 tr_SpawnShot(trigData
.trigShotType
, wx
, wy
, dx
, dy
, trigData
.trigShotSound
, TargetUID
);
660 if (trigData
.trigShotIntReload
> 0) and (ShotReloadTime
= 0) then
661 ShotReloadTime
:= trigData
.trigShotIntReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
664 procedure tr_MakeEffect(X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
669 if T
= TRIGGER_EFFECT_PARTICLE
then
671 TRIGGER_EFFECT_SLIQUID
:
673 if (CR
= 255) and (CG
= 0) and (CB
= 0) then
674 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
675 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then
676 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
677 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then
678 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
680 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
682 TRIGGER_EFFECT_LLIQUID
:
683 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
684 TRIGGER_EFFECT_DLIQUID
:
685 g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
686 TRIGGER_EFFECT_BLOOD
:
687 g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
688 TRIGGER_EFFECT_SPARK
:
689 g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
690 TRIGGER_EFFECT_BUBBLE
:
691 g_GFX_Bubbles(X
, Y
, 1, 0, 0);
693 if T
= TRIGGER_EFFECT_ANIMATION
then
695 EFFECT_TELEPORT
: begin
696 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
698 Anim
:= TAnimation
.Create(FramesID
, False, 3);
700 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
701 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
704 if Send
and g_Game_IsServer
and g_Game_IsNet
then
705 MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
707 EFFECT_RESPAWN
: begin
708 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
710 Anim
:= TAnimation
.Create(FramesID
, False, 4);
712 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
713 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
716 if Send
and g_Game_IsServer
and g_Game_IsNet
then
717 MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
720 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
722 Anim
:= TAnimation
.Create(FramesID
, False, 4);
724 g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
725 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
728 if Send
and g_Game_IsServer
and g_Game_IsNet
then
729 MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
734 function tr_Teleport(ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
740 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
741 case g_GetUIDType(ActivateUID
) of
744 p
:= g_Player_Get(ActivateUID
);
750 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2),
751 TY
-p
.Obj
.Rect
.Height
,
757 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then
763 m
:= g_Monsters_ByUID(ActivateUID
);
769 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2),
770 TY
-m
.Obj
.Rect
.Height
,
776 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then
782 function tr_Push(ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
788 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
789 case g_GetUIDType(ActivateUID
) of
792 p
:= g_Player_Get(ActivateUID
);
809 m
:= g_Monsters_ByUID(ActivateUID
);
826 function tr_Message(MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
833 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
834 msg
:= b_Text_Format(MText
);
838 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
840 if g_Game_IsWatchedPlayer(ActivateUID
) then
843 g_Console_Add(msg
, True)
844 else if MKind
= 1 then
845 g_Game_Message(msg
, MTime
);
849 p
:= g_Player_Get(ActivateUID
);
850 if g_Game_IsNet
and (p
.FClientID
>= 0) then
852 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
853 else if MKind
= 1 then
854 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
859 1: // activator's team
861 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
863 p
:= g_Player_Get(ActivateUID
);
864 if g_Game_IsWatchedTeam(p
.Team
) then
866 g_Console_Add(msg
, True)
867 else if MKind
= 1 then
868 g_Game_Message(msg
, MTime
);
872 for i
:= Low(gPlayers
) to High(gPlayers
) do
873 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
875 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
876 else if MKind
= 1 then
877 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
882 2: // activator's enemy team
884 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
886 p
:= g_Player_Get(ActivateUID
);
887 if g_Game_IsWatchedTeam(p
.Team
) then
889 g_Console_Add(msg
, True)
890 else if MKind
= 1 then
891 g_Game_Message(msg
, MTime
);
895 for i
:= Low(gPlayers
) to High(gPlayers
) do
896 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
898 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
899 else if MKind
= 1 then
900 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
907 if g_Game_IsWatchedTeam(TEAM_RED
) then
909 g_Console_Add(msg
, True)
910 else if MKind
= 1 then
911 g_Game_Message(msg
, MTime
);
915 for i
:= Low(gPlayers
) to High(gPlayers
) do
916 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
918 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
919 else if MKind
= 1 then
920 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
926 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
928 g_Console_Add(msg
, True)
929 else if MKind
= 1 then
930 g_Game_Message(msg
, MTime
);
934 for i
:= Low(gPlayers
) to High(gPlayers
) do
935 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
937 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
938 else if MKind
= 1 then
939 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
946 g_Console_Add(msg
, True)
947 else if MKind
= 1 then
948 g_Game_Message(msg
, MTime
);
953 MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
954 else if MKind
= 1 then
955 MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
961 function tr_ShotAimCheck(var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
966 if TriggerType
<> TRIGGER_SHOT
then
968 Result
:= (trigData
.trigShotAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
969 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
970 if Result
and (trigData
.trigShotAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
971 Result
:= g_TraceVector(trigData
.trigShotPos
.X
,
972 trigData
.trigShotPos
.Y
,
973 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
974 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
978 function ActivateTrigger(var Trigger
: TTrigger
; actType
: Byte): Boolean;
983 idx
, k
, wx
, wy
, xd
, yd
: Integer;
994 function monsShotTarget (mon
: TMonster
): Boolean;
996 result
:= false; // don't stop
997 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
999 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1000 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1001 TargetUID
:= mon
.UID
;
1002 result
:= true; // stop
1006 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1008 result
:= false; // don't stop
1009 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1011 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1012 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1013 TargetUID
:= mon
.UID
;
1014 result
:= true; // stop
1018 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1020 result
:= false; // don't stop
1021 if mon
.Live
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1023 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1024 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1025 TargetUID
:= mon
.UID
;
1026 result
:= true; // stop
1032 if g_Game_IsClient
then
1035 if not Trigger
.Enabled
then
1037 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1039 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
1044 coolDown
:= (actType
<> 0);
1051 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1052 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1053 gExitByTrigger
:= True;
1054 g_Game_ExitLevel(trigData
.trigMapName
);
1063 Result
:= tr_Teleport(ActivateUID
,
1064 trigData
.trigTargetPoint
.X
, trigData
.trigTargetPoint
.Y
,
1065 trigData
.trigTlpDir
, trigData
.trigsilent_teleport
,
1066 trigData
.trigd2d_teleport
);
1072 Result
:= tr_OpenDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1078 Result
:= tr_CloseDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1082 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1084 if trigPanelID
<> -1 then
1086 if gWalls
[trigPanelID
].Enabled
then
1088 Result
:= tr_OpenDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1090 if TriggerType
= TRIGGER_DOOR5
then
1094 Result
:= tr_CloseDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1101 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1103 tr_CloseTrap(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1105 if TriggerType
= TRIGGER_TRAP
then
1119 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1121 PressCount
:= PressCount
+ 1;
1123 if PressTime
= -1 then
1124 PressTime
:= trigData
.trigWait
;
1134 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1138 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1140 g_Player_Get(ActivateUID
).GetSecret();
1141 Inc(gCoopSecretsFound
);
1142 if g_Game_IsNet
then MH_SEND_GameStats();
1148 Result
:= tr_SetLift(trigPanelID
, 0, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1151 if (not trigData
.trigNoSound
) and Result
then begin
1152 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1154 Y
+ (Height
div 2));
1155 if g_Game_IsServer
and g_Game_IsNet
then
1156 MH_SEND_Sound(X
+ (Width
div 2),
1158 'SOUND_GAME_SWITCH0');
1164 Result
:= tr_SetLift(trigPanelID
, 1, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1167 if (not trigData
.trigNoSound
) and Result
then begin
1168 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1170 Y
+ (Height
div 2));
1171 if g_Game_IsServer
and g_Game_IsNet
then
1172 MH_SEND_Sound(X
+ (Width
div 2),
1174 'SOUND_GAME_SWITCH0');
1180 Result
:= tr_SetLift(trigPanelID
, 3, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
1186 if (not trigData
.trigNoSound
) and Result
then begin
1187 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1189 Y
+ (Height
div 2));
1190 if g_Game_IsServer
and g_Game_IsNet
then
1191 MH_SEND_Sound(X
+ (Width
div 2),
1193 'SOUND_GAME_SWITCH0');
1200 if trigData
.trigActivateOnce
then
1203 TriggerType
:= TRIGGER_NONE
;
1211 animonce
:= trigData
.trigAnimOnce
;
1217 if Sound
<> nil then
1219 if trigData
.trigSoundSwitch
and Sound
.IsPlaying() then
1220 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1222 SoundPlayCount
:= 0;
1225 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1226 if (trigData
.trigPlayCount
> 0) or (not Sound
.IsPlaying()) then
1228 if trigData
.trigPlayCount
> 0 then
1229 SoundPlayCount
:= trigData
.trigPlayCount
1230 else // 0 - èãðàåì áåñêîíå÷íî
1231 SoundPlayCount
:= 1;
1234 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1238 TRIGGER_SPAWNMONSTER
:
1239 if (trigData
.trigMonType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1242 if (trigData
.trigMonDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1244 AutoSpawn
:= not AutoSpawn
;
1246 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1250 if ((trigData
.trigMonDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1251 or ((trigData
.trigMonDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1252 for k
:= 1 to trigData
.trigMonCount
do
1254 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigMonDelay
> 0) then
1255 SpawnCooldown
:= trigData
.trigMonDelay
;
1256 if (trigData
.trigMonMax
> 0) and (SpawnedCount
>= trigData
.trigMonMax
) then
1259 mon
:= g_Monsters_Create(trigData
.trigMonType
,
1260 trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
,
1261 TDirection(trigData
.trigMonDir
), True);
1266 if (trigData
.trigMonHealth
> 0) then
1267 mon
.SetHealth(trigData
.trigMonHealth
);
1268 // Óñòàíàâëèâàåì ïîâåäåíèå:
1269 mon
.MonsterBehaviour
:= trigData
.trigMonBehav
;
1270 mon
.FNoRespawn
:= True;
1271 if g_Game_IsNet
then
1272 MH_SEND_MonsterSpawn(mon
.UID
);
1273 // Èäåì èñêàòü öåëü, åñëè íàäî:
1274 if trigData
.trigMonActive
then
1277 if trigData
.trigMonType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1279 if g_Game_IsNet
then
1281 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1282 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1285 if trigData
.trigMonMax
> 0 then
1287 mon
.SpawnTrigger
:= ID
;
1291 case trigData
.trigMonEffect
of
1292 EFFECT_TELEPORT
: begin
1293 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1295 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1296 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1297 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1298 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1301 if g_Game_IsServer
and g_Game_IsNet
then
1302 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1303 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1306 EFFECT_RESPAWN
: begin
1307 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1309 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1310 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1311 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1312 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1315 if g_Game_IsServer
and g_Game_IsNet
then
1316 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1317 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1321 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1323 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1324 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigMonPos
.X
, trigData
.trigMonPos
.Y
);
1325 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1326 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1329 if g_Game_IsServer
and g_Game_IsNet
then
1330 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1331 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1336 if g_Game_IsNet
then
1338 MH_SEND_GameStats();
1339 MH_SEND_CoopStats();
1346 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1347 if actType
= ACTIVATE_CUSTOM
then
1352 if (trigData
.trigItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1355 if (trigData
.trigItemDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1357 AutoSpawn
:= not AutoSpawn
;
1359 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1363 if ((trigData
.trigItemDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1364 or ((trigData
.trigItemDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1365 if (not trigData
.trigItemOnlyDM
) or
1366 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1367 for k
:= 1 to trigData
.trigItemCount
do
1369 if (actType
= ACTIVATE_CUSTOM
) and (trigData
.trigItemDelay
> 0) then
1370 SpawnCooldown
:= trigData
.trigItemDelay
;
1371 if (trigData
.trigItemMax
> 0) and (SpawnedCount
>= trigData
.trigItemMax
) then
1374 iid
:= g_Items_Create(trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
,
1375 trigData
.trigItemType
, trigData
.trigItemFalls
, False, True);
1379 if trigData
.trigItemMax
> 0 then
1381 it
:= g_Items_ByIdx(iid
);
1382 it
.SpawnTrigger
:= ID
;
1386 case trigData
.trigItemEffect
of
1387 EFFECT_TELEPORT
: begin
1388 it
:= g_Items_ByIdx(iid
);
1389 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1391 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1392 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1393 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1394 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1397 if g_Game_IsServer
and g_Game_IsNet
then
1398 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1399 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1402 EFFECT_RESPAWN
: begin
1403 it
:= g_Items_ByIdx(iid
);
1404 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1406 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1407 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1408 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1409 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1412 if g_Game_IsServer
and g_Game_IsNet
then
1413 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1414 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1418 it
:= g_Items_ByIdx(iid
);
1419 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1421 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1422 g_Sound_PlayExAt('SOUND_FIRE', trigData
.trigItemPos
.X
, trigData
.trigItemPos
.Y
);
1423 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1424 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1427 if g_Game_IsServer
and g_Game_IsNet
then
1428 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1429 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1434 if g_Game_IsNet
then
1435 MH_SEND_ItemSpawn(True, iid
);
1442 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1443 if actType
= ACTIVATE_CUSTOM
then
1449 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1450 if (Trigger
.trigData
.trigMusicName
<> '') then
1452 gMusic
.SetByName(Trigger
.trigData
.trigMusicName
);
1453 gMusic
.SpecPause
:= True;
1457 if Trigger
.trigData
.trigMusicAction
= 1 then
1459 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1460 gMusic
.SpecPause
:= False
1461 else // Èãðàëà => ñíà÷àëà
1462 gMusic
.SetPosition(0);
1467 gMusic
.SpecPause
:= True;
1475 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1480 pAngle
:= -DegToRad(trigData
.trigPushAngle
);
1481 Result
:= tr_Push(ActivateUID
,
1482 Floor(Cos(pAngle
)*trigData
.trigPushForce
),
1483 Floor(Sin(pAngle
)*trigData
.trigPushForce
),
1484 trigData
.trigResetVel
);
1491 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1492 if (trigData
.trigScoreAction
in [0..1]) and (trigData
.trigScoreCount
> 0) then
1494 // Ñâîåé èëè ÷óæîé êîìàíäå
1495 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1497 p
:= g_Player_Get(ActivateUID
);
1498 if ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1499 or ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1501 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1503 if trigData
.trigScoreCon
then
1504 if trigData
.trigScoreTeam
= 0 then
1506 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1507 if g_Game_IsServer
and g_Game_IsNet
then
1508 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+r');
1511 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1512 if g_Game_IsServer
and g_Game_IsNet
then
1513 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+re');
1516 if trigData
.trigScoreMsg
then
1518 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1519 if g_Game_IsServer
and g_Game_IsNet
then
1520 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1523 if ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
))
1524 or ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1526 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1528 if trigData
.trigScoreCon
then
1529 if trigData
.trigScoreTeam
= 0 then
1531 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1532 if g_Game_IsServer
and g_Game_IsNet
then
1533 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-r');
1536 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1537 if g_Game_IsServer
and g_Game_IsNet
then
1538 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-re');
1541 if trigData
.trigScoreMsg
then
1543 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1544 if g_Game_IsServer
and g_Game_IsNet
then
1545 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1548 if ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1549 or ((trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1551 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1553 if trigData
.trigScoreCon
then
1554 if trigData
.trigScoreTeam
= 0 then
1556 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1557 if g_Game_IsServer
and g_Game_IsNet
then
1558 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+b');
1561 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1562 if g_Game_IsServer
and g_Game_IsNet
then
1563 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '+be');
1566 if trigData
.trigScoreMsg
then
1568 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1569 if g_Game_IsServer
and g_Game_IsNet
then
1570 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1573 if ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
))
1574 or ((trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1576 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1578 if trigData
.trigScoreCon
then
1579 if trigData
.trigScoreTeam
= 0 then
1581 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1582 if g_Game_IsServer
and g_Game_IsNet
then
1583 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-b');
1586 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, trigData
.trigScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1587 if g_Game_IsServer
and g_Game_IsNet
then
1588 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (trigData
.trigScoreCount
shl 16), '-be');
1591 if trigData
.trigScoreMsg
then
1593 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1594 if g_Game_IsServer
and g_Game_IsNet
then
1595 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1598 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1600 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1601 if trigData
.trigScoreTeam
in [2..3] then
1603 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 2) then
1605 Inc(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Scores
1607 if trigData
.trigScoreCon
then
1609 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1610 if g_Game_IsServer
and g_Game_IsNet
then
1611 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tr');
1614 if trigData
.trigScoreMsg
then
1616 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1617 if g_Game_IsServer
and g_Game_IsNet
then
1618 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1621 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 2) then
1623 Dec(gTeamStat
[TEAM_RED
].Goals
, trigData
.trigScoreCount
); // Red Fouls
1625 if trigData
.trigScoreCon
then
1627 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], trigData
.trigScoreCount
]), True);
1628 if g_Game_IsServer
and g_Game_IsNet
then
1629 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tr');
1632 if trigData
.trigScoreMsg
then
1634 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1635 if g_Game_IsServer
and g_Game_IsNet
then
1636 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1639 if (trigData
.trigScoreAction
= 0) and (trigData
.trigScoreTeam
= 3) then
1641 Inc(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Scores
1643 if trigData
.trigScoreCon
then
1645 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1646 if g_Game_IsServer
and g_Game_IsNet
then
1647 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '+tb');
1650 if trigData
.trigScoreMsg
then
1652 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1653 if g_Game_IsServer
and g_Game_IsNet
then
1654 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1657 if (trigData
.trigScoreAction
= 1) and (trigData
.trigScoreTeam
= 3) then
1659 Dec(gTeamStat
[TEAM_BLUE
].Goals
, trigData
.trigScoreCount
); // Blue Fouls
1661 if trigData
.trigScoreCon
then
1663 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], trigData
.trigScoreCount
]), True);
1664 if g_Game_IsServer
and g_Game_IsNet
then
1665 MH_SEND_GameEvent(NET_EV_SCORE
, trigData
.trigScoreCount
shl 16, '-tb');
1668 if trigData
.trigScoreMsg
then
1670 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1671 if g_Game_IsServer
and g_Game_IsNet
then
1672 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1679 if (trigData
.trigScoreAction
= 2) and (gGameSettings
.GoalLimit
> 0) then
1681 // Ñâîåé èëè ÷óæîé êîìàíäû
1682 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1684 p
:= g_Player_Get(ActivateUID
);
1685 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Red Wins
1686 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1687 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1689 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1691 if trigData
.trigScoreCon
then
1692 if trigData
.trigScoreTeam
= 0 then
1694 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1695 if g_Game_IsServer
and g_Game_IsNet
then
1696 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1699 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1700 if g_Game_IsServer
and g_Game_IsNet
then
1701 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1706 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1707 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1708 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1710 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1712 if trigData
.trigScoreCon
then
1713 if trigData
.trigScoreTeam
= 0 then
1715 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1716 if g_Game_IsServer
and g_Game_IsNet
then
1717 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1720 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1721 if g_Game_IsServer
and g_Game_IsNet
then
1722 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1728 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1729 if trigData
.trigScoreTeam
in [2..3] then
1731 if trigData
.trigScoreTeam
= 2 then // Red Wins
1732 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1734 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1737 if trigData
.trigScoreTeam
= 3 then // Blue Wins
1738 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1740 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1746 if (trigData
.trigScoreAction
= 3) and (gGameSettings
.GoalLimit
> 0) then
1748 // Ñâîåé èëè ÷óæîé êîìàíäû
1749 if (trigData
.trigScoreTeam
in [0..1]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1751 p
:= g_Player_Get(ActivateUID
);
1752 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1753 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_RED
)) then
1754 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1756 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1758 if trigData
.trigScoreCon
then
1759 if trigData
.trigScoreTeam
= 0 then
1761 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1762 if g_Game_IsServer
and g_Game_IsNet
then
1763 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1766 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1767 if g_Game_IsServer
and g_Game_IsNet
then
1768 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1773 if ((trigData
.trigScoreTeam
= 0) and (p
.Team
= TEAM_RED
)) // Blue Wins
1774 or ((trigData
.trigScoreTeam
= 1) and (p
.Team
= TEAM_BLUE
)) then
1775 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1777 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1779 if trigData
.trigScoreCon
then
1780 if trigData
.trigScoreTeam
= 0 then
1782 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1783 if g_Game_IsServer
and g_Game_IsNet
then
1784 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1787 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1788 if g_Game_IsServer
and g_Game_IsNet
then
1789 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1795 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1796 if trigData
.trigScoreTeam
in [2..3] then
1798 if trigData
.trigScoreTeam
= 3 then // Red Wins
1799 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1801 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1804 if trigData
.trigScoreTeam
= 2 then // Blue Wins
1805 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1807 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1812 if Result
then begin
1817 if g_Game_IsServer
and g_Game_IsNet
then
1824 Result
:= tr_Message(trigData
.trigMessageKind
, trigData
.trigMessageText
,
1825 trigData
.trigMessageSendTo
, trigData
.trigMessageTime
,
1830 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
1833 UIDType
:= g_GetUIDType(ActivateUID
);
1834 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
1840 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1841 for idx
:= 0 to High(Activators
) do
1842 if Activators
[idx
].UID
= ActivateUID
then
1848 begin // Âèäèì åãî âïåðâûå
1850 SetLength(Activators
, Length(Activators
) + 1);
1851 k
:= High(Activators
);
1852 Activators
[k
].UID
:= ActivateUID
;
1854 begin // Óæå âèäåëè åãî
1855 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1856 if (trigData
.trigDamageInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
1857 Activators
[k
].TimeOut
:= 65535;
1858 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1859 Result
:= Activators
[k
].TimeOut
= 0;
1868 p
:= g_Player_Get(ActivateUID
);
1872 // Íàíîñèì óðîí èãðîêó
1873 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1874 p
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1877 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1878 if p
.Heal(trigData
.trigHealValue
, not trigData
.trigHealMax
) and (not trigData
.trigHealSilent
) then
1880 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
1881 if g_Game_IsServer
and g_Game_IsNet
then
1882 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1888 m
:= g_Monsters_ByUID(ActivateUID
);
1892 // Íàíîñèì óðîí ìîíñòðó
1893 if (TriggerType
= TRIGGER_DAMAGE
) and (trigData
.trigDamageValue
> 0) then
1894 m
.Damage(trigData
.trigDamageValue
, 0, 0, 0, HIT_SOME
);
1897 if (TriggerType
= TRIGGER_HEALTH
) and (trigData
.trigHealValue
> 0) then
1898 if m
.Heal(trigData
.trigHealValue
) and (not trigData
.trigHealSilent
) then
1900 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
1901 if g_Game_IsServer
and g_Game_IsNet
then
1902 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
1906 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1907 if TriggerType
= TRIGGER_DAMAGE
then
1908 idx
:= trigData
.trigDamageInterval
1910 idx
:= trigData
.trigHealInterval
;
1913 Activators
[k
].TimeOut
:= idx
1915 Activators
[k
].TimeOut
:= 65535;
1923 if ShotSightTime
> 0 then
1926 // put this at the beginning so it doesn't trigger itself
1927 TimeOut
:= trigData
.trigShotWait
+ 1;
1929 wx
:= trigData
.trigShotPos
.X
;
1930 wy
:= trigData
.trigShotPos
.Y
;
1931 pAngle
:= -DegToRad(trigData
.trigShotAngle
);
1932 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
1933 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
1936 case trigData
.trigShotTarget
of
1937 TRIGGER_SHOT_TARGET_MON
: // monsters
1938 //TODO: accelerate this!
1939 g_Mons_ForEachAlive(monsShotTarget
);
1941 TRIGGER_SHOT_TARGET_PLR
: // players
1942 if gPlayers
<> nil then
1943 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1944 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1945 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1947 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1948 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1949 TargetUID
:= gPlayers
[idx
].UID
;
1953 TRIGGER_SHOT_TARGET_RED
: // red team
1954 if gPlayers
<> nil then
1955 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1956 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1957 (gPlayers
[idx
].Team
= TEAM_RED
) and
1958 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1960 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1961 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1962 TargetUID
:= gPlayers
[idx
].UID
;
1966 TRIGGER_SHOT_TARGET_BLUE
: // blue team
1967 if gPlayers
<> nil then
1968 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1969 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1970 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
1971 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1973 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1974 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1975 TargetUID
:= gPlayers
[idx
].UID
;
1979 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
1981 //TODO: accelerate this!
1982 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
1984 if (TargetUID
= 0) and (gPlayers
<> nil) then
1985 for idx
:= Low(gPlayers
) to High(gPlayers
) do
1986 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
1987 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
1989 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
1990 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
1991 TargetUID
:= gPlayers
[idx
].UID
;
1996 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
1998 if gPlayers
<> nil then
1999 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2000 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].Live
and
2001 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2003 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2004 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2005 TargetUID
:= gPlayers
[idx
].UID
;
2008 if TargetUID
= 0 then
2010 //TODO: accelerate this!
2011 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2016 if (trigData
.trigShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2017 (trigData
.trigShotType
<> TRIGGER_SHOT_REV
) then
2018 TargetUID
:= ActivateUID
;
2022 if (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2023 ((trigData
.trigShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2026 if (trigData
.trigShotIntSight
= 0) or
2027 (trigData
.trigShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2028 (TargetUID
= ShotSightTarget
) then
2029 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2032 ShotSightTime
:= trigData
.trigShotIntSight
;
2033 ShotSightTargetN
:= TargetUID
;
2034 if trigData
.trigShotType
= TRIGGER_SHOT_BFG
then
2036 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2037 if g_Game_IsNet
and g_Game_IsServer
then
2038 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2046 idx
:= trigData
.trigFXCount
;
2050 case trigData
.trigFXPos
of
2051 TRIGGER_EFFECT_POS_CENTER
:
2053 wx
:= X
+ Width
div 2;
2054 wy
:= Y
+ Height
div 2;
2056 TRIGGER_EFFECT_POS_AREA
:
2058 wx
:= X
+ Random(Width
);
2059 wy
:= Y
+ Random(Height
);
2062 wx
:= X
+ Width
div 2;
2063 wy
:= Y
+ Height
div 2;
2066 xd
:= trigData
.trigFXVelX
;
2067 yd
:= trigData
.trigFXVelY
;
2068 if trigData
.trigFXSpreadL
> 0 then xd
:= xd
- Random(trigData
.trigFXSpreadL
+ 1);
2069 if trigData
.trigFXSpreadR
> 0 then xd
:= xd
+ Random(trigData
.trigFXSpreadR
+ 1);
2070 if trigData
.trigFXSpreadU
> 0 then yd
:= yd
- Random(trigData
.trigFXSpreadU
+ 1);
2071 if trigData
.trigFXSpreadD
> 0 then yd
:= yd
+ Random(trigData
.trigFXSpreadD
+ 1);
2072 tr_MakeEffect(wx
, wy
, xd
, yd
,
2073 trigData
.trigFXType
, trigData
.trigFXSubType
,
2074 trigData
.trigFXColorR
, trigData
.trigFXColorG
, trigData
.trigFXColorB
, True, False);
2077 TimeOut
:= trigData
.trigFXWait
;
2082 if Result
and (Trigger
.TexturePanel
<> -1) then
2083 g_Map_SwitchTexture(Trigger
.TexturePanelType
, Trigger
.TexturePanel
, IfThen(animonce
, 2, 1));
2086 function g_Triggers_Create(Trigger
: TTrigger
): DWORD
;
2091 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2092 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2093 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2094 Trigger
.TriggerType
:= TRIGGER_NONE
;
2096 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2097 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2098 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2099 (gGameSettings
.GameType
<> GT_SINGLE
) then
2100 Trigger
.TriggerType
:= TRIGGER_NONE
;
2102 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2103 if Trigger
.TriggerType
= TRIGGER_SECRET
then
2104 gSecretsCount
:= gSecretsCount
+ 1;
2106 find_id
:= FindTrigger();
2107 gTriggers
[find_id
] := Trigger
;
2109 writeln('trigger #', find_id
, ': pos=(', Trigger
.x
, ',', Trigger
.y
, ')-(', Trigger
.width
, 'x', Trigger
.height
, ')',
2110 '; TexturePanel=', Trigger
.TexturePanel
,
2111 '; TexturePanelType=', Trigger
.TexturePanelType
,
2112 '; ShotPanelType=', Trigger
.ShotPanelType
,
2113 '; TriggerType=', Trigger
.TriggerType
,
2114 '; ActivateType=', Trigger
.ActivateType
,
2115 '; Keys=', Trigger
.Keys
,
2116 '; trigPanelId=', Trigger
.trigPanelId
,
2117 '; trigShotPanelId=', Trigger
.trigShotPanelId
2120 with gTriggers
[find_id
] do
2123 // if this type of trigger exists both on the client and on the server
2124 // use an uniform numeration
2125 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2127 Inc(gTriggerClientID
);
2128 ClientID
:= gTriggerClientID
;
2134 PlayerCollide
:= False;
2138 SoundPlayCount
:= 0;
2145 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2146 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and
2147 (Trigger
.trigData
.trigSoundName
<> '') then
2149 // Åùå íåò òàêîãî çâóêà:
2150 if not g_Sound_Exists(Trigger
.trigData
.trigSoundName
) then
2152 fn
:= g_ExtractWadName(Trigger
.trigData
.trigSoundName
);
2155 begin // Çâóê â ôàéëå ñ êàðòîé
2156 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2157 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigSoundName
);
2159 else // Çâóê â îòäåëüíîì ôàéëå
2160 fn
:= GameDir
+ '/wads/' + Trigger
.trigData
.trigSoundName
;
2162 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigSoundName
, fn
) then
2163 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigSoundName
]));
2166 // Ñîçäàåì îáúåêò çâóêà:
2167 with gTriggers
[find_id
] do
2169 Sound
:= TPlayableSound
.Create();
2170 if not Sound
.SetByName(Trigger
.trigData
.trigSoundName
) then
2178 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2179 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and
2180 (Trigger
.trigData
.trigMusicName
<> '') then
2182 // Åùå íåò òàêîé ìóçûêè:
2183 if not g_Sound_Exists(Trigger
.trigData
.trigMusicName
) then
2185 fn
:= g_ExtractWadName(Trigger
.trigData
.trigMusicName
);
2188 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2189 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2190 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.trigData
.trigMusicName
);
2192 else // Ìóçûêà â ôàéëå ñ êàðòîé
2193 fn
:= GameDir
+'/wads/'+Trigger
.trigData
.trigMusicName
;
2195 if not g_Sound_CreateWADEx(Trigger
.trigData
.trigMusicName
, fn
, True) then
2196 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.trigData
.trigMusicName
]));
2200 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2201 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2202 with gTriggers
[find_id
] do
2206 ShotSightTimeout
:= 0;
2207 ShotSightTarget
:= 0;
2208 ShotSightTargetN
:= 0;
2209 ShotAmmoCount
:= Trigger
.trigData
.trigShotAmmo
;
2210 ShotReloadTime
:= 0;
2217 // sorry; grid doesn't support recursive queries, so we have to do this
2219 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2222 tgMonsList
: TSimpleMonsterList
= nil;
2224 procedure g_Triggers_Update();
2227 Affected
: array of Integer;
2229 function monsNear (mon
: TMonster
): Boolean;
2231 result
:= false; // don't stop
2233 gTriggers[a].ActivateUID := mon.UID;
2234 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2236 tgMonsList
.append(mon
);
2242 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2244 if gTriggers
= nil then
2246 SetLength(Affected
, 0);
2248 for a
:= 0 to High(gTriggers
) do
2249 with gTriggers
[a
] do
2251 if TriggerType
<> TRIGGER_NONE
then
2253 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè):
2254 if DoorTime
> 0 then
2255 DoorTime
:= DoorTime
- 1;
2256 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ:
2257 if PressTime
> 0 then
2258 PressTime
:= PressTime
- 1;
2259 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2260 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2261 for b
:= 0 to High(Activators
) do
2263 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2264 if Activators
[b
].TimeOut
> 0 then
2265 Dec(Activators
[b
].TimeOut
)
2268 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2269 if (trigData
.trigDamageInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then
2270 Activators
[b
].TimeOut
:= 0;
2273 // Îáðàáàòûâàåì ñïàâíåðû:
2274 if Enabled
and AutoSpawn
then
2275 if SpawnCooldown
= 0 then
2277 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà:
2278 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (trigData
.trigMonDelay
> 0) then
2281 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2283 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò:
2284 if (TriggerType
= TRIGGER_SPAWNITEM
) and (trigData
.trigItemDelay
> 0) then
2287 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2289 end else // Óìåíüøàåì âðåìÿ îæèäàíèÿ:
2292 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü":
2293 if TriggerType
= TRIGGER_SHOT
then
2295 if ShotPanelTime
> 0 then
2298 if ShotPanelTime
= 0 then
2299 g_Map_SwitchTexture(ShotPanelType
, trigShotPanelID
);
2301 if ShotSightTime
> 0 then
2304 if ShotSightTime
= 0 then
2305 ShotSightTarget
:= ShotSightTargetN
;
2307 if ShotSightTimeout
> 0 then
2309 Dec(ShotSightTimeout
);
2310 if ShotSightTimeout
= 0 then
2311 ShotSightTarget
:= 0;
2313 if ShotReloadTime
> 0 then
2315 Dec(ShotReloadTime
);
2316 if ShotReloadTime
= 0 then
2317 ShotAmmoCount
:= trigData
.trigShotAmmo
;
2321 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì:
2322 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2323 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2325 if trigData
.trigPlayCount
> 0 then // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2326 SoundPlayCount
:= SoundPlayCount
- 1;
2327 if trigData
.trigLocal
then
2328 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), trigData
.trigVolume
/255.0)
2330 Sound
.PlayPanVolume((trigData
.trigPan
-127.0)/128.0, trigData
.trigVolume
/255.0);
2331 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then
2332 MH_SEND_TriggerSound(gTriggers
[a
]);
2335 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü:
2336 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (trigPanelID
<> -1) then
2338 tr_OpenDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
);
2342 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü:
2343 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (trigPanelID
<> -1) then
2346 if gWalls
[trigPanelID
].Enabled
then
2348 else // Ïîêà îòêðûòà - çàêðûâàåì
2349 if tr_CloseDoor(trigPanelID
, trigData
.trigNoSound
, trigData
.trigd2d_doors
) then
2353 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2354 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2355 (PressTime
= 0) and (PressCount
>= trigData
.trigCount
) then
2357 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2359 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2360 if trigData
.trigCount
> 0 then
2361 PressCount
:= PressCount
- trigData
.trigCount
2365 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2366 for b
:= 0 to High(gTriggers
) do
2367 if g_Collide(trigData
.trigtX
, trigData
.trigtY
, trigData
.trigtWidth
, trigData
.trigtHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2368 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2369 ((b
<> a
) or (trigData
.trigWait
> 0)) then
2370 begin // Can be self-activated, if there is Data.Wait
2371 if (not trigData
.trigExtRandom
) or gTriggers
[b
].Enabled
then
2373 SetLength(Affected
, Length(Affected
) + 1);
2374 Affected
[High(Affected
)] := b
;
2377 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2378 if (TriggerType
= TRIGGER_PRESS
) and trigData
.trigExtRandom
then
2380 if (Length(Affected
) > 0) then
2382 b
:= Affected
[Random(Length(Affected
))];
2383 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2384 ActivateTrigger(gTriggers
[b
], 0);
2387 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2388 for i
:= 0 to High(Affected
) do
2394 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2395 ActivateTrigger(gTriggers
[b
], 0);
2399 gTriggers
[b
].Enabled
:= True;
2403 gTriggers
[b
].Enabled
:= False;
2404 gTriggers
[b
].TimeOut
:= 0;
2405 if gTriggers
[b
].AutoSpawn
then
2407 gTriggers
[b
].AutoSpawn
:= False;
2408 gTriggers
[b
].SpawnCooldown
:= 0;
2413 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2414 if not gTriggers
[b
].Enabled
then
2416 gTriggers
[b
].TimeOut
:= 0;
2417 if gTriggers
[b
].AutoSpawn
then
2419 gTriggers
[b
].AutoSpawn
:= False;
2420 gTriggers
[b
].SpawnCooldown
:= 0;
2426 SetLength(Affected
, 0);
2429 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2432 TimeOut
:= TimeOut
- 1;
2433 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2436 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2441 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2443 if gPlayers
<> nil then
2444 for b
:= 0 to High(gPlayers
) do
2445 if gPlayers
[b
] <> nil then
2447 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2448 if Live
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2449 Collide(X
, Y
, Width
, Height
) then
2451 gTriggers
[a
].ActivateUID
:= UID
;
2453 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2455 { Don't activate sound/music again if player is here }
2457 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2460 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2462 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2463 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2464 (TimeOut
= 0) and (Keys
= 0) then
2466 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2467 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2468 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2469 gTriggers
[a
].ActivateUID
:= 0;
2470 ActivateTrigger(gTriggers
[a
], 0);
2474 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2475 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2477 //g_Mons_ForEach(monsNear);
2480 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2481 for mon
in tgMonsList
do
2483 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2484 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2486 tgMonsList
.reset(); // just in case
2490 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2491 (TimeOut
= 0) and (Keys
= 0) then
2492 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2494 gTriggers
[a
].ActivateUID
:= 0;
2495 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2499 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2503 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2505 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2506 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2509 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2510 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2518 if gTriggers
= nil then Exit
;
2520 case g_GetUIDType(UID
) of
2524 p
:= g_Player_Get(UID
);
2533 for a
:= 0 to High(gTriggers
) do
2534 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2535 (gTriggers
[a
].TimeOut
= 0) and
2536 (not InDWArray(a
, IgnoreList
)) and
2537 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2538 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2539 if g_Collide(X
, Y
, Width
, Height
,
2540 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2541 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2543 gTriggers
[a
].ActivateUID
:= UID
;
2544 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2546 SetLength(Result
, Length(Result
)+1);
2547 Result
[High(Result
)] := a
;
2552 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2558 if gTriggers
= nil then Exit
;
2560 case g_GetUIDType(UID
) of
2564 p
:= g_Player_Get(UID
);
2573 for a
:= 0 to High(gTriggers
) do
2574 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2575 (gTriggers
[a
].TimeOut
= 0) and
2576 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2577 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2578 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2579 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2581 gTriggers
[a
].ActivateUID
:= UID
;
2582 ActivateTrigger(gTriggers
[a
], ActivateType
);
2586 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
2593 if gTriggers
= nil then
2596 case g_GetUIDType(UID
) of
2600 p
:= g_Player_Get(UID
);
2609 rsq
:= Radius
* Radius
;
2611 for a
:= 0 to High(gTriggers
) do
2612 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
2613 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2614 (gTriggers
[a
].TimeOut
= 0) and
2615 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2616 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2617 with gTriggers
[a
] do
2618 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
2619 X
, Y
, Width
, Height
) then
2620 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2621 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2622 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2623 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2624 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
2625 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2626 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
2627 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2630 ActivateTrigger(gTriggers
[a
], ActivateType
);
2634 procedure g_Triggers_OpenAll();
2639 if gTriggers
= nil then Exit
;
2642 for a
:= 0 to High(gTriggers
) do
2643 with gTriggers
[a
] do
2644 if (TriggerType
= TRIGGER_OPENDOOR
) or
2645 (TriggerType
= TRIGGER_DOOR5
) or
2646 (TriggerType
= TRIGGER_DOOR
) then
2648 tr_OpenDoor(trigPanelID
, True, trigData
.trigd2d_doors
);
2649 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
2653 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2656 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
2658 if (gTriggers
<> nil) then
2659 if gTriggers
[ID
].SpawnedCount
> 0 then
2660 Dec(gTriggers
[ID
].SpawnedCount
);
2663 procedure g_Triggers_Free();
2667 for a
:= 0 to High(gTriggers
) do
2669 gTriggers
[a
].trigData
.Free();
2670 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
2672 if g_Sound_Exists(gTriggers
[a
].trigData
.trigSoundName
) then
2674 g_Sound_Delete(gTriggers
[a
].trigData
.trigSoundName
);
2676 gTriggers
[a
].Sound
.Free();
2678 if (gTriggers
[a
].Activators
<> nil) then
2680 SetLength(gTriggers
[a
].Activators
, 0);
2686 SetLength(gMonstersSpawned
, 0);
2689 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
2691 count
, act_count
, i
, j
: Integer;
2697 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ:
2699 if gTriggers
<> nil then
2700 for i
:= 0 to High(gTriggers
) do
2703 Mem
:= TBinMemoryWriter
.Create((count
+1) * 200);
2705 // Êîëè÷åñòâî òðèããåðîâ:
2706 Mem
.WriteInt(count
);
2711 for i
:= 0 to High(gTriggers
) do
2713 // Ñèãíàòóðà òðèããåðà:
2714 dw
:= TRIGGER_SIGNATURE
; // 'TRGR'
2717 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
2718 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2720 //p := @gTriggers[i].Data;
2721 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2722 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2723 Mem
.WriteInt(gTriggers
[i
].X
);
2724 Mem
.WriteInt(gTriggers
[i
].Y
);
2726 Mem
.WriteWord(gTriggers
[i
].Width
);
2727 Mem
.WriteWord(gTriggers
[i
].Height
);
2728 // Âêëþ÷åí ëè òðèããåð:
2729 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
2730 // Òèï àêòèâàöèè òðèããåðà:
2731 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
2732 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2733 Mem
.WriteByte(gTriggers
[i
].Keys
);
2734 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2735 Mem
.WriteInt(gTriggers
[i
].TexturePanel
);
2737 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
2738 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2739 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
2740 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2741 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
2742 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2743 act_count
:= Length(gTriggers
[i
].Activators
);
2744 Mem
.WriteInt(act_count
);
2745 for j
:= 0 to act_count
-1 do
2748 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
2750 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2752 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2753 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
2754 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2755 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
2756 // Çàäåðæêà àêòèâàöèè:
2757 Mem
.WriteInt(gTriggers
[i
].PressTime
);
2759 Mem
.WriteInt(gTriggers
[i
].PressCount
);
2761 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
2762 // Çàäåðæêà ñïàâíåðà:
2763 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
2764 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2765 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
2766 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2767 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
2768 // Ïðîèãðûâàåòñÿ ëè çâóê?
2769 if gTriggers
[i
].Sound
<> nil then
2770 b
:= gTriggers
[i
].Sound
.IsPlaying()
2773 Mem
.WriteBoolean(b
);
2776 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2777 dw
:= gTriggers
[i
].Sound
.GetPosition();
2780 sg
:= gTriggers
[i
].Sound
.GetVolume();
2781 sg
:= sg
/ (gSoundLevel
/255.0);
2782 Mem
.WriteSingle(sg
);
2783 // Ñòåðåî ñìåùåíèå çâóêà:
2784 sg
:= gTriggers
[i
].Sound
.GetPan();
2785 Mem
.WriteSingle(sg
);
2790 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
2792 count
, act_count
, i
, j
, a
: Integer;
2804 // Êîëè÷åñòâî òðèããåðîâ:
2810 for a
:= 0 to count
-1 do
2812 // Ñèãíàòóðà òðèããåðà:
2814 if dw
<> TRIGGER_SIGNATURE
then // 'TRGR'
2816 raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2819 Mem
.ReadByte(Trig
.TriggerType
);
2820 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2823 Mem.ReadMemory(p, dw);
2824 if dw <> SizeOf(TTriggerData) then
2826 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2828 Trig.Data := TTriggerData(p^);
2831 i
:= g_Triggers_Create(Trig
);
2832 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2833 Mem
.ReadInt(gTriggers
[i
].X
);
2834 Mem
.ReadInt(gTriggers
[i
].Y
);
2836 Mem
.ReadWord(gTriggers
[i
].Width
);
2837 Mem
.ReadWord(gTriggers
[i
].Height
);
2838 // Âêëþ÷åí ëè òðèããåð:
2839 Mem
.ReadBoolean(gTriggers
[i
].Enabled
);
2840 // Òèï àêòèâàöèè òðèããåðà:
2841 Mem
.ReadByte(gTriggers
[i
].ActivateType
);
2842 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2843 Mem
.ReadByte(gTriggers
[i
].Keys
);
2844 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2845 Mem
.ReadInt(gTriggers
[i
].TexturePanel
);
2847 Mem
.ReadWord(gTriggers
[i
].TexturePanelType
);
2848 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2849 Mem
.ReadWord(gTriggers
[i
].TimeOut
);
2850 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2851 Mem
.ReadWord(gTriggers
[i
].ActivateUID
);
2852 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2853 Mem
.ReadInt(act_count
);
2854 if act_count
> 0 then
2856 SetLength(gTriggers
[i
].Activators
, act_count
);
2857 for j
:= 0 to act_count
-1 do
2860 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
2862 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
2865 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2866 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
2867 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2868 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
2869 // Çàäåðæêà àêòèâàöèè:
2870 Mem
.ReadInt(gTriggers
[i
].PressTime
);
2872 Mem
.ReadInt(gTriggers
[i
].PressCount
);
2874 Mem
.ReadBoolean(gTriggers
[i
].AutoSpawn
);
2875 // Çàäåðæêà ñïàâíåðà:
2876 Mem
.ReadInt(gTriggers
[i
].SpawnCooldown
);
2877 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2878 Mem
.ReadInt(gTriggers
[i
].SpawnedCount
);
2879 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2880 Mem
.ReadInt(gTriggers
[i
].SoundPlayCount
);
2881 // Ïðîèãðûâàåòñÿ ëè çâóê?
2885 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2888 Mem
.ReadSingle(vol
);
2889 // Ñòåðåî ñìåùåíèå çâóêà:
2890 Mem
.ReadSingle(pan
);
2891 // Çàïóñêàåì çâóê, åñëè åñòü:
2892 if gTriggers
[i
].Sound
<> nil then
2894 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
2895 gTriggers
[i
].Sound
.Pause(True);
2896 gTriggers
[i
].Sound
.SetPosition(dw
);