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}
23 MAPDEF
, e_graphics
, g_basic
, g_sound
,
24 BinEditor
, xdynrec
, hashtable
, exoma
;
27 THashStrVariant
= specialize THashBase
<AnsiString, Variant>;
45 TexturePanelGUID
: Integer;
46 TexturePanelType
: Word;
50 Activators
: array of TActivator
;
51 PlayerCollide
: Boolean;
55 SoundPlayCount
: Integer;
56 Sound
: TPlayableSound
;
58 SpawnCooldown
: Integer;
59 SpawnedCount
: Integer;
61 ShotPanelTime
: Integer;
62 ShotSightTime
: Integer;
63 ShotSightTimeout
: Integer;
64 ShotSightTarget
: Word;
65 ShotSightTargetN
: Word;
67 ShotReloadTime
: Integer;
69 mapId
: AnsiString; // trigger id, from map
70 mapIndex
: Integer; // index in fields['trigger'], used in save/load
71 trigPanelGUID
: Integer;
73 trigDataRec
: TDynRecord
; // triggerdata; owned by trigger (cloned)
74 exoInit
, exoThink
, exoCheck
, exoAction
: TExprBase
;
76 userVars
: THashStrVariant
;
78 {$INCLUDE ../shared/mapdef_tgc_def.inc}
81 function trigCenter (): TDFPoint
; inline;
84 function g_Triggers_Create(Trigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
85 procedure g_Triggers_Update();
86 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
87 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
88 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
89 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
90 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
91 procedure g_Triggers_OpenAll();
92 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
93 procedure g_Triggers_Free();
94 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
95 procedure g_Triggers_LoadState(var Mem
: TBinMemoryReader
);
99 gTriggerClientID
: Integer = 0;
100 gTriggers
: array of TTrigger
;
101 gSecretsCount
: Integer = 0;
102 gMonstersSpawned
: array of LongInt = nil;
109 g_player
, g_map
, g_panel
, g_gfx
, g_game
, g_textures
,
110 g_console
, g_monsters
, g_items
, g_phys
, g_weapons
,
111 wadreader
, g_main
, SysUtils
, e_log
, g_language
,
112 g_options
, g_net
, g_netmsg
, utils
, xparser
;
115 TRIGGER_SIGNATURE
= $58475254; // 'TRGX'
118 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
121 // ////////////////////////////////////////////////////////////////////////// //
123 TTrigScope
= class(TExprScope
)
126 monsprops
: TPropHash
;
127 platprops
: TPropHash
;
133 constructor Create ();
134 destructor Destroy (); override;
136 function getObj (const aname
: AnsiString): TObject
; override;
137 function getField (obj
: TObject
; const afldname
: AnsiString): Variant; override;
138 procedure setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant); override;
142 // ////////////////////////////////////////////////////////////////////////// //
144 TMyConstList
= class(TExprConstList
)
146 function valid (const cname
: AnsiString): Boolean; override;
147 function get (const cname
: AnsiString; out v
: Variant): Boolean; override;
151 // ////////////////////////////////////////////////////////////////////////// //
152 function TMyConstList
.valid (const cname
: AnsiString): Boolean;
154 //writeln('CHECK: ''', cname, '''');
156 (cname
= 'player') or
161 function TMyConstList
.get (const cname
: AnsiString; out v
: Variant): Boolean;
166 //if (cname = 'answer') then begin v := LongInt(42); result := true; exit; end;
168 if (gCurrentMap
= nil) then exit
;
169 for eidx
:= 0 to gCurrentMap
.mapdef
.ebsTypeCount
-1 do
171 ebs
:= gCurrentMap
.mapdef
.ebsTypeAt
[eidx
];
172 if ebs
.has
[cname
] then
174 //writeln('FOUND: ''', cname, '''');
183 // ////////////////////////////////////////////////////////////////////////// //
184 constructor TTrigScope
.Create ();
186 plrprops
:= TPropHash
.Create(TPlayer
, 'e');
187 monsprops
:= TPropHash
.Create(TMonster
, 'e');
188 platprops
:= TPropHash
.Create(TPanel
, 'e');
193 destructor TTrigScope
.Destroy ();
202 function TTrigScope
.getObj (const aname
: AnsiString): TObject
;
204 if (aname
= 'player') then result
:= gPlayers
[0] //FIXME
205 else if (aname
= 'self') or (aname
= 'this') then result
:= TObject(Pointer(PtrUInt(1)))
206 else result
:= inherited getObj(aname
);
210 function TTrigScope
.getField (obj
: TObject
; const afldname
: AnsiString): Variant;
212 if (obj
= gPlayers
[0]) then
214 if plrprops
.get(obj
, afldname
, result
) then exit
;
216 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
218 if (me
<> nil) and (me
.userVars
<> nil) then
220 if me
.userVars
.get(afldname
, result
) then exit
;
223 result
:= inherited getField(obj
, afldname
);
227 procedure TTrigScope
.setField (obj
: TObject
; const afldname
: AnsiString; var aval
: Variant);
229 if (obj
= gPlayers
[0]) then
231 if plrprops
.put(obj
, afldname
, aval
) then exit
;
233 else if (obj
= TObject(Pointer(PtrUInt(1)))) then
237 if (Length(afldname
) > 4) and (afldname
[1] = 'u') and (afldname
[2] = 's') and
238 (afldname
[3] = 'e') and (afldname
[4] = 'r') then
240 if (me
.userVars
= nil) then me
.userVars
:= THashStrVariant
.Create(hsihash
, hsiequ
);
241 me
.userVars
.put(afldname
, aval
);
246 inherited setField(obj
, afldname
, aval
);
250 // ////////////////////////////////////////////////////////////////////////// //
252 tgscope
: TTrigScope
= nil;
253 tgclist
: TMyConstList
= nil;
256 // ////////////////////////////////////////////////////////////////////////// //
257 function TTrigger
.trigCenter (): TDFPoint
; inline;
259 result
:= TDFPoint
.Create(x
+width
div 2, y
+height
div 2);
263 function FindTrigger (): DWORD
;
267 olen
:= Length(gTriggers
);
269 for i
:= 0 to olen
-1 do
271 if gTriggers
[i
].TriggerType
= TRIGGER_NONE
then begin result
:= i
; exit
; end;
274 SetLength(gTriggers
, olen
+8);
277 for i
:= result
to High(gTriggers
) do
279 gTriggers
[i
].TriggerType
:= TRIGGER_NONE
;
280 gTriggers
[i
].trigDataRec
:= nil;
281 gTriggers
[i
].exoInit
:= nil;
282 gTriggers
[i
].exoThink
:= nil;
283 gTriggers
[i
].exoCheck
:= nil;
284 gTriggers
[i
].exoAction
:= nil;
285 gTriggers
[i
].userVars
:= nil;
290 function tr_CloseDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
297 pan
:= g_Map_PanelByGUID(PanelGUID
);
298 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
299 PanelID
:= pan
.arrIdx
;
303 with gWalls
[PanelID
] do
305 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then Exit
;
310 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
311 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
313 g_Map_EnableWallGUID(PanelGUID
);
320 if (gDoorMap
= nil) then exit
;
323 for a
:= 0 to High(gDoorMap
) do
325 for b
:= 0 to High(gDoorMap
[a
]) do
327 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
333 if (c
<> -1) then break
;
335 if (c
= -1) then exit
;
337 for b
:= 0 to High(gDoorMap
[c
]) do
339 with gWalls
[gDoorMap
[c
, b
]] do
341 if g_CollidePlayer(X
, Y
, Width
, Height
) or g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then exit
;
347 for b
:= 0 to High(gDoorMap
[c
]) do
349 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
351 with gWalls
[PanelID
] do
353 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X
, Y
);
354 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOORCLOSE');
361 for b
:= 0 to High(gDoorMap
[c
]) do
363 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
365 g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
373 procedure tr_CloseTrap (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean);
376 wx
, wy
, wh
, ww
: Integer;
380 function monsDamage (mon
: TMonster
): Boolean;
382 result
:= false; // don't stop
383 if g_Obj_Collide(wx
, wy
, ww
, wh
, @mon
.Obj
) then mon
.Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
387 pan
:= g_Map_PanelByGUID(PanelGUID
);
391 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
395 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
398 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
399 PanelID
:= pan
.arrIdx
;
403 with gWalls
[PanelID
] do
405 if (not NoSound
) and (not Enabled
) then
407 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
408 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
412 wx
:= gWalls
[PanelID
].X
;
413 wy
:= gWalls
[PanelID
].Y
;
414 ww
:= gWalls
[PanelID
].Width
;
415 wh
:= gWalls
[PanelID
].Height
;
417 with gWalls
[PanelID
] do
419 if gPlayers
<> nil then
421 for a
:= 0 to High(gPlayers
) do
423 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
425 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
430 //g_Mons_ForEach(monsDamage);
431 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
433 if not Enabled
then g_Map_EnableWallGUID(PanelGUID
);
438 if (gDoorMap
= nil) then exit
;
441 for a
:= 0 to High(gDoorMap
) do
443 for b
:= 0 to High(gDoorMap
[a
]) do
445 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
451 if (c
<> -1) then break
;
453 if (c
= -1) then exit
;
457 for b
:= 0 to High(gDoorMap
[c
]) do
459 if not gWalls
[gDoorMap
[c
, b
]].Enabled
then
461 with gWalls
[PanelID
] do
463 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X
, Y
);
464 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH1');
471 for b
:= 0 to High(gDoorMap
[c
]) do
473 wx
:= gWalls
[gDoorMap
[c
, b
]].X
;
474 wy
:= gWalls
[gDoorMap
[c
, b
]].Y
;
475 ww
:= gWalls
[gDoorMap
[c
, b
]].Width
;
476 wh
:= gWalls
[gDoorMap
[c
, b
]].Height
;
478 with gWalls
[gDoorMap
[c
, b
]] do
480 if gPlayers
<> nil then
482 for a
:= 0 to High(gPlayers
) do
484 if (gPlayers
[a
] <> nil) and gPlayers
[a
].alive
and gPlayers
[a
].Collide(X
, Y
, Width
, Height
) then
486 gPlayers
[a
].Damage(TRAP_DAMAGE
, 0, 0, 0, HIT_TRAP
);
491 //g_Mons_ForEach(monsDamage);
492 g_Mons_ForEachAliveAt(wx
, wy
, ww
, wh
, monsDamage
);
494 if gMonsters <> nil then
495 for a := 0 to High(gMonsters) do
496 if (gMonsters[a] <> nil) and gMonsters[a].alive and
497 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
498 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
501 if not Enabled
then g_Map_EnableWall_XXX(gDoorMap
[c
, b
]);
508 function tr_OpenDoor (PanelGUID
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
515 pan
:= g_Map_PanelByGUID(PanelGUID
);
516 if (pan
= nil) or not pan
.isGWall
then exit
; //!FIXME!TRIGANY!
517 PanelID
:= pan
.arrIdx
;
521 with gWalls
[PanelID
] do
527 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
528 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
530 g_Map_DisableWallGUID(PanelGUID
);
537 if (gDoorMap
= nil) then exit
;
540 for a
:= 0 to High(gDoorMap
) do
542 for b
:= 0 to High(gDoorMap
[a
]) do
544 if gDoorMap
[a
, b
] = DWORD(PanelID
) then
550 if (c
<> -1) then break
;
552 if (c
= -1) then exit
;
556 for b
:= 0 to High(gDoorMap
[c
]) do
558 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
560 with gWalls
[PanelID
] do
562 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X
, Y
);
563 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_DOOROPEN');
570 for b
:= 0 to High(gDoorMap
[c
]) do
572 if gWalls
[gDoorMap
[c
, b
]].Enabled
then
574 g_Map_DisableWall_XXX(gDoorMap
[c
, b
]);
582 function tr_SetLift (PanelGUID
: Integer; d
: Integer; NoSound
: Boolean; d2d
: Boolean): Boolean;
590 pan
:= g_Map_PanelByGUID(PanelGUID
);
591 if (pan
= nil) or not pan
.isGLift
then exit
; //!FIXME!TRIGANY!
592 PanelID
:= pan
.arrIdx
;
594 if (gLifts
[PanelID
].PanelType
= PANEL_LIFTUP
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTDOWN
) then
599 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 1, 0, 1);
602 else if (gLifts
[PanelID
].PanelType
= PANEL_LIFTLEFT
) or (gLifts
[PanelID
].PanelType
= PANEL_LIFTRIGHT
) then
607 else t
:= IfThen(gLifts
[PanelID
].LiftType
= 2, 3, 2);
613 with gLifts
[PanelID
] do
615 if (LiftType
<> t
) then
617 g_Map_SetLiftGUID(PanelGUID
, t
); //???
618 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
625 if (gLiftMap
= nil) then exit
;
628 for a
:= 0 to High(gLiftMap
) do
630 for b
:= 0 to High(gLiftMap
[a
]) do
632 if (gLiftMap
[a
, b
] = DWORD(PanelID
)) then
638 if (c
<> -1) then break
;
640 if (c
= -1) then exit
;
643 for b := 0 to High(gLiftMap[c]) do
644 if gLifts[gLiftMap[c, b]].LiftType <> t then
646 with gLifts[PanelID] do
647 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
651 for b
:= 0 to High(gLiftMap
[c
]) do
653 with gLifts
[gLiftMap
[c
, b
]] do
655 if (LiftType
<> t
) then
657 g_Map_SetLift_XXX(gLiftMap
[c
, b
], t
);
666 function tr_SpawnShot (ShotType
: Integer; wx
, wy
, dx
, dy
: Integer; ShotSound
: Boolean; ShotTarget
: Word): Integer;
674 TextureID
:= DWORD(-1);
675 snd
:= 'SOUND_WEAPON_FIREROCKET';
681 g_Weapon_pistol(wx
, wy
, dx
, dy
, 0, True);
682 snd
:= 'SOUND_WEAPON_FIREPISTOL';
686 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
687 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
693 g_Weapon_mgun(wx
, wy
, dx
, dy
, 0, True);
694 if gSoundEffectsDF
then snd
:= 'SOUND_WEAPON_FIRECGUN'
695 else snd
:= 'SOUND_WEAPON_FIREPISTOL';
699 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_BULLET
);
700 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL1
);
704 TRIGGER_SHOT_SHOTGUN
:
706 g_Weapon_Shotgun(wx
, wy
, dx
, dy
, 0, True);
707 snd
:= 'SOUND_WEAPON_FIRESHOTGUN';
711 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
712 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL2
);
718 g_Weapon_DShotgun(wx
, wy
, dx
, dy
, 0, True);
719 snd
:= 'SOUND_WEAPON_FIRESHOTGUN2';
723 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
724 g_Player_CreateShell(wx
, wy
, 0, -2, SHELL_SHELL
);
725 if g_Game_IsNet
then MH_SEND_Effect(wx
, wy
, 0, NET_GFX_SHELL3
);
731 g_Weapon_ball1(wx
, wy
, dx
, dy
, 0, -1, True);
732 snd
:= 'SOUND_WEAPON_FIREBALL';
737 g_Weapon_Plasma(wx
, wy
, dx
, dy
, 0, -1, True);
738 snd
:= 'SOUND_WEAPON_FIREPLASMA';
743 g_Weapon_aplasma(wx
, wy
, dx
, dy
, 0, -1, True);
744 snd
:= 'SOUND_WEAPON_FIREPLASMA';
749 g_Weapon_ball2(wx
, wy
, dx
, dy
, 0, -1, True);
750 snd
:= 'SOUND_WEAPON_FIREBALL';
755 g_Weapon_ball7(wx
, wy
, dx
, dy
, 0, -1, True);
756 snd
:= 'SOUND_WEAPON_FIREBALL';
761 g_Weapon_manfire(wx
, wy
, dx
, dy
, 0, -1, True);
762 snd
:= 'SOUND_WEAPON_FIREBALL';
767 g_Weapon_revf(wx
, wy
, dx
, dy
, 0, ShotTarget
, -1, True);
768 snd
:= 'SOUND_WEAPON_FIREREV';
773 g_Weapon_Rocket(wx
, wy
, dx
, dy
, 0, -1, True);
774 snd
:= 'SOUND_WEAPON_FIREROCKET';
779 g_Weapon_BFGShot(wx
, wy
, dx
, dy
, 0, -1, True);
780 snd
:= 'SOUND_WEAPON_FIREBFG';
785 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_ROCKET') then
787 Anim
:= TAnimation
.Create(TextureID
, False, 6);
788 Anim
.Blending
:= False;
789 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
793 g_Weapon_Explode(wx
, wy
, 60, 0);
794 snd
:= 'SOUND_WEAPON_EXPLODEROCKET';
797 TRIGGER_SHOT_BFGEXPL
:
799 if g_Frames_Get(TextureID
, 'FRAMES_EXPLODE_BFG') then
801 Anim
:= TAnimation
.Create(TextureID
, False, 6);
802 Anim
.Blending
:= False;
803 g_GFX_OnceAnim(wx
-64, wy
-64, Anim
);
807 g_Weapon_BFG9000(wx
, wy
, 0);
808 snd
:= 'SOUND_WEAPON_EXPLODEBFG';
814 if g_Game_IsNet
and g_Game_IsServer
then
817 TRIGGER_SHOT_EXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_EXPLODE
);
818 TRIGGER_SHOT_BFGEXPL
: MH_SEND_Effect(wx
, wy
, Byte(ShotSound
), NET_GFX_BFGEXPL
);
821 if Projectile
then MH_SEND_CreateShot(LastShotID
);
822 if ShotSound
then MH_SEND_Sound(wx
, wy
, snd
);
827 if ShotSound
then g_Sound_PlayExAt(snd
, wx
, wy
);
829 if Projectile
then Result
:= LastShotID
;
833 procedure MakeShot (var Trigger
: TTrigger
; wx
, wy
, dx
, dy
: Integer; TargetUID
: Word);
837 if (tgcAmmo
= 0) or ((tgcAmmo
> 0) and (ShotAmmoCount
> 0)) then
839 if (trigPanelGUID
<> -1) and (ShotPanelTime
= 0) then
841 g_Map_SwitchTextureGUID(ShotPanelType
, trigPanelGUID
);
842 ShotPanelTime
:= 4; // òèêîâ íà âñïûøêó âûñòðåëà
845 if (tgcSight
> 0) then ShotSightTimeout
:= 180; // ~= 5 ñåêóíä
847 if (ShotAmmoCount
> 0) then Dec(ShotAmmoCount
);
849 dx
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
850 dy
+= Random(tgcAccuracy
)-Random(tgcAccuracy
);
852 tr_SpawnShot(tgcShotType
, wx
, wy
, dx
, dy
, not tgcQuiet
, TargetUID
);
856 if (tgcReload
> 0) and (ShotReloadTime
= 0) then
858 ShotReloadTime
:= tgcReload
; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
865 procedure tr_MakeEffect (X
, Y
, VX
, VY
: Integer; T
, ST
, CR
, CG
, CB
: Byte; Silent
, Send
: Boolean);
870 if T
= TRIGGER_EFFECT_PARTICLE
then
873 TRIGGER_EFFECT_SLIQUID
:
875 if (CR
= 255) and (CG
= 0) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 1, 0, 0, 0)
876 else if (CR
= 0) and (CG
= 255) and (CB
= 0) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 2, 0, 0, 0)
877 else if (CR
= 0) and (CG
= 0) and (CB
= 255) then g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 3, 0, 0, 0)
878 else g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 0, 0, 0, 0);
880 TRIGGER_EFFECT_LLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 4, CR
, CG
, CB
);
881 TRIGGER_EFFECT_DLIQUID
: g_GFX_SimpleWater(X
, Y
, 1, VX
, VY
, 5, CR
, CG
, CB
);
882 TRIGGER_EFFECT_BLOOD
: g_GFX_Blood(X
, Y
, 1, VX
, VY
, 0, 0, CR
, CG
, CB
);
883 TRIGGER_EFFECT_SPARK
: g_GFX_Spark(X
, Y
, 1, GetAngle2(VX
, VY
), 0, 0);
884 TRIGGER_EFFECT_BUBBLE
: g_GFX_Bubbles(X
, Y
, 1, 0, 0);
888 if T
= TRIGGER_EFFECT_ANIMATION
then
891 EFFECT_TELEPORT
: begin
892 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
894 Anim
:= TAnimation
.Create(FramesID
, False, 3);
895 if not Silent
then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X
, Y
);
896 g_GFX_OnceAnim(X
-32, Y
-32, Anim
);
899 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
, Y
, Byte(not Silent
), NET_GFX_TELE
);
901 EFFECT_RESPAWN
: begin
902 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
904 Anim
:= TAnimation
.Create(FramesID
, False, 4);
905 if not Silent
then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X
, Y
);
906 g_GFX_OnceAnim(X
-16, Y
-16, Anim
);
909 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-16, Y
-16, Byte(not Silent
), NET_GFX_RESPAWN
);
912 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
914 Anim
:= TAnimation
.Create(FramesID
, False, 4);
915 if not Silent
then g_Sound_PlayExAt('SOUND_FIRE', X
, Y
);
916 g_GFX_OnceAnim(X
-32, Y
-128, Anim
);
919 if Send
and g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Effect(X
-32, Y
-128, Byte(not Silent
), NET_GFX_FIRE
);
926 function tr_Teleport (ActivateUID
: Integer; TX
, TY
: Integer; TDir
: Integer; Silent
: Boolean; D2D
: Boolean): Boolean;
932 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
933 case g_GetUIDType(ActivateUID
) of
936 p
:= g_Player_Get(ActivateUID
);
937 if p
= nil then Exit
;
940 if p
.TeleportTo(TX
-(p
.Obj
.Rect
.Width
div 2), TY
-p
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
944 if p
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
949 m
:= g_Monsters_ByUID(ActivateUID
);
950 if m
= nil then Exit
;
953 if m
.TeleportTo(TX
-(m
.Obj
.Rect
.Width
div 2), TY
-m
.Obj
.Rect
.Height
, Silent
, TDir
) then result
:= true;
957 if m
.TeleportTo(TX
, TY
, Silent
, TDir
) then result
:= true;
964 function tr_Push (ActivateUID
: Integer; VX
, VY
: Integer; ResetVel
: Boolean): Boolean;
970 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then exit
;
971 case g_GetUIDType(ActivateUID
) of
974 p
:= g_Player_Get(ActivateUID
);
975 if p
= nil then Exit
;
990 m
:= g_Monsters_ByUID(ActivateUID
);
991 if m
= nil then Exit
;
1007 function tr_Message (MKind
: Integer; MText
: string; MSendTo
: Integer; MTime
: Integer; ActivateUID
: Integer): Boolean;
1014 if (ActivateUID
< 0) or (ActivateUID
> $FFFF) then Exit
;
1015 msg
:= b_Text_Format(MText
);
1017 TRIGGER_MESSAGE_DEST_ME
: // activator
1019 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1021 if g_Game_IsWatchedPlayer(ActivateUID
) then
1023 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1024 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1028 p
:= g_Player_Get(ActivateUID
);
1029 if g_Game_IsNet
and (p
.FClientID
>= 0) then
1031 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, p
.FClientID
)
1032 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, p
.FClientID
);
1038 TRIGGER_MESSAGE_DEST_MY_TEAM
: // activator's team
1040 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1042 p
:= g_Player_Get(ActivateUID
);
1043 if g_Game_IsWatchedTeam(p
.Team
) then
1045 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1046 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1049 if g_Game_IsNet
then
1051 for i
:= Low(gPlayers
) to High(gPlayers
) do
1053 if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1055 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1056 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1063 TRIGGER_MESSAGE_DEST_ENEMY_TEAM
: // activator's enemy team
1065 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1067 p
:= g_Player_Get(ActivateUID
);
1068 if g_Game_IsWatchedTeam(p
.Team
) then
1070 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1071 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1074 if g_Game_IsNet
then
1076 for i
:= Low(gPlayers
) to High(gPlayers
) do
1078 if (gPlayers
[i
].Team
<> p
.Team
) and (gPlayers
[i
].FClientID
>= 0) then
1080 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1081 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1088 TRIGGER_MESSAGE_DEST_RED_TEAM
: // red team
1090 if g_Game_IsWatchedTeam(TEAM_RED
) then
1092 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1093 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1096 if g_Game_IsNet
then
1098 for i
:= Low(gPlayers
) to High(gPlayers
) do
1100 if (gPlayers
[i
].Team
= TEAM_RED
) and (gPlayers
[i
].FClientID
>= 0) then
1102 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1103 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1109 TRIGGER_MESSAGE_DEST_BLUE_TEAM
: // blue team
1111 if g_Game_IsWatchedTeam(TEAM_BLUE
) then
1113 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1114 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1117 if g_Game_IsNet
then
1119 for i
:= Low(gPlayers
) to High(gPlayers
) do
1121 if (gPlayers
[i
].Team
= TEAM_BLUE
) and (gPlayers
[i
].FClientID
>= 0) then
1123 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
, gPlayers
[i
].FClientID
)
1124 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
, gPlayers
[i
].FClientID
);
1130 TRIGGER_MESSAGE_DEST_EVERYONE
: // everyone
1132 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then g_Console_Add(msg
, True)
1133 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then g_Game_Message(msg
, MTime
);
1135 if g_Game_IsNet
then
1137 if MKind
= TRIGGER_MESSAGE_KIND_CHAT
then MH_SEND_Chat(msg
, NET_CHAT_SYSTEM
)
1138 else if MKind
= TRIGGER_MESSAGE_KIND_GAME
then MH_SEND_GameEvent(NET_EV_BIGTEXT
, MTime
, msg
);
1145 function tr_ShotAimCheck (var Trigger
: TTrigger
; Obj
: PObj
): Boolean;
1150 if TriggerType
<> TRIGGER_SHOT
then Exit
;
1151 result
:= (tgcAim
and TRIGGER_SHOT_AIM_ALLMAP
> 0)
1152 or g_Obj_Collide(X
, Y
, Width
, Height
, Obj
);
1153 if result
and (tgcAim
and TRIGGER_SHOT_AIM_TRACE
> 0) then
1155 result
:= g_TraceVector(tgcTX
, tgcTY
,
1156 Obj
^.X
+ Obj
^.Rect
.X
+ (Obj
^.Rect
.Width
div 2),
1157 Obj
^.Y
+ Obj
^.Rect
.Y
+ (Obj
^.Rect
.Height
div 2));
1163 function ActivateTrigger (var Trigger
: TTrigger
; actType
: Byte): Boolean;
1169 idx
, k
, wx
, wy
, xd
, yd
: Integer;
1180 function monsShotTarget (mon
: TMonster
): Boolean;
1182 result
:= false; // don't stop
1183 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1185 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1186 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1187 TargetUID
:= mon
.UID
;
1188 result
:= true; // stop
1192 function monsShotTargetMonPlr (mon
: TMonster
): Boolean;
1194 result
:= false; // don't stop
1195 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1197 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1198 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1199 TargetUID
:= mon
.UID
;
1200 result
:= true; // stop
1204 function monShotTargetPlrMon (mon
: TMonster
): Boolean;
1206 result
:= false; // don't stop
1207 if mon
.alive
and tr_ShotAimCheck(Trigger
, @(mon
.Obj
)) then
1209 xd
:= mon
.GameX
+ mon
.Obj
.Rect
.Width
div 2;
1210 yd
:= mon
.GameY
+ mon
.Obj
.Rect
.Height
div 2;
1211 TargetUID
:= mon
.UID
;
1212 result
:= true; // stop
1220 if g_Game_IsClient
then exit
;
1222 if not Trigger
.Enabled
then exit
;
1223 if (Trigger
.TimeOut
<> 0) and (actType
<> ACTIVATE_CUSTOM
) then exit
;
1224 if (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then exit
;
1226 if (Trigger
.exoCheck
<> nil) then
1228 //conwritefln('exocheck: [%s]', [Trigger.exoCheck.toString()]);
1230 tgscope
.me
:= @Trigger
;
1231 tvval
:= Trigger
.exoCheck
.value(tgscope
);
1233 if not Boolean(tvval
) then exit
;
1234 except on e
: Exception
do
1237 conwritefln('trigger exocheck error: %s [%s]', [e
.message, Trigger
.exoCheck
.toString()]);
1245 coolDown
:= (actType
<> 0);
1247 if (Trigger
.exoAction
<> nil) then
1249 //conwritefln('exoactivate: [%s]', [Trigger.exoAction.toString()]);
1251 tgscope
.me
:= @Trigger
;
1252 Trigger
.exoAction
.value(tgscope
);
1254 except on e
: Exception
do
1257 conwritefln('trigger exoactivate error: %s [%s]', [e
.message, Trigger
.exoAction
.toString()]);
1268 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1269 if g_Game_IsNet
then MH_SEND_Sound(X
, Y
, 'SOUND_GAME_SWITCH0');
1270 gExitByTrigger
:= True;
1271 g_Game_ExitLevel(tgcMap
);
1280 Result
:= tr_Teleport(ActivateUID
,
1281 tgcTarget
.X
, tgcTarget
.Y
,
1282 tgcDirection
, tgcSilent
,
1289 Result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1295 Result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1299 TRIGGER_DOOR
, TRIGGER_DOOR5
:
1301 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
1302 if (pan
<> nil) and pan
.isGWall
then
1304 if gWalls
[{trigPanelID}pan
.arrIdx
].Enabled
then
1306 result
:= tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1307 if (TriggerType
= TRIGGER_DOOR5
) then DoorTime
:= 180;
1311 result
:= tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
1314 if result
then TimeOut
:= 18;
1318 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
:
1320 tr_CloseTrap(trigPanelGUID
, tgcSilent
, tgcD2d
);
1322 if TriggerType
= TRIGGER_TRAP
then
1336 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
:
1339 if PressTime
= -1 then PressTime
:= tgcWait
;
1340 if coolDown
then TimeOut
:= 18 else TimeOut
:= 0;
1345 if g_GetUIDType(ActivateUID
) = UID_PLAYER
then
1349 if gLMSRespawn
= LMS_RESPAWN_NONE
then
1351 g_Player_Get(ActivateUID
).GetSecret();
1352 Inc(gCoopSecretsFound
);
1353 if g_Game_IsNet
then MH_SEND_GameStats();
1359 Result
:= tr_SetLift(trigPanelGUID
, 0, tgcSilent
, tgcD2d
);
1362 if (not tgcSilent
) and Result
then begin
1363 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1365 Y
+ (Height
div 2));
1366 if g_Game_IsServer
and g_Game_IsNet
then
1367 MH_SEND_Sound(X
+ (Width
div 2),
1369 'SOUND_GAME_SWITCH0');
1375 Result
:= tr_SetLift(trigPanelGUID
, 1, tgcSilent
, tgcD2d
);
1378 if (not tgcSilent
) and Result
then begin
1379 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1381 Y
+ (Height
div 2));
1382 if g_Game_IsServer
and g_Game_IsNet
then
1383 MH_SEND_Sound(X
+ (Width
div 2),
1385 'SOUND_GAME_SWITCH0');
1391 Result
:= tr_SetLift(trigPanelGUID
, 3, tgcSilent
, tgcD2d
);
1397 if (not tgcSilent
) and Result
then begin
1398 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1400 Y
+ (Height
div 2));
1401 if g_Game_IsServer
and g_Game_IsNet
then
1402 MH_SEND_Sound(X
+ (Width
div 2),
1404 'SOUND_GAME_SWITCH0');
1411 if tgcActivateOnce
then
1414 TriggerType
:= TRIGGER_NONE
;
1422 animonce
:= tgcAnimateOnce
;
1428 if Sound
<> nil then
1430 if tgcSoundSwitch
and Sound
.IsPlaying() then
1431 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1433 SoundPlayCount
:= 0;
1436 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1437 if (tgcPlayCount
> 0) or (not Sound
.IsPlaying()) then
1439 if tgcPlayCount
> 0 then
1440 SoundPlayCount
:= tgcPlayCount
1441 else // 0 - èãðàåì áåñêîíå÷íî
1442 SoundPlayCount
:= 1;
1445 if g_Game_IsNet
then MH_SEND_TriggerSound(Trigger
);
1449 TRIGGER_SPAWNMONSTER
:
1450 if (tgcSpawnMonsType
in [MONSTER_DEMON
..MONSTER_MAN
]) then
1453 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1455 AutoSpawn
:= not AutoSpawn
;
1457 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1461 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1462 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1463 for k
:= 1 to tgcMonsCount
do
1465 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1466 SpawnCooldown
:= tgcDelay
;
1467 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1470 mon
:= g_Monsters_Create(tgcSpawnMonsType
,
1472 TDirection(tgcDirection
), True);
1477 if (tgcHealth
> 0) then
1478 mon
.SetHealth(tgcHealth
);
1479 // Óñòàíàâëèâàåì ïîâåäåíèå:
1480 mon
.MonsterBehaviour
:= tgcBehaviour
;
1481 mon
.FNoRespawn
:= True;
1482 if g_Game_IsNet
then
1483 MH_SEND_MonsterSpawn(mon
.UID
);
1484 // Èäåì èñêàòü öåëü, åñëè íàäî:
1488 if tgcSpawnMonsType
<> MONSTER_BARREL
then Inc(gTotalMonsters
);
1490 if g_Game_IsNet
then
1492 SetLength(gMonstersSpawned
, Length(gMonstersSpawned
)+1);
1493 gMonstersSpawned
[High(gMonstersSpawned
)] := mon
.UID
;
1498 mon
.SpawnTrigger
:= ID
;
1503 EFFECT_TELEPORT
: begin
1504 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1506 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1507 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1508 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1509 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, Anim
);
1512 if g_Game_IsServer
and g_Game_IsNet
then
1513 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1514 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-32, 1,
1517 EFFECT_RESPAWN
: begin
1518 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1520 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1521 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1522 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1523 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, Anim
);
1526 if g_Game_IsServer
and g_Game_IsNet
then
1527 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-16,
1528 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2)-16, 1,
1532 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1534 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1535 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1536 g_GFX_OnceAnim(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1537 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, Anim
);
1540 if g_Game_IsServer
and g_Game_IsNet
then
1541 MH_SEND_Effect(mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2)-32,
1542 mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+mon
.Obj
.Rect
.Height
-128, 1,
1547 if g_Game_IsNet
then
1549 MH_SEND_GameStats();
1550 MH_SEND_CoopStats();
1557 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1558 if actType
= ACTIVATE_CUSTOM
then
1563 if (tgcSpawnItemType
in [ITEM_MEDKIT_SMALL
..ITEM_MAX
]) then
1566 if (tgcDelay
> 0) and (actType
<> ACTIVATE_CUSTOM
) then
1568 AutoSpawn
:= not AutoSpawn
;
1570 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1574 if ((tgcDelay
= 0) and (actType
<> ACTIVATE_CUSTOM
))
1575 or ((tgcDelay
> 0) and (actType
= ACTIVATE_CUSTOM
)) then
1576 if (not tgcDmonly
) or
1577 (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
1578 for k
:= 1 to tgcItemCount
do
1580 if (actType
= ACTIVATE_CUSTOM
) and (tgcDelay
> 0) then
1581 SpawnCooldown
:= tgcDelay
;
1582 if (tgcMax
> 0) and (SpawnedCount
>= tgcMax
) then
1585 iid
:= g_Items_Create(tgcTX
, tgcTY
,
1586 tgcSpawnItemType
, tgcGravity
, False, True);
1592 it
:= g_Items_ByIdx(iid
);
1593 it
.SpawnTrigger
:= ID
;
1598 EFFECT_TELEPORT
: begin
1599 it
:= g_Items_ByIdx(iid
);
1600 if g_Frames_Get(FramesID
, 'FRAMES_TELEPORT') then
1602 Anim
:= TAnimation
.Create(FramesID
, False, 3);
1603 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX
, tgcTY
);
1604 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1605 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, Anim
);
1608 if g_Game_IsServer
and g_Game_IsNet
then
1609 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1610 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-32, 1,
1613 EFFECT_RESPAWN
: begin
1614 it
:= g_Items_ByIdx(iid
);
1615 if g_Frames_Get(FramesID
, 'FRAMES_ITEM_RESPAWN') then
1617 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1618 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX
, tgcTY
);
1619 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1620 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, Anim
);
1623 if g_Game_IsServer
and g_Game_IsNet
then
1624 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-16,
1625 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+(it
.Obj
.Rect
.Height
div 2)-16, 1,
1629 it
:= g_Items_ByIdx(iid
);
1630 if g_Frames_Get(FramesID
, 'FRAMES_FIRE') then
1632 Anim
:= TAnimation
.Create(FramesID
, False, 4);
1633 g_Sound_PlayExAt('SOUND_FIRE', tgcTX
, tgcTY
);
1634 g_GFX_OnceAnim(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1635 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, Anim
);
1638 if g_Game_IsServer
and g_Game_IsNet
then
1639 MH_SEND_Effect(it
.Obj
.X
+it
.Obj
.Rect
.X
+(it
.Obj
.Rect
.Width
div 2)-32,
1640 it
.Obj
.Y
+it
.Obj
.Rect
.Y
+it
.Obj
.Rect
.Height
-128, 1,
1645 if g_Game_IsNet
then
1646 MH_SEND_ItemSpawn(True, iid
);
1653 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1654 if actType
= ACTIVATE_CUSTOM
then
1660 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1661 if (Trigger
.tgcMusicName
<> '') then
1663 gMusic
.SetByName(Trigger
.tgcMusicName
);
1664 gMusic
.SpecPause
:= True;
1668 case Trigger
.tgcMusicAction
of
1669 TRIGGER_MUSIC_ACTION_STOP
: // Âûêëþ÷èòü
1670 gMusic
.SpecPause
:= True; // Ïàóçà
1671 TRIGGER_MUSIC_ACTION_PLAY
: // Âêëþ÷èòü
1672 if gMusic
.SpecPause
then // Áûëà íà ïàóçå => èãðàòü
1673 gMusic
.SpecPause
:= False
1674 else // Èãðàëà => ñíà÷àëà
1675 gMusic
.SetPosition(0);
1683 if g_Game_IsNet
then MH_SEND_TriggerMusic
;
1688 pAngle
:= -DegToRad(tgcAngle
);
1689 Result
:= tr_Push(ActivateUID
,
1690 Floor(Cos(pAngle
)*tgcForce
),
1691 Floor(Sin(pAngle
)*tgcForce
),
1699 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1700 if (tgcScoreAction
in [TRIGGER_SCORE_ACTION_ADD
, TRIGGER_SCORE_ACTION_SUB
]) and (tgcScoreCount
> 0) then
1702 // Ñâîåé èëè ÷óæîé êîìàíäå
1703 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1705 p
:= g_Player_Get(ActivateUID
);
1706 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1707 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1709 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1713 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1715 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1716 if g_Game_IsServer
and g_Game_IsNet
then
1717 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+r');
1720 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1721 if g_Game_IsServer
and g_Game_IsNet
then
1722 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+re');
1728 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1729 if g_Game_IsServer
and g_Game_IsNet
then
1730 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1733 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
))
1734 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1736 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1740 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1742 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1743 if g_Game_IsServer
and g_Game_IsNet
then
1744 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-r');
1747 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1748 if g_Game_IsServer
and g_Game_IsNet
then
1749 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-re');
1755 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1756 if g_Game_IsServer
and g_Game_IsNet
then
1757 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1760 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1761 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1763 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1767 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1769 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1770 if g_Game_IsServer
and g_Game_IsNet
then
1771 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+b');
1774 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1775 if g_Game_IsServer
and g_Game_IsNet
then
1776 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '+be');
1782 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1783 if g_Game_IsServer
and g_Game_IsNet
then
1784 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1787 if ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
))
1788 or ((tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1790 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1794 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1796 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_OWN
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1797 if g_Game_IsServer
and g_Game_IsNet
then
1798 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-b');
1801 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_ENEMY
], [p
.Name
, tgcScoreCount
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1802 if g_Game_IsServer
and g_Game_IsNet
then
1803 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
or (tgcScoreCount
shl 16), '-be');
1809 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1810 if g_Game_IsServer
and g_Game_IsNet
then
1811 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1814 Result
:= (p
.Team
= TEAM_RED
) or (p
.Team
= TEAM_BLUE
);
1816 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1817 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1819 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1821 Inc(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Scores
1825 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1826 if g_Game_IsServer
and g_Game_IsNet
then
1827 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tr');
1832 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1833 if g_Game_IsServer
and g_Game_IsNet
then
1834 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_RED
);
1837 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then
1839 Dec(gTeamStat
[TEAM_RED
].Goals
, tgcScoreCount
); // Red Fouls
1843 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_RED
], tgcScoreCount
]), True);
1844 if g_Game_IsServer
and g_Game_IsNet
then
1845 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tr');
1850 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 108);
1851 if g_Game_IsServer
and g_Game_IsNet
then
1852 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_RED
);
1855 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_ADD
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1857 Inc(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Scores
1861 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_ADD_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1862 if g_Game_IsServer
and g_Game_IsNet
then
1863 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '+tb');
1868 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_ADD
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1869 if g_Game_IsServer
and g_Game_IsNet
then
1870 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, TEAM_BLUE
);
1873 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_SUB
) and (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then
1875 Dec(gTeamStat
[TEAM_BLUE
].Goals
, tgcScoreCount
); // Blue Fouls
1879 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_SUB_TEAM
], [_lc
[I_PLAYER_SCORE_BLUE
], tgcScoreCount
]), True);
1880 if g_Game_IsServer
and g_Game_IsNet
then
1881 MH_SEND_GameEvent(NET_EV_SCORE
, tgcScoreCount
shl 16, '-tb');
1886 g_Game_Message(Format(_lc
[I_MESSAGE_SCORE_SUB
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 108);
1887 if g_Game_IsServer
and g_Game_IsNet
then
1888 MH_SEND_GameEvent(NET_EV_SCORE_MSG
, -TEAM_BLUE
);
1895 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_WIN
) and (gGameSettings
.GoalLimit
> 0) then
1897 // Ñâîåé èëè ÷óæîé êîìàíäû
1898 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1900 p
:= g_Player_Get(ActivateUID
);
1901 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Red Wins
1902 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
1904 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1906 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1910 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1912 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1913 if g_Game_IsServer
and g_Game_IsNet
then
1914 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
1917 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1918 if g_Game_IsServer
and g_Game_IsNet
then
1919 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1926 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Blue Wins
1927 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1929 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1931 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1935 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) then
1937 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1938 if g_Game_IsServer
and g_Game_IsNet
then
1939 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
1942 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
1943 if g_Game_IsServer
and g_Game_IsNet
then
1944 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
1952 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1953 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_RED
, TRIGGER_SCORE_TEAM_FORCE_BLUE
] then
1955 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Red Wins
1957 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1959 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1963 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Blue Wins
1965 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1967 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
1974 if (tgcScoreAction
= TRIGGER_SCORE_ACTION_LOOSE
) and (gGameSettings
.GoalLimit
> 0) then
1976 // Ñâîåé èëè ÷óæîé êîìàíäû
1977 if (tgcScoreTeam
in [TRIGGER_SCORE_TEAM_MINE_RED
, TRIGGER_SCORE_TEAM_MINE_BLUE
]) and (g_GetUIDType(ActivateUID
) = UID_PLAYER
) then
1979 p
:= g_Player_Get(ActivateUID
);
1980 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_BLUE
)) // Red Wins
1981 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_RED
)) then
1982 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
1984 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
1987 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
1989 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1990 if g_Game_IsServer
and g_Game_IsNet
then
1991 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wre');
1994 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_RED
]]), True);
1995 if g_Game_IsServer
and g_Game_IsNet
then
1996 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wr');
2001 if ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
) and (p
.Team
= TEAM_RED
)) // Blue Wins
2002 or ((tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_BLUE
) and (p
.Team
= TEAM_BLUE
)) then
2003 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2005 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2008 if tgcScoreTeam
= TRIGGER_SCORE_TEAM_MINE_RED
then
2010 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_ENEMY
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2011 if g_Game_IsServer
and g_Game_IsNet
then
2012 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wbe');
2015 g_Console_Add(Format(_lc
[I_PLAYER_SCORE_WIN_OWN
], [p
.Name
, _lc
[I_PLAYER_SCORE_TO_BLUE
]]), True);
2016 if g_Game_IsServer
and g_Game_IsNet
then
2017 MH_SEND_GameEvent(NET_EV_SCORE
, p
.UID
, 'wb');
2023 // Êàêîé-òî êîíêðåòíîé êîìàíäû
2024 if tgcScoreTeam
in [TRIGGER_SCORE_TEAM_FORCE_BLUE
, TRIGGER_SCORE_TEAM_FORCE_RED
] then
2026 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_BLUE
) then // Red Wins
2028 if gTeamStat
[TEAM_RED
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2030 gTeamStat
[TEAM_RED
].Goals
:= gGameSettings
.GoalLimit
;
2034 if (tgcScoreTeam
= TRIGGER_SCORE_TEAM_FORCE_RED
) then // Blue Wins
2036 if gTeamStat
[TEAM_BLUE
].Goals
< SmallInt(gGameSettings
.GoalLimit
) then
2038 gTeamStat
[TEAM_BLUE
].Goals
:= gGameSettings
.GoalLimit
;
2044 if Result
then begin
2049 if g_Game_IsServer
and g_Game_IsNet
then
2056 Result
:= tr_Message(tgcKind
, tgcText
,
2057 tgcMsgDest
, tgcMsgTime
,
2062 TRIGGER_DAMAGE
, TRIGGER_HEALTH
:
2065 UIDType
:= g_GetUIDType(ActivateUID
);
2066 if (UIDType
= UID_PLAYER
) or (UIDType
= UID_MONSTER
) then
2072 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
2073 for idx
:= 0 to High(Activators
) do
2074 if Activators
[idx
].UID
= ActivateUID
then
2080 begin // Âèäèì åãî âïåðâûå
2082 SetLength(Activators
, Length(Activators
) + 1);
2083 k
:= High(Activators
);
2084 Activators
[k
].UID
:= ActivateUID
;
2086 begin // Óæå âèäåëè åãî
2087 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
2088 if (tgcInterval
= 0) and (Activators
[k
].TimeOut
> 0) then
2089 Activators
[k
].TimeOut
:= 65535;
2090 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
2091 Result
:= Activators
[k
].TimeOut
= 0;
2100 p
:= g_Player_Get(ActivateUID
);
2104 // Íàíîñèì óðîí èãðîêó
2105 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2106 p
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
2109 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2110 if p
.Heal(tgcAmount
, not tgcHealMax
) and (not tgcSilent
) then
2112 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p
.Obj
.X
, p
.Obj
.Y
);
2113 if g_Game_IsServer
and g_Game_IsNet
then
2114 MH_SEND_Sound(p
.Obj
.X
, p
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2120 m
:= g_Monsters_ByUID(ActivateUID
);
2124 // Íàíîñèì óðîí ìîíñòðó
2125 if (TriggerType
= TRIGGER_DAMAGE
) and (tgcAmount
> 0) then
2126 m
.Damage(tgcAmount
, 0, 0, 0, HIT_SOME
);
2129 if (TriggerType
= TRIGGER_HEALTH
) and (tgcAmount
> 0) then
2130 if m
.Heal(tgcAmount
) and (not tgcSilent
) then
2132 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m
.Obj
.X
, m
.Obj
.Y
);
2133 if g_Game_IsServer
and g_Game_IsNet
then
2134 MH_SEND_Sound(m
.Obj
.X
, m
.Obj
.Y
, 'SOUND_ITEM_GETITEM');
2138 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
2142 Activators
[k
].TimeOut
:= idx
2144 Activators
[k
].TimeOut
:= 65535;
2152 if ShotSightTime
> 0 then
2155 // put this at the beginning so it doesn't trigger itself
2156 TimeOut
:= tgcWait
+ 1;
2160 pAngle
:= -DegToRad(tgcAngle
);
2161 xd
:= wx
+ Round(Cos(pAngle
) * 32.0);
2162 yd
:= wy
+ Round(Sin(pAngle
) * 32.0);
2165 case tgcShotTarget
of
2166 TRIGGER_SHOT_TARGET_MON
: // monsters
2167 //TODO: accelerate this!
2168 g_Mons_ForEachAlive(monsShotTarget
);
2170 TRIGGER_SHOT_TARGET_PLR
: // players
2171 if gPlayers
<> nil then
2172 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2173 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2174 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2176 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2177 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2178 TargetUID
:= gPlayers
[idx
].UID
;
2182 TRIGGER_SHOT_TARGET_RED
: // red team
2183 if gPlayers
<> nil then
2184 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2185 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2186 (gPlayers
[idx
].Team
= TEAM_RED
) and
2187 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2189 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2190 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2191 TargetUID
:= gPlayers
[idx
].UID
;
2195 TRIGGER_SHOT_TARGET_BLUE
: // blue team
2196 if gPlayers
<> nil then
2197 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2198 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2199 (gPlayers
[idx
].Team
= TEAM_BLUE
) and
2200 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2202 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2203 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2204 TargetUID
:= gPlayers
[idx
].UID
;
2208 TRIGGER_SHOT_TARGET_MONPLR
: // monsters then players
2210 //TODO: accelerate this!
2211 g_Mons_ForEachAlive(monsShotTargetMonPlr
);
2213 if (TargetUID
= 0) and (gPlayers
<> nil) then
2214 for idx
:= Low(gPlayers
) to High(gPlayers
) do
2215 if (gPlayers
[idx
] <> nil) and gPlayers
[idx
].alive
and
2216 tr_ShotAimCheck(Trigger
, @(gPlayers
[idx
].Obj
)) then
2218 xd
:= gPlayers
[idx
].GameX
+ PLAYER_RECT_CX
;
2219 yd
:= gPlayers
[idx
].GameY
+ PLAYER_RECT_CY
;
2220 TargetUID
:= gPlayers
[idx
].UID
;
2225 TRIGGER_SHOT_TARGET_PLRMON
: // players then monsters
2227 if 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
;
2237 if TargetUID
= 0 then
2239 //TODO: accelerate this!
2240 g_Mons_ForEachAlive(monShotTargetPlrMon
);
2245 if (tgcShotTarget
<> TRIGGER_SHOT_TARGET_NONE
) or
2246 (tgcShotType
<> TRIGGER_SHOT_REV
) then
2247 TargetUID
:= ActivateUID
;
2251 if (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or (TargetUID
> 0) or
2252 ((tgcShotTarget
> TRIGGER_SHOT_TARGET_NONE
) and (TargetUID
= 0)) then
2255 if (tgcSight
= 0) or
2256 (tgcShotTarget
= TRIGGER_SHOT_TARGET_NONE
) or
2257 (TargetUID
= ShotSightTarget
) then
2258 MakeShot(Trigger
, wx
, wy
, xd
, yd
, TargetUID
)
2261 ShotSightTime
:= tgcSight
;
2262 ShotSightTargetN
:= TargetUID
;
2263 if tgcShotType
= TRIGGER_SHOT_BFG
then
2265 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx
, wy
);
2266 if g_Game_IsNet
and g_Game_IsServer
then
2267 MH_SEND_Sound(wx
, wy
, 'SOUND_WEAPON_STARTFIREBFG');
2280 TRIGGER_EFFECT_POS_CENTER
:
2282 wx
:= X
+ Width
div 2;
2283 wy
:= Y
+ Height
div 2;
2285 TRIGGER_EFFECT_POS_AREA
:
2287 wx
:= X
+ Random(Width
);
2288 wy
:= Y
+ Random(Height
);
2291 wx
:= X
+ Width
div 2;
2292 wy
:= Y
+ Height
div 2;
2297 if tgcSpreadL
> 0 then xd
-= Random(tgcSpreadL
+1);
2298 if tgcSpreadR
> 0 then xd
+= Random(tgcSpreadR
+1);
2299 if tgcSpreadU
> 0 then yd
-= Random(tgcSpreadU
+1);
2300 if tgcSpreadD
> 0 then yd
+= Random(tgcSpreadD
+1);
2301 tr_MakeEffect(wx
, wy
, xd
, yd
,
2302 tgcFXType
, tgcFXSubType
,
2303 tgcFXRed
, tgcFXGreen
, tgcFXBlue
, True, False);
2311 if Result
{and (Trigger.TexturePanel <> -1)} then
2313 g_Map_SwitchTextureGUID(Trigger
.TexturePanelType
, Trigger
.TexturePanelGUID
, IfThen(animonce
, 2, 1));
2318 function g_Triggers_CreateWithMapIndex (Trigger
: TTrigger
; arridx
, mapidx
: Integer): DWORD
;
2320 triggers
: TDynField
;
2322 triggers
:= gCurrentMap
['trigger'];
2323 if (triggers
= nil) then raise Exception
.Create('LOAD: map has no triggers');
2324 if (mapidx
< 0) or (mapidx
>= triggers
.count
) then raise Exception
.Create('LOAD: invalid map trigger index');
2325 //Trigger.trigDataRec := triggers.itemAt[mapidx];
2326 //if (Trigger.trigDataRec = nil) then raise Exception.Create('LOAD: internal error in trigger loader');
2327 //Trigger.mapId := Trigger.trigDataRec.id;
2328 Trigger
.mapIndex
:= mapidx
;
2330 if (Trigger.trigDataRec.trigRec <> nil) then
2332 Trigger.trigDataRec := Trigger.trigDataRec.trigRec.clone(nil);
2336 Trigger.trigDataRec := nil;
2339 result
:= g_Triggers_Create(Trigger
, triggers
.itemAt
[mapidx
], arridx
);
2343 function g_Triggers_Create(Trigger
: TTrigger
; trec
: TDynRecord
; forceInternalIndex
: Integer=-1): DWORD
;
2346 fn
, mapw
: AnsiString;
2349 if (tgscope
= nil) then tgscope
:= TTrigScope
.Create();
2350 if (tgclist
= nil) then tgclist
:= TMyConstList
.Create();
2352 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2353 if (Trigger
.TriggerType
= TRIGGER_EXIT
) and
2354 (not LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWEXIT
)) then
2355 Trigger
.TriggerType
:= TRIGGER_NONE
;
2357 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2358 if (Trigger
.TriggerType
= TRIGGER_SPAWNMONSTER
) and
2359 (not LongBool(gGameSettings
.Options
and GAME_OPTION_MONSTERS
)) and
2360 (gGameSettings
.GameType
<> GT_SINGLE
) then
2361 Trigger
.TriggerType
:= TRIGGER_NONE
;
2363 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2364 if Trigger
.TriggerType
= TRIGGER_SECRET
then gSecretsCount
+= 1;
2366 if (forceInternalIndex
< 0) then
2368 find_id
:= FindTrigger();
2372 olen
:= Length(gTriggers
);
2373 if (forceInternalIndex
>= olen
) then
2375 SetLength(gTriggers
, forceInternalIndex
+1);
2376 for f
:= olen
to High(gTriggers
) do
2378 gTriggers
[f
].TriggerType
:= TRIGGER_NONE
;
2379 gTriggers
[f
].trigDataRec
:= nil;
2380 gTriggers
[f
].exoInit
:= nil;
2381 gTriggers
[f
].exoThink
:= nil;
2382 gTriggers
[f
].exoCheck
:= nil;
2383 gTriggers
[f
].exoAction
:= nil;
2384 gTriggers
[f
].userVars
:= nil;
2387 f
:= forceInternalIndex
;
2388 gTriggers
[f
].trigDataRec
.Free();
2389 gTriggers
[f
].exoInit
.Free();
2390 gTriggers
[f
].exoThink
.Free();
2391 gTriggers
[f
].exoCheck
.Free();
2392 gTriggers
[f
].exoAction
.Free();
2393 gTriggers
[f
].userVars
.Free();
2394 gTriggers
[f
].trigDataRec
:= nil;
2395 gTriggers
[f
].exoInit
:= nil;
2396 gTriggers
[f
].exoThink
:= nil;
2397 gTriggers
[f
].exoCheck
:= nil;
2398 gTriggers
[f
].exoAction
:= nil;
2399 gTriggers
[f
].userVars
:= nil;
2400 find_id
:= DWORD(forceInternalIndex
);
2402 gTriggers
[find_id
] := Trigger
;
2404 Trigger
.mapId
:= trec
.id
;
2405 // clone trigger data
2406 if (trec
.trigRec
= nil) then
2408 gTriggers
[find_id
].trigDataRec
:= nil;
2410 if (gTriggers
[find_id
].TriggerType
<> TRIGGER_SECRET
) then
2412 e_LogWritefln('trigger of type %s has no triggerdata; wtf?!', [gTriggers
[find_id
].TriggerType
], MSG_WARNING
);
2417 gTriggers
[find_id
].trigDataRec
:= trec
.trigRec
.clone(nil);
2420 with gTriggers
[find_id
] do
2423 // if this type of trigger exists both on the client and on the server
2424 // use an uniform numeration
2425 if Trigger
.TriggerType
= TRIGGER_SOUND
then
2427 Inc(gTriggerClientID
);
2428 ClientID
:= gTriggerClientID
;
2436 PlayerCollide
:= False;
2440 SoundPlayCount
:= 0;
2447 // update cached trigger variables
2448 trigUpdateCacheData(gTriggers
[find_id
], gTriggers
[find_id
].trigDataRec
);
2450 gTriggers
[find_id
].userVars
:= nil; //THashStrVariant.Create(hsihash, hsiequ);
2453 gTriggers
[find_id
].exoThink
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_think']));
2455 on e
: TExomaParseException
do
2457 conwritefln('*** ERROR parsing exoma_think (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_think'])]);
2458 gTriggers
[find_id
].exoThink
:= nil;
2464 gTriggers
[find_id
].exoCheck
:= TExprBase
.parse(tgclist
, VarToStr(trec
.user
['exoma_check']));
2466 on e
: TExomaParseException
do
2468 conwritefln('*** ERROR parsing exoma_check (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_check'])]);
2469 gTriggers
[find_id
].exoCheck
:= nil;
2475 gTriggers
[find_id
].exoAction
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_action']));
2477 on e
: TExomaParseException
do
2479 conwritefln('*** ERROR parsing exoma_action (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_action'])]);
2480 gTriggers
[find_id
].exoAction
:= nil;
2486 gTriggers
[find_id
].exoInit
:= TExprBase
.parseStatList(tgclist
, VarToStr(trec
.user
['exoma_init']));
2488 on e
: TExomaParseException
do
2490 conwritefln('*** ERROR parsing exoma_init (%s,%s): %s [%s]', [e
.tokLine
, e
.tokCol
, e
.message, VarToStr(trec
.user
['exoma_init'])]);
2491 gTriggers
[find_id
].exoInit
:= nil;
2497 if (forceInternalIndex
< 0) and (gTriggers
[find_id
].exoInit
<> nil) then
2499 //conwritefln('executing trigger init: [%s]', [gTriggers[find_id].exoInit.toString()]);
2501 tgscope
.me
:= @gTriggers
[find_id
];
2502 gTriggers
[find_id
].exoInit
.value(tgscope
);
2506 conwritefln('*** trigger exoactivate error: %s', [gTriggers
[find_id
].exoInit
.toString()]);
2511 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2512 if (Trigger
.TriggerType
= TRIGGER_SOUND
) and (Trigger
.tgcSoundName
<> '') then
2514 // Åùå íåò òàêîãî çâóêà
2515 if not g_Sound_Exists(Trigger
.tgcSoundName
) then
2517 fn
:= g_ExtractWadName(Trigger
.tgcSoundName
);
2519 begin // Çâóê â ôàéëå ñ êàðòîé
2520 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2521 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.tgcSoundName
);
2523 else // Çâóê â îòäåëüíîì ôàéëå
2525 fn
:= GameDir
+ '/wads/' + Trigger
.tgcSoundName
;
2528 if not g_Sound_CreateWADEx(Trigger
.tgcSoundName
, fn
) then
2530 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.tgcSoundName
]));
2534 // Ñîçäàåì îáúåêò çâóêà
2535 with gTriggers
[find_id
] do
2537 Sound
:= TPlayableSound
.Create();
2538 if not Sound
.SetByName(Trigger
.tgcSoundName
) then
2546 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2547 if (Trigger
.TriggerType
= TRIGGER_MUSIC
) and (Trigger
.tgcMusicName
<> '') then
2549 // Åùå íåò òàêîé ìóçûêè
2550 if not g_Sound_Exists(Trigger
.tgcMusicName
) then
2552 fn
:= g_ExtractWadName(Trigger
.tgcMusicName
);
2555 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2556 mapw
:= g_ExtractWadName(gMapInfo
.Map
);
2557 fn
:= mapw
+':'+g_ExtractFilePathName(Trigger
.tgcMusicName
);
2559 else // Ìóçûêà â ôàéëå ñ êàðòîé
2561 fn
:= GameDir
+'/wads/'+Trigger
.tgcMusicName
;
2564 if not g_Sound_CreateWADEx(Trigger
.tgcMusicName
, fn
, True) then
2566 g_FatalError(Format(_lc
[I_GAME_ERROR_TR_SOUND
], [fn
, Trigger
.tgcMusicName
]));
2571 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2572 if Trigger
.TriggerType
= TRIGGER_SHOT
then
2574 with gTriggers
[find_id
] do
2578 ShotSightTimeout
:= 0;
2579 ShotSightTarget
:= 0;
2580 ShotSightTargetN
:= 0;
2581 ShotAmmoCount
:= Trigger
.tgcAmmo
;
2582 ShotReloadTime
:= 0;
2590 // sorry; grid doesn't support recursive queries, so we have to do this
2592 TSimpleMonsterList
= specialize TSimpleList
<TMonster
>;
2595 tgMonsList
: TSimpleMonsterList
= nil;
2597 procedure g_Triggers_Update();
2600 Affected
: array of Integer;
2602 function monsNear (mon
: TMonster
): Boolean;
2604 result
:= false; // don't stop
2606 gTriggers[a].ActivateUID := mon.UID;
2607 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2609 tgMonsList
.append(mon
);
2616 if (tgMonsList
= nil) then tgMonsList
:= TSimpleMonsterList
.Create();
2618 if gTriggers
= nil then
2620 SetLength(Affected
, 0);
2622 for a
:= 0 to High(gTriggers
) do
2623 with gTriggers
[a
] do
2625 if TriggerType
<> TRIGGER_NONE
then
2627 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2628 if DoorTime
> 0 then DoorTime
:= DoorTime
- 1;
2629 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2630 if PressTime
> 0 then PressTime
:= PressTime
- 1;
2631 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2632 if (TriggerType
= TRIGGER_DAMAGE
) or (TriggerType
= TRIGGER_HEALTH
) then
2634 for b
:= 0 to High(Activators
) do
2636 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2637 if Activators
[b
].TimeOut
> 0 then
2639 Dec(Activators
[b
].TimeOut
);
2645 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2646 if (tgcInterval
= 0) and (Activators
[b
].TimeOut
< 65530) then Activators
[b
].TimeOut
:= 0;
2650 // Îáðàáàòûâàåì ñïàâíåðû
2651 if Enabled
and AutoSpawn
then
2653 if SpawnCooldown
= 0 then
2655 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2656 if (TriggerType
= TRIGGER_SPAWNMONSTER
) and (tgcDelay
> 0) then
2659 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2661 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2662 if (TriggerType
= TRIGGER_SPAWNITEM
) and (tgcDelay
> 0) then
2665 ActivateTrigger(gTriggers
[a
], ACTIVATE_CUSTOM
);
2670 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2675 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2676 if TriggerType
= TRIGGER_SHOT
then
2678 if ShotPanelTime
> 0 then
2681 if ShotPanelTime
= 0 then g_Map_SwitchTextureGUID(ShotPanelType
, trigPanelGUID
);
2683 if ShotSightTime
> 0 then
2686 if ShotSightTime
= 0 then ShotSightTarget
:= ShotSightTargetN
;
2688 if ShotSightTimeout
> 0 then
2690 Dec(ShotSightTimeout
);
2691 if ShotSightTimeout
= 0 then ShotSightTarget
:= 0;
2693 if ShotReloadTime
> 0 then
2695 Dec(ShotReloadTime
);
2696 if ShotReloadTime
= 0 then ShotAmmoCount
:= tgcAmmo
;
2700 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2701 if Enabled
and (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) then
2703 if (SoundPlayCount
> 0) and (not Sound
.IsPlaying()) then
2705 if tgcPlayCount
> 0 then SoundPlayCount
-= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2708 Sound
.PlayVolumeAt(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
2712 Sound
.PlayPanVolume((tgcPan
-127.0)/128.0, tgcVolume
/255.0);
2714 if Sound
.IsPlaying() and g_Game_IsNet
and g_Game_IsServer
then MH_SEND_TriggerSound(gTriggers
[a
]);
2718 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2719 if (TriggerType
= TRIGGER_TRAP
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2721 tr_OpenDoor(trigPanelGUID
, tgcSilent
, tgcD2d
);
2725 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2726 if (TriggerType
= TRIGGER_DOOR5
) and (DoorTime
= 0) and (g_Map_PanelByGUID(trigPanelGUID
) <> nil) then
2728 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2729 if (pan
<> nil) and pan
.isGWall
then
2732 if {gWalls[trigPanelID].Enabled} pan
.Enabled
then
2738 // Ïîêà îòêðûòà - çàêðûâàåì
2739 if tr_CloseDoor(trigPanelGUID
, tgcSilent
, tgcD2d
) then DoorTime
:= -1;
2744 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2745 if (TriggerType
in [TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
]) and
2746 (PressTime
= 0) and (PressCount
>= tgcPressCount
) then
2748 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2750 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2751 if tgcPressCount
> 0 then PressCount
-= tgcPressCount
else PressCount
:= 0;
2753 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2754 for b
:= 0 to High(gTriggers
) do
2756 if g_Collide(tgcTX
, tgcTY
, tgcTWidth
, tgcTHeight
, gTriggers
[b
].X
, gTriggers
[b
].Y
,
2757 gTriggers
[b
].Width
, gTriggers
[b
].Height
) and
2758 ((b
<> a
) or (tgcWait
> 0)) then
2759 begin // Can be self-activated, if there is Data.Wait
2760 if (not tgcExtRandom
) or gTriggers
[b
].Enabled
then
2762 SetLength(Affected
, Length(Affected
) + 1);
2763 Affected
[High(Affected
)] := b
;
2769 // if we have panelid, assume that it will switch the moving platform
2770 pan
:= g_Map_PanelByGUID(trigPanelGUID
);
2771 if (pan
<> nil) then
2774 TRIGGER_PRESS
: pan
.movingActive
:= true; // what to do here?
2775 TRIGGER_ON
: pan
.movingActive
:= true;
2776 TRIGGER_OFF
: pan
.movingActive
:= false;
2777 TRIGGER_ONOFF
: pan
.movingActive
:= not pan
.movingActive
;
2779 if not tgcSilent
and (Length(tgcSound
) > 0) then
2781 g_Sound_PlayExAt(tgcSound
, X
, Y
);
2782 if g_Game_IsServer
and g_Game_IsNet
then MH_SEND_Sound(X
, Y
, tgcSound
);
2786 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2787 if (TriggerType
= TRIGGER_PRESS
) and tgcExtRandom
then
2789 if (Length(Affected
) > 0) then
2791 b
:= Affected
[Random(Length(Affected
))];
2792 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2793 ActivateTrigger(gTriggers
[b
], 0);
2796 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2798 for i
:= 0 to High(Affected
) do
2804 gTriggers
[b
].ActivateUID
:= gTriggers
[a
].ActivateUID
;
2805 ActivateTrigger(gTriggers
[b
], 0);
2809 gTriggers
[b
].Enabled
:= True;
2813 gTriggers
[b
].Enabled
:= False;
2814 gTriggers
[b
].TimeOut
:= 0;
2815 if gTriggers
[b
].AutoSpawn
then
2817 gTriggers
[b
].AutoSpawn
:= False;
2818 gTriggers
[b
].SpawnCooldown
:= 0;
2823 gTriggers
[b
].Enabled
:= not gTriggers
[b
].Enabled
;
2824 if not gTriggers
[b
].Enabled
then
2826 gTriggers
[b
].TimeOut
:= 0;
2827 if gTriggers
[b
].AutoSpawn
then
2829 gTriggers
[b
].AutoSpawn
:= False;
2830 gTriggers
[b
].SpawnCooldown
:= 0;
2837 SetLength(Affected
, 0);
2840 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2843 TimeOut
:= TimeOut
- 1;
2844 Continue
; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2847 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2852 if ByteBool(ActivateType
and ACTIVATE_PLAYERCOLLIDE
) and
2854 if gPlayers
<> nil then
2855 for b
:= 0 to High(gPlayers
) do
2856 if gPlayers
[b
] <> nil then
2858 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2859 if alive
and ((gTriggers
[a
].Keys
and GetKeys
) = gTriggers
[a
].Keys
) and
2860 Collide(X
, Y
, Width
, Height
) then
2862 gTriggers
[a
].ActivateUID
:= UID
;
2864 if (gTriggers
[a
].TriggerType
in [TRIGGER_SOUND
, TRIGGER_MUSIC
]) and
2866 { Don't activate sound/music again if player is here }
2868 ActivateTrigger(gTriggers
[a
], ACTIVATE_PLAYERCOLLIDE
);
2871 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2873 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2874 ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2875 (TimeOut
= 0) and (Keys
= 0) then
2877 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2878 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2879 ActivateType
:= ActivateType
and not (ACTIVATE_MONSTERCOLLIDE
or ACTIVATE_NOMONSTER
);
2880 gTriggers
[a
].ActivateUID
:= 0;
2881 ActivateTrigger(gTriggers
[a
], 0);
2885 if ByteBool(ActivateType
and ACTIVATE_MONSTERCOLLIDE
) and
2886 (TimeOut
= 0) and (Keys
= 0) then // Åñëè íå íóæíû êëþ÷è
2888 //g_Mons_ForEach(monsNear);
2891 g_Mons_ForEachAt(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
, monsNear
);
2892 for mon
in tgMonsList
do
2894 gTriggers
[a
].ActivateUID
:= mon
.UID
;
2895 ActivateTrigger(gTriggers
[a
], ACTIVATE_MONSTERCOLLIDE
);
2897 tgMonsList
.reset(); // just in case
2901 if ByteBool(ActivateType
and ACTIVATE_NOMONSTER
) and
2902 (TimeOut
= 0) and (Keys
= 0) then
2903 if not g_Mons_IsAnyAliveAt(X
, Y
, Width
, Height
) then
2905 gTriggers
[a
].ActivateUID
:= 0;
2906 ActivateTrigger(gTriggers
[a
], ACTIVATE_NOMONSTER
);
2910 PlayerCollide
:= g_CollidePlayer(X
, Y
, Width
, Height
);
2914 procedure g_Triggers_Press(ID
: DWORD
; ActivateType
: Byte; ActivateUID
: Word = 0);
2916 if (ID
>= Length(gTriggers
)) then exit
;
2917 gTriggers
[ID
].ActivateUID
:= ActivateUID
;
2918 ActivateTrigger(gTriggers
[ID
], ActivateType
);
2921 function g_Triggers_PressR(X
, Y
: Integer; Width
, Height
: Word; UID
: Word;
2922 ActivateType
: Byte; IgnoreList
: DWArray
= nil): DWArray
;
2930 if gTriggers
= nil then Exit
;
2932 case g_GetUIDType(UID
) of
2936 p
:= g_Player_Get(UID
);
2945 for a
:= 0 to High(gTriggers
) do
2946 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2947 (gTriggers
[a
].TimeOut
= 0) and
2948 (not InDWArray(a
, IgnoreList
)) and
2949 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2950 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2951 if g_Collide(X
, Y
, Width
, Height
,
2952 gTriggers
[a
].X
, gTriggers
[a
].Y
,
2953 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2955 gTriggers
[a
].ActivateUID
:= UID
;
2956 if ActivateTrigger(gTriggers
[a
], ActivateType
) then
2958 SetLength(Result
, Length(Result
)+1);
2959 Result
[High(Result
)] := a
;
2964 procedure g_Triggers_PressL(X1
, Y1
, X2
, Y2
: Integer; UID
: DWORD
; ActivateType
: Byte);
2970 if gTriggers
= nil then Exit
;
2972 case g_GetUIDType(UID
) of
2976 p
:= g_Player_Get(UID
);
2985 for a
:= 0 to High(gTriggers
) do
2986 if (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
2987 (gTriggers
[a
].TimeOut
= 0) and
2988 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
2989 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
2990 if g_CollideLine(x1
, y1
, x2
, y2
, gTriggers
[a
].X
, gTriggers
[a
].Y
,
2991 gTriggers
[a
].Width
, gTriggers
[a
].Height
) then
2993 gTriggers
[a
].ActivateUID
:= UID
;
2994 ActivateTrigger(gTriggers
[a
], ActivateType
);
2998 procedure g_Triggers_PressC(CX
, CY
: Integer; Radius
: Word; UID
: Word; ActivateType
: Byte; IgnoreTrigger
: Integer = -1);
3005 if gTriggers
= nil then
3008 case g_GetUIDType(UID
) of
3012 p
:= g_Player_Get(UID
);
3021 rsq
:= Radius
* Radius
;
3023 for a
:= 0 to High(gTriggers
) do
3024 if (gTriggers
[a
].ID
<> DWORD(IgnoreTrigger
)) and
3025 (gTriggers
[a
].TriggerType
<> TRIGGER_NONE
) and
3026 (gTriggers
[a
].TimeOut
= 0) and
3027 ((gTriggers
[a
].Keys
and k
) = gTriggers
[a
].Keys
) and
3028 ByteBool(gTriggers
[a
].ActivateType
and ActivateType
) then
3029 with gTriggers
[a
] do
3030 if g_Collide(CX
-Radius
, CY
-Radius
, 2*Radius
, 2*Radius
,
3031 X
, Y
, Width
, Height
) then
3032 if ((Sqr(CX
-X
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
3033 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
3034 ((Sqr(CX
-X
-Width
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
3035 ((Sqr(CX
-X
)+Sqr(CY
-Y
-Height
)) < rsq
) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
3036 ( (CX
> (X
-Radius
)) and (CX
< (X
+Width
+Radius
)) and
3037 (CY
> Y
) and (CY
< (Y
+Height
)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3038 ( (CY
> (Y
-Radius
)) and (CY
< (Y
+Height
+Radius
)) and
3039 (CX
> X
) and (CX
< (X
+Width
)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
3042 ActivateTrigger(gTriggers
[a
], ActivateType
);
3046 procedure g_Triggers_OpenAll();
3051 if gTriggers
= nil then Exit
;
3054 for a
:= 0 to High(gTriggers
) do
3056 with gTriggers
[a
] do
3058 if (TriggerType
= TRIGGER_OPENDOOR
) or
3059 (TriggerType
= TRIGGER_DOOR5
) or
3060 (TriggerType
= TRIGGER_DOOR
) then
3062 tr_OpenDoor(trigPanelGUID
, True, tgcD2d
);
3063 if TriggerType
= TRIGGER_DOOR5
then DoorTime
:= 180;
3069 if b
then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
3072 procedure g_Triggers_DecreaseSpawner(ID
: DWORD
);
3074 if (gTriggers
<> nil) then
3075 if gTriggers
[ID
].SpawnedCount
> 0 then
3076 Dec(gTriggers
[ID
].SpawnedCount
);
3080 procedure g_Triggers_Free ();
3084 for a
:= 0 to High(gTriggers
) do
3086 if (gTriggers
[a
].TriggerType
= TRIGGER_SOUND
) then
3088 if g_Sound_Exists(gTriggers
[a
].tgcSoundName
) then
3090 g_Sound_Delete(gTriggers
[a
].tgcSoundName
);
3092 gTriggers
[a
].Sound
.Free();
3094 if (gTriggers
[a
].Activators
<> nil) then
3096 SetLength(gTriggers
[a
].Activators
, 0);
3098 gTriggers
[a
].trigDataRec
.Free();
3100 gTriggers
[a
].exoThink
.Free();
3101 gTriggers
[a
].exoCheck
.Free();
3102 gTriggers
[a
].exoAction
.Free();
3103 gTriggers
[a
].userVars
.Free();
3108 SetLength(gMonstersSpawned
, 0);
3112 procedure g_Triggers_SaveState(var Mem
: TBinMemoryWriter
);
3114 count
, actCount
, i
, j
: Integer;
3118 kv
: THashStrVariant
.PEntry
;
3119 //it: THashStrVariant.TKeyValEnumerator;
3120 //uname: AnsiString;
3123 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
3124 count
:= Length(gTriggers
);
3125 Mem
:= TBinMemoryWriter
.Create((count
+1)*200);
3127 // Êîëè÷åñòâî òðèããåðîâ
3128 Mem
.WriteInt(count
);
3129 if (count
= 0) then exit
;
3131 for i
:= 0 to High(gTriggers
) do
3133 // Ñèãíàòóðà òðèããåðà
3134 dw
:= TRIGGER_SIGNATURE
; // 'TRGX'
3137 Mem
.WriteByte(gTriggers
[i
].TriggerType
);
3138 if (gTriggers
[i
].TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3139 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
3140 Mem
.WriteInt(gTriggers
[i
].mapIndex
);
3141 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
3142 Mem
.WriteInt(gTriggers
[i
].X
);
3143 Mem
.WriteInt(gTriggers
[i
].Y
);
3145 Mem
.WriteWord(gTriggers
[i
].Width
);
3146 Mem
.WriteWord(gTriggers
[i
].Height
);
3147 // Âêëþ÷åí ëè òðèããåð
3148 Mem
.WriteBoolean(gTriggers
[i
].Enabled
);
3149 // Òèï àêòèâàöèè òðèããåðà
3150 Mem
.WriteByte(gTriggers
[i
].ActivateType
);
3151 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
3152 Mem
.WriteByte(gTriggers
[i
].Keys
);
3153 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
3154 Mem
.WriteInt(gTriggers
[i
].TexturePanelGUID
);
3156 Mem
.WriteWord(gTriggers
[i
].TexturePanelType
);
3157 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3158 Mem
.WriteInt(gTriggers
[i
].trigPanelGUID
);
3159 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
3160 Mem
.WriteWord(gTriggers
[i
].TimeOut
);
3161 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
3162 Mem
.WriteWord(gTriggers
[i
].ActivateUID
);
3163 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
3164 actCount
:= Length(gTriggers
[i
].Activators
);
3165 Mem
.WriteInt(actCount
);
3166 for j
:= 0 to actCount
-1 do
3169 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].UID
);
3171 Mem
.WriteWord(gTriggers
[i
].Activators
[j
].TimeOut
);
3173 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
3174 Mem
.WriteBoolean(gTriggers
[i
].PlayerCollide
);
3175 // Âðåìÿ äî çàêðûòèÿ äâåðè
3176 Mem
.WriteInt(gTriggers
[i
].DoorTime
);
3177 // Çàäåðæêà àêòèâàöèè
3178 Mem
.WriteInt(gTriggers
[i
].PressTime
);
3180 Mem
.WriteInt(gTriggers
[i
].PressCount
);
3182 Mem
.WriteBoolean(gTriggers
[i
].AutoSpawn
);
3183 // Çàäåðæêà ñïàâíåðà
3184 Mem
.WriteInt(gTriggers
[i
].SpawnCooldown
);
3185 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
3186 Mem
.WriteInt(gTriggers
[i
].SpawnedCount
);
3187 // Ñêîëüêî ðàç ïðîèãðàí çâóê
3188 Mem
.WriteInt(gTriggers
[i
].SoundPlayCount
);
3189 // Ïðîèãðûâàåòñÿ ëè çâóê?
3190 if (gTriggers
[i
].Sound
<> nil) then b
:= gTriggers
[i
].Sound
.IsPlaying() else b
:= false;
3191 Mem
.WriteBoolean(b
);
3194 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
3195 dw
:= gTriggers
[i
].Sound
.GetPosition();
3198 sg
:= gTriggers
[i
].Sound
.GetVolume();
3199 sg
:= sg
/ (gSoundLevel
/255.0);
3200 Mem
.WriteSingle(sg
);
3201 // Ñòåðåî ñìåùåíèå çâóêà
3202 sg
:= gTriggers
[i
].Sound
.GetPan();
3203 Mem
.WriteSingle(sg
);
3206 if (gTriggers
[i
].userVars
= nil) then
3212 Mem
.WriteInt(gTriggers
[i
].userVars
.count
);
3213 for kv
in gTriggers
[i
].userVars
.byKeyValue
do
3215 //writeln('<', kv.key, '>:<', VarToStr(kv.value), '>');
3216 Mem
.WriteString(kv
.key
);
3217 t
:= LongInt(varType(kv
.value
));
3220 varString
: Mem
.WriteString(AnsiString(kv
.value
));
3221 varBoolean
: Mem
.WriteBoolean(Boolean(kv
.value
));
3222 varShortInt
: Mem
.WriteInt(Integer(kv
.value
));
3223 varSmallint
: Mem
.WriteInt(Integer(kv
.value
));
3224 varInteger
: Mem
.WriteInt(Integer(kv
.value
));
3225 //varInt64: Mem.WriteInt(Integer(kv.value));
3226 varByte
: Mem
.WriteInt(Integer(kv
.value
));
3227 varWord
: Mem
.WriteInt(Integer(kv
.value
));
3228 varLongWord
: Mem
.WriteInt(Integer(kv
.value
));
3230 else raise Exception
.CreateFmt('cannot save uservar ''%s''', [kv
.key
]);
3238 procedure g_Triggers_LoadState (var Mem
: TBinMemoryReader
);
3240 count
, actCount
, i
, j
, a
: Integer;
3254 if (Mem
= nil) then exit
;
3258 // Êîëè÷åñòâî òðèããåðîâ
3260 if (count
= 0) then exit
;
3262 for a
:= 0 to count
-1 do
3264 // Ñèãíàòóðà òðèããåðà
3265 Mem
.ReadDWORD(dw
); // 'TRGX'
3266 if (dw
<> TRIGGER_SIGNATURE
) then raise EBinSizeError
.Create('g_Triggers_LoadState: Wrong Trigger Signature');
3268 Mem
.ReadByte(Trig
.TriggerType
);
3269 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
3270 if (Trig
.TriggerType
= TRIGGER_NONE
) then continue
; // empty one
3271 Mem
.ReadInt(mapIndex
);
3272 i
:= g_Triggers_CreateWithMapIndex(Trig
, a
, mapIndex
);
3273 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
3274 Mem
.ReadInt(gTriggers
[i
].X
);
3275 Mem
.ReadInt(gTriggers
[i
].Y
);
3277 Mem
.ReadWord(gTriggers
[i
].Width
);
3278 Mem
.ReadWord(gTriggers
[i
].Height
);
3279 // Âêëþ÷åí ëè òðèããåð:
3280 Mem
.ReadBoolean(gTriggers
[i
].Enabled
);
3281 // Òèï àêòèâàöèè òðèããåðà:
3282 Mem
.ReadByte(gTriggers
[i
].ActivateType
);
3283 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
3284 Mem
.ReadByte(gTriggers
[i
].Keys
);
3285 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
3286 Mem
.ReadInt(gTriggers
[i
].TexturePanelGUID
);
3288 Mem
.ReadWord(gTriggers
[i
].TexturePanelType
);
3289 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
3290 Mem
.ReadInt(gTriggers
[i
].trigPanelGUID
);
3291 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
3292 Mem
.ReadWord(gTriggers
[i
].TimeOut
);
3293 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
3294 Mem
.ReadWord(gTriggers
[i
].ActivateUID
);
3295 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
3296 Mem
.ReadInt(actCount
);
3297 if actCount
> 0 then
3299 SetLength(gTriggers
[i
].Activators
, actCount
);
3300 for j
:= 0 to actCount
-1 do
3303 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].UID
);
3305 Mem
.ReadWord(gTriggers
[i
].Activators
[j
].TimeOut
);
3308 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
3309 Mem
.ReadBoolean(gTriggers
[i
].PlayerCollide
);
3310 // Âðåìÿ äî çàêðûòèÿ äâåðè:
3311 Mem
.ReadInt(gTriggers
[i
].DoorTime
);
3312 // Çàäåðæêà àêòèâàöèè:
3313 Mem
.ReadInt(gTriggers
[i
].PressTime
);
3315 Mem
.ReadInt(gTriggers
[i
].PressCount
);
3317 Mem
.ReadBoolean(gTriggers
[i
].AutoSpawn
);
3318 // Çàäåðæêà ñïàâíåðà:
3319 Mem
.ReadInt(gTriggers
[i
].SpawnCooldown
);
3320 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3321 Mem
.ReadInt(gTriggers
[i
].SpawnedCount
);
3322 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3323 Mem
.ReadInt(gTriggers
[i
].SoundPlayCount
);
3324 // Ïðîèãðûâàåòñÿ ëè çâóê?
3328 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3331 Mem
.ReadSingle(vol
);
3332 // Ñòåðåî ñìåùåíèå çâóêà:
3333 Mem
.ReadSingle(pan
);
3334 // Çàïóñêàåì çâóê, åñëè åñòü:
3335 if gTriggers
[i
].Sound
<> nil then
3337 gTriggers
[i
].Sound
.PlayPanVolume(pan
, vol
);
3338 gTriggers
[i
].Sound
.Pause(True);
3339 gTriggers
[i
].Sound
.SetPosition(dw
);
3343 gTriggers
[i
].userVars
.Free();
3344 gTriggers
[i
].userVars
:= nil;
3345 Mem
.ReadInt(uvcount
);
3346 if (uvcount
> 0) then
3348 gTriggers
[i
].userVars
:= THashStrVariant
.Create(hsihash
, hsiequ
);
3350 while (uvcount
> 0) do
3354 Mem
.ReadString(uvname
);
3357 varString
: begin ustr
:= ''; Mem
.ReadString(ustr
); vv
:= ustr
; end;
3358 varBoolean
: begin Mem
.ReadBoolean(ubool
); vv
:= ubool
; end;
3359 varShortInt
: begin Mem
.ReadInt(uint
); vv
:= ShortInt(uint
); end;
3360 varSmallint
: begin Mem
.ReadInt(uint
); vv
:= SmallInt(uint
); end;
3361 varInteger
: begin Mem
.ReadInt(uint
); vv
:= LongInt(uint
); end;
3362 varByte
: begin Mem
.ReadInt(uint
); vv
:= Byte(uint
); end;
3363 varWord
: begin Mem
.ReadInt(uint
); vv
:= Word(uint
); end;
3364 varLongWord
: begin Mem
.ReadInt(uint
); vv
:= LongWord(uint
); end;
3365 else raise Exception
.CreateFmt('cannot load uservar ''%s''', [uvname
]);
3367 gTriggers
[i
].userVars
.put(uvname
, vv
);