DEADSOFTWARE

mplat triggers can make sound now
[d2df-sdl.git] / src / game / g_triggers.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
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.
7 *
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.
12 *
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/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_triggers;
19 interface
21 uses
22 MAPDEF, e_graphics, g_basic, g_sound,
23 BinEditor, xdynrec;
25 type
26 TActivator = record
27 UID: Word;
28 TimeOut: Word;
29 end;
30 PTrigger = ^TTrigger;
31 TTrigger = record
32 public
33 ID: DWORD;
34 ClientID: DWORD;
35 TriggerType: Byte;
36 X, Y: Integer;
37 Width, Height: Word;
38 Enabled: Boolean;
39 ActivateType: Byte;
40 Keys: Byte;
41 TexturePanelGUID: Integer;
42 TexturePanelType: Word;
44 TimeOut: Word;
45 ActivateUID: Word;
46 Activators: array of TActivator;
47 PlayerCollide: Boolean;
48 DoorTime: Integer;
49 PressTime: Integer;
50 PressCount: Integer;
51 SoundPlayCount: Integer;
52 Sound: TPlayableSound;
53 AutoSpawn: Boolean;
54 SpawnCooldown: Integer;
55 SpawnedCount: Integer;
56 ShotPanelType: Word;
57 ShotPanelTime: Integer;
58 ShotSightTime: Integer;
59 ShotSightTimeout: Integer;
60 ShotSightTarget: Word;
61 ShotSightTargetN: Word;
62 ShotAmmoCount: Word;
63 ShotReloadTime: Integer;
65 mapId: AnsiString; // trigger id, from map
66 mapIndex: Integer; // index in fields['trigger'], used in save/load
67 trigPanelGUID: Integer;
69 //TrigData: TTriggerData;
70 trigData: TDynRecord; // triggerdata; owned by trigger
72 public
73 function trigCenter (): TDFPoint; inline;
75 public
76 property trigShotPanelGUID: Integer read trigPanelGUID write trigPanelGUID;
77 end;
79 function g_Triggers_Create(Trigger: TTrigger; forceInternalIndex: Integer=-1): DWORD;
80 procedure g_Triggers_Update();
81 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
82 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
83 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
84 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
85 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
86 procedure g_Triggers_OpenAll();
87 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
88 procedure g_Triggers_Free();
89 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
90 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
93 var
94 gTriggerClientID: Integer = 0;
95 gTriggers: array of TTrigger;
96 gSecretsCount: Integer = 0;
97 gMonstersSpawned: array of LongInt = nil;
100 implementation
102 uses
103 Math,
104 g_player, g_map, g_panel, g_gfx, g_game, g_textures,
105 g_console, g_monsters, g_items, g_phys, g_weapons,
106 wadreader, g_main, SysUtils, e_log, g_language,
107 g_options, g_net, g_netmsg, utils, xparser;
109 const
110 TRIGGER_SIGNATURE = $58475254; // 'TRGX'
111 TRAP_DAMAGE = 1000;
114 function TTrigger.trigCenter (): TDFPoint; inline;
115 begin
116 result := TDFPoint.Create(x+width div 2, y+height div 2);
117 end;
120 function FindTrigger (): DWORD;
121 var
122 i: Integer;
123 begin
124 for i := 0 to High(gTriggers) do
125 begin
126 if gTriggers[i].TriggerType = TRIGGER_NONE then begin result := i; exit; end;
127 end;
129 if (gTriggers = nil) then
130 begin
131 SetLength(gTriggers, 8);
132 result := 0;
133 end
134 else
135 begin
136 result := Length(gTriggers);
137 SetLength(gTriggers, result+8);
138 for i := result to High(gTriggers) do gTriggers[i].TriggerType := TRIGGER_NONE;
139 end;
140 end;
143 function tr_CloseDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
144 var
145 a, b, c: Integer;
146 pan: TPanel;
147 PanelID: Integer;
148 begin
149 result := false;
150 pan := g_Map_PanelByGUID(PanelGUID);
151 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
152 PanelID := pan.arrIdx;
154 if not d2d then
155 begin
156 with gWalls[PanelID] do
157 begin
158 if g_CollidePlayer(X, Y, Width, Height) or g_Mons_IsAnyAliveAt(X, Y, Width, Height) then Exit;
159 if not Enabled then
160 begin
161 if not NoSound then
162 begin
163 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
164 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
165 end;
166 g_Map_EnableWallGUID(PanelGUID);
167 result := true;
168 end;
169 end;
170 end
171 else
172 begin
173 if (gDoorMap = nil) then exit;
175 c := -1;
176 for a := 0 to High(gDoorMap) do
177 begin
178 for b := 0 to High(gDoorMap[a]) do
179 begin
180 if gDoorMap[a, b] = DWORD(PanelID) then
181 begin
182 c := a;
183 break;
184 end;
185 end;
186 if (c <> -1) then break;
187 end;
188 if (c = -1) then exit;
190 for b := 0 to High(gDoorMap[c]) do
191 begin
192 with gWalls[gDoorMap[c, b]] do
193 begin
194 if g_CollidePlayer(X, Y, Width, Height) or g_Mons_IsAnyAliveAt(X, Y, Width, Height) then exit;
195 end;
196 end;
198 if not NoSound then
199 begin
200 for b := 0 to High(gDoorMap[c]) do
201 begin
202 if not gWalls[gDoorMap[c, b]].Enabled then
203 begin
204 with gWalls[PanelID] do
205 begin
206 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
207 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
208 end;
209 break;
210 end;
211 end;
212 end;
214 for b := 0 to High(gDoorMap[c]) do
215 begin
216 if not gWalls[gDoorMap[c, b]].Enabled then
217 begin
218 g_Map_EnableWall_XXX(gDoorMap[c, b]);
219 result := true;
220 end;
221 end;
222 end;
223 end;
226 procedure tr_CloseTrap (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean);
227 var
228 a, b, c: Integer;
229 wx, wy, wh, ww: Integer;
230 pan: TPanel;
231 PanelID: Integer;
233 function monsDamage (mon: TMonster): Boolean;
234 begin
235 result := false; // don't stop
236 if g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
237 end;
239 begin
240 pan := g_Map_PanelByGUID(PanelGUID);
242 if (pan = nil) then
243 begin
244 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
245 end
246 else
247 begin
248 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
249 end;
251 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
252 PanelID := pan.arrIdx;
254 if not d2d then
255 begin
256 with gWalls[PanelID] do
257 begin
258 if (not NoSound) and (not Enabled) then
259 begin
260 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
261 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
262 end;
263 end;
265 wx := gWalls[PanelID].X;
266 wy := gWalls[PanelID].Y;
267 ww := gWalls[PanelID].Width;
268 wh := gWalls[PanelID].Height;
270 with gWalls[PanelID] do
271 begin
272 if gPlayers <> nil then
273 begin
274 for a := 0 to High(gPlayers) do
275 begin
276 if (gPlayers[a] <> nil) and gPlayers[a].alive and gPlayers[a].Collide(X, Y, Width, Height) then
277 begin
278 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
279 end;
280 end;
281 end;
283 //g_Mons_ForEach(monsDamage);
284 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
286 if not Enabled then g_Map_EnableWallGUID(PanelGUID);
287 end;
288 end
289 else
290 begin
291 if (gDoorMap = nil) then exit;
293 c := -1;
294 for a := 0 to High(gDoorMap) do
295 begin
296 for b := 0 to High(gDoorMap[a]) do
297 begin
298 if gDoorMap[a, b] = DWORD(PanelID) then
299 begin
300 c := a;
301 break;
302 end;
303 end;
304 if (c <> -1) then break;
305 end;
306 if (c = -1) then exit;
308 if not NoSound then
309 begin
310 for b := 0 to High(gDoorMap[c]) do
311 begin
312 if not gWalls[gDoorMap[c, b]].Enabled then
313 begin
314 with gWalls[PanelID] do
315 begin
316 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
317 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
318 end;
319 Break;
320 end;
321 end;
322 end;
324 for b := 0 to High(gDoorMap[c]) do
325 begin
326 wx := gWalls[gDoorMap[c, b]].X;
327 wy := gWalls[gDoorMap[c, b]].Y;
328 ww := gWalls[gDoorMap[c, b]].Width;
329 wh := gWalls[gDoorMap[c, b]].Height;
331 with gWalls[gDoorMap[c, b]] do
332 begin
333 if gPlayers <> nil then
334 begin
335 for a := 0 to High(gPlayers) do
336 begin
337 if (gPlayers[a] <> nil) and gPlayers[a].alive and gPlayers[a].Collide(X, Y, Width, Height) then
338 begin
339 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
340 end;
341 end;
342 end;
344 //g_Mons_ForEach(monsDamage);
345 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
346 (*
347 if gMonsters <> nil then
348 for a := 0 to High(gMonsters) do
349 if (gMonsters[a] <> nil) and gMonsters[a].alive and
350 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
351 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
352 *)
354 if not Enabled then g_Map_EnableWall_XXX(gDoorMap[c, b]);
355 end;
356 end;
357 end;
358 end;
361 function tr_OpenDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
362 var
363 a, b, c: Integer;
364 pan: TPanel;
365 PanelID: Integer;
366 begin
367 result := false;
368 pan := g_Map_PanelByGUID(PanelGUID);
369 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
370 PanelID := pan.arrIdx;
372 if not d2d then
373 begin
374 with gWalls[PanelID] do
375 begin
376 if Enabled then
377 begin
378 if not NoSound then
379 begin
380 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
381 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
382 end;
383 g_Map_DisableWallGUID(PanelGUID);
384 result := true;
385 end;
386 end
387 end
388 else
389 begin
390 if (gDoorMap = nil) then exit;
392 c := -1;
393 for a := 0 to High(gDoorMap) do
394 begin
395 for b := 0 to High(gDoorMap[a]) do
396 begin
397 if gDoorMap[a, b] = DWORD(PanelID) then
398 begin
399 c := a;
400 break;
401 end;
402 end;
403 if (c <> -1) then break;
404 end;
405 if (c = -1) then exit;
407 if not NoSound then
408 begin
409 for b := 0 to High(gDoorMap[c]) do
410 begin
411 if gWalls[gDoorMap[c, b]].Enabled then
412 begin
413 with gWalls[PanelID] do
414 begin
415 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
416 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
417 end;
418 break;
419 end;
420 end;
421 end;
423 for b := 0 to High(gDoorMap[c]) do
424 begin
425 if gWalls[gDoorMap[c, b]].Enabled then
426 begin
427 g_Map_DisableWall_XXX(gDoorMap[c, b]);
428 result := true;
429 end;
430 end;
431 end;
432 end;
435 function tr_SetLift (PanelGUID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
436 var
437 a, b, c: Integer;
438 t: Integer = 0;
439 pan: TPanel;
440 PanelID: Integer;
441 begin
442 result := false;
443 pan := g_Map_PanelByGUID(PanelGUID);
444 if (pan = nil) or not pan.isGLift then exit; //!FIXME!TRIGANY!
445 PanelID := pan.arrIdx;
447 if (gLifts[PanelID].PanelType = PANEL_LIFTUP) or (gLifts[PanelID].PanelType = PANEL_LIFTDOWN) then
448 begin
449 case d of
450 0: t := 0;
451 1: t := 1;
452 else t := IfThen(gLifts[PanelID].LiftType = 1, 0, 1);
453 end
454 end
455 else if (gLifts[PanelID].PanelType = PANEL_LIFTLEFT) or (gLifts[PanelID].PanelType = PANEL_LIFTRIGHT) then
456 begin
457 case d of
458 0: t := 2;
459 1: t := 3;
460 else t := IfThen(gLifts[PanelID].LiftType = 2, 3, 2);
461 end;
462 end;
464 if not d2d then
465 begin
466 with gLifts[PanelID] do
467 begin
468 if (LiftType <> t) then
469 begin
470 g_Map_SetLiftGUID(PanelGUID, t); //???
471 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
472 result := true;
473 end;
474 end;
475 end
476 else // Êàê â D2d
477 begin
478 if (gLiftMap = nil) then exit;
480 c := -1;
481 for a := 0 to High(gLiftMap) do
482 begin
483 for b := 0 to High(gLiftMap[a]) do
484 begin
485 if (gLiftMap[a, b] = DWORD(PanelID)) then
486 begin
487 c := a;
488 break;
489 end;
490 end;
491 if (c <> -1) then break;
492 end;
493 if (c = -1) then exit;
495 {if not NoSound then
496 for b := 0 to High(gLiftMap[c]) do
497 if gLifts[gLiftMap[c, b]].LiftType <> t then
498 begin
499 with gLifts[PanelID] do
500 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
501 Break;
502 end;}
504 for b := 0 to High(gLiftMap[c]) do
505 begin
506 with gLifts[gLiftMap[c, b]] do
507 begin
508 if (LiftType <> t) then
509 begin
510 g_Map_SetLift_XXX(gLiftMap[c, b], t);
511 result := true;
512 end;
513 end;
514 end;
515 end;
516 end;
519 function tr_SpawnShot (ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
520 var
521 snd: string;
522 Projectile: Boolean;
523 TextureID: DWORD;
524 Anim: TAnimation;
525 begin
526 result := -1;
527 TextureID := DWORD(-1);
528 snd := 'SOUND_WEAPON_FIREROCKET';
529 Projectile := true;
531 case ShotType of
532 TRIGGER_SHOT_PISTOL:
533 begin
534 g_Weapon_pistol(wx, wy, dx, dy, 0, True);
535 snd := 'SOUND_WEAPON_FIREPISTOL';
536 Projectile := False;
537 if ShotSound then
538 begin
539 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
540 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
541 end;
542 end;
544 TRIGGER_SHOT_BULLET:
545 begin
546 g_Weapon_mgun(wx, wy, dx, dy, 0, True);
547 if gSoundEffectsDF then snd := 'SOUND_WEAPON_FIRECGUN'
548 else snd := 'SOUND_WEAPON_FIREPISTOL';
549 Projectile := False;
550 if ShotSound then
551 begin
552 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
553 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
554 end;
555 end;
557 TRIGGER_SHOT_SHOTGUN:
558 begin
559 g_Weapon_Shotgun(wx, wy, dx, dy, 0, True);
560 snd := 'SOUND_WEAPON_FIRESHOTGUN';
561 Projectile := False;
562 if ShotSound then
563 begin
564 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
565 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL2);
566 end;
567 end;
569 TRIGGER_SHOT_SSG:
570 begin
571 g_Weapon_DShotgun(wx, wy, dx, dy, 0, True);
572 snd := 'SOUND_WEAPON_FIRESHOTGUN2';
573 Projectile := False;
574 if ShotSound then
575 begin
576 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
577 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
578 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL3);
579 end;
580 end;
582 TRIGGER_SHOT_IMP:
583 begin
584 g_Weapon_ball1(wx, wy, dx, dy, 0, -1, True);
585 snd := 'SOUND_WEAPON_FIREBALL';
586 end;
588 TRIGGER_SHOT_PLASMA:
589 begin
590 g_Weapon_Plasma(wx, wy, dx, dy, 0, -1, True);
591 snd := 'SOUND_WEAPON_FIREPLASMA';
592 end;
594 TRIGGER_SHOT_SPIDER:
595 begin
596 g_Weapon_aplasma(wx, wy, dx, dy, 0, -1, True);
597 snd := 'SOUND_WEAPON_FIREPLASMA';
598 end;
600 TRIGGER_SHOT_CACO:
601 begin
602 g_Weapon_ball2(wx, wy, dx, dy, 0, -1, True);
603 snd := 'SOUND_WEAPON_FIREBALL';
604 end;
606 TRIGGER_SHOT_BARON:
607 begin
608 g_Weapon_ball7(wx, wy, dx, dy, 0, -1, True);
609 snd := 'SOUND_WEAPON_FIREBALL';
610 end;
612 TRIGGER_SHOT_MANCUB:
613 begin
614 g_Weapon_manfire(wx, wy, dx, dy, 0, -1, True);
615 snd := 'SOUND_WEAPON_FIREBALL';
616 end;
618 TRIGGER_SHOT_REV:
619 begin
620 g_Weapon_revf(wx, wy, dx, dy, 0, ShotTarget, -1, True);
621 snd := 'SOUND_WEAPON_FIREREV';
622 end;
624 TRIGGER_SHOT_ROCKET:
625 begin
626 g_Weapon_Rocket(wx, wy, dx, dy, 0, -1, True);
627 snd := 'SOUND_WEAPON_FIREROCKET';
628 end;
630 TRIGGER_SHOT_BFG:
631 begin
632 g_Weapon_BFGShot(wx, wy, dx, dy, 0, -1, True);
633 snd := 'SOUND_WEAPON_FIREBFG';
634 end;
636 TRIGGER_SHOT_EXPL:
637 begin
638 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
639 begin
640 Anim := TAnimation.Create(TextureID, False, 6);
641 Anim.Blending := False;
642 g_GFX_OnceAnim(wx-64, wy-64, Anim);
643 Anim.Free();
644 end;
645 Projectile := False;
646 g_Weapon_Explode(wx, wy, 60, 0);
647 snd := 'SOUND_WEAPON_EXPLODEROCKET';
648 end;
650 TRIGGER_SHOT_BFGEXPL:
651 begin
652 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
653 begin
654 Anim := TAnimation.Create(TextureID, False, 6);
655 Anim.Blending := False;
656 g_GFX_OnceAnim(wx-64, wy-64, Anim);
657 Anim.Free();
658 end;
659 Projectile := False;
660 g_Weapon_BFG9000(wx, wy, 0);
661 snd := 'SOUND_WEAPON_EXPLODEBFG';
662 end;
664 else exit;
665 end;
667 if g_Game_IsNet and g_Game_IsServer then
668 begin
669 case ShotType of
670 TRIGGER_SHOT_EXPL: MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_EXPLODE);
671 TRIGGER_SHOT_BFGEXPL: MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_BFGEXPL);
672 else
673 begin
674 if Projectile then MH_SEND_CreateShot(LastShotID);
675 if ShotSound then MH_SEND_Sound(wx, wy, snd);
676 end;
677 end;
678 end;
680 if ShotSound then g_Sound_PlayExAt(snd, wx, wy);
682 if Projectile then Result := LastShotID;
683 end;
686 procedure MakeShot (var Trigger: TTrigger; wx, wy, dx, dy: Integer; TargetUID: Word);
687 begin
688 with Trigger do
689 begin
690 if (trigData.trigAmmo = 0) or ((trigData.trigAmmo > 0) and (ShotAmmoCount > 0)) then
691 begin
692 if (trigShotPanelGUID <> -1) and (ShotPanelTime = 0) then
693 begin
694 g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID);
695 ShotPanelTime := 4; // òèêîâ íà âñïûøêó âûñòðåëà
696 end;
698 if (trigData.trigSight > 0) then ShotSightTimeout := 180; // ~= 5 ñåêóíä
700 if (ShotAmmoCount > 0) then Dec(ShotAmmoCount);
702 dx += Random(trigData.trigAccuracy)-Random(trigData.trigAccuracy);
703 dy += Random(trigData.trigAccuracy)-Random(trigData.trigAccuracy);
705 tr_SpawnShot(trigData.trigShotType, wx, wy, dx, dy, not trigData.trigQuiet, TargetUID);
706 end
707 else
708 begin
709 if (trigData.trigReload > 0) and (ShotReloadTime = 0) then
710 begin
711 ShotReloadTime := trigData.trigReload; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
712 end;
713 end;
714 end;
715 end;
718 procedure tr_MakeEffect (X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
719 var
720 FramesID: DWORD;
721 Anim: TAnimation;
722 begin
723 if T = TRIGGER_EFFECT_PARTICLE then
724 begin
725 case ST of
726 TRIGGER_EFFECT_SLIQUID:
727 begin
728 if (CR = 255) and (CG = 0) and (CB = 0) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 1, 0, 0, 0)
729 else if (CR = 0) and (CG = 255) and (CB = 0) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 2, 0, 0, 0)
730 else if (CR = 0) and (CG = 0) and (CB = 255) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 3, 0, 0, 0)
731 else g_GFX_SimpleWater(X, Y, 1, VX, VY, 0, 0, 0, 0);
732 end;
733 TRIGGER_EFFECT_LLIQUID: g_GFX_SimpleWater(X, Y, 1, VX, VY, 4, CR, CG, CB);
734 TRIGGER_EFFECT_DLIQUID: g_GFX_SimpleWater(X, Y, 1, VX, VY, 5, CR, CG, CB);
735 TRIGGER_EFFECT_BLOOD: g_GFX_Blood(X, Y, 1, VX, VY, 0, 0, CR, CG, CB);
736 TRIGGER_EFFECT_SPARK: g_GFX_Spark(X, Y, 1, GetAngle2(VX, VY), 0, 0);
737 TRIGGER_EFFECT_BUBBLE: g_GFX_Bubbles(X, Y, 1, 0, 0);
738 end;
739 end;
741 if T = TRIGGER_EFFECT_ANIMATION then
742 begin
743 case ST of
744 EFFECT_TELEPORT: begin
745 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
746 begin
747 Anim := TAnimation.Create(FramesID, False, 3);
748 if not Silent then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
749 g_GFX_OnceAnim(X-32, Y-32, Anim);
750 Anim.Free();
751 end;
752 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X, Y, Byte(not Silent), NET_GFX_TELE);
753 end;
754 EFFECT_RESPAWN: begin
755 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
756 begin
757 Anim := TAnimation.Create(FramesID, False, 4);
758 if not Silent then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
759 g_GFX_OnceAnim(X-16, Y-16, Anim);
760 Anim.Free();
761 end;
762 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X-16, Y-16, Byte(not Silent), NET_GFX_RESPAWN);
763 end;
764 EFFECT_FIRE: begin
765 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
766 begin
767 Anim := TAnimation.Create(FramesID, False, 4);
768 if not Silent then g_Sound_PlayExAt('SOUND_FIRE', X, Y);
769 g_GFX_OnceAnim(X-32, Y-128, Anim);
770 Anim.Free();
771 end;
772 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X-32, Y-128, Byte(not Silent), NET_GFX_FIRE);
773 end;
774 end;
775 end;
776 end;
779 function tr_Teleport (ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
780 var
781 p: TPlayer;
782 m: TMonster;
783 begin
784 Result := False;
785 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
786 case g_GetUIDType(ActivateUID) of
787 UID_PLAYER:
788 begin
789 p := g_Player_Get(ActivateUID);
790 if p = nil then Exit;
791 if D2D then
792 begin
793 if p.TeleportTo(TX-(p.Obj.Rect.Width div 2), TY-p.Obj.Rect.Height, Silent, TDir) then result := true;
794 end
795 else
796 begin
797 if p.TeleportTo(TX, TY, Silent, TDir) then result := true;
798 end;
799 end;
800 UID_MONSTER:
801 begin
802 m := g_Monsters_ByUID(ActivateUID);
803 if m = nil then Exit;
804 if D2D then
805 begin
806 if m.TeleportTo(TX-(m.Obj.Rect.Width div 2), TY-m.Obj.Rect.Height, Silent, TDir) then result := true;
807 end
808 else
809 begin
810 if m.TeleportTo(TX, TY, Silent, TDir) then result := true;
811 end;
812 end;
813 end;
814 end;
817 function tr_Push (ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
818 var
819 p: TPlayer;
820 m: TMonster;
821 begin
822 result := true;
823 if (ActivateUID < 0) or (ActivateUID > $FFFF) then exit;
824 case g_GetUIDType(ActivateUID) of
825 UID_PLAYER:
826 begin
827 p := g_Player_Get(ActivateUID);
828 if p = nil then Exit;
830 if ResetVel then
831 begin
832 p.GameVelX := 0;
833 p.GameVelY := 0;
834 p.GameAccelX := 0;
835 p.GameAccelY := 0;
836 end;
838 p.Push(VX, VY);
839 end;
841 UID_MONSTER:
842 begin
843 m := g_Monsters_ByUID(ActivateUID);
844 if m = nil then Exit;
846 if ResetVel then
847 begin
848 m.GameVelX := 0;
849 m.GameVelY := 0;
850 m.GameAccelX := 0;
851 m.GameAccelY := 0;
852 end;
854 m.Push(VX, VY);
855 end;
856 end;
857 end;
860 function tr_Message (MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
861 var
862 msg: string;
863 p: TPlayer;
864 i: Integer;
865 begin
866 Result := True;
867 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
868 msg := b_Text_Format(MText);
869 case MSendTo of
870 TRIGGER_MESSAGE_DEST_ME: // activator
871 begin
872 if g_GetUIDType(ActivateUID) = UID_PLAYER then
873 begin
874 if g_Game_IsWatchedPlayer(ActivateUID) then
875 begin
876 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
877 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
878 end
879 else
880 begin
881 p := g_Player_Get(ActivateUID);
882 if g_Game_IsNet and (p.FClientID >= 0) then
883 begin
884 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, p.FClientID)
885 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, p.FClientID);
886 end;
887 end;
888 end;
889 end;
891 TRIGGER_MESSAGE_DEST_MY_TEAM: // activator's team
892 begin
893 if g_GetUIDType(ActivateUID) = UID_PLAYER then
894 begin
895 p := g_Player_Get(ActivateUID);
896 if g_Game_IsWatchedTeam(p.Team) then
897 begin
898 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
899 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
900 end;
902 if g_Game_IsNet then
903 begin
904 for i := Low(gPlayers) to High(gPlayers) do
905 begin
906 if (gPlayers[i].Team = p.Team) and (gPlayers[i].FClientID >= 0) then
907 begin
908 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
909 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
910 end;
911 end;
912 end;
913 end;
914 end;
916 TRIGGER_MESSAGE_DEST_ENEMY_TEAM: // activator's enemy team
917 begin
918 if g_GetUIDType(ActivateUID) = UID_PLAYER then
919 begin
920 p := g_Player_Get(ActivateUID);
921 if g_Game_IsWatchedTeam(p.Team) then
922 begin
923 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
924 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
925 end;
927 if g_Game_IsNet then
928 begin
929 for i := Low(gPlayers) to High(gPlayers) do
930 begin
931 if (gPlayers[i].Team <> p.Team) and (gPlayers[i].FClientID >= 0) then
932 begin
933 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
934 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
935 end;
936 end;
937 end;
938 end;
939 end;
941 TRIGGER_MESSAGE_DEST_RED_TEAM: // red team
942 begin
943 if g_Game_IsWatchedTeam(TEAM_RED) then
944 begin
945 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
946 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
947 end;
949 if g_Game_IsNet then
950 begin
951 for i := Low(gPlayers) to High(gPlayers) do
952 begin
953 if (gPlayers[i].Team = TEAM_RED) and (gPlayers[i].FClientID >= 0) then
954 begin
955 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
956 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
957 end;
958 end;
959 end;
960 end;
962 TRIGGER_MESSAGE_DEST_BLUE_TEAM: // blue team
963 begin
964 if g_Game_IsWatchedTeam(TEAM_BLUE) then
965 begin
966 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
967 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
968 end;
970 if g_Game_IsNet then
971 begin
972 for i := Low(gPlayers) to High(gPlayers) do
973 begin
974 if (gPlayers[i].Team = TEAM_BLUE) and (gPlayers[i].FClientID >= 0) then
975 begin
976 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
977 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
978 end;
979 end;
980 end;
981 end;
983 TRIGGER_MESSAGE_DEST_EVERYONE: // everyone
984 begin
985 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
986 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
988 if g_Game_IsNet then
989 begin
990 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM)
991 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg);
992 end;
993 end;
994 end;
995 end;
998 function tr_ShotAimCheck (var Trigger: TTrigger; Obj: PObj): Boolean;
999 begin
1000 result := false;
1001 with Trigger do
1002 begin
1003 if TriggerType <> TRIGGER_SHOT then Exit;
1004 result := (trigData.trigAim and TRIGGER_SHOT_AIM_ALLMAP > 0)
1005 or g_Obj_Collide(X, Y, Width, Height, Obj);
1006 if result and (trigData.trigAim and TRIGGER_SHOT_AIM_TRACE > 0) then
1007 begin
1008 result := g_TraceVector(trigData.trigTX, trigData.trigTY,
1009 Obj^.X + Obj^.Rect.X + (Obj^.Rect.Width div 2),
1010 Obj^.Y + Obj^.Rect.Y + (Obj^.Rect.Height div 2));
1011 end;
1012 end;
1013 end;
1016 function ActivateTrigger (var Trigger: TTrigger; actType: Byte): Boolean;
1017 var
1018 animonce: Boolean;
1019 p: TPlayer;
1020 m: TMonster;
1021 pan: TPanel;
1022 idx, k, wx, wy, xd, yd: Integer;
1023 iid: LongWord;
1024 coolDown: Boolean;
1025 pAngle: Real;
1026 FramesID: DWORD;
1027 Anim: TAnimation;
1028 UIDType: Byte;
1029 TargetUID: Word;
1030 it: PItem;
1031 mon: TMonster;
1033 function monsShotTarget (mon: TMonster): Boolean;
1034 begin
1035 result := false; // don't stop
1036 if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1037 begin
1038 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1039 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1040 TargetUID := mon.UID;
1041 result := true; // stop
1042 end;
1043 end;
1045 function monsShotTargetMonPlr (mon: TMonster): Boolean;
1046 begin
1047 result := false; // don't stop
1048 if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1049 begin
1050 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1051 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1052 TargetUID := mon.UID;
1053 result := true; // stop
1054 end;
1055 end;
1057 function monShotTargetPlrMon (mon: TMonster): Boolean;
1058 begin
1059 result := false; // don't stop
1060 if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1061 begin
1062 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1063 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1064 TargetUID := mon.UID;
1065 result := true; // stop
1066 end;
1067 end;
1069 begin
1070 result := false;
1071 if g_Game_IsClient then exit;
1073 if not Trigger.Enabled then exit;
1074 if (Trigger.TimeOut <> 0) and (actType <> ACTIVATE_CUSTOM) then exit;
1075 if gLMSRespawn = LMS_RESPAWN_WARMUP then exit;
1077 animonce := False;
1079 coolDown := (actType <> 0);
1081 with Trigger do
1082 begin
1083 case TriggerType of
1084 TRIGGER_EXIT:
1085 begin
1086 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1087 if g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH0');
1088 gExitByTrigger := True;
1089 g_Game_ExitLevel(trigData.trigMap);
1090 TimeOut := 18;
1091 Result := True;
1093 Exit;
1094 end;
1096 TRIGGER_TELEPORT:
1097 begin
1098 Result := tr_Teleport(ActivateUID,
1099 trigData.trigTarget.X, trigData.trigTarget.Y,
1100 trigData.trigDirection, trigData.trigSilent,
1101 trigData.trigD2d);
1102 TimeOut := 0;
1103 end;
1105 TRIGGER_OPENDOOR:
1106 begin
1107 Result := tr_OpenDoor(trigPanelGUID, trigData.trigSilent, trigData.trigD2d);
1108 TimeOut := 0;
1109 end;
1111 TRIGGER_CLOSEDOOR:
1112 begin
1113 Result := tr_CloseDoor(trigPanelGUID, trigData.trigSilent, trigData.trigD2d);
1114 TimeOut := 0;
1115 end;
1117 TRIGGER_DOOR, TRIGGER_DOOR5:
1118 begin
1119 pan := g_Map_PanelByGUID(trigPanelGUID);
1120 if (pan <> nil) and pan.isGWall then
1121 begin
1122 if gWalls[{trigPanelID}pan.arrIdx].Enabled then
1123 begin
1124 result := tr_OpenDoor(trigPanelGUID, trigData.trigSilent, trigData.trigD2d);
1125 if (TriggerType = TRIGGER_DOOR5) then DoorTime := 180;
1126 end
1127 else
1128 begin
1129 result := tr_CloseDoor(trigPanelGUID, trigData.trigSilent, trigData.trigD2d);
1130 end;
1132 if result then TimeOut := 18;
1133 end;
1134 end;
1136 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1137 begin
1138 tr_CloseTrap(trigPanelGUID, trigData.trigSilent, trigData.trigD2d);
1140 if TriggerType = TRIGGER_TRAP then
1141 begin
1142 DoorTime := 40;
1143 TimeOut := 76;
1144 end
1145 else
1146 begin
1147 DoorTime := -1;
1148 TimeOut := 0;
1149 end;
1151 Result := True;
1152 end;
1154 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
1155 begin
1156 PressCount += 1;
1157 if PressTime = -1 then PressTime := trigData.trigWait;
1158 if coolDown then TimeOut := 18 else TimeOut := 0;
1159 Result := True;
1160 end;
1162 TRIGGER_SECRET:
1163 if g_GetUIDType(ActivateUID) = UID_PLAYER then
1164 begin
1165 Enabled := False;
1166 Result := True;
1167 if gLMSRespawn = LMS_RESPAWN_NONE then
1168 begin
1169 g_Player_Get(ActivateUID).GetSecret();
1170 Inc(gCoopSecretsFound);
1171 if g_Game_IsNet then MH_SEND_GameStats();
1172 end;
1173 end;
1175 TRIGGER_LIFTUP:
1176 begin
1177 Result := tr_SetLift(trigPanelGUID, 0, trigData.trigSilent, trigData.trigD2d);
1178 TimeOut := 0;
1180 if (not trigData.trigSilent) and Result then begin
1181 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1182 X + (Width div 2),
1183 Y + (Height div 2));
1184 if g_Game_IsServer and g_Game_IsNet then
1185 MH_SEND_Sound(X + (Width div 2),
1186 Y + (Height div 2),
1187 'SOUND_GAME_SWITCH0');
1188 end;
1189 end;
1191 TRIGGER_LIFTDOWN:
1192 begin
1193 Result := tr_SetLift(trigPanelGUID, 1, trigData.trigSilent, trigData.trigD2d);
1194 TimeOut := 0;
1196 if (not trigData.trigSilent) and Result then begin
1197 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1198 X + (Width div 2),
1199 Y + (Height div 2));
1200 if g_Game_IsServer and g_Game_IsNet then
1201 MH_SEND_Sound(X + (Width div 2),
1202 Y + (Height div 2),
1203 'SOUND_GAME_SWITCH0');
1204 end;
1205 end;
1207 TRIGGER_LIFT:
1208 begin
1209 Result := tr_SetLift(trigPanelGUID, 3, trigData.trigSilent, trigData.trigD2d);
1211 if Result then
1212 begin
1213 TimeOut := 18;
1215 if (not trigData.trigSilent) and Result then begin
1216 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1217 X + (Width div 2),
1218 Y + (Height div 2));
1219 if g_Game_IsServer and g_Game_IsNet then
1220 MH_SEND_Sound(X + (Width div 2),
1221 Y + (Height div 2),
1222 'SOUND_GAME_SWITCH0');
1223 end;
1224 end;
1225 end;
1227 TRIGGER_TEXTURE:
1228 begin
1229 if trigData.trigActivateOnce then
1230 begin
1231 Enabled := False;
1232 TriggerType := TRIGGER_NONE;
1233 end
1234 else
1235 if coolDown then
1236 TimeOut := 6
1237 else
1238 TimeOut := 0;
1240 animonce := trigData.trigAnimateOnce;
1241 Result := True;
1242 end;
1244 TRIGGER_SOUND:
1245 begin
1246 if Sound <> nil then
1247 begin
1248 if trigData.trigSoundSwitch and Sound.IsPlaying() then
1249 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1250 Sound.Stop();
1251 SoundPlayCount := 0;
1252 Result := True;
1253 end
1254 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1255 if (trigData.trigPlayCount > 0) or (not Sound.IsPlaying()) then
1256 begin
1257 if trigData.trigPlayCount > 0 then
1258 SoundPlayCount := trigData.trigPlayCount
1259 else // 0 - èãðàåì áåñêîíå÷íî
1260 SoundPlayCount := 1;
1261 Result := True;
1262 end;
1263 if g_Game_IsNet then MH_SEND_TriggerSound(Trigger);
1264 end;
1265 end;
1267 TRIGGER_SPAWNMONSTER:
1268 if (trigData.trigSpawnMonsType in [MONSTER_DEMON..MONSTER_MAN]) then
1269 begin
1270 Result := False;
1271 if (trigData.trigDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1272 begin
1273 AutoSpawn := not AutoSpawn;
1274 SpawnCooldown := 0;
1275 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1276 Result := True;
1277 end;
1279 if ((trigData.trigDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1280 or ((trigData.trigDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1281 for k := 1 to trigData.trigMonsCount do
1282 begin
1283 if (actType = ACTIVATE_CUSTOM) and (trigData.trigDelay > 0) then
1284 SpawnCooldown := trigData.trigDelay;
1285 if (trigData.trigMax > 0) and (SpawnedCount >= trigData.trigMax) then
1286 Break;
1288 mon := g_Monsters_Create(trigData.trigSpawnMonsType,
1289 trigData.trigTX, trigData.trigTY,
1290 TDirection(trigData.trigDirection), True);
1292 Result := True;
1294 // Çäîðîâüå:
1295 if (trigData.trigHealth > 0) then
1296 mon.SetHealth(trigData.trigHealth);
1297 // Óñòàíàâëèâàåì ïîâåäåíèå:
1298 mon.MonsterBehaviour := trigData.trigBehaviour;
1299 mon.FNoRespawn := True;
1300 if g_Game_IsNet then
1301 MH_SEND_MonsterSpawn(mon.UID);
1302 // Èäåì èñêàòü öåëü, åñëè íàäî:
1303 if trigData.trigActive then
1304 mon.WakeUp();
1306 if trigData.trigSpawnMonsType <> MONSTER_BARREL then Inc(gTotalMonsters);
1308 if g_Game_IsNet then
1309 begin
1310 SetLength(gMonstersSpawned, Length(gMonstersSpawned)+1);
1311 gMonstersSpawned[High(gMonstersSpawned)] := mon.UID;
1312 end;
1314 if trigData.trigMax > 0 then
1315 begin
1316 mon.SpawnTrigger := ID;
1317 Inc(SpawnedCount);
1318 end;
1320 case trigData.trigEffect of
1321 EFFECT_TELEPORT: begin
1322 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1323 begin
1324 Anim := TAnimation.Create(FramesID, False, 3);
1325 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigTX, trigData.trigTY);
1326 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1327 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, Anim);
1328 Anim.Free();
1329 end;
1330 if g_Game_IsServer and g_Game_IsNet then
1331 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1332 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, 1,
1333 NET_GFX_TELE);
1334 end;
1335 EFFECT_RESPAWN: begin
1336 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1337 begin
1338 Anim := TAnimation.Create(FramesID, False, 4);
1339 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigTX, trigData.trigTY);
1340 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1341 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, Anim);
1342 Anim.Free();
1343 end;
1344 if g_Game_IsServer and g_Game_IsNet then
1345 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1346 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, 1,
1347 NET_GFX_RESPAWN);
1348 end;
1349 EFFECT_FIRE: begin
1350 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1351 begin
1352 Anim := TAnimation.Create(FramesID, False, 4);
1353 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigTX, trigData.trigTY);
1354 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1355 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, Anim);
1356 Anim.Free();
1357 end;
1358 if g_Game_IsServer and g_Game_IsNet then
1359 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1360 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, 1,
1361 NET_GFX_FIRE);
1362 end;
1363 end;
1364 end;
1365 if g_Game_IsNet then
1366 begin
1367 MH_SEND_GameStats();
1368 MH_SEND_CoopStats();
1369 end;
1371 if coolDown then
1372 TimeOut := 18
1373 else
1374 TimeOut := 0;
1375 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1376 if actType = ACTIVATE_CUSTOM then
1377 Result := False;
1378 end;
1380 TRIGGER_SPAWNITEM:
1381 if (trigData.trigSpawnItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX]) then
1382 begin
1383 Result := False;
1384 if (trigData.trigDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1385 begin
1386 AutoSpawn := not AutoSpawn;
1387 SpawnCooldown := 0;
1388 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1389 Result := True;
1390 end;
1392 if ((trigData.trigDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1393 or ((trigData.trigDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1394 if (not trigData.trigDmonly) or
1395 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1396 for k := 1 to trigData.trigItemCount do
1397 begin
1398 if (actType = ACTIVATE_CUSTOM) and (trigData.trigDelay > 0) then
1399 SpawnCooldown := trigData.trigDelay;
1400 if (trigData.trigMax > 0) and (SpawnedCount >= trigData.trigMax) then
1401 Break;
1403 iid := g_Items_Create(trigData.trigTX, trigData.trigTY,
1404 trigData.trigSpawnItemType, trigData.trigGravity, False, True);
1406 Result := True;
1408 if trigData.trigMax > 0 then
1409 begin
1410 it := g_Items_ByIdx(iid);
1411 it.SpawnTrigger := ID;
1412 Inc(SpawnedCount);
1413 end;
1415 case trigData.trigEffect of
1416 EFFECT_TELEPORT: begin
1417 it := g_Items_ByIdx(iid);
1418 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1419 begin
1420 Anim := TAnimation.Create(FramesID, False, 3);
1421 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigTX, trigData.trigTY);
1422 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1423 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, Anim);
1424 Anim.Free();
1425 end;
1426 if g_Game_IsServer and g_Game_IsNet then
1427 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1428 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, 1,
1429 NET_GFX_TELE);
1430 end;
1431 EFFECT_RESPAWN: begin
1432 it := g_Items_ByIdx(iid);
1433 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1434 begin
1435 Anim := TAnimation.Create(FramesID, False, 4);
1436 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigTX, trigData.trigTY);
1437 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1438 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, Anim);
1439 Anim.Free();
1440 end;
1441 if g_Game_IsServer and g_Game_IsNet then
1442 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1443 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, 1,
1444 NET_GFX_RESPAWN);
1445 end;
1446 EFFECT_FIRE: begin
1447 it := g_Items_ByIdx(iid);
1448 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1449 begin
1450 Anim := TAnimation.Create(FramesID, False, 4);
1451 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigTX, trigData.trigTY);
1452 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1453 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, Anim);
1454 Anim.Free();
1455 end;
1456 if g_Game_IsServer and g_Game_IsNet then
1457 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1458 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, 1,
1459 NET_GFX_FIRE);
1460 end;
1461 end;
1463 if g_Game_IsNet then
1464 MH_SEND_ItemSpawn(True, iid);
1465 end;
1467 if coolDown then
1468 TimeOut := 18
1469 else
1470 TimeOut := 0;
1471 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1472 if actType = ACTIVATE_CUSTOM then
1473 Result := False;
1474 end;
1476 TRIGGER_MUSIC:
1477 begin
1478 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1479 if (Trigger.trigData.trigMusicName <> '') then
1480 begin
1481 gMusic.SetByName(Trigger.trigData.trigMusicName);
1482 gMusic.SpecPause := True;
1483 gMusic.Play();
1484 end;
1486 case Trigger.trigData.trigMusicAction of
1487 TRIGGER_MUSIC_ACTION_STOP: // Âûêëþ÷èòü
1488 gMusic.SpecPause := True; // Ïàóçà
1489 TRIGGER_MUSIC_ACTION_PLAY: // Âêëþ÷èòü
1490 if gMusic.SpecPause then // Áûëà íà ïàóçå => èãðàòü
1491 gMusic.SpecPause := False
1492 else // Èãðàëà => ñíà÷àëà
1493 gMusic.SetPosition(0);
1494 end;
1496 if coolDown then
1497 TimeOut := 36
1498 else
1499 TimeOut := 0;
1500 Result := True;
1501 if g_Game_IsNet then MH_SEND_TriggerMusic;
1502 end;
1504 TRIGGER_PUSH:
1505 begin
1506 pAngle := -DegToRad(trigData.trigAngle);
1507 Result := tr_Push(ActivateUID,
1508 Floor(Cos(pAngle)*trigData.trigForce),
1509 Floor(Sin(pAngle)*trigData.trigForce),
1510 trigData.trigResetVelocity);
1511 TimeOut := 0;
1512 end;
1514 TRIGGER_SCORE:
1515 begin
1516 Result := False;
1517 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1518 if (trigData.trigScoreAction in [TRIGGER_SCORE_ACTION_ADD, TRIGGER_SCORE_ACTION_SUB]) and (trigData.trigScoreCount > 0) then
1519 begin
1520 // Ñâîåé èëè ÷óæîé êîìàíäå
1521 if (trigData.trigScoreTeam in [TRIGGER_SCORE_TEAM_MINE_RED, TRIGGER_SCORE_TEAM_MINE_BLUE]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1522 begin
1523 p := g_Player_Get(ActivateUID);
1524 if ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_ADD) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED))
1525 or ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_ADD) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1526 begin
1527 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1529 if trigData.trigScoreCon then
1530 begin
1531 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1532 begin
1533 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1534 if g_Game_IsServer and g_Game_IsNet then
1535 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+r');
1536 end else
1537 begin
1538 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1539 if g_Game_IsServer and g_Game_IsNet then
1540 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+re');
1541 end;
1542 end;
1544 if trigData.trigScoreMsg then
1545 begin
1546 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1547 if g_Game_IsServer and g_Game_IsNet then
1548 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1549 end;
1550 end;
1551 if ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_SUB) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED))
1552 or ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_SUB) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1553 begin
1554 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1556 if trigData.trigScoreCon then
1557 begin
1558 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1559 begin
1560 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1561 if g_Game_IsServer and g_Game_IsNet then
1562 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-r');
1563 end else
1564 begin
1565 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1566 if g_Game_IsServer and g_Game_IsNet then
1567 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-re');
1568 end;
1569 end;
1571 if trigData.trigScoreMsg then
1572 begin
1573 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1574 if g_Game_IsServer and g_Game_IsNet then
1575 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1576 end;
1577 end;
1578 if ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_ADD) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE))
1579 or ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_ADD) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1580 begin
1581 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1583 if trigData.trigScoreCon then
1584 begin
1585 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1586 begin
1587 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1588 if g_Game_IsServer and g_Game_IsNet then
1589 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+b');
1590 end else
1591 begin
1592 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1593 if g_Game_IsServer and g_Game_IsNet then
1594 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+be');
1595 end;
1596 end;
1598 if trigData.trigScoreMsg then
1599 begin
1600 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1601 if g_Game_IsServer and g_Game_IsNet then
1602 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1603 end;
1604 end;
1605 if ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_SUB) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE))
1606 or ((trigData.trigScoreAction = TRIGGER_SCORE_ACTION_SUB) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1607 begin
1608 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1610 if trigData.trigScoreCon then
1611 begin
1612 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1613 begin
1614 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1615 if g_Game_IsServer and g_Game_IsNet then
1616 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-b');
1617 end else
1618 begin
1619 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1620 if g_Game_IsServer and g_Game_IsNet then
1621 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-be');
1622 end;
1623 end;
1625 if trigData.trigScoreMsg then
1626 begin
1627 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1628 if g_Game_IsServer and g_Game_IsNet then
1629 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1630 end;
1631 end;
1632 Result := (p.Team = TEAM_RED) or (p.Team = TEAM_BLUE);
1633 end;
1634 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1635 if trigData.trigScoreTeam in [TRIGGER_SCORE_TEAM_FORCE_RED, TRIGGER_SCORE_TEAM_FORCE_BLUE] then
1636 begin
1637 if (trigData.trigScoreAction = TRIGGER_SCORE_ACTION_ADD) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then
1638 begin
1639 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1641 if trigData.trigScoreCon then
1642 begin
1643 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1644 if g_Game_IsServer and g_Game_IsNet then
1645 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tr');
1646 end;
1648 if trigData.trigScoreMsg then
1649 begin
1650 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1651 if g_Game_IsServer and g_Game_IsNet then
1652 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1653 end;
1654 end;
1655 if (trigData.trigScoreAction = TRIGGER_SCORE_ACTION_SUB) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then
1656 begin
1657 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1659 if trigData.trigScoreCon then
1660 begin
1661 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1662 if g_Game_IsServer and g_Game_IsNet then
1663 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tr');
1664 end;
1666 if trigData.trigScoreMsg then
1667 begin
1668 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1669 if g_Game_IsServer and g_Game_IsNet then
1670 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1671 end;
1672 end;
1673 if (trigData.trigScoreAction = TRIGGER_SCORE_ACTION_ADD) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then
1674 begin
1675 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1677 if trigData.trigScoreCon then
1678 begin
1679 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1680 if g_Game_IsServer and g_Game_IsNet then
1681 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tb');
1682 end;
1684 if trigData.trigScoreMsg then
1685 begin
1686 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1687 if g_Game_IsServer and g_Game_IsNet then
1688 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1689 end;
1690 end;
1691 if (trigData.trigScoreAction = TRIGGER_SCORE_ACTION_SUB) and (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then
1692 begin
1693 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1695 if trigData.trigScoreCon then
1696 begin
1697 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1698 if g_Game_IsServer and g_Game_IsNet then
1699 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tb');
1700 end;
1702 if trigData.trigScoreMsg then
1703 begin
1704 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1705 if g_Game_IsServer and g_Game_IsNet then
1706 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1707 end;
1708 end;
1709 Result := True;
1710 end;
1711 end;
1712 // Âûèãðûø
1713 if (trigData.trigScoreAction = TRIGGER_SCORE_ACTION_WIN) and (gGameSettings.GoalLimit > 0) then
1714 begin
1715 // Ñâîåé èëè ÷óæîé êîìàíäû
1716 if (trigData.trigScoreTeam in [TRIGGER_SCORE_TEAM_MINE_RED, TRIGGER_SCORE_TEAM_MINE_BLUE]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1717 begin
1718 p := g_Player_Get(ActivateUID);
1719 if ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED)) // Red Wins
1720 or ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1721 begin
1722 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1723 begin
1724 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1726 if trigData.trigScoreCon then
1727 begin
1728 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1729 begin
1730 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1731 if g_Game_IsServer and g_Game_IsNet then
1732 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1733 end else
1734 begin
1735 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1736 if g_Game_IsServer and g_Game_IsNet then
1737 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1738 end;
1739 end;
1741 Result := True;
1742 end;
1743 end;
1744 if ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE)) // Blue Wins
1745 or ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1746 begin
1747 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1748 begin
1749 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1751 if trigData.trigScoreCon then
1752 begin
1753 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1754 begin
1755 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1756 if g_Game_IsServer and g_Game_IsNet then
1757 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1758 end else
1759 begin
1760 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1761 if g_Game_IsServer and g_Game_IsNet then
1762 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1763 end;
1764 end;
1766 Result := True;
1767 end;
1768 end;
1769 end;
1770 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1771 if trigData.trigScoreTeam in [TRIGGER_SCORE_TEAM_FORCE_RED, TRIGGER_SCORE_TEAM_FORCE_BLUE] then
1772 begin
1773 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then // Red Wins
1774 begin
1775 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1776 begin
1777 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1778 Result := True;
1779 end;
1780 end;
1781 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then // Blue Wins
1782 begin
1783 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1784 begin
1785 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1786 Result := True;
1787 end;
1788 end;
1789 end;
1790 end;
1791 // Ïðîèãðûø
1792 if (trigData.trigScoreAction = TRIGGER_SCORE_ACTION_LOOSE) and (gGameSettings.GoalLimit > 0) then
1793 begin
1794 // Ñâîåé èëè ÷óæîé êîìàíäû
1795 if (trigData.trigScoreTeam in [TRIGGER_SCORE_TEAM_MINE_RED, TRIGGER_SCORE_TEAM_MINE_BLUE]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1796 begin
1797 p := g_Player_Get(ActivateUID);
1798 if ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE)) // Red Wins
1799 or ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1800 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1801 begin
1802 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1804 if trigData.trigScoreCon then
1805 if trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED then
1806 begin
1807 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1808 if g_Game_IsServer and g_Game_IsNet then
1809 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1810 end else
1811 begin
1812 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1813 if g_Game_IsServer and g_Game_IsNet then
1814 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1815 end;
1817 Result := True;
1818 end;
1819 if ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED)) // Blue Wins
1820 or ((trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1821 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1822 begin
1823 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1825 if trigData.trigScoreCon then
1826 if trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED then
1827 begin
1828 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1829 if g_Game_IsServer and g_Game_IsNet then
1830 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1831 end else
1832 begin
1833 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1834 if g_Game_IsServer and g_Game_IsNet then
1835 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1836 end;
1838 Result := True;
1839 end;
1840 end;
1841 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1842 if trigData.trigScoreTeam in [TRIGGER_SCORE_TEAM_FORCE_BLUE, TRIGGER_SCORE_TEAM_FORCE_RED] then
1843 begin
1844 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then // Red Wins
1845 begin
1846 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1847 begin
1848 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1849 Result := True;
1850 end;
1851 end;
1852 if (trigData.trigScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then // Blue Wins
1853 begin
1854 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1855 begin
1856 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1857 Result := True;
1858 end;
1859 end;
1860 end;
1861 end;
1862 if Result then begin
1863 if coolDown then
1864 TimeOut := 18
1865 else
1866 TimeOut := 0;
1867 if g_Game_IsServer and g_Game_IsNet then
1868 MH_SEND_GameStats;
1869 end;
1870 end;
1872 TRIGGER_MESSAGE:
1873 begin
1874 Result := tr_Message(trigData.trigKind, trigData.trigText,
1875 trigData.trigMsgDest, trigData.trigMsgTime,
1876 ActivateUID);
1877 TimeOut := 18;
1878 end;
1880 TRIGGER_DAMAGE, TRIGGER_HEALTH:
1881 begin
1882 Result := False;
1883 UIDType := g_GetUIDType(ActivateUID);
1884 if (UIDType = UID_PLAYER) or (UIDType = UID_MONSTER) then
1885 begin
1886 Result := True;
1887 k := -1;
1888 if coolDown then
1889 begin
1890 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1891 for idx := 0 to High(Activators) do
1892 if Activators[idx].UID = ActivateUID then
1893 begin
1894 k := idx;
1895 Break;
1896 end;
1897 if k = -1 then
1898 begin // Âèäèì åãî âïåðâûå
1899 // Çàïîìèíàåì åãî
1900 SetLength(Activators, Length(Activators) + 1);
1901 k := High(Activators);
1902 Activators[k].UID := ActivateUID;
1903 end else
1904 begin // Óæå âèäåëè åãî
1905 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1906 if (trigData.trigInterval = 0) and (Activators[k].TimeOut > 0) then
1907 Activators[k].TimeOut := 65535;
1908 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1909 Result := Activators[k].TimeOut = 0;
1910 end;
1911 end;
1913 if Result then
1914 begin
1915 case UIDType of
1916 UID_PLAYER:
1917 begin
1918 p := g_Player_Get(ActivateUID);
1919 if p = nil then
1920 Exit;
1922 // Íàíîñèì óðîí èãðîêó
1923 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigAmount > 0) then
1924 p.Damage(trigData.trigAmount, 0, 0, 0, HIT_SOME);
1926 // Ëå÷èì èãðîêà
1927 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigAmount > 0) then
1928 if p.Heal(trigData.trigAmount, not trigData.trigHealMax) and (not trigData.trigSilent) then
1929 begin
1930 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p.Obj.X, p.Obj.Y);
1931 if g_Game_IsServer and g_Game_IsNet then
1932 MH_SEND_Sound(p.Obj.X, p.Obj.Y, 'SOUND_ITEM_GETITEM');
1933 end;
1934 end;
1936 UID_MONSTER:
1937 begin
1938 m := g_Monsters_ByUID(ActivateUID);
1939 if m = nil then
1940 Exit;
1942 // Íàíîñèì óðîí ìîíñòðó
1943 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigAmount > 0) then
1944 m.Damage(trigData.trigAmount, 0, 0, 0, HIT_SOME);
1946 // Ëå÷èì ìîíñòðà
1947 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigAmount > 0) then
1948 if m.Heal(trigData.trigAmount) and (not trigData.trigSilent) then
1949 begin
1950 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m.Obj.X, m.Obj.Y);
1951 if g_Game_IsServer and g_Game_IsNet then
1952 MH_SEND_Sound(m.Obj.X, m.Obj.Y, 'SOUND_ITEM_GETITEM');
1953 end;
1954 end;
1955 end;
1956 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1957 idx := trigData.trigInterval;
1958 if coolDown then
1959 if idx > 0 then
1960 Activators[k].TimeOut := idx
1961 else
1962 Activators[k].TimeOut := 65535;
1963 end;
1964 end;
1965 TimeOut := 0;
1966 end;
1968 TRIGGER_SHOT:
1969 begin
1970 if ShotSightTime > 0 then
1971 Exit;
1973 // put this at the beginning so it doesn't trigger itself
1974 TimeOut := trigData.trigWait + 1;
1976 wx := trigData.trigTX;
1977 wy := trigData.trigTY;
1978 pAngle := -DegToRad(trigData.trigAngle);
1979 xd := wx + Round(Cos(pAngle) * 32.0);
1980 yd := wy + Round(Sin(pAngle) * 32.0);
1981 TargetUID := 0;
1983 case trigData.trigShotTarget of
1984 TRIGGER_SHOT_TARGET_MON: // monsters
1985 //TODO: accelerate this!
1986 g_Mons_ForEachAlive(monsShotTarget);
1988 TRIGGER_SHOT_TARGET_PLR: // players
1989 if gPlayers <> nil then
1990 for idx := Low(gPlayers) to High(gPlayers) do
1991 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
1992 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1993 begin
1994 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1995 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1996 TargetUID := gPlayers[idx].UID;
1997 break;
1998 end;
2000 TRIGGER_SHOT_TARGET_RED: // red team
2001 if gPlayers <> nil then
2002 for idx := Low(gPlayers) to High(gPlayers) do
2003 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2004 (gPlayers[idx].Team = TEAM_RED) and
2005 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2006 begin
2007 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2008 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2009 TargetUID := gPlayers[idx].UID;
2010 break;
2011 end;
2013 TRIGGER_SHOT_TARGET_BLUE: // blue team
2014 if gPlayers <> nil then
2015 for idx := Low(gPlayers) to High(gPlayers) do
2016 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2017 (gPlayers[idx].Team = TEAM_BLUE) and
2018 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2019 begin
2020 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2021 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2022 TargetUID := gPlayers[idx].UID;
2023 break;
2024 end;
2026 TRIGGER_SHOT_TARGET_MONPLR: // monsters then players
2027 begin
2028 //TODO: accelerate this!
2029 g_Mons_ForEachAlive(monsShotTargetMonPlr);
2031 if (TargetUID = 0) and (gPlayers <> nil) then
2032 for idx := Low(gPlayers) to High(gPlayers) do
2033 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2034 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2035 begin
2036 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2037 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2038 TargetUID := gPlayers[idx].UID;
2039 break;
2040 end;
2041 end;
2043 TRIGGER_SHOT_TARGET_PLRMON: // players then monsters
2044 begin
2045 if gPlayers <> nil then
2046 for idx := Low(gPlayers) to High(gPlayers) do
2047 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2048 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2049 begin
2050 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2051 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2052 TargetUID := gPlayers[idx].UID;
2053 break;
2054 end;
2055 if TargetUID = 0 then
2056 begin
2057 //TODO: accelerate this!
2058 g_Mons_ForEachAlive(monShotTargetPlrMon);
2059 end;
2060 end;
2062 else begin
2063 if (trigData.trigShotTarget <> TRIGGER_SHOT_TARGET_NONE) or
2064 (trigData.trigShotType <> TRIGGER_SHOT_REV) then
2065 TargetUID := ActivateUID;
2066 end;
2067 end;
2069 if (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or (TargetUID > 0) or
2070 ((trigData.trigShotTarget > TRIGGER_SHOT_TARGET_NONE) and (TargetUID = 0)) then
2071 begin
2072 Result := True;
2073 if (trigData.trigSight = 0) or
2074 (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or
2075 (TargetUID = ShotSightTarget) then
2076 MakeShot(Trigger, wx, wy, xd, yd, TargetUID)
2077 else
2078 begin
2079 ShotSightTime := trigData.trigSight;
2080 ShotSightTargetN := TargetUID;
2081 if trigData.trigShotType = TRIGGER_SHOT_BFG then
2082 begin
2083 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx, wy);
2084 if g_Game_IsNet and g_Game_IsServer then
2085 MH_SEND_Sound(wx, wy, 'SOUND_WEAPON_STARTFIREBFG');
2086 end;
2087 end;
2088 end;
2089 end;
2091 TRIGGER_EFFECT:
2092 begin
2093 idx := trigData.trigFXCount;
2095 while idx > 0 do
2096 begin
2097 case trigData.trigFXPos of
2098 TRIGGER_EFFECT_POS_CENTER:
2099 begin
2100 wx := X + Width div 2;
2101 wy := Y + Height div 2;
2102 end;
2103 TRIGGER_EFFECT_POS_AREA:
2104 begin
2105 wx := X + Random(Width);
2106 wy := Y + Random(Height);
2107 end;
2108 else begin
2109 wx := X + Width div 2;
2110 wy := Y + Height div 2;
2111 end;
2112 end;
2113 xd := trigData.trigVelX;
2114 yd := trigData.trigVelY;
2115 if trigData.trigSpreadL > 0 then xd -= Random(trigData.trigSpreadL+1);
2116 if trigData.trigSpreadR > 0 then xd += Random(trigData.trigSpreadR+1);
2117 if trigData.trigSpreadU > 0 then yd -= Random(trigData.trigSpreadU+1);
2118 if trigData.trigSpreadD > 0 then yd += Random(trigData.trigSpreadD+1);
2119 tr_MakeEffect(wx, wy, xd, yd,
2120 trigData.trigFXType, trigData.trigFXSubType,
2121 trigData.trigFXRed, trigData.trigFXGreen, trigData.trigFXBlue, True, False);
2122 Dec(idx);
2123 end;
2124 TimeOut := trigData.trigWait;
2125 end;
2126 end;
2127 end;
2129 if Result {and (Trigger.TexturePanel <> -1)} then
2130 begin
2131 g_Map_SwitchTextureGUID(Trigger.TexturePanelType, Trigger.TexturePanelGUID, IfThen(animonce, 2, 1));
2132 end;
2133 end;
2136 function g_Triggers_CreateWithMapIndex (Trigger: TTrigger; arridx, mapidx: Integer): DWORD;
2137 var
2138 triggers: TDynField;
2139 begin
2140 triggers := gCurrentMap['trigger'];
2141 if (triggers = nil) then raise Exception.Create('LOAD: map has no triggers');
2142 if (mapidx < 0) or (mapidx >= triggers.count) then raise Exception.Create('LOAD: invalid map trigger index');
2143 Trigger.trigData := triggers.itemAt[mapidx];
2144 if (Trigger.trigData = nil) then raise Exception.Create('LOAD: internal error in trigger loader');
2145 Trigger.mapId := Trigger.trigData.id;
2146 Trigger.mapIndex := mapidx;
2147 if (Trigger.trigData.trigRec <> nil) then
2148 begin
2149 Trigger.trigData := Trigger.trigData.trigRec.clone({Trigger.trigData.headerRec}nil);
2150 end
2151 else
2152 begin
2153 Trigger.trigData := nil;
2154 end;
2155 result := g_Triggers_Create(Trigger, arridx);
2156 end;
2159 function g_Triggers_Create(Trigger: TTrigger; forceInternalIndex: Integer=-1): DWORD;
2160 var
2161 find_id: DWORD;
2162 fn, mapw: AnsiString;
2163 f, olen: Integer;
2164 begin
2165 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2166 if (Trigger.TriggerType = TRIGGER_EXIT) and
2167 (not LongBool(gGameSettings.Options and GAME_OPTION_ALLOWEXIT)) then
2168 Trigger.TriggerType := TRIGGER_NONE;
2170 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2171 if (Trigger.TriggerType = TRIGGER_SPAWNMONSTER) and
2172 (not LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS)) and
2173 (gGameSettings.GameType <> GT_SINGLE) then
2174 Trigger.TriggerType := TRIGGER_NONE;
2176 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2177 if Trigger.TriggerType = TRIGGER_SECRET then
2178 gSecretsCount := gSecretsCount + 1;
2180 if (forceInternalIndex < 0) then
2181 begin
2182 find_id := FindTrigger();
2183 end
2184 else
2185 begin
2186 olen := Length(gTriggers);
2187 if (forceInternalIndex >= olen) then
2188 begin
2189 SetLength(gTriggers, forceInternalIndex+1);
2190 for f := olen to High(gTriggers) do gTriggers[f].TriggerType := TRIGGER_NONE;
2191 end;
2192 find_id := DWORD(forceInternalIndex);
2193 end;
2194 gTriggers[find_id] := Trigger;
2196 //e_LogWritefln('created trigger with map index %s, findid=%s (%s)', [Trigger.mapIndex, find_id, Trigger.mapId]);
2199 writeln('trigger #', find_id, ': pos=(', Trigger.x, ',', Trigger.y, ')-(', Trigger.width, 'x', Trigger.height, ')',
2200 '; TexturePanel=', Trigger.TexturePanel,
2201 '; TexturePanelType=', Trigger.TexturePanelType,
2202 '; ShotPanelType=', Trigger.ShotPanelType,
2203 '; TriggerType=', Trigger.TriggerType,
2204 '; ActivateType=', Trigger.ActivateType,
2205 '; Keys=', Trigger.Keys,
2206 '; trigPanelId=', Trigger.trigPanelId,
2207 '; trigShotPanelId=', Trigger.trigShotPanelId
2208 );
2211 with gTriggers[find_id] do
2212 begin
2213 ID := find_id;
2214 // if this type of trigger exists both on the client and on the server
2215 // use an uniform numeration
2216 if Trigger.TriggerType = TRIGGER_SOUND then
2217 begin
2218 Inc(gTriggerClientID);
2219 ClientID := gTriggerClientID;
2220 end
2221 else
2222 ClientID := 0;
2223 TimeOut := 0;
2224 ActivateUID := 0;
2225 PlayerCollide := False;
2226 DoorTime := -1;
2227 PressTime := -1;
2228 PressCount := 0;
2229 SoundPlayCount := 0;
2230 Sound := nil;
2231 AutoSpawn := False;
2232 SpawnCooldown := 0;
2233 SpawnedCount := 0;
2234 end;
2236 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2237 if (Trigger.TriggerType = TRIGGER_SOUND) and
2238 (Trigger.trigData.trigSoundName <> '') then
2239 begin
2240 // Åùå íåò òàêîãî çâóêà:
2241 if not g_Sound_Exists(Trigger.trigData.trigSoundName) then
2242 begin
2243 fn := g_ExtractWadName(Trigger.trigData.trigSoundName);
2245 if fn = '' then
2246 begin // Çâóê â ôàéëå ñ êàðòîé
2247 mapw := g_ExtractWadName(gMapInfo.Map);
2248 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigSoundName);
2249 end
2250 else // Çâóê â îòäåëüíîì ôàéëå
2251 fn := GameDir + '/wads/' + Trigger.trigData.trigSoundName;
2253 if not g_Sound_CreateWADEx(Trigger.trigData.trigSoundName, fn) then
2254 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigSoundName]));
2255 end;
2257 // Ñîçäàåì îáúåêò çâóêà:
2258 with gTriggers[find_id] do
2259 begin
2260 Sound := TPlayableSound.Create();
2261 if not Sound.SetByName(Trigger.trigData.trigSoundName) then
2262 begin
2263 Sound.Free();
2264 Sound := nil;
2265 end;
2266 end;
2267 end;
2269 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2270 if (Trigger.TriggerType = TRIGGER_MUSIC) and
2271 (Trigger.trigData.trigMusicName <> '') then
2272 begin
2273 // Åùå íåò òàêîé ìóçûêè:
2274 if not g_Sound_Exists(Trigger.trigData.trigMusicName) then
2275 begin
2276 fn := g_ExtractWadName(Trigger.trigData.trigMusicName);
2278 if fn = '' then
2279 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2280 mapw := g_ExtractWadName(gMapInfo.Map);
2281 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigMusicName);
2282 end
2283 else // Ìóçûêà â ôàéëå ñ êàðòîé
2284 fn := GameDir+'/wads/'+Trigger.trigData.trigMusicName;
2286 if not g_Sound_CreateWADEx(Trigger.trigData.trigMusicName, fn, True) then
2287 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigMusicName]));
2288 end;
2289 end;
2291 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2292 if Trigger.TriggerType = TRIGGER_SHOT then
2293 with gTriggers[find_id] do
2294 begin
2295 ShotPanelTime := 0;
2296 ShotSightTime := 0;
2297 ShotSightTimeout := 0;
2298 ShotSightTarget := 0;
2299 ShotSightTargetN := 0;
2300 ShotAmmoCount := Trigger.trigData.trigAmmo;
2301 ShotReloadTime := 0;
2302 end;
2304 Result := find_id;
2305 end;
2308 // sorry; grid doesn't support recursive queries, so we have to do this
2309 type
2310 TSimpleMonsterList = specialize TSimpleList<TMonster>;
2312 var
2313 tgMonsList: TSimpleMonsterList = nil;
2315 procedure g_Triggers_Update();
2316 var
2317 a, b, i: Integer;
2318 Affected: array of Integer;
2320 function monsNear (mon: TMonster): Boolean;
2321 begin
2322 result := false; // don't stop
2324 gTriggers[a].ActivateUID := mon.UID;
2325 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2327 tgMonsList.append(mon);
2328 end;
2330 var
2331 mon: TMonster;
2332 pan: TPanel;
2333 begin
2334 if (tgMonsList = nil) then tgMonsList := TSimpleMonsterList.Create();
2336 if gTriggers = nil then
2337 Exit;
2338 SetLength(Affected, 0);
2340 for a := 0 to High(gTriggers) do
2341 with gTriggers[a] do
2342 // Åñòü òðèããåð:
2343 if TriggerType <> TRIGGER_NONE then
2344 begin
2345 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2346 if DoorTime > 0 then DoorTime := DoorTime - 1;
2347 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2348 if PressTime > 0 then PressTime := PressTime - 1;
2349 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2350 if (TriggerType = TRIGGER_DAMAGE) or (TriggerType = TRIGGER_HEALTH) then
2351 begin
2352 for b := 0 to High(Activators) do
2353 begin
2354 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2355 if Activators[b].TimeOut > 0 then
2356 begin
2357 Dec(Activators[b].TimeOut);
2358 end
2359 else
2360 begin
2361 continue;
2362 end;
2363 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2364 if (trigData.trigInterval = 0) and (Activators[b].TimeOut < 65530) then Activators[b].TimeOut := 0;
2365 end;
2366 end;
2368 // Îáðàáàòûâàåì ñïàâíåðû
2369 if Enabled and AutoSpawn then
2370 begin
2371 if SpawnCooldown = 0 then
2372 begin
2373 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2374 if (TriggerType = TRIGGER_SPAWNMONSTER) and (trigData.trigDelay > 0) then
2375 begin
2376 ActivateUID := 0;
2377 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2378 end;
2379 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2380 if (TriggerType = TRIGGER_SPAWNITEM) and (trigData.trigDelay > 0) then
2381 begin
2382 ActivateUID := 0;
2383 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2384 end;
2385 end
2386 else
2387 begin
2388 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2389 Dec(SpawnCooldown);
2390 end;
2391 end;
2393 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2394 if TriggerType = TRIGGER_SHOT then
2395 begin
2396 if ShotPanelTime > 0 then
2397 begin
2398 Dec(ShotPanelTime);
2399 if ShotPanelTime = 0 then g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID);
2400 end;
2401 if ShotSightTime > 0 then
2402 begin
2403 Dec(ShotSightTime);
2404 if ShotSightTime = 0 then ShotSightTarget := ShotSightTargetN;
2405 end;
2406 if ShotSightTimeout > 0 then
2407 begin
2408 Dec(ShotSightTimeout);
2409 if ShotSightTimeout = 0 then ShotSightTarget := 0;
2410 end;
2411 if ShotReloadTime > 0 then
2412 begin
2413 Dec(ShotReloadTime);
2414 if ShotReloadTime = 0 then ShotAmmoCount := trigData.trigAmmo;
2415 end;
2416 end;
2418 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2419 if Enabled and (TriggerType = TRIGGER_SOUND) and (Sound <> nil) then
2420 begin
2421 if (SoundPlayCount > 0) and (not Sound.IsPlaying()) then
2422 begin
2423 if trigData.trigPlayCount > 0 then SoundPlayCount -= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2424 if trigData.trigLocal then
2425 begin
2426 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), trigData.trigVolume/255.0);
2427 end
2428 else
2429 begin
2430 Sound.PlayPanVolume((trigData.trigPan-127.0)/128.0, trigData.trigVolume/255.0);
2431 end;
2432 if Sound.IsPlaying() and g_Game_IsNet and g_Game_IsServer then MH_SEND_TriggerSound(gTriggers[a]);
2433 end;
2434 end;
2436 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2437 if (TriggerType = TRIGGER_TRAP) and (DoorTime = 0) and (g_Map_PanelByGUID(trigPanelGUID) <> nil) then
2438 begin
2439 tr_OpenDoor(trigPanelGUID, trigData.trigSilent, trigData.trigD2d);
2440 DoorTime := -1;
2441 end;
2443 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2444 if (TriggerType = TRIGGER_DOOR5) and (DoorTime = 0) and (g_Map_PanelByGUID(trigPanelGUID) <> nil) then
2445 begin
2446 pan := g_Map_PanelByGUID(trigPanelGUID);
2447 if (pan <> nil) and pan.isGWall then
2448 begin
2449 // Óæå çàêðûòà
2450 if {gWalls[trigPanelID].Enabled} pan.Enabled then
2451 begin
2452 DoorTime := -1;
2453 end
2454 else
2455 begin
2456 // Ïîêà îòêðûòà - çàêðûâàåì
2457 if tr_CloseDoor(trigPanelGUID, trigData.trigSilent, trigData.trigD2d) then DoorTime := -1;
2458 end;
2459 end;
2460 end;
2462 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2463 if (TriggerType in [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) and
2464 (PressTime = 0) and (PressCount >= trigData.trigPressCount) then
2465 begin
2466 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2467 PressTime := -1;
2468 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2469 if trigData.trigPressCount > 0 then PressCount -= trigData.trigPressCount else PressCount := 0;
2471 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2472 for b := 0 to High(gTriggers) do
2473 begin
2474 if g_Collide(trigData.trigtX, trigData.trigtY, trigData.trigtWidth, trigData.trigtHeight, gTriggers[b].X, gTriggers[b].Y,
2475 gTriggers[b].Width, gTriggers[b].Height) and
2476 ((b <> a) or (trigData.trigWait > 0)) then
2477 begin // Can be self-activated, if there is Data.Wait
2478 if (not trigData.trigExtRandom) or gTriggers[b].Enabled then
2479 begin
2480 SetLength(Affected, Length(Affected) + 1);
2481 Affected[High(Affected)] := b;
2482 end;
2483 end;
2484 end;
2486 //HACK!
2487 // if we have panelid, assume that it will switch the moving platform
2488 pan := g_Map_PanelByGUID(trigPanelGUID);
2489 if (pan <> nil) then
2490 begin
2491 case TriggerType of
2492 TRIGGER_PRESS: pan.movingActive := true; // what to do here?
2493 TRIGGER_ON: pan.movingActive := true;
2494 TRIGGER_OFF: pan.movingActive := false;
2495 TRIGGER_ONOFF: pan.movingActive := not pan.movingActive;
2496 end;
2497 if not trigData.trigSilent and (Length(trigData.trigSound) > 0) then
2498 begin
2499 g_Sound_PlayExAt(trigData.trigSound, X, Y);
2500 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, trigData.trigSound);
2501 end;
2502 end;
2504 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2505 if (TriggerType = TRIGGER_PRESS) and trigData.trigExtRandom then
2506 begin
2507 if (Length(Affected) > 0) then
2508 begin
2509 b := Affected[Random(Length(Affected))];
2510 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2511 ActivateTrigger(gTriggers[b], 0);
2512 end;
2513 end
2514 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2515 begin
2516 for i := 0 to High(Affected) do
2517 begin
2518 b := Affected[i];
2519 case TriggerType of
2520 TRIGGER_PRESS:
2521 begin
2522 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2523 ActivateTrigger(gTriggers[b], 0);
2524 end;
2525 TRIGGER_ON:
2526 begin
2527 gTriggers[b].Enabled := True;
2528 end;
2529 TRIGGER_OFF:
2530 begin
2531 gTriggers[b].Enabled := False;
2532 gTriggers[b].TimeOut := 0;
2533 if gTriggers[b].AutoSpawn then
2534 begin
2535 gTriggers[b].AutoSpawn := False;
2536 gTriggers[b].SpawnCooldown := 0;
2537 end;
2538 end;
2539 TRIGGER_ONOFF:
2540 begin
2541 gTriggers[b].Enabled := not gTriggers[b].Enabled;
2542 if not gTriggers[b].Enabled then
2543 begin
2544 gTriggers[b].TimeOut := 0;
2545 if gTriggers[b].AutoSpawn then
2546 begin
2547 gTriggers[b].AutoSpawn := False;
2548 gTriggers[b].SpawnCooldown := 0;
2549 end;
2550 end;
2551 end;
2552 end;
2553 end;
2554 end;
2555 SetLength(Affected, 0);
2556 end;
2558 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2559 if TimeOut > 0 then
2560 begin
2561 TimeOut := TimeOut - 1;
2562 Continue; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2563 end;
2565 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2566 if not Enabled then
2567 Continue;
2569 // "Èãðîê áëèçêî":
2570 if ByteBool(ActivateType and ACTIVATE_PLAYERCOLLIDE) and
2571 (TimeOut = 0) then
2572 if gPlayers <> nil then
2573 for b := 0 to High(gPlayers) do
2574 if gPlayers[b] <> nil then
2575 with gPlayers[b] do
2576 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2577 if alive and ((gTriggers[a].Keys and GetKeys) = gTriggers[a].Keys) and
2578 Collide(X, Y, Width, Height) then
2579 begin
2580 gTriggers[a].ActivateUID := UID;
2582 if (gTriggers[a].TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) and
2583 PlayerCollide then
2584 { Don't activate sound/music again if player is here }
2585 else
2586 ActivateTrigger(gTriggers[a], ACTIVATE_PLAYERCOLLIDE);
2587 end;
2589 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2591 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2592 ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2593 (TimeOut = 0) and (Keys = 0) then
2594 begin
2595 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2596 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2597 ActivateType := ActivateType and not (ACTIVATE_MONSTERCOLLIDE or ACTIVATE_NOMONSTER);
2598 gTriggers[a].ActivateUID := 0;
2599 ActivateTrigger(gTriggers[a], 0);
2600 end else
2601 begin
2602 // "Ìîíñòð áëèçêî"
2603 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2604 (TimeOut = 0) and (Keys = 0) then // Åñëè íå íóæíû êëþ÷è
2605 begin
2606 //g_Mons_ForEach(monsNear);
2607 //Alive?!
2608 tgMonsList.reset();
2609 g_Mons_ForEachAt(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height, monsNear);
2610 for mon in tgMonsList do
2611 begin
2612 gTriggers[a].ActivateUID := mon.UID;
2613 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2614 end;
2615 tgMonsList.reset(); // just in case
2616 end;
2618 // "Ìîíñòðîâ íåò"
2619 if ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2620 (TimeOut = 0) and (Keys = 0) then
2621 if not g_Mons_IsAnyAliveAt(X, Y, Width, Height) then
2622 begin
2623 gTriggers[a].ActivateUID := 0;
2624 ActivateTrigger(gTriggers[a], ACTIVATE_NOMONSTER);
2625 end;
2626 end;
2628 PlayerCollide := g_CollidePlayer(X, Y, Width, Height);
2629 end;
2630 end;
2632 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
2633 begin
2634 if (ID >= Length(gTriggers)) then exit;
2635 gTriggers[ID].ActivateUID := ActivateUID;
2636 ActivateTrigger(gTriggers[ID], ActivateType);
2637 end;
2639 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
2640 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
2641 var
2642 a: Integer;
2643 k: Byte;
2644 p: TPlayer;
2645 begin
2646 Result := nil;
2648 if gTriggers = nil then Exit;
2650 case g_GetUIDType(UID) of
2651 UID_GAME: k := 255;
2652 UID_PLAYER:
2653 begin
2654 p := g_Player_Get(UID);
2655 if p <> nil then
2656 k := p.GetKeys
2657 else
2658 k := 0;
2659 end;
2660 else k := 0;
2661 end;
2663 for a := 0 to High(gTriggers) do
2664 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2665 (gTriggers[a].TimeOut = 0) and
2666 (not InDWArray(a, IgnoreList)) and
2667 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2668 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2669 if g_Collide(X, Y, Width, Height,
2670 gTriggers[a].X, gTriggers[a].Y,
2671 gTriggers[a].Width, gTriggers[a].Height) then
2672 begin
2673 gTriggers[a].ActivateUID := UID;
2674 if ActivateTrigger(gTriggers[a], ActivateType) then
2675 begin
2676 SetLength(Result, Length(Result)+1);
2677 Result[High(Result)] := a;
2678 end;
2679 end;
2680 end;
2682 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
2683 var
2684 a: Integer;
2685 k: Byte;
2686 p: TPlayer;
2687 begin
2688 if gTriggers = nil then Exit;
2690 case g_GetUIDType(UID) of
2691 UID_GAME: k := 255;
2692 UID_PLAYER:
2693 begin
2694 p := g_Player_Get(UID);
2695 if p <> nil then
2696 k := p.GetKeys
2697 else
2698 k := 0;
2699 end;
2700 else k := 0;
2701 end;
2703 for a := 0 to High(gTriggers) do
2704 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2705 (gTriggers[a].TimeOut = 0) and
2706 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2707 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2708 if g_CollideLine(x1, y1, x2, y2, gTriggers[a].X, gTriggers[a].Y,
2709 gTriggers[a].Width, gTriggers[a].Height) then
2710 begin
2711 gTriggers[a].ActivateUID := UID;
2712 ActivateTrigger(gTriggers[a], ActivateType);
2713 end;
2714 end;
2716 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
2717 var
2718 a: Integer;
2719 k: Byte;
2720 rsq: Word;
2721 p: TPlayer;
2722 begin
2723 if gTriggers = nil then
2724 Exit;
2726 case g_GetUIDType(UID) of
2727 UID_GAME: k := 255;
2728 UID_PLAYER:
2729 begin
2730 p := g_Player_Get(UID);
2731 if p <> nil then
2732 k := p.GetKeys
2733 else
2734 k := 0;
2735 end;
2736 else k := 0;
2737 end;
2739 rsq := Radius * Radius;
2741 for a := 0 to High(gTriggers) do
2742 if (gTriggers[a].ID <> DWORD(IgnoreTrigger)) and
2743 (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2744 (gTriggers[a].TimeOut = 0) and
2745 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2746 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2747 with gTriggers[a] do
2748 if g_Collide(CX-Radius, CY-Radius, 2*Radius, 2*Radius,
2749 X, Y, Width, Height) then
2750 if ((Sqr(CX-X)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2751 ((Sqr(CX-X-Width)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2752 ((Sqr(CX-X-Width)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2753 ((Sqr(CX-X)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2754 ( (CX > (X-Radius)) and (CX < (X+Width+Radius)) and
2755 (CY > Y) and (CY < (Y+Height)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2756 ( (CY > (Y-Radius)) and (CY < (Y+Height+Radius)) and
2757 (CX > X) and (CX < (X+Width)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2758 begin
2759 ActivateUID := UID;
2760 ActivateTrigger(gTriggers[a], ActivateType);
2761 end;
2762 end;
2764 procedure g_Triggers_OpenAll();
2765 var
2766 a: Integer;
2767 b: Boolean;
2768 begin
2769 if gTriggers = nil then Exit;
2771 b := False;
2772 for a := 0 to High(gTriggers) do
2773 begin
2774 with gTriggers[a] do
2775 begin
2776 if (TriggerType = TRIGGER_OPENDOOR) or
2777 (TriggerType = TRIGGER_DOOR5) or
2778 (TriggerType = TRIGGER_DOOR) then
2779 begin
2780 tr_OpenDoor(trigPanelGUID, True, trigData.trigD2d);
2781 if TriggerType = TRIGGER_DOOR5 then DoorTime := 180;
2782 b := True;
2783 end;
2784 end;
2785 end;
2787 if b then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2788 end;
2790 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
2791 begin
2792 if (gTriggers <> nil) then
2793 if gTriggers[ID].SpawnedCount > 0 then
2794 Dec(gTriggers[ID].SpawnedCount);
2795 end;
2797 procedure g_Triggers_Free();
2798 var
2799 a: Integer;
2800 begin
2801 for a := 0 to High(gTriggers) do
2802 begin
2803 if (gTriggers[a].TriggerType = TRIGGER_SOUND) then
2804 begin
2805 if g_Sound_Exists(gTriggers[a].trigData.trigSoundName) then
2806 begin
2807 g_Sound_Delete(gTriggers[a].trigData.trigSoundName);
2808 end;
2809 gTriggers[a].Sound.Free();
2810 end;
2811 if (gTriggers[a].Activators <> nil) then
2812 begin
2813 SetLength(gTriggers[a].Activators, 0);
2814 end;
2815 gTriggers[a].trigData.Free();
2816 end;
2818 gTriggers := nil;
2819 gSecretsCount := 0;
2820 SetLength(gMonstersSpawned, 0);
2821 end;
2823 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
2824 var
2825 count, act_count, i, j: Integer;
2826 dw: DWORD;
2827 sg: Single;
2828 b: Boolean;
2829 begin
2830 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2831 count := Length(gTriggers);
2833 Mem := TBinMemoryWriter.Create((count+1) * 200);
2835 // Êîëè÷åñòâî òðèããåðîâ:
2836 Mem.WriteInt(count);
2838 //e_LogWritefln('saving %s triggers (count=%s)', [Length(gTriggers), count]);
2840 if count = 0 then exit;
2842 for i := 0 to High(gTriggers) do
2843 begin
2844 // Ñèãíàòóðà òðèããåðà:
2845 dw := TRIGGER_SIGNATURE; // 'TRGX'
2846 Mem.WriteDWORD(dw);
2847 // Òèï òðèããåðà:
2848 Mem.WriteByte(gTriggers[i].TriggerType);
2849 if (gTriggers[i].TriggerType = TRIGGER_NONE) then continue; // empty one
2850 // Ñïåöèàëüíûå äàííûå òðèããåðà: äà â æîïó, ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2851 //e_LogWritefln('=== trigger #%s saved ===', [gTriggers[i].mapIndex]);
2852 Mem.WriteInt(gTriggers[i].mapIndex);
2853 //p := @gTriggers[i].Data;
2854 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2855 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2856 Mem.WriteInt(gTriggers[i].X);
2857 Mem.WriteInt(gTriggers[i].Y);
2858 // Ðàçìåðû:
2859 Mem.WriteWord(gTriggers[i].Width);
2860 Mem.WriteWord(gTriggers[i].Height);
2861 // Âêëþ÷åí ëè òðèããåð:
2862 Mem.WriteBoolean(gTriggers[i].Enabled);
2863 // Òèï àêòèâàöèè òðèããåðà:
2864 Mem.WriteByte(gTriggers[i].ActivateType);
2865 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2866 Mem.WriteByte(gTriggers[i].Keys);
2867 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2868 Mem.WriteInt(gTriggers[i].TexturePanelGUID);
2869 // Òèï ýòîé ïàíåëè:
2870 Mem.WriteWord(gTriggers[i].TexturePanelType);
2871 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2872 Mem.WriteInt(gTriggers[i].trigPanelGUID);
2873 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2874 Mem.WriteWord(gTriggers[i].TimeOut);
2875 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2876 Mem.WriteWord(gTriggers[i].ActivateUID);
2877 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2878 act_count := Length(gTriggers[i].Activators);
2879 Mem.WriteInt(act_count);
2880 for j := 0 to act_count-1 do
2881 begin
2882 // UID îáúåêòà
2883 Mem.WriteWord(gTriggers[i].Activators[j].UID);
2884 // Âðåìÿ îæèäàíèÿ
2885 Mem.WriteWord(gTriggers[i].Activators[j].TimeOut);
2886 end;
2887 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2888 Mem.WriteBoolean(gTriggers[i].PlayerCollide);
2889 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2890 Mem.WriteInt(gTriggers[i].DoorTime);
2891 // Çàäåðæêà àêòèâàöèè:
2892 Mem.WriteInt(gTriggers[i].PressTime);
2893 // Ñ÷åò÷èê íàæàòèé:
2894 Mem.WriteInt(gTriggers[i].PressCount);
2895 // Ñïàâíåð àêòèâåí:
2896 Mem.WriteBoolean(gTriggers[i].AutoSpawn);
2897 // Çàäåðæêà ñïàâíåðà:
2898 Mem.WriteInt(gTriggers[i].SpawnCooldown);
2899 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2900 Mem.WriteInt(gTriggers[i].SpawnedCount);
2901 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2902 Mem.WriteInt(gTriggers[i].SoundPlayCount);
2903 // Ïðîèãðûâàåòñÿ ëè çâóê?
2904 if gTriggers[i].Sound <> nil then
2905 b := gTriggers[i].Sound.IsPlaying()
2906 else
2907 b := False;
2908 Mem.WriteBoolean(b);
2909 if b then
2910 begin
2911 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2912 dw := gTriggers[i].Sound.GetPosition();
2913 Mem.WriteDWORD(dw);
2914 // Ãðîìêîñòü çâóêà:
2915 sg := gTriggers[i].Sound.GetVolume();
2916 sg := sg / (gSoundLevel/255.0);
2917 Mem.WriteSingle(sg);
2918 // Ñòåðåî ñìåùåíèå çâóêà:
2919 sg := gTriggers[i].Sound.GetPan();
2920 Mem.WriteSingle(sg);
2921 end;
2922 end;
2923 end;
2925 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
2926 var
2927 count, act_count, i, j, a: Integer;
2928 dw: DWORD;
2929 vol, pan: Single;
2930 b: Boolean;
2931 //p: Pointer;
2932 Trig: TTrigger;
2933 mapIndex: Integer;
2934 //tw: TStrTextWriter;
2935 begin
2936 if Mem = nil then
2937 Exit;
2939 g_Triggers_Free();
2941 // Êîëè÷åñòâî òðèããåðîâ:
2942 Mem.ReadInt(count);
2944 if (count = 0) then exit;
2946 for a := 0 to count-1 do
2947 begin
2948 // Ñèãíàòóðà òðèããåðà:
2949 Mem.ReadDWORD(dw);
2950 if (dw <> TRIGGER_SIGNATURE) then // 'TRGX'
2951 begin
2952 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2953 end;
2954 // Òèï òðèããåðà:
2955 Mem.ReadByte(Trig.TriggerType);
2956 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2957 if (Trig.TriggerType = TRIGGER_NONE) then continue; // empty one
2958 Mem.ReadInt(mapIndex);
2959 //!!!FIXME!!!
2961 Mem.ReadMemory(p, dw);
2962 if dw <> SizeOf(TTriggerData) then
2963 begin
2964 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2965 end;
2966 Trig.Data := TTriggerData(p^);
2968 // Ñîçäàåì òðèããåð:
2969 i := g_Triggers_CreateWithMapIndex(Trig, a, mapIndex);
2971 if (gTriggers[i].trigData <> nil) then
2972 begin
2973 tw := TStrTextWriter.Create();
2974 try
2975 gTriggers[i].trigData.writeTo(tw);
2976 e_LogWritefln('=== trigger #%s loaded ==='#10'%s'#10'---', [mapIndex, tw.str]);
2977 finally
2978 tw.Free();
2979 end;
2980 end;
2982 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2983 Mem.ReadInt(gTriggers[i].X);
2984 Mem.ReadInt(gTriggers[i].Y);
2985 // Ðàçìåðû:
2986 Mem.ReadWord(gTriggers[i].Width);
2987 Mem.ReadWord(gTriggers[i].Height);
2988 // Âêëþ÷åí ëè òðèããåð:
2989 Mem.ReadBoolean(gTriggers[i].Enabled);
2990 // Òèï àêòèâàöèè òðèããåðà:
2991 Mem.ReadByte(gTriggers[i].ActivateType);
2992 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2993 Mem.ReadByte(gTriggers[i].Keys);
2994 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2995 Mem.ReadInt(gTriggers[i].TexturePanelGUID);
2996 // Òèï ýòîé ïàíåëè:
2997 Mem.ReadWord(gTriggers[i].TexturePanelType);
2998 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2999 Mem.ReadInt(gTriggers[i].trigPanelGUID);
3000 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
3001 Mem.ReadWord(gTriggers[i].TimeOut);
3002 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
3003 Mem.ReadWord(gTriggers[i].ActivateUID);
3004 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
3005 Mem.ReadInt(act_count);
3006 if act_count > 0 then
3007 begin
3008 SetLength(gTriggers[i].Activators, act_count);
3009 for j := 0 to act_count-1 do
3010 begin
3011 // UID îáúåêòà
3012 Mem.ReadWord(gTriggers[i].Activators[j].UID);
3013 // Âðåìÿ îæèäàíèÿ
3014 Mem.ReadWord(gTriggers[i].Activators[j].TimeOut);
3015 end;
3016 end;
3017 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
3018 Mem.ReadBoolean(gTriggers[i].PlayerCollide);
3019 // Âðåìÿ äî çàêðûòèÿ äâåðè:
3020 Mem.ReadInt(gTriggers[i].DoorTime);
3021 // Çàäåðæêà àêòèâàöèè:
3022 Mem.ReadInt(gTriggers[i].PressTime);
3023 // Ñ÷åò÷èê íàæàòèé:
3024 Mem.ReadInt(gTriggers[i].PressCount);
3025 // Ñïàâíåð àêòèâåí:
3026 Mem.ReadBoolean(gTriggers[i].AutoSpawn);
3027 // Çàäåðæêà ñïàâíåðà:
3028 Mem.ReadInt(gTriggers[i].SpawnCooldown);
3029 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3030 Mem.ReadInt(gTriggers[i].SpawnedCount);
3031 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3032 Mem.ReadInt(gTriggers[i].SoundPlayCount);
3033 // Ïðîèãðûâàåòñÿ ëè çâóê?
3034 Mem.ReadBoolean(b);
3035 if b then
3036 begin
3037 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3038 Mem.ReadDWORD(dw);
3039 // Ãðîìêîñòü çâóêà:
3040 Mem.ReadSingle(vol);
3041 // Ñòåðåî ñìåùåíèå çâóêà:
3042 Mem.ReadSingle(pan);
3043 // Çàïóñêàåì çâóê, åñëè åñòü:
3044 if gTriggers[i].Sound <> nil then
3045 begin
3046 gTriggers[i].Sound.PlayPanVolume(pan, vol);
3047 gTriggers[i].Sound.Pause(True);
3048 gTriggers[i].Sound.SetPosition(dw);
3049 end
3050 end;
3051 end;
3052 end;
3054 end.