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 SysUtils
, Variants
, Classes
,
23 MAPDEF
, e_graphics
, g_basic
, g_sound
,
24 xdynrec
, hashtable
, exoma
;
43 TexturePanelGUID
: Integer;
44 //TexturePanelType: Word;
48 Activators
: array of TActivator
;
49 PlayerCollide
: Boolean;
53 SoundPlayCount
: Integer;
54 Sound
: TPlayableSound
;
56 SpawnCooldown
: Integer;
57 SpawnedCount
: Integer;
58 //ShotPanelType: Word;
59 ShotPanelTime
: Integer;
60 ShotSightTime
: Integer;
61 ShotSightTimeout
: Integer;
62 ShotSightTarget
: Word;
63 ShotSightTargetN
: Word;
65 ShotReloadTime
: Integer;
67 mapId
: AnsiString; // trigger id, from map
68 mapIndex
: Integer; // index in fields['trigger'], used in save/load
69 trigPanelGUID
: Integer;
71 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger (cloned)
72 exoInit
, exoThink
, exoCheck
, exoAction
: TExprBase
;
74 userVars
: THashStrVariant
;
76 {$INCLUDE ../shared/mapdef_tgc_def.inc}
79 function trigCenter (): TDFPoint
; inline;
82 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
83 procedure g_Triggers_Update();
84 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
85 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
86 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
87 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
88 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
89 procedure g_Triggers_OpenAll();
90 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
91 procedure g_Triggers_Free();
92 procedure g_Triggers_SaveState (st
: TStream
);
93 procedure g_Triggers_LoadState (st
: TStream
);
97 gTriggerClientID
: Integer = 0;
98 gTriggers
: array of TTrigger
;
99 gSecretsCount
: Integer = 0;
100 gMonstersSpawned
: array of LongInt = nil;
107 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
108 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
109 wadreader
, g_main
, e_log
, g_language
,
110 g_options
, g_net
, g_netmsg
, utils
, xparser
, xstreams
;
113 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
116 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
119 // ////////////////////////////////////////////////////////////////////////// //
121 TTrigScope
= class(TExprScope
)
124 monsprops
: TPropHash
;
125 platprops
: TPropHash
;
131 constructor Create ();
132 destructor Destroy (); override;
134 function getObj (const aname
: AnsiString): TObject
; override;
135 function getField (obj
: TObject
; const afldname
: AnsiString): Variant; override;
136 procedure setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant); override;
140 // ////////////////////////////////////////////////////////////////////////// //
142 TMyConstList
= class(TExprConstList
)
144 function valid (const cname
: AnsiString): Boolean; override;
145 function get (const cname
: AnsiString; out v
: Variant): Boolean; override;
149 // ////////////////////////////////////////////////////////////////////////// //
150 function TMyConstList
.valid (const cname
: AnsiString): Boolean;
152 //writeln('CHECK: ''', cname, '''');
154 (cname
= 'player') or
159 function TMyConstList
.get (const cname
: AnsiString; out v
: Variant): Boolean;
164 //if (cname = 'answer') then begin v := LongInt(42); result := true; exit; end;
166 if (gCurrentMap
= nil) then exit
;
167 for eidx
:= 0 to gCurrentMap
.mapdef
.ebsTypeCount
-1 do
169 ebs
:= gCurrentMap
.mapdef
.ebsTypeAt
[eidx
];
170 if ebs
.has
[cname
] then
172 //writeln('FOUND: ''', cname, '''');
181 // ////////////////////////////////////////////////////////////////////////// //
182 constructor TTrigScope
.Create ();
184 plrprops
:= TPropHash
.Create(TPlayer
, 'e');
185 monsprops
:= TPropHash
.Create(TMonster
, 'e');
186 platprops
:= TPropHash
.Create(TPanel
, 'e');
191 destructor TTrigScope
.Destroy ();
200 function TTrigScope
.getObj (const aname
: AnsiString): TObject
;
202 if (aname
= 'player') then result
:= gPlayers
[0] //FIXME
203 else if (aname
= 'self') or (aname
= 'this') then result
:= TObject(Pointer(PtrUInt(1)))
204 else result
:= inherited getObj(aname
);
208 function TTrigScope
.getField (obj
: TObject
; const afldname
: AnsiString): Variant;
210 if (obj
= gPlayers
[0]) then
212 if plrprops
.get(obj
, afldname
, result
) then exit
;
214 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
216 if (me
<> nil) and (me
.userVars
<> nil) then
218 if me
.userVars
.get(afldname
, result
) then exit
;
221 result
:= inherited getField(obj
, afldname
);
225 procedure TTrigScope
.setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant);
227 if (obj
= gPlayers
[0]) then
229 if plrprops
.put(obj
, afldname
, aval
) then exit
;
231 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
235 if (Length(afldname
) > 4) and (afldname
[1] = 'u') and (afldname
[2] = 's') and
236 (afldname
[3] = 'e') and (afldname
[4] = 'r') then
238 if (me
.userVars
= nil) then me
.userVars
:= THashStrVariant
.Create();
239 me
.userVars
.put(afldname
, aval
);
244 inherited setField(obj
, afldname
, aval
);
248 // ////////////////////////////////////////////////////////////////////////// //
250 tgscope
: TTrigScope
= nil;
251 tgclist
: TMyConstList
= nil;
254 // ////////////////////////////////////////////////////////////////////////// //
255 function TTrigger
.trigCenter (): TDFPoint
; inline;
257 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
261 function FindTrigger (): DWORD
;
265 olen
:= Length(gTriggers
);
267 for i
:= 0 to olen
-1 do
269 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
272 SetLength(gTriggers
, olen
+8);
275 for i
:= result
to High(gTriggers
) do
277 gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
278 gTriggers
[i
].trigDataRec
:= nil;
279 gTriggers
[i
].exoInit
:= nil;
280 gTriggers
[i
].exoThink
:= nil;
281 gTriggers
[i
].exoCheck
:= nil;
282 gTriggers
[i
].exoAction
:= nil;
283 gTriggers
[i
].userVars
:= nil;
288 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
295 pan
:= g_Map_PanelByGUID(PanelGUID
);
296 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
297 PanelID
:= pan
.arrIdx
;
301 with gWalls
[PanelID
] do
303 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
308 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
309 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
311 g_Map_EnableWallGUID(PanelGUID
);
318 if (gDoorMap
= nil) then exit
;
321 for a
:= 0 to High(gDoorMap
) do
323 for b
:= 0 to High(gDoorMap
[a
]) do
325 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
331 if (c
<> -1) then break
;
333 if (c
= -1) then exit
;
335 for b
:= 0 to High(gDoorMap
[c
]) do
337 with gWalls
[gDoorMap
[c
, b
]] do
339 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
345 for b
:= 0 to High(gDoorMap
[c
]) do
347 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
349 with gWalls
[PanelID
] do
351 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
352 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
359 for b
:= 0 to High(gDoorMap
[c
]) do
361 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
363 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
371 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
374 wx
, wy
, wh
, ww
: Integer;
378 function monsDamage (mon
: TMonster
): Boolean;
380 result
:= false; // don't stop
381 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
385 pan
:= g_Map_PanelByGUID(PanelGUID
);
389 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
393 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
396 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
397 PanelID
:= pan
.arrIdx
;
401 with gWalls
[PanelID
] do
403 if (not NoSound
) and (not Enabled
) then
405 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
406 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
410 wx
:= gWalls
[PanelID
].X
;
411 wy
:= gWalls
[PanelID
].Y
;
412 ww
:= gWalls
[PanelID
].Width
;
413 wh
:= gWalls
[PanelID
].Height
;
415 with gWalls
[PanelID
] do
417 if gPlayers
<> nil then
419 for a
:= 0 to High(gPlayers
) do
421 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
423 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
428 //g_Mons_ForEach(monsDamage);
429 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
431 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
436 if (gDoorMap
= nil) then exit
;
439 for a
:= 0 to High(gDoorMap
) do
441 for b
:= 0 to High(gDoorMap
[a
]) do
443 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
449 if (c
<> -1) then break
;
451 if (c
= -1) then exit
;
455 for b
:= 0 to High(gDoorMap
[c
]) do
457 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
459 with gWalls
[PanelID
] do
461 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
462 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
469 for b
:= 0 to High(gDoorMap
[c
]) do
471 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
472 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
473 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
474 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
476 with gWalls
[gDoorMap
[c
, b
]] do
478 if gPlayers
<> nil then
480 for a
:= 0 to High(gPlayers
) do
482 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
484 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
489 //g_Mons_ForEach(monsDamage);
490 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
492 if gMonsters <> nil then
493 for a := 0 to High(gMonsters) do
494 if (gMonsters[a] <> nil) and gMonsters[a].alive and
495 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
496 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
499 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
506 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
513 pan
:= g_Map_PanelByGUID(PanelGUID
);
514 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
515 PanelID
:= pan
.arrIdx
;
519 with gWalls
[PanelID
] do
525 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
526 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
528 g_Map_DisableWallGUID(PanelGUID
);
535 if (gDoorMap
= nil) then exit
;
538 for a
:= 0 to High(gDoorMap
) do
540 for b
:= 0 to High(gDoorMap
[a
]) do
542 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
548 if (c
<> -1) then break
;
550 if (c
= -1) then exit
;
554 for b
:= 0 to High(gDoorMap
[c
]) do
556 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
558 with gWalls
[PanelID
] do
560 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
561 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
568 for b
:= 0 to High(gDoorMap
[c
]) do
570 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
572 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
580 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
588 pan
:= g_Map_PanelByGUID(PanelGUID
);
589 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
590 PanelID
:= pan
.arrIdx
;
592 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
596 1: t
:= LIFTTYPE_DOWN
;
597 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_DOWN
, LIFTTYPE_UP
, LIFTTYPE_DOWN
);
600 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
603 0: t
:= LIFTTYPE_LEFT
;
604 1: t
:= LIFTTYPE_RIGHT
;
605 else t
:= IfThen(gLifts
[PanelID
].LiftType
= LIFTTYPE_LEFT
, LIFTTYPE_RIGHT
, LIFTTYPE_LEFT
);
611 with gLifts
[PanelID
] do
613 if (LiftType
<> t
) then
615 g_Map_SetLiftGUID(PanelGUID
, t
); //???
616 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
623 if (gLiftMap
= nil) then exit
;
626 for a
:= 0 to High(gLiftMap
) do
628 for b
:= 0 to High(gLiftMap
[a
]) do
630 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
636 if (c
<> -1) then break
;
638 if (c
= -1) then exit
;
641 for b := 0 to High(gLiftMap[c]) do
642 if gLifts[gLiftMap[c, b]].LiftType <> t then
644 with gLifts[PanelID] do
645 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
649 for b
:= 0 to High(gLiftMap
[c
]) do
651 with gLifts
[gLiftMap
[c
, b
]] do
653 if (LiftType
<> t
) then
655 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
664 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
672 TextureID
:= DWORD(-1);
673 snd
:= 'SOUND_WEAPON_FIREROCKET';
679 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
680 snd
:= 'SOUND_WEAPON_FIREPISTOL';
684 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
685 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
691 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
692 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
693 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
697 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
698 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
702 TRIGGER_SHOT_SHOTGUN
:
704 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
705 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
709 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
710 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
716 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
717 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
721 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
722 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
723 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
729 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
730 snd
:= 'SOUND_WEAPON_FIREBALL';
735 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
736 snd
:= 'SOUND_WEAPON_FIREPLASMA';
741 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
742 snd
:= 'SOUND_WEAPON_FIREPLASMA';
747 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
748 snd
:= 'SOUND_WEAPON_FIREBALL';
753 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
754 snd
:= 'SOUND_WEAPON_FIREBALL';
759 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
760 snd
:= 'SOUND_WEAPON_FIREBALL';
765 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
766 snd
:= 'SOUND_WEAPON_FIREREV';
771 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
772 snd
:= 'SOUND_WEAPON_FIREROCKET';
777 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
778 snd
:= 'SOUND_WEAPON_FIREBFG';
783 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
785 Anim
:= TAnimation
.Create(TextureID
, False, 6);
786 Anim
.Blending
:= False;
787 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
791 g_Weapon_Explode(wx
, wy
, 60, 0);
792 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
795 TRIGGER_SHOT_BFGEXPL
:
797 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
799 Anim
:= TAnimation
.Create(TextureID
, False, 6);
800 Anim
.Blending
:= False;
801 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
805 g_Weapon_BFG9000(wx
, wy
, 0);
806 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
811 g_Weapon_flame(wx
, wy
, dx
, dy
, 0, -1, True);
812 snd
:= 'SOUND_GAME_BURNING';
818 if g_Game_IsNet
and g_Game_IsServer
then
821 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
822 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
825 if Projectile
then MH_SEND_CreateShot(LastShotID
);
826 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
831 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
833 if Projectile
then Result
:= LastShotID
;
837 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
841 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
843 if (trigPanelGUID
<> -1) and (ShotPanelTime
= 0) then
845 g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
846 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
849 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
851 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
853 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
854 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
856 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, tgcShotSound
, TargetUID
);
860 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
862 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
869 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
874 if T
= TRIGGER_EFFECT_PARTICLE
then
877 TRIGGER_EFFECT_SLIQUID
:
879 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
880 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
881 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
882 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
884 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
885 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
886 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
887 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
888 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
892 if T
= TRIGGER_EFFECT_ANIMATION
then
895 EFFECT_TELEPORT
: begin
896 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
898 Anim
:= TAnimation
.Create(FramesID
, False, 3);
899 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
900 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
903 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
905 EFFECT_RESPAWN
: begin
906 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
908 Anim
:= TAnimation
.Create(FramesID
, False, 4);
909 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
910 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
913 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
916 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
918 Anim
:= TAnimation
.Create(FramesID
, False, 4);
919 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
920 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
923 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
930 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
936 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
937 case g_GetUIDType(ActivateUID
) of
940 p
:= g_Player_Get(ActivateUID
);
941 if p
= nil then Exit
;
944 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
948 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
953 m
:= g_Monsters_ByUID(ActivateUID
);
954 if m
= nil then Exit
;
957 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
961 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
968 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
974 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
975 case g_GetUIDType(ActivateUID
) of
978 p
:= g_Player_Get(ActivateUID
);
979 if p
= nil then Exit
;
994 m
:= g_Monsters_ByUID(ActivateUID
);
995 if m
= nil then Exit
;
1011 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
1018 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
1019 msg
:= b_Text_Format(MText
);
1021 TRIGGER_MESSAGE_DEST_ME
: // activator
1023 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1025 if g_Game_IsWatchedPlayer(ActivateUID
) then
1027 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1028 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1032 p
:= g_Player_Get(ActivateUID
);
1033 if g_Game_IsNet
and (p
.FClientID
>= 0) then
1035 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
1036 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
1042 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
1044 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1046 p
:= g_Player_Get(ActivateUID
);
1047 if g_Game_IsWatchedTeam(p
.Team
) then
1049 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1050 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1053 if g_Game_IsNet
then
1055 for i
:= Low(gPlayers
) to High(gPlayers
) do
1057 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1059 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1060 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1067 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
1069 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1071 p
:= g_Player_Get(ActivateUID
);
1072 if g_Game_IsWatchedTeam(p
.Team
) then
1074 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1075 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1078 if g_Game_IsNet
then
1080 for i
:= Low(gPlayers
) to High(gPlayers
) do
1082 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1084 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1085 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1092 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
1094 if g_Game_IsWatchedTeam(TEAM_RED
) then
1096 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1097 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1100 if g_Game_IsNet
then
1102 for i
:= Low(gPlayers
) to High(gPlayers
) do
1104 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
1106 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1107 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1113 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
1115 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
1117 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1118 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1121 if g_Game_IsNet
then
1123 for i
:= Low(gPlayers
) to High(gPlayers
) do
1125 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
1127 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1128 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1134 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
1136 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1137 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1139 if g_Game_IsNet
then
1141 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
1142 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1149 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1154 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1155 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1156 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1157 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1159 result
:= g_TraceVector(tgcTX
, tgcTY
,
1160 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1161 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1167 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1173 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1184 function monsShotTarget (mon
: TMonster
): Boolean;
1186 result
:= false; // don't stop
1187 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1189 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1190 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1191 TargetUID
:= mon
.UID
;
1192 result
:= true; // stop
1196 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1198 result
:= false; // don't stop
1199 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1201 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1202 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1203 TargetUID
:= mon
.UID
;
1204 result
:= true; // stop
1208 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1210 result
:= false; // don't stop
1211 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1213 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1214 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1215 TargetUID
:= mon
.UID
;
1216 result
:= true; // stop
1224 if g_Game_IsClient
then exit
;
1226 if not Trigger
.Enabled
then exit
;
1227 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1228 if (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then exit
;
1230 if (Trigger
.exoCheck
<> nil) then
1232 //conwritefln('exocheck: [%s]', [Trigger.exoCheck.toString()]);
1234 tgscope
.me
:= @Trigger
;
1235 tvval
:= Trigger
.exoCheck
.value(tgscope
);
1237 if not Boolean(tvval
) then exit
;
1238 except on e
: Exception
do
1241 conwritefln('trigger exocheck error: %s [%s]', [e
.message, Trigger
.exoCheck
.toString()]);
1249 coolDown
:= (actType
<> 0);
1251 if (Trigger
.exoAction
<> nil) then
1253 //conwritefln('exoactivate: [%s]', [Trigger.exoAction.toString()]);
1255 tgscope
.me
:= @Trigger
;
1256 Trigger
.exoAction
.value(tgscope
);
1258 except on e
: Exception
do
1261 conwritefln('trigger exoactivate error: %s [%s]', [e
.message, Trigger
.exoAction
.toString()]);
1272 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1273 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1274 gExitByTrigger
:= True;
1275 g_Game_ExitLevel(tgcMap
);
1284 Result
:= tr_Teleport(ActivateUID
,
1285 tgcTarget
.X
, tgcTarget
.Y
,
1286 tgcDirection
, tgcSilent
,
1293 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1299 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1303 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1305 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1306 if (pan
<> nil) and pan
.isGWall
then
1308 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1310 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1311 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1315 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1318 if result
then TimeOut
:= 18;
1322 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1324 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1326 if TriggerType
= TRIGGER_TRAP
then
1340 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1343 if PressTime
= -1 then PressTime
:= tgcWait
;
1344 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1349 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1353 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1355 p
:= g_Player_Get(ActivateUID
);
1357 Inc(gCoopSecretsFound
);
1358 if g_Game_IsNet
then
1360 MH_SEND_GameStats();
1361 if p
.FClientID
>= 0 then
1362 MH_SEND_GameEvent(NET_EV_SECRET
, p
.UID
, '');
1369 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1372 if (not tgcSilent
) and Result
then begin
1373 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1375 Y
+ (Height
div 2));
1376 if g_Game_IsServer
and g_Game_IsNet
then
1377 MH_SEND_Sound(X
+ (Width
div 2),
1379 'SOUND_GAME_SWITCH0');
1385 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1388 if (not tgcSilent
) and Result
then begin
1389 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1391 Y
+ (Height
div 2));
1392 if g_Game_IsServer
and g_Game_IsNet
then
1393 MH_SEND_Sound(X
+ (Width
div 2),
1395 'SOUND_GAME_SWITCH0');
1401 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1407 if (not tgcSilent
) and Result
then begin
1408 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1410 Y
+ (Height
div 2));
1411 if g_Game_IsServer
and g_Game_IsNet
then
1412 MH_SEND_Sound(X
+ (Width
div 2),
1414 'SOUND_GAME_SWITCH0');
1421 if tgcActivateOnce
then
1424 TriggerType
:= TRIGGER_NONE
;
1432 animonce
:= tgcAnimateOnce
;
1438 if Sound
<> nil then
1440 if tgcSoundSwitch
and Sound
.IsPlaying() then
1441 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1443 SoundPlayCount
:= 0;
1446 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1447 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1449 if tgcPlayCount
> 0 then
1450 SoundPlayCount
:= tgcPlayCount
1451 else // 0 - èãðàåì áåñêîíå÷íî
1452 SoundPlayCount
:= 1;
1455 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1459 TRIGGER_SPAWNMONSTER
:
1460 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1463 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1465 AutoSpawn
:= not AutoSpawn
;
1467 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1471 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1472 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1473 for k
:= 1 to tgcMonsCount
do
1475 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1476 SpawnCooldown
:= -1; // Çàäåðæêà âûñòàâèòñÿ ìîíñòðîì ïðè óíè÷òîæåíèè
1477 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1480 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1482 TDirection(tgcDirection
), True);
1487 if (tgcHealth
> 0) then
1488 mon
.SetHealth(tgcHealth
);
1489 // Óñòàíàâëèâàåì ïîâåäåíèå:
1490 mon
.MonsterBehaviour
:= tgcBehaviour
;
1491 mon
.FNoRespawn
:= True;
1492 if g_Game_IsNet
then
1493 MH_SEND_MonsterSpawn(mon
.UID
);
1494 // Èäåì èñêàòü öåëü, åñëè íàäî:
1498 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1500 if g_Game_IsNet
then
1502 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1503 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1506 mon
.SpawnTrigger
:= ID
;
1507 if tgcMax
> 0 then Inc(SpawnedCount
);
1510 EFFECT_TELEPORT
: begin
1511 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1513 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1514 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1515 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1516 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1519 if g_Game_IsServer
and g_Game_IsNet
then
1520 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1521 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1524 EFFECT_RESPAWN
: begin
1525 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1527 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1528 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1529 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1530 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1533 if g_Game_IsServer
and g_Game_IsNet
then
1534 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1535 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1539 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1541 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1542 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1543 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1544 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1547 if g_Game_IsServer
and g_Game_IsNet
then
1548 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1549 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1554 if g_Game_IsNet
then
1556 MH_SEND_GameStats();
1557 MH_SEND_CoopStats();
1564 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1565 if actType
= ACTIVATE_CUSTOM
then
1570 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1573 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1575 AutoSpawn
:= not AutoSpawn
;
1577 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1581 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1582 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1583 if (not tgcDmonly
) or
1584 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1585 for k
:= 1 to tgcItemCount
do
1587 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1588 SpawnCooldown
:= -1; // Çàäåðæêà âûñòàâèòñÿ èòåìîì ïðè óíè÷òîæåíèè
1589 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1592 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1593 tgcSpawnItemType
, tgcGravity
, False, True);
1597 it
:= g_Items_ByIdx(iid
);
1598 it
.SpawnTrigger
:= ID
;
1599 if tgcMax
> 0 then Inc(SpawnedCount
);
1602 EFFECT_TELEPORT
: begin
1603 it
:= g_Items_ByIdx(iid
);
1604 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1606 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1607 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1608 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1609 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1612 if g_Game_IsServer
and g_Game_IsNet
then
1613 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1614 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1617 EFFECT_RESPAWN
: begin
1618 it
:= g_Items_ByIdx(iid
);
1619 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1621 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1622 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1623 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1624 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1627 if g_Game_IsServer
and g_Game_IsNet
then
1628 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1629 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1633 it
:= g_Items_ByIdx(iid
);
1634 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1636 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1637 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1638 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1639 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1642 if g_Game_IsServer
and g_Game_IsNet
then
1643 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1644 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1649 if g_Game_IsNet
then
1650 MH_SEND_ItemSpawn(True, iid
);
1657 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1658 if actType
= ACTIVATE_CUSTOM
then
1664 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1665 if (Trigger
.tgcMusicName
<> '') then
1667 gMusic
.SetByName(Trigger
.tgcMusicName
);
1668 gMusic
.SpecPause
:= True;
1672 case Trigger
.tgcMusicAction
of
1673 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1674 gMusic
.SpecPause
:= True; // Ïàóçà
1675 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1676 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1677 gMusic
.SpecPause
:= False
1678 else // Èãðàëà => ñíà÷àëà
1679 gMusic
.SetPosition(0);
1687 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1692 pAngle
:= -DegToRad(tgcAngle
);
1693 Result
:= tr_Push(ActivateUID
,
1694 Floor(Cos(pAngle
)*tgcForce
),
1695 Floor(Sin(pAngle
)*tgcForce
),
1703 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1704 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1706 // Ñâîåé èëè ÷óæîé êîìàíäå
1707 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1709 p
:= g_Player_Get(ActivateUID
);
1710 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1711 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1713 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1717 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1719 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1720 if g_Game_IsServer
and g_Game_IsNet
then
1721 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+r');
1724 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1725 if g_Game_IsServer
and g_Game_IsNet
then
1726 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1732 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1733 if g_Game_IsServer
and g_Game_IsNet
then
1734 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1737 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1738 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1740 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1744 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1746 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1747 if g_Game_IsServer
and g_Game_IsNet
then
1748 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-r');
1751 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1752 if g_Game_IsServer
and g_Game_IsNet
then
1753 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1759 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1760 if g_Game_IsServer
and g_Game_IsNet
then
1761 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1764 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1765 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1767 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1771 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1773 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1774 if g_Game_IsServer
and g_Game_IsNet
then
1775 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+b');
1778 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1779 if g_Game_IsServer
and g_Game_IsNet
then
1780 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1786 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1787 if g_Game_IsServer
and g_Game_IsNet
then
1788 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1791 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1792 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1794 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1798 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1800 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1801 if g_Game_IsServer
and g_Game_IsNet
then
1802 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-b');
1805 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1806 if g_Game_IsServer
and g_Game_IsNet
then
1807 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1813 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1814 if g_Game_IsServer
and g_Game_IsNet
then
1815 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1818 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1820 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1821 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1823 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1825 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1829 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1830 if g_Game_IsServer
and g_Game_IsNet
then
1831 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1836 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1837 if g_Game_IsServer
and g_Game_IsNet
then
1838 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1841 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1843 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1847 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1848 if g_Game_IsServer
and g_Game_IsNet
then
1849 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1854 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1855 if g_Game_IsServer
and g_Game_IsNet
then
1856 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1859 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1861 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1865 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1866 if g_Game_IsServer
and g_Game_IsNet
then
1867 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1872 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1873 if g_Game_IsServer
and g_Game_IsNet
then
1874 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1877 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1879 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1883 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1884 if g_Game_IsServer
and g_Game_IsNet
then
1885 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1890 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1891 if g_Game_IsServer
and g_Game_IsNet
then
1892 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1899 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1901 // Ñâîåé èëè ÷óæîé êîìàíäû
1902 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1904 p
:= g_Player_Get(ActivateUID
);
1905 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1906 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1908 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1910 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1914 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1916 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1917 if g_Game_IsServer
and g_Game_IsNet
then
1918 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1921 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1922 if g_Game_IsServer
and g_Game_IsNet
then
1923 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1930 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1931 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1933 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1935 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1939 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1941 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1942 if g_Game_IsServer
and g_Game_IsNet
then
1943 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1946 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1947 if g_Game_IsServer
and g_Game_IsNet
then
1948 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1956 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1957 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1959 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1961 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1963 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1967 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1969 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1971 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1978 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1980 // Ñâîåé èëè ÷óæîé êîìàíäû
1981 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1983 p
:= g_Player_Get(ActivateUID
);
1984 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1985 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1986 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1988 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1991 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1993 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1994 if g_Game_IsServer
and g_Game_IsNet
then
1995 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1998 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1999 if g_Game_IsServer
and g_Game_IsNet
then
2000 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
2005 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
2006 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
2007 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2009 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2012 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
2014 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2015 if g_Game_IsServer
and g_Game_IsNet
then
2016 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
2019 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2020 if g_Game_IsServer
and g_Game_IsNet
then
2021 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
2027 // Êàêîé-òî êîíêðåòíîé êîìàíäû
2028 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
2030 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
2032 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2034 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
2038 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
2040 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2042 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2048 if Result
then begin
2053 if g_Game_IsServer
and g_Game_IsNet
then
2060 Result
:= tr_Message(tgcKind
, tgcText
,
2061 tgcMsgDest
, tgcMsgTime
,
2066 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
2069 UIDType
:= g_GetUIDType(ActivateUID
);
2070 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
2076 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
2077 for idx
:= 0 to High(Activators
) do
2078 if Activators
[idx
].UID
= ActivateUID
then
2084 begin // Âèäèì åãî âïåðâûå
2086 SetLength(Activators
, Length(Activators
) + 1);
2087 k
:= High(Activators
);
2088 Activators
[k
].UID
:= ActivateUID
;
2090 begin // Óæå âèäåëè åãî
2091 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
2092 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
2093 Activators
[k
].TimeOut
:= 65535;
2094 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
2095 Result
:= Activators
[k
].TimeOut
= 0;
2104 p
:= g_Player_Get(ActivateUID
);
2108 // Íàíîñèì óðîí èãðîêó
2109 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2111 // Êèñëîòíûé óðîí íå íàíîñèòñÿ êîãäà åñòü êîñòþì
2112 // "Âîäÿíîé" óðîí íå íàíîñèòñÿ êîãäà åñòü êèñëîðîä
2113 if not (((tgcKind
= HIT_ACID
) and (p
.FMegaRulez
[MR_SUIT
] > gTime
)) or
2114 ((tgcKind
= HIT_WATER
) and (p
.Air
> 0))) then
2115 p
.Damage(tgcAmount
, 0, 0, 0, tgcKind
);
2116 if (tgcKind
= HIT_FLAME
) then p
.CatchFire(0);
2120 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2121 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
2123 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
2124 if g_Game_IsServer
and g_Game_IsNet
then
2125 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2131 m
:= g_Monsters_ByUID(ActivateUID
);
2135 // Íàíîñèì óðîí ìîíñòðó
2136 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2138 m
.Damage(tgcAmount
, 0, 0, 0, tgcKind
);
2139 if (tgcKind
= HIT_FLAME
) then m
.CatchFire(0);
2143 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2144 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
2146 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
2147 if g_Game_IsServer
and g_Game_IsNet
then
2148 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2152 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
2156 Activators
[k
].TimeOut
:= idx
2158 Activators
[k
].TimeOut
:= 65535;
2166 if ShotSightTime
> 0 then
2169 // put this at the beginning so it doesn't trigger itself
2170 TimeOut
:= tgcWait
+ 1;
2174 pAngle
:= -DegToRad(tgcAngle
);
2175 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
2176 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
2179 case tgcShotTarget
of
2180 TRIGGER_SHOT_TARGET_MON
: // monsters
2181 //TODO: accelerate this!
2182 g_Mons_ForEachAlive(monsShotTarget
);
2184 TRIGGER_SHOT_TARGET_PLR
: // players
2185 if gPlayers
<> nil then
2186 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2187 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2188 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2190 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2191 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2192 TargetUID
:= gPlayers
[idx
].UID
;
2196 TRIGGER_SHOT_TARGET_RED
: // red team
2197 if gPlayers
<> nil then
2198 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2199 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2200 (gPlayers
[idx
].Team
= TEAM_RED
) and
2201 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2203 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2204 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2205 TargetUID
:= gPlayers
[idx
].UID
;
2209 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2210 if gPlayers
<> nil then
2211 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2212 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2213 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2214 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2216 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2217 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2218 TargetUID
:= gPlayers
[idx
].UID
;
2222 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2224 //TODO: accelerate this!
2225 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2227 if (TargetUID
= 0) and (gPlayers
<> nil) then
2228 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2229 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2230 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2232 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2233 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2234 TargetUID
:= gPlayers
[idx
].UID
;
2239 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2241 if gPlayers
<> nil then
2242 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2243 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2244 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2246 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2247 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2248 TargetUID
:= gPlayers
[idx
].UID
;
2251 if TargetUID
= 0 then
2253 //TODO: accelerate this!
2254 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2259 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2260 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2261 TargetUID
:= ActivateUID
;
2265 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2266 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2269 if (tgcSight
= 0) or
2270 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2271 (TargetUID
= ShotSightTarget
) then
2272 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2275 ShotSightTime
:= tgcSight
;
2276 ShotSightTargetN
:= TargetUID
;
2277 if tgcShotType
= TRIGGER_SHOT_BFG
then
2279 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2280 if g_Game_IsNet
and g_Game_IsServer
then
2281 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2294 TRIGGER_EFFECT_POS_CENTER
:
2296 wx
:= X
+ Width
div 2;
2297 wy
:= Y
+ Height
div 2;
2299 TRIGGER_EFFECT_POS_AREA
:
2301 wx
:= X
+ Random(Width
);
2302 wy
:= Y
+ Random(Height
);
2305 wx
:= X
+ Width
div 2;
2306 wy
:= Y
+ Height
div 2;
2311 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2312 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2313 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2314 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2315 tr_MakeEffect(wx
, wy
, xd
, yd
,
2316 tgcFXType
, tgcFXSubType
,
2317 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, False);
2326 if Result
{and (Trigger.TexturePanel <> -1)} then
2328 g_Map_SwitchTextureGUID({Trigger.TexturePanelType,} Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2333 function g_Triggers_CreateWithMapIndex (aTrigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2335 triggers
: TDynField
;
2337 triggers
:= gCurrentMap
['trigger'];
2338 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2339 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2340 aTrigger
.mapIndex
:= mapidx
;
2341 result
:= g_Triggers_Create(aTrigger
, triggers
.itemAt
[mapidx
], arridx
);
2345 function g_Triggers_Create (aTrigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
2348 fn
, mapw
: AnsiString;
2352 if (tgscope
= nil) then tgscope
:= TTrigScope
.Create();
2353 if (tgclist
= nil) then tgclist
:= TMyConstList
.Create();
2355 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2356 if (aTrigger
.TriggerType
= TRIGGER_EXIT
) and
2357 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2359 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2362 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2363 if (aTrigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2364 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2365 (gGameSettings
.GameType
<> GT_SINGLE
) then
2367 aTrigger
.TriggerType
:= TRIGGER_NONE
;
2370 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2371 if (aTrigger
.TriggerType
= TRIGGER_SECRET
) then gSecretsCount
+= 1;
2373 if (forceInternalIndex
< 0) then
2375 find_id
:= FindTrigger();
2379 olen
:= Length(gTriggers
);
2380 if (forceInternalIndex
>= olen
) then
2382 SetLength(gTriggers
, forceInternalIndex
+1);
2383 for f
:= olen
to High(gTriggers
) do
2385 gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2386 gTriggers
[f
].trigDataRec
:= nil;
2387 gTriggers
[f
].exoInit
:= nil;
2388 gTriggers
[f
].exoThink
:= nil;
2389 gTriggers
[f
].exoCheck
:= nil;
2390 gTriggers
[f
].exoAction
:= nil;
2391 gTriggers
[f
].userVars
:= nil;
2394 f
:= forceInternalIndex
;
2395 gTriggers
[f
].trigDataRec
.Free();
2396 gTriggers
[f
].exoInit
.Free();
2397 gTriggers
[f
].exoThink
.Free();
2398 gTriggers
[f
].exoCheck
.Free();
2399 gTriggers
[f
].exoAction
.Free();
2400 gTriggers
[f
].userVars
.Free();
2401 gTriggers
[f
].trigDataRec
:= nil;
2402 gTriggers
[f
].exoInit
:= nil;
2403 gTriggers
[f
].exoThink
:= nil;
2404 gTriggers
[f
].exoCheck
:= nil;
2405 gTriggers
[f
].exoAction
:= nil;
2406 gTriggers
[f
].userVars
:= nil;
2407 find_id
:= DWORD(forceInternalIndex
);
2409 gTriggers
[find_id
] := aTrigger
;
2410 ptg
:= @gTriggers
[find_id
];
2412 ptg
.mapId
:= trec
.id
;
2413 // clone trigger data
2414 if (trec
.trigRec
= nil) then
2416 ptg
.trigDataRec
:= nil;
2418 if (ptg
.TriggerType
<> TRIGGER_SECRET
) then
2420 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [ptg
.TriggerType
], TMsgType
.Warning
);
2425 ptg
.trigDataRec
:= trec
.trigRec
.clone(nil);
2431 // if this type of trigger exists both on the client and on the server
2432 // use an uniform numeration
2434 if (ptg
.TriggerType
= TRIGGER_SOUND
) then
2436 Inc(gTriggerClientID
);
2437 ClientID
:= gTriggerClientID
;
2441 PlayerCollide
:= False;
2445 SoundPlayCount
:= 0;
2452 // update cached trigger variables
2453 trigUpdateCacheData(ptg
^, ptg
.trigDataRec
);
2455 ptg
.userVars
:= nil;
2458 ptg
.exoThink
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_think']));
2460 on e
: TExomaParseException
do
2462 conwritefln('*** ERROR parsing exoma_think (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_think'])]);
2463 ptg
.exoThink
:= nil;
2469 ptg
.exoCheck
:= TExprBase
.parse(tgclist
, VarToStr(trec
.user
['exoma_check']));
2471 on e
: TExomaParseException
do
2473 conwritefln('*** ERROR parsing exoma_check (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_check'])]);
2474 ptg
.exoCheck
:= nil;
2480 ptg
.exoAction
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_action']));
2482 on e
: TExomaParseException
do
2484 conwritefln('*** ERROR parsing exoma_action (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_action'])]);
2485 ptg
.exoAction
:= nil;
2491 ptg
.exoInit
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_init']));
2493 on e
: TExomaParseException
do
2495 conwritefln('*** ERROR parsing exoma_init (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_init'])]);
2502 if (forceInternalIndex
< 0) and (ptg
.exoInit
<> nil) then
2504 //conwritefln('executing trigger init: [%s]', [gTriggers[find_id].exoInit.toString()]);
2507 ptg
.exoInit
.value(tgscope
);
2511 conwritefln('*** trigger exoactivate error: %s', [ptg
.exoInit
.toString()]);
2516 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2517 if (ptg
.TriggerType
= TRIGGER_SOUND
) and (ptg
.tgcSoundName
<> '') then
2519 // Åùå íåò òàêîãî çâóêà
2520 if not g_Sound_Exists(ptg
.tgcSoundName
) then
2522 fn
:= g_ExtractWadName(ptg
.tgcSoundName
);
2524 begin // Çâóê â ôàéëå ñ êàðòîé
2525 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2526 fn
:= mapw
+':'+g_ExtractFilePathName(ptg
.tgcSoundName
);
2528 else // Çâóê â îòäåëüíîì ôàéëå
2530 fn
:= GameDir
+ '/wads/' + ptg
.tgcSoundName
;
2533 //e_LogWritefln('loading trigger sound ''%s''', [fn]);
2534 if not g_Sound_CreateWADEx(ptg
.tgcSoundName
, fn
) then
2536 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcSoundName
]));
2540 // Ñîçäàåì îáúåêò çâóêà
2543 Sound
:= TPlayableSound
.Create();
2544 if not Sound
.SetByName(ptg
.tgcSoundName
) then
2552 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2553 if (ptg
.TriggerType
= TRIGGER_MUSIC
) and (ptg
.tgcMusicName
<> '') then
2555 // Åùå íåò òàêîé ìóçûêè
2556 if not g_Sound_Exists(ptg
.tgcMusicName
) then
2558 fn
:= g_ExtractWadName(ptg
.tgcMusicName
);
2561 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2562 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2563 fn
:= mapw
+':'+g_ExtractFilePathName(ptg
.tgcMusicName
);
2565 else // Ìóçûêà â ôàéëå ñ êàðòîé
2567 fn
:= GameDir
+'/wads/'+ptg
.tgcMusicName
;
2570 if not g_Sound_CreateWADEx(ptg
.tgcMusicName
, fn
, True) then
2572 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, ptg
.tgcMusicName
]));
2577 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2578 if (ptg
.TriggerType
= TRIGGER_SHOT
) then
2584 ShotSightTimeout
:= 0;
2585 ShotSightTarget
:= 0;
2586 ShotSightTargetN
:= 0;
2587 ShotAmmoCount
:= ptg
.tgcAmmo
;
2588 ShotReloadTime
:= 0;
2596 // sorry; grid doesn't support recursive queries, so we have to do this
2598 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2601 tgMonsList
: TSimpleMonsterList
= nil;
2603 procedure g_Triggers_Update();
2606 Affected
: array of Integer;
2608 function monsNear (mon
: TMonster
): Boolean;
2610 result
:= false; // don't stop
2612 gTriggers[a].ActivateUID := mon.UID;
2613 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2615 tgMonsList
.append(mon
);
2622 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2624 if gTriggers
= nil then
2626 SetLength(Affected
, 0);
2628 for a
:= 0 to High(gTriggers
) do
2629 with gTriggers
[a
] do
2631 if TriggerType
<> TRIGGER_NONE
then
2633 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2634 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2635 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2636 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2637 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2638 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2640 for b
:= 0 to High(Activators
) do
2642 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2643 if Activators
[b
].TimeOut
> 0 then
2645 Dec(Activators
[b
].TimeOut
);
2651 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2652 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2656 // Îáðàáàòûâàåì ñïàâíåðû
2657 if Enabled
and AutoSpawn
then
2659 if SpawnCooldown
= 0 then
2661 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2662 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2665 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2667 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2668 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2671 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2676 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2681 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2682 if TriggerType
= TRIGGER_SHOT
then
2684 if ShotPanelTime
> 0 then
2687 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID({ShotPanelType,} trigPanelGUID
);
2689 if ShotSightTime
> 0 then
2692 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2694 if ShotSightTimeout
> 0 then
2696 Dec(ShotSightTimeout
);
2697 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2699 if ShotReloadTime
> 0 then
2701 Dec(ShotReloadTime
);
2702 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2706 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2707 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2709 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2711 if tgcPlayCount
> 0 then Dec(SoundPlayCount
); (* looped sound if zero *)
2713 Sound
.PlayVolumeAtRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
2715 Sound
.PlayPanVolume((tgcPan
- 127.0) / 128.0, tgcVolume
/ 255.0);
2716 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then
2717 MH_SEND_TriggerSound(gTriggers
[a
])
2721 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2722 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2724 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2728 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2729 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2731 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2732 if (pan
<> nil) and pan
.isGWall
then
2735 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2741 // Ïîêà îòêðûòà - çàêðûâàåì
2742 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2747 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2748 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2749 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2751 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2753 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2754 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2756 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2757 for b
:= 0 to High(gTriggers
) do
2759 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2760 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2761 ((b
<> a
) or (tgcWait
> 0)) then
2762 begin // Can be self-activated, if there is Data.Wait
2763 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2765 SetLength(Affected
, Length(Affected
) + 1);
2766 Affected
[High(Affected
)] := b
;
2772 // if we have panelid, assume that it will switch the moving platform
2773 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2774 if (pan
<> nil) then
2777 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2778 TRIGGER_ON
: pan
.movingActive
:= true;
2779 TRIGGER_OFF
: pan
.movingActive
:= false;
2780 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2782 if not tgcSilent
and (Length(tgcSound
) > 0) then
2784 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2785 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2789 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2790 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2792 if (Length(Affected
) > 0) then
2794 b
:= Affected
[Random(Length(Affected
))];
2795 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2796 ActivateTrigger(gTriggers
[b
], 0);
2799 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2801 for i
:= 0 to High(Affected
) do
2807 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2808 ActivateTrigger(gTriggers
[b
], 0);
2812 gTriggers
[b
].Enabled
:= True;
2816 gTriggers
[b
].Enabled
:= False;
2817 gTriggers
[b
].TimeOut
:= 0;
2818 if gTriggers
[b
].AutoSpawn
then
2820 gTriggers
[b
].AutoSpawn
:= False;
2821 gTriggers
[b
].SpawnCooldown
:= 0;
2826 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2827 if not gTriggers
[b
].Enabled
then
2829 gTriggers
[b
].TimeOut
:= 0;
2830 if gTriggers
[b
].AutoSpawn
then
2832 gTriggers
[b
].AutoSpawn
:= False;
2833 gTriggers
[b
].SpawnCooldown
:= 0;
2840 SetLength(Affected
, 0);
2843 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2846 TimeOut
:= TimeOut
- 1;
2847 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2850 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2855 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2857 if gPlayers
<> nil then
2858 for b
:= 0 to High(gPlayers
) do
2859 if gPlayers
[b
] <> nil then
2861 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2862 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2863 Collide(X
, Y
, Width
, Height
) then
2865 gTriggers
[a
].ActivateUID
:= UID
;
2867 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2869 { Don't activate sound/music again if player is here }
2871 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2874 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2876 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2877 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2878 (TimeOut
= 0) and (Keys
= 0) then
2880 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2881 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2882 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2883 gTriggers
[a
].ActivateUID
:= 0;
2884 ActivateTrigger(gTriggers
[a
], 0);
2888 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2889 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2891 //g_Mons_ForEach(monsNear);
2894 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2895 for mon
in tgMonsList
do
2897 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2898 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2900 tgMonsList
.reset(); // just in case
2904 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2905 (TimeOut
= 0) and (Keys
= 0) then
2906 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2908 gTriggers
[a
].ActivateUID
:= 0;
2909 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2913 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2917 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2919 if (ID
>= Length(gTriggers
)) then exit
;
2920 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2921 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2924 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2925 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2933 if gTriggers
= nil then Exit
;
2935 case g_GetUIDType(UID
) of
2939 p
:= g_Player_Get(UID
);
2948 for a
:= 0 to High(gTriggers
) do
2949 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2950 (gTriggers
[a
].TimeOut
= 0) and
2951 (not InDWArray(a
, IgnoreList
)) and
2952 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2953 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2954 if g_Collide(X
, Y
, Width
, Height
,
2955 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2956 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2958 gTriggers
[a
].ActivateUID
:= UID
;
2959 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2961 SetLength(Result
, Length(Result
)+1);
2962 Result
[High(Result
)] := a
;
2967 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2973 if gTriggers
= nil then Exit
;
2975 case g_GetUIDType(UID
) of
2979 p
:= g_Player_Get(UID
);
2988 for a
:= 0 to High(gTriggers
) do
2989 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2990 (gTriggers
[a
].TimeOut
= 0) and
2991 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2992 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2993 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2994 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2996 gTriggers
[a
].ActivateUID
:= UID
;
2997 ActivateTrigger(gTriggers
[a
], ActivateType
);
3001 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
3008 if gTriggers
= nil then
3011 case g_GetUIDType(UID
) of
3015 p
:= g_Player_Get(UID
);
3024 rsq
:= Radius
* Radius
;
3026 for a
:= 0 to High(gTriggers
) do
3027 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
3028 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3029 (gTriggers
[a
].TimeOut
= 0) and
3030 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3031 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3032 with gTriggers
[a
] do
3033 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
3034 X
, Y
, Width
, Height
) then
3035 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
3036 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
3037 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
3038 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
3039 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
3040 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3041 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
3042 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3045 ActivateTrigger(gTriggers
[a
], ActivateType
);
3049 procedure g_Triggers_OpenAll();
3054 if gTriggers
= nil then Exit
;
3057 for a
:= 0 to High(gTriggers
) do
3059 with gTriggers
[a
] do
3061 if (TriggerType
= TRIGGER_OPENDOOR
) or
3062 (TriggerType
= TRIGGER_DOOR5
) or
3063 (TriggerType
= TRIGGER_DOOR
) then
3065 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
3066 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
3072 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
3075 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
3077 if (gTriggers
<> nil) then
3079 if gTriggers
[ID
].tgcMax
> 0 then
3081 if gTriggers
[ID
].SpawnedCount
> 0 then
3082 Dec(gTriggers
[ID
].SpawnedCount
);
3084 if gTriggers
[ID
].tgcDelay
> 0 then
3086 if gTriggers
[ID
].SpawnCooldown
< 0 then
3087 gTriggers
[ID
].SpawnCooldown
:= gTriggers
[ID
].tgcDelay
;
3092 procedure g_Triggers_Free ();
3096 for a
:= 0 to High(gTriggers
) do
3098 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
3100 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
3102 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
3104 gTriggers
[a
].Sound
.Free();
3106 if (gTriggers
[a
].Activators
<> nil) then
3108 SetLength(gTriggers
[a
].Activators
, 0);
3110 gTriggers
[a
].trigDataRec
.Free();
3112 gTriggers
[a
].exoThink
.Free();
3113 gTriggers
[a
].exoCheck
.Free();
3114 gTriggers
[a
].exoAction
.Free();
3115 gTriggers
[a
].userVars
.Free();
3120 SetLength(gMonstersSpawned
, 0);
3124 procedure g_Triggers_SaveState (st
: TStream
);
3126 count
, actCount
, i
, j
: Integer;
3129 kv
: THashStrVariant
.PEntry
;
3132 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
3133 count
:= Length(gTriggers
);
3135 // Êîëè÷åñòâî òðèããåðîâ
3136 utils
.writeInt(st
, LongInt(count
));
3137 if (count
= 0) then exit
;
3139 for i
:= 0 to High(gTriggers
) do
3141 // Ñèãíàòóðà òðèããåðà
3142 utils
.writeSign(st
, 'TRGX');
3143 utils
.writeInt(st
, Byte(0));
3145 utils
.writeInt(st
, Byte(gTriggers
[i
].TriggerType
));
3146 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3147 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
3148 utils
.writeInt(st
, LongInt(gTriggers
[i
].mapIndex
));
3149 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3150 utils
.writeInt(st
, LongInt(gTriggers
[i
].X
));
3151 utils
.writeInt(st
, LongInt(gTriggers
[i
].Y
));
3153 utils
.writeInt(st
, Word(gTriggers
[i
].Width
));
3154 utils
.writeInt(st
, Word(gTriggers
[i
].Height
));
3155 // Âêëþ÷åí ëè òðèããåð
3156 utils
.writeBool(st
, gTriggers
[i
].Enabled
);
3157 // Òèï àêòèâàöèè òðèããåðà
3158 utils
.writeInt(st
, Byte(gTriggers
[i
].ActivateType
));
3159 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3160 utils
.writeInt(st
, Byte(gTriggers
[i
].Keys
));
3161 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3162 utils
.writeInt(st
, LongInt(gTriggers
[i
].TexturePanelGUID
));
3164 //Mem.WriteWord(gTriggers[i].TexturePanelType);
3165 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3166 utils
.writeInt(st
, LongInt(gTriggers
[i
].trigPanelGUID
));
3167 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3168 utils
.writeInt(st
, Word(gTriggers
[i
].TimeOut
));
3169 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3170 utils
.writeInt(st
, Word(gTriggers
[i
].ActivateUID
));
3171 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3172 actCount
:= Length(gTriggers
[i
].Activators
);
3173 utils
.writeInt(st
, LongInt(actCount
));
3174 for j
:= 0 to actCount
-1 do
3177 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].UID
));
3179 utils
.writeInt(st
, Word(gTriggers
[i
].Activators
[j
].TimeOut
));
3181 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3182 utils
.writeBool(st
, gTriggers
[i
].PlayerCollide
);
3183 // Âðåìÿ äî çàêðûòèÿ äâåðè
3184 utils
.writeInt(st
, LongInt(gTriggers
[i
].DoorTime
));
3185 // Çàäåðæêà àêòèâàöèè
3186 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressTime
));
3188 utils
.writeInt(st
, LongInt(gTriggers
[i
].PressCount
));
3190 utils
.writeBool(st
, gTriggers
[i
].AutoSpawn
);
3191 // Çàäåðæêà ñïàâíåðà
3192 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnCooldown
));
3193 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3194 utils
.writeInt(st
, LongInt(gTriggers
[i
].SpawnedCount
));
3195 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3196 utils
.writeInt(st
, LongInt(gTriggers
[i
].SoundPlayCount
));
3197 // Ïðîèãðûâàåòñÿ ëè çâóê?
3198 if (gTriggers
[i
].Sound
<> nil) then b
:= gTriggers
[i
].Sound
.IsPlaying() else b
:= false;
3199 utils
.writeBool(st
, b
);
3202 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3203 utils
.writeInt(st
, LongWord(gTriggers
[i
].Sound
.GetPosition()));
3205 sg
:= gTriggers
[i
].Sound
.GetVolume();
3206 sg
:= sg
/(gSoundLevel
/255.0);
3207 //Mem.WriteSingle(sg);
3208 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3209 // Ñòåðåî ñìåùåíèå çâóêà
3210 sg
:= gTriggers
[i
].Sound
.GetPan();
3211 //Mem.WriteSingle(sg);
3212 st
.WriteBuffer(sg
, sizeof(sg
)); // sorry
3215 if (gTriggers
[i
].userVars
= nil) then
3217 utils
.writeInt(st
, LongInt(0));
3221 utils
.writeInt(st
, LongInt(gTriggers
[i
].userVars
.count
)); //FIXME: check for overflow
3222 for kv
in gTriggers
[i
].userVars
.byKeyValue
do
3224 //writeln('<', kv.key, '>:<', VarToStr(kv.value), '>');
3225 utils
.writeStr(st
, kv
.key
);
3226 t
:= LongInt(varType(kv
.value
));
3227 utils
.writeInt(st
, LongInt(t
));
3229 varString
: utils
.writeStr(st
, AnsiString(kv
.value
));
3230 varBoolean
: utils
.writeBool(st
, Boolean(kv
.value
));
3231 varShortInt
: utils
.writeInt(st
, LongInt(kv
.value
));
3232 varSmallint
: utils
.writeInt(st
, LongInt(kv
.value
));
3233 varInteger
: utils
.writeInt(st
, LongInt(kv
.value
));
3234 //varInt64: Mem.WriteInt(Integer(kv.value));
3235 varByte
: utils
.writeInt(st
, LongInt(kv
.value
));
3236 varWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3237 varLongWord
: utils
.writeInt(st
, LongInt(kv
.value
));
3239 else raise Exception
.CreateFmt('cannot save uservar ''%s''', [kv
.key
]);
3247 procedure g_Triggers_LoadState (st
: TStream
);
3249 count
, actCount
, i
, j
, a
: Integer;
3258 uvname
: AnsiString = '';
3259 ustr
: AnsiString = '';
3267 // Êîëè÷åñòâî òðèããåðîâ
3268 count
:= utils
.readLongInt(st
);
3269 if (count
= 0) then exit
;
3270 if (count
< 0) or (count
> 1024*1024) then raise XStreamError
.Create('invalid trigger count');
3272 for a
:= 0 to count
-1 do
3274 // Ñèãíàòóðà òðèããåðà
3275 if not utils
.checkSign(st
, 'TRGX') then raise XStreamError
.Create('invalid trigger signature');
3276 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid trigger version');
3278 Trig
.TriggerType
:= utils
.readByte(st
);
3279 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3280 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
3281 mapIndex
:= utils
.readLongInt(st
);
3282 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
3283 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3284 gTriggers
[i
].X
:= utils
.readLongInt(st
);
3285 gTriggers
[i
].Y
:= utils
.readLongInt(st
);
3287 gTriggers
[i
].Width
:= utils
.readWord(st
);
3288 gTriggers
[i
].Height
:= utils
.readWord(st
);
3289 // Âêëþ÷åí ëè òðèããåð
3290 gTriggers
[i
].Enabled
:= utils
.readBool(st
);
3291 // Òèï àêòèâàöèè òðèããåðà
3292 gTriggers
[i
].ActivateType
:= utils
.readByte(st
);
3293 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3294 gTriggers
[i
].Keys
:= utils
.readByte(st
);
3295 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3296 gTriggers
[i
].TexturePanelGUID
:= utils
.readLongInt(st
);
3298 //Mem.ReadWord(gTriggers[i].TexturePanelType);
3299 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3300 gTriggers
[i
].trigPanelGUID
:= utils
.readLongInt(st
);
3301 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3302 gTriggers
[i
].TimeOut
:= utils
.readWord(st
);
3303 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3304 gTriggers
[i
].ActivateUID
:= utils
.readWord(st
);
3305 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3306 actCount
:= utils
.readLongInt(st
);
3307 if (actCount
< 0) or (actCount
> 1024*1024) then raise XStreamError
.Create('invalid activated object count');
3308 if (actCount
> 0) then
3310 SetLength(gTriggers
[i
].Activators
, actCount
);
3311 for j
:= 0 to actCount
-1 do
3314 gTriggers
[i
].Activators
[j
].UID
:= utils
.readWord(st
);
3316 gTriggers
[i
].Activators
[j
].TimeOut
:= utils
.readWord(st
);
3319 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3320 gTriggers
[i
].PlayerCollide
:= utils
.readBool(st
);
3321 // Âðåìÿ äî çàêðûòèÿ äâåðè
3322 gTriggers
[i
].DoorTime
:= utils
.readLongInt(st
);
3323 // Çàäåðæêà àêòèâàöèè
3324 gTriggers
[i
].PressTime
:= utils
.readLongInt(st
);
3326 gTriggers
[i
].PressCount
:= utils
.readLongInt(st
);
3328 gTriggers
[i
].AutoSpawn
:= utils
.readBool(st
);
3329 // Çàäåðæêà ñïàâíåðà
3330 gTriggers
[i
].SpawnCooldown
:= utils
.readLongInt(st
);
3331 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3332 gTriggers
[i
].SpawnedCount
:= utils
.readLongInt(st
);
3333 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3334 gTriggers
[i
].SoundPlayCount
:= utils
.readLongInt(st
);
3335 // Ïðîèãðûâàåòñÿ ëè çâóê?
3336 b
:= utils
.readBool(st
);
3339 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3340 dw
:= utils
.readLongWord(st
);
3342 //Mem.ReadSingle(vol);
3343 st
.ReadBuffer(vol
, sizeof(vol
)); // sorry
3344 // Ñòåðåî ñìåùåíèå çâóêà
3345 //Mem.ReadSingle(pan);
3346 st
.ReadBuffer(pan
, sizeof(pan
)); // sorry
3347 // Çàïóñêàåì çâóê, åñëè åñòü
3348 if (gTriggers
[i
].Sound
<> nil) then
3350 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3351 gTriggers
[i
].Sound
.Pause(True);
3352 gTriggers
[i
].Sound
.SetPosition(dw
);
3356 gTriggers
[i
].userVars
.Free();
3357 gTriggers
[i
].userVars
:= nil;
3358 uvcount
:= utils
.readLongInt(st
);
3359 if (uvcount
< 0) or (uvcount
> 1024*1024) then raise XStreamError
.Create('invalid number of user vars in trigger');
3360 if (uvcount
> 0) then
3362 gTriggers
[i
].userVars
:= THashStrVariant
.Create();
3364 while (uvcount
> 0) do
3367 uvname
:= utils
.readStr(st
);
3368 vt
:= utils
.readLongInt(st
);
3370 varString
: begin ustr
:= utils
.readStr(st
); vv
:= ustr
; end;
3371 varBoolean
: begin ubool
:= utils
.readBool(st
); vv
:= ubool
; end;
3372 varShortInt
: begin uint
:= utils
.readLongInt(st
); vv
:= ShortInt(uint
); end;
3373 varSmallint
: begin uint
:= utils
.readLongInt(st
); vv
:= SmallInt(uint
); end;
3374 varInteger
: begin uint
:= utils
.readLongInt(st
); vv
:= LongInt(uint
); end;
3375 varByte
: begin uint
:= utils
.readLongInt(st
); vv
:= Byte(uint
); end;
3376 varWord
: begin uint
:= utils
.readLongInt(st
); vv
:= Word(uint
); end;
3377 varLongWord
: begin uint
:= utils
.readLongInt(st
); vv
:= LongWord(uint
); end;
3378 else raise Exception
.CreateFmt('cannot load uservar ''%s''', [uvname
]);
3380 gTriggers
[i
].userVars
.put(uvname
, vv
);