DEADSOFTWARE

fixed typo in trigger caching; Anower Station is REALLY working 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 trigDataRec: TDynRecord; // triggerdata; owned by trigger
72 {$INCLUDE ../shared/mapdef_tgc_def.inc}
74 public
75 function trigCenter (): TDFPoint; inline;
77 public
78 property trigShotPanelGUID: Integer read trigPanelGUID write trigPanelGUID;
79 end;
81 function g_Triggers_Create(Trigger: TTrigger; forceInternalIndex: Integer=-1): DWORD;
82 procedure g_Triggers_Update();
83 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
84 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
85 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
86 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
87 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
88 procedure g_Triggers_OpenAll();
89 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
90 procedure g_Triggers_Free();
91 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
92 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
95 var
96 gTriggerClientID: Integer = 0;
97 gTriggers: array of TTrigger;
98 gSecretsCount: Integer = 0;
99 gMonstersSpawned: array of LongInt = nil;
102 implementation
104 uses
105 Math,
106 g_player, g_map, g_panel, g_gfx, g_game, g_textures,
107 g_console, g_monsters, g_items, g_phys, g_weapons,
108 wadreader, g_main, SysUtils, e_log, g_language,
109 g_options, g_net, g_netmsg, utils, xparser;
111 const
112 TRIGGER_SIGNATURE = $58475254; // 'TRGX'
113 TRAP_DAMAGE = 1000;
115 {$INCLUDE ../shared/mapdef_tgc_impl.inc}
117 function TTrigger.trigCenter (): TDFPoint; inline;
118 begin
119 result := TDFPoint.Create(x+width div 2, y+height div 2);
120 end;
123 function FindTrigger (): DWORD;
124 var
125 i: Integer;
126 begin
127 for i := 0 to High(gTriggers) do
128 begin
129 if gTriggers[i].TriggerType = TRIGGER_NONE then begin result := i; exit; end;
130 end;
132 if (gTriggers = nil) then
133 begin
134 SetLength(gTriggers, 8);
135 result := 0;
136 end
137 else
138 begin
139 result := Length(gTriggers);
140 SetLength(gTriggers, result+8);
141 for i := result to High(gTriggers) do gTriggers[i].TriggerType := TRIGGER_NONE;
142 end;
143 end;
146 function tr_CloseDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
147 var
148 a, b, c: Integer;
149 pan: TPanel;
150 PanelID: Integer;
151 begin
152 result := false;
153 pan := g_Map_PanelByGUID(PanelGUID);
154 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
155 PanelID := pan.arrIdx;
157 if not d2d then
158 begin
159 with gWalls[PanelID] do
160 begin
161 if g_CollidePlayer(X, Y, Width, Height) or g_Mons_IsAnyAliveAt(X, Y, Width, Height) then Exit;
162 if not Enabled then
163 begin
164 if not NoSound then
165 begin
166 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
167 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
168 end;
169 g_Map_EnableWallGUID(PanelGUID);
170 result := true;
171 end;
172 end;
173 end
174 else
175 begin
176 if (gDoorMap = nil) then exit;
178 c := -1;
179 for a := 0 to High(gDoorMap) do
180 begin
181 for b := 0 to High(gDoorMap[a]) do
182 begin
183 if gDoorMap[a, b] = DWORD(PanelID) then
184 begin
185 c := a;
186 break;
187 end;
188 end;
189 if (c <> -1) then break;
190 end;
191 if (c = -1) then exit;
193 for b := 0 to High(gDoorMap[c]) do
194 begin
195 with gWalls[gDoorMap[c, b]] do
196 begin
197 if g_CollidePlayer(X, Y, Width, Height) or g_Mons_IsAnyAliveAt(X, Y, Width, Height) then exit;
198 end;
199 end;
201 if not NoSound then
202 begin
203 for b := 0 to High(gDoorMap[c]) do
204 begin
205 if not gWalls[gDoorMap[c, b]].Enabled then
206 begin
207 with gWalls[PanelID] do
208 begin
209 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
210 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
211 end;
212 break;
213 end;
214 end;
215 end;
217 for b := 0 to High(gDoorMap[c]) do
218 begin
219 if not gWalls[gDoorMap[c, b]].Enabled then
220 begin
221 g_Map_EnableWall_XXX(gDoorMap[c, b]);
222 result := true;
223 end;
224 end;
225 end;
226 end;
229 procedure tr_CloseTrap (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean);
230 var
231 a, b, c: Integer;
232 wx, wy, wh, ww: Integer;
233 pan: TPanel;
234 PanelID: Integer;
236 function monsDamage (mon: TMonster): Boolean;
237 begin
238 result := false; // don't stop
239 if g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
240 end;
242 begin
243 pan := g_Map_PanelByGUID(PanelGUID);
245 if (pan = nil) then
246 begin
247 e_LogWritefln('tr_CloseTrap: pguid=%s; NO PANEL!', [PanelGUID], MSG_WARNING);
248 end
249 else
250 begin
251 e_LogWritefln('tr_CloseTrap: pguid=%s; isGWall=%s; arrIdx=%s', [PanelGUID, pan.isGWall, pan.arrIdx]);
252 end;
254 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
255 PanelID := pan.arrIdx;
257 if not d2d then
258 begin
259 with gWalls[PanelID] do
260 begin
261 if (not NoSound) and (not Enabled) then
262 begin
263 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
264 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
265 end;
266 end;
268 wx := gWalls[PanelID].X;
269 wy := gWalls[PanelID].Y;
270 ww := gWalls[PanelID].Width;
271 wh := gWalls[PanelID].Height;
273 with gWalls[PanelID] do
274 begin
275 if gPlayers <> nil then
276 begin
277 for a := 0 to High(gPlayers) do
278 begin
279 if (gPlayers[a] <> nil) and gPlayers[a].alive and gPlayers[a].Collide(X, Y, Width, Height) then
280 begin
281 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
282 end;
283 end;
284 end;
286 //g_Mons_ForEach(monsDamage);
287 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
289 if not Enabled then g_Map_EnableWallGUID(PanelGUID);
290 end;
291 end
292 else
293 begin
294 if (gDoorMap = nil) then exit;
296 c := -1;
297 for a := 0 to High(gDoorMap) do
298 begin
299 for b := 0 to High(gDoorMap[a]) do
300 begin
301 if gDoorMap[a, b] = DWORD(PanelID) then
302 begin
303 c := a;
304 break;
305 end;
306 end;
307 if (c <> -1) then break;
308 end;
309 if (c = -1) then exit;
311 if not NoSound then
312 begin
313 for b := 0 to High(gDoorMap[c]) do
314 begin
315 if not gWalls[gDoorMap[c, b]].Enabled then
316 begin
317 with gWalls[PanelID] do
318 begin
319 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
320 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
321 end;
322 Break;
323 end;
324 end;
325 end;
327 for b := 0 to High(gDoorMap[c]) do
328 begin
329 wx := gWalls[gDoorMap[c, b]].X;
330 wy := gWalls[gDoorMap[c, b]].Y;
331 ww := gWalls[gDoorMap[c, b]].Width;
332 wh := gWalls[gDoorMap[c, b]].Height;
334 with gWalls[gDoorMap[c, b]] do
335 begin
336 if gPlayers <> nil then
337 begin
338 for a := 0 to High(gPlayers) do
339 begin
340 if (gPlayers[a] <> nil) and gPlayers[a].alive and gPlayers[a].Collide(X, Y, Width, Height) then
341 begin
342 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
343 end;
344 end;
345 end;
347 //g_Mons_ForEach(monsDamage);
348 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
349 (*
350 if gMonsters <> nil then
351 for a := 0 to High(gMonsters) do
352 if (gMonsters[a] <> nil) and gMonsters[a].alive and
353 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
354 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
355 *)
357 if not Enabled then g_Map_EnableWall_XXX(gDoorMap[c, b]);
358 end;
359 end;
360 end;
361 end;
364 function tr_OpenDoor (PanelGUID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
365 var
366 a, b, c: Integer;
367 pan: TPanel;
368 PanelID: Integer;
369 begin
370 result := false;
371 pan := g_Map_PanelByGUID(PanelGUID);
372 if (pan = nil) or not pan.isGWall then exit; //!FIXME!TRIGANY!
373 PanelID := pan.arrIdx;
375 if not d2d then
376 begin
377 with gWalls[PanelID] do
378 begin
379 if Enabled then
380 begin
381 if not NoSound then
382 begin
383 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
384 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
385 end;
386 g_Map_DisableWallGUID(PanelGUID);
387 result := true;
388 end;
389 end
390 end
391 else
392 begin
393 if (gDoorMap = nil) then exit;
395 c := -1;
396 for a := 0 to High(gDoorMap) do
397 begin
398 for b := 0 to High(gDoorMap[a]) do
399 begin
400 if gDoorMap[a, b] = DWORD(PanelID) then
401 begin
402 c := a;
403 break;
404 end;
405 end;
406 if (c <> -1) then break;
407 end;
408 if (c = -1) then exit;
410 if not NoSound then
411 begin
412 for b := 0 to High(gDoorMap[c]) do
413 begin
414 if gWalls[gDoorMap[c, b]].Enabled then
415 begin
416 with gWalls[PanelID] do
417 begin
418 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
419 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
420 end;
421 break;
422 end;
423 end;
424 end;
426 for b := 0 to High(gDoorMap[c]) do
427 begin
428 if gWalls[gDoorMap[c, b]].Enabled then
429 begin
430 g_Map_DisableWall_XXX(gDoorMap[c, b]);
431 result := true;
432 end;
433 end;
434 end;
435 end;
438 function tr_SetLift (PanelGUID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
439 var
440 a, b, c: Integer;
441 t: Integer = 0;
442 pan: TPanel;
443 PanelID: Integer;
444 begin
445 result := false;
446 pan := g_Map_PanelByGUID(PanelGUID);
447 if (pan = nil) or not pan.isGLift then exit; //!FIXME!TRIGANY!
448 PanelID := pan.arrIdx;
450 if (gLifts[PanelID].PanelType = PANEL_LIFTUP) or (gLifts[PanelID].PanelType = PANEL_LIFTDOWN) then
451 begin
452 case d of
453 0: t := 0;
454 1: t := 1;
455 else t := IfThen(gLifts[PanelID].LiftType = 1, 0, 1);
456 end
457 end
458 else if (gLifts[PanelID].PanelType = PANEL_LIFTLEFT) or (gLifts[PanelID].PanelType = PANEL_LIFTRIGHT) then
459 begin
460 case d of
461 0: t := 2;
462 1: t := 3;
463 else t := IfThen(gLifts[PanelID].LiftType = 2, 3, 2);
464 end;
465 end;
467 if not d2d then
468 begin
469 with gLifts[PanelID] do
470 begin
471 if (LiftType <> t) then
472 begin
473 g_Map_SetLiftGUID(PanelGUID, t); //???
474 //if not NoSound then g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
475 result := true;
476 end;
477 end;
478 end
479 else // Êàê â D2d
480 begin
481 if (gLiftMap = nil) then exit;
483 c := -1;
484 for a := 0 to High(gLiftMap) do
485 begin
486 for b := 0 to High(gLiftMap[a]) do
487 begin
488 if (gLiftMap[a, b] = DWORD(PanelID)) then
489 begin
490 c := a;
491 break;
492 end;
493 end;
494 if (c <> -1) then break;
495 end;
496 if (c = -1) then exit;
498 {if not NoSound then
499 for b := 0 to High(gLiftMap[c]) do
500 if gLifts[gLiftMap[c, b]].LiftType <> t then
501 begin
502 with gLifts[PanelID] do
503 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
504 Break;
505 end;}
507 for b := 0 to High(gLiftMap[c]) do
508 begin
509 with gLifts[gLiftMap[c, b]] do
510 begin
511 if (LiftType <> t) then
512 begin
513 g_Map_SetLift_XXX(gLiftMap[c, b], t);
514 result := true;
515 end;
516 end;
517 end;
518 end;
519 end;
522 function tr_SpawnShot (ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
523 var
524 snd: string;
525 Projectile: Boolean;
526 TextureID: DWORD;
527 Anim: TAnimation;
528 begin
529 result := -1;
530 TextureID := DWORD(-1);
531 snd := 'SOUND_WEAPON_FIREROCKET';
532 Projectile := true;
534 case ShotType of
535 TRIGGER_SHOT_PISTOL:
536 begin
537 g_Weapon_pistol(wx, wy, dx, dy, 0, True);
538 snd := 'SOUND_WEAPON_FIREPISTOL';
539 Projectile := False;
540 if ShotSound then
541 begin
542 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
543 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
544 end;
545 end;
547 TRIGGER_SHOT_BULLET:
548 begin
549 g_Weapon_mgun(wx, wy, dx, dy, 0, True);
550 if gSoundEffectsDF then snd := 'SOUND_WEAPON_FIRECGUN'
551 else snd := 'SOUND_WEAPON_FIREPISTOL';
552 Projectile := False;
553 if ShotSound then
554 begin
555 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
556 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
557 end;
558 end;
560 TRIGGER_SHOT_SHOTGUN:
561 begin
562 g_Weapon_Shotgun(wx, wy, dx, dy, 0, True);
563 snd := 'SOUND_WEAPON_FIRESHOTGUN';
564 Projectile := False;
565 if ShotSound then
566 begin
567 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
568 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL2);
569 end;
570 end;
572 TRIGGER_SHOT_SSG:
573 begin
574 g_Weapon_DShotgun(wx, wy, dx, dy, 0, True);
575 snd := 'SOUND_WEAPON_FIRESHOTGUN2';
576 Projectile := False;
577 if ShotSound then
578 begin
579 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
580 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
581 if g_Game_IsNet then MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL3);
582 end;
583 end;
585 TRIGGER_SHOT_IMP:
586 begin
587 g_Weapon_ball1(wx, wy, dx, dy, 0, -1, True);
588 snd := 'SOUND_WEAPON_FIREBALL';
589 end;
591 TRIGGER_SHOT_PLASMA:
592 begin
593 g_Weapon_Plasma(wx, wy, dx, dy, 0, -1, True);
594 snd := 'SOUND_WEAPON_FIREPLASMA';
595 end;
597 TRIGGER_SHOT_SPIDER:
598 begin
599 g_Weapon_aplasma(wx, wy, dx, dy, 0, -1, True);
600 snd := 'SOUND_WEAPON_FIREPLASMA';
601 end;
603 TRIGGER_SHOT_CACO:
604 begin
605 g_Weapon_ball2(wx, wy, dx, dy, 0, -1, True);
606 snd := 'SOUND_WEAPON_FIREBALL';
607 end;
609 TRIGGER_SHOT_BARON:
610 begin
611 g_Weapon_ball7(wx, wy, dx, dy, 0, -1, True);
612 snd := 'SOUND_WEAPON_FIREBALL';
613 end;
615 TRIGGER_SHOT_MANCUB:
616 begin
617 g_Weapon_manfire(wx, wy, dx, dy, 0, -1, True);
618 snd := 'SOUND_WEAPON_FIREBALL';
619 end;
621 TRIGGER_SHOT_REV:
622 begin
623 g_Weapon_revf(wx, wy, dx, dy, 0, ShotTarget, -1, True);
624 snd := 'SOUND_WEAPON_FIREREV';
625 end;
627 TRIGGER_SHOT_ROCKET:
628 begin
629 g_Weapon_Rocket(wx, wy, dx, dy, 0, -1, True);
630 snd := 'SOUND_WEAPON_FIREROCKET';
631 end;
633 TRIGGER_SHOT_BFG:
634 begin
635 g_Weapon_BFGShot(wx, wy, dx, dy, 0, -1, True);
636 snd := 'SOUND_WEAPON_FIREBFG';
637 end;
639 TRIGGER_SHOT_EXPL:
640 begin
641 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
642 begin
643 Anim := TAnimation.Create(TextureID, False, 6);
644 Anim.Blending := False;
645 g_GFX_OnceAnim(wx-64, wy-64, Anim);
646 Anim.Free();
647 end;
648 Projectile := False;
649 g_Weapon_Explode(wx, wy, 60, 0);
650 snd := 'SOUND_WEAPON_EXPLODEROCKET';
651 end;
653 TRIGGER_SHOT_BFGEXPL:
654 begin
655 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
656 begin
657 Anim := TAnimation.Create(TextureID, False, 6);
658 Anim.Blending := False;
659 g_GFX_OnceAnim(wx-64, wy-64, Anim);
660 Anim.Free();
661 end;
662 Projectile := False;
663 g_Weapon_BFG9000(wx, wy, 0);
664 snd := 'SOUND_WEAPON_EXPLODEBFG';
665 end;
667 else exit;
668 end;
670 if g_Game_IsNet and g_Game_IsServer then
671 begin
672 case ShotType of
673 TRIGGER_SHOT_EXPL: MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_EXPLODE);
674 TRIGGER_SHOT_BFGEXPL: MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_BFGEXPL);
675 else
676 begin
677 if Projectile then MH_SEND_CreateShot(LastShotID);
678 if ShotSound then MH_SEND_Sound(wx, wy, snd);
679 end;
680 end;
681 end;
683 if ShotSound then g_Sound_PlayExAt(snd, wx, wy);
685 if Projectile then Result := LastShotID;
686 end;
689 procedure MakeShot (var Trigger: TTrigger; wx, wy, dx, dy: Integer; TargetUID: Word);
690 begin
691 with Trigger do
692 begin
693 if (tgcAmmo = 0) or ((tgcAmmo > 0) and (ShotAmmoCount > 0)) then
694 begin
695 if (trigShotPanelGUID <> -1) and (ShotPanelTime = 0) then
696 begin
697 g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID);
698 ShotPanelTime := 4; // òèêîâ íà âñïûøêó âûñòðåëà
699 end;
701 if (tgcSight > 0) then ShotSightTimeout := 180; // ~= 5 ñåêóíä
703 if (ShotAmmoCount > 0) then Dec(ShotAmmoCount);
705 dx += Random(tgcAccuracy)-Random(tgcAccuracy);
706 dy += Random(tgcAccuracy)-Random(tgcAccuracy);
708 tr_SpawnShot(tgcShotType, wx, wy, dx, dy, not tgcQuiet, TargetUID);
709 end
710 else
711 begin
712 if (tgcReload > 0) and (ShotReloadTime = 0) then
713 begin
714 ShotReloadTime := tgcReload; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
715 end;
716 end;
717 end;
718 end;
721 procedure tr_MakeEffect (X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
722 var
723 FramesID: DWORD;
724 Anim: TAnimation;
725 begin
726 if T = TRIGGER_EFFECT_PARTICLE then
727 begin
728 case ST of
729 TRIGGER_EFFECT_SLIQUID:
730 begin
731 if (CR = 255) and (CG = 0) and (CB = 0) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 1, 0, 0, 0)
732 else if (CR = 0) and (CG = 255) and (CB = 0) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 2, 0, 0, 0)
733 else if (CR = 0) and (CG = 0) and (CB = 255) then g_GFX_SimpleWater(X, Y, 1, VX, VY, 3, 0, 0, 0)
734 else g_GFX_SimpleWater(X, Y, 1, VX, VY, 0, 0, 0, 0);
735 end;
736 TRIGGER_EFFECT_LLIQUID: g_GFX_SimpleWater(X, Y, 1, VX, VY, 4, CR, CG, CB);
737 TRIGGER_EFFECT_DLIQUID: g_GFX_SimpleWater(X, Y, 1, VX, VY, 5, CR, CG, CB);
738 TRIGGER_EFFECT_BLOOD: g_GFX_Blood(X, Y, 1, VX, VY, 0, 0, CR, CG, CB);
739 TRIGGER_EFFECT_SPARK: g_GFX_Spark(X, Y, 1, GetAngle2(VX, VY), 0, 0);
740 TRIGGER_EFFECT_BUBBLE: g_GFX_Bubbles(X, Y, 1, 0, 0);
741 end;
742 end;
744 if T = TRIGGER_EFFECT_ANIMATION then
745 begin
746 case ST of
747 EFFECT_TELEPORT: begin
748 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
749 begin
750 Anim := TAnimation.Create(FramesID, False, 3);
751 if not Silent then g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
752 g_GFX_OnceAnim(X-32, Y-32, Anim);
753 Anim.Free();
754 end;
755 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X, Y, Byte(not Silent), NET_GFX_TELE);
756 end;
757 EFFECT_RESPAWN: begin
758 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
759 begin
760 Anim := TAnimation.Create(FramesID, False, 4);
761 if not Silent then g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
762 g_GFX_OnceAnim(X-16, Y-16, Anim);
763 Anim.Free();
764 end;
765 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X-16, Y-16, Byte(not Silent), NET_GFX_RESPAWN);
766 end;
767 EFFECT_FIRE: begin
768 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
769 begin
770 Anim := TAnimation.Create(FramesID, False, 4);
771 if not Silent then g_Sound_PlayExAt('SOUND_FIRE', X, Y);
772 g_GFX_OnceAnim(X-32, Y-128, Anim);
773 Anim.Free();
774 end;
775 if Send and g_Game_IsServer and g_Game_IsNet then MH_SEND_Effect(X-32, Y-128, Byte(not Silent), NET_GFX_FIRE);
776 end;
777 end;
778 end;
779 end;
782 function tr_Teleport (ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
783 var
784 p: TPlayer;
785 m: TMonster;
786 begin
787 Result := False;
788 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
789 case g_GetUIDType(ActivateUID) of
790 UID_PLAYER:
791 begin
792 p := g_Player_Get(ActivateUID);
793 if p = nil then Exit;
794 if D2D then
795 begin
796 if p.TeleportTo(TX-(p.Obj.Rect.Width div 2), TY-p.Obj.Rect.Height, Silent, TDir) then result := true;
797 end
798 else
799 begin
800 if p.TeleportTo(TX, TY, Silent, TDir) then result := true;
801 end;
802 end;
803 UID_MONSTER:
804 begin
805 m := g_Monsters_ByUID(ActivateUID);
806 if m = nil then Exit;
807 if D2D then
808 begin
809 if m.TeleportTo(TX-(m.Obj.Rect.Width div 2), TY-m.Obj.Rect.Height, Silent, TDir) then result := true;
810 end
811 else
812 begin
813 if m.TeleportTo(TX, TY, Silent, TDir) then result := true;
814 end;
815 end;
816 end;
817 end;
820 function tr_Push (ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
821 var
822 p: TPlayer;
823 m: TMonster;
824 begin
825 result := true;
826 if (ActivateUID < 0) or (ActivateUID > $FFFF) then exit;
827 case g_GetUIDType(ActivateUID) of
828 UID_PLAYER:
829 begin
830 p := g_Player_Get(ActivateUID);
831 if p = nil then Exit;
833 if ResetVel then
834 begin
835 p.GameVelX := 0;
836 p.GameVelY := 0;
837 p.GameAccelX := 0;
838 p.GameAccelY := 0;
839 end;
841 p.Push(VX, VY);
842 end;
844 UID_MONSTER:
845 begin
846 m := g_Monsters_ByUID(ActivateUID);
847 if m = nil then Exit;
849 if ResetVel then
850 begin
851 m.GameVelX := 0;
852 m.GameVelY := 0;
853 m.GameAccelX := 0;
854 m.GameAccelY := 0;
855 end;
857 m.Push(VX, VY);
858 end;
859 end;
860 end;
863 function tr_Message (MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
864 var
865 msg: string;
866 p: TPlayer;
867 i: Integer;
868 begin
869 Result := True;
870 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
871 msg := b_Text_Format(MText);
872 case MSendTo of
873 TRIGGER_MESSAGE_DEST_ME: // activator
874 begin
875 if g_GetUIDType(ActivateUID) = UID_PLAYER then
876 begin
877 if g_Game_IsWatchedPlayer(ActivateUID) then
878 begin
879 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
880 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
881 end
882 else
883 begin
884 p := g_Player_Get(ActivateUID);
885 if g_Game_IsNet and (p.FClientID >= 0) then
886 begin
887 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, p.FClientID)
888 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, p.FClientID);
889 end;
890 end;
891 end;
892 end;
894 TRIGGER_MESSAGE_DEST_MY_TEAM: // activator's team
895 begin
896 if g_GetUIDType(ActivateUID) = UID_PLAYER then
897 begin
898 p := g_Player_Get(ActivateUID);
899 if g_Game_IsWatchedTeam(p.Team) then
900 begin
901 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
902 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
903 end;
905 if g_Game_IsNet then
906 begin
907 for i := Low(gPlayers) to High(gPlayers) do
908 begin
909 if (gPlayers[i].Team = p.Team) and (gPlayers[i].FClientID >= 0) then
910 begin
911 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
912 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
913 end;
914 end;
915 end;
916 end;
917 end;
919 TRIGGER_MESSAGE_DEST_ENEMY_TEAM: // activator's enemy team
920 begin
921 if g_GetUIDType(ActivateUID) = UID_PLAYER then
922 begin
923 p := g_Player_Get(ActivateUID);
924 if g_Game_IsWatchedTeam(p.Team) then
925 begin
926 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
927 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
928 end;
930 if g_Game_IsNet then
931 begin
932 for i := Low(gPlayers) to High(gPlayers) do
933 begin
934 if (gPlayers[i].Team <> p.Team) and (gPlayers[i].FClientID >= 0) then
935 begin
936 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
937 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
938 end;
939 end;
940 end;
941 end;
942 end;
944 TRIGGER_MESSAGE_DEST_RED_TEAM: // red team
945 begin
946 if g_Game_IsWatchedTeam(TEAM_RED) then
947 begin
948 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
949 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
950 end;
952 if g_Game_IsNet then
953 begin
954 for i := Low(gPlayers) to High(gPlayers) do
955 begin
956 if (gPlayers[i].Team = TEAM_RED) and (gPlayers[i].FClientID >= 0) then
957 begin
958 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
959 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
960 end;
961 end;
962 end;
963 end;
965 TRIGGER_MESSAGE_DEST_BLUE_TEAM: // blue team
966 begin
967 if g_Game_IsWatchedTeam(TEAM_BLUE) then
968 begin
969 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
970 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
971 end;
973 if g_Game_IsNet then
974 begin
975 for i := Low(gPlayers) to High(gPlayers) do
976 begin
977 if (gPlayers[i].Team = TEAM_BLUE) and (gPlayers[i].FClientID >= 0) then
978 begin
979 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
980 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
981 end;
982 end;
983 end;
984 end;
986 TRIGGER_MESSAGE_DEST_EVERYONE: // everyone
987 begin
988 if MKind = TRIGGER_MESSAGE_KIND_CHAT then g_Console_Add(msg, True)
989 else if MKind = TRIGGER_MESSAGE_KIND_GAME then g_Game_Message(msg, MTime);
991 if g_Game_IsNet then
992 begin
993 if MKind = TRIGGER_MESSAGE_KIND_CHAT then MH_SEND_Chat(msg, NET_CHAT_SYSTEM)
994 else if MKind = TRIGGER_MESSAGE_KIND_GAME then MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg);
995 end;
996 end;
997 end;
998 end;
1001 function tr_ShotAimCheck (var Trigger: TTrigger; Obj: PObj): Boolean;
1002 begin
1003 result := false;
1004 with Trigger do
1005 begin
1006 if TriggerType <> TRIGGER_SHOT then Exit;
1007 result := (tgcAim and TRIGGER_SHOT_AIM_ALLMAP > 0)
1008 or g_Obj_Collide(X, Y, Width, Height, Obj);
1009 if result and (tgcAim and TRIGGER_SHOT_AIM_TRACE > 0) then
1010 begin
1011 result := g_TraceVector(tgcTX, tgcTY,
1012 Obj^.X + Obj^.Rect.X + (Obj^.Rect.Width div 2),
1013 Obj^.Y + Obj^.Rect.Y + (Obj^.Rect.Height div 2));
1014 end;
1015 end;
1016 end;
1019 function ActivateTrigger (var Trigger: TTrigger; actType: Byte): Boolean;
1020 var
1021 animonce: Boolean;
1022 p: TPlayer;
1023 m: TMonster;
1024 pan: TPanel;
1025 idx, k, wx, wy, xd, yd: Integer;
1026 iid: LongWord;
1027 coolDown: Boolean;
1028 pAngle: Real;
1029 FramesID: DWORD;
1030 Anim: TAnimation;
1031 UIDType: Byte;
1032 TargetUID: Word;
1033 it: PItem;
1034 mon: TMonster;
1036 function monsShotTarget (mon: TMonster): Boolean;
1037 begin
1038 result := false; // don't stop
1039 if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1040 begin
1041 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1042 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1043 TargetUID := mon.UID;
1044 result := true; // stop
1045 end;
1046 end;
1048 function monsShotTargetMonPlr (mon: TMonster): Boolean;
1049 begin
1050 result := false; // don't stop
1051 if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1052 begin
1053 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1054 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1055 TargetUID := mon.UID;
1056 result := true; // stop
1057 end;
1058 end;
1060 function monShotTargetPlrMon (mon: TMonster): Boolean;
1061 begin
1062 result := false; // don't stop
1063 if mon.alive and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1064 begin
1065 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1066 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1067 TargetUID := mon.UID;
1068 result := true; // stop
1069 end;
1070 end;
1072 begin
1073 result := false;
1074 if g_Game_IsClient then exit;
1076 if not Trigger.Enabled then exit;
1077 if (Trigger.TimeOut <> 0) and (actType <> ACTIVATE_CUSTOM) then exit;
1078 if gLMSRespawn = LMS_RESPAWN_WARMUP then exit;
1080 animonce := False;
1082 coolDown := (actType <> 0);
1084 with Trigger do
1085 begin
1086 case TriggerType of
1087 TRIGGER_EXIT:
1088 begin
1089 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1090 if g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH0');
1091 gExitByTrigger := True;
1092 g_Game_ExitLevel(tgcMap);
1093 TimeOut := 18;
1094 Result := True;
1096 Exit;
1097 end;
1099 TRIGGER_TELEPORT:
1100 begin
1101 Result := tr_Teleport(ActivateUID,
1102 tgcTarget.X, tgcTarget.Y,
1103 tgcDirection, tgcSilent,
1104 tgcD2d);
1105 TimeOut := 0;
1106 end;
1108 TRIGGER_OPENDOOR:
1109 begin
1110 Result := tr_OpenDoor(trigPanelGUID, tgcSilent, tgcD2d);
1111 TimeOut := 0;
1112 end;
1114 TRIGGER_CLOSEDOOR:
1115 begin
1116 Result := tr_CloseDoor(trigPanelGUID, tgcSilent, tgcD2d);
1117 TimeOut := 0;
1118 end;
1120 TRIGGER_DOOR, TRIGGER_DOOR5:
1121 begin
1122 pan := g_Map_PanelByGUID(trigPanelGUID);
1123 if (pan <> nil) and pan.isGWall then
1124 begin
1125 if gWalls[{trigPanelID}pan.arrIdx].Enabled then
1126 begin
1127 result := tr_OpenDoor(trigPanelGUID, tgcSilent, tgcD2d);
1128 if (TriggerType = TRIGGER_DOOR5) then DoorTime := 180;
1129 end
1130 else
1131 begin
1132 result := tr_CloseDoor(trigPanelGUID, tgcSilent, tgcD2d);
1133 end;
1135 if result then TimeOut := 18;
1136 end;
1137 end;
1139 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1140 begin
1141 tr_CloseTrap(trigPanelGUID, tgcSilent, tgcD2d);
1143 if TriggerType = TRIGGER_TRAP then
1144 begin
1145 DoorTime := 40;
1146 TimeOut := 76;
1147 end
1148 else
1149 begin
1150 DoorTime := -1;
1151 TimeOut := 0;
1152 end;
1154 Result := True;
1155 end;
1157 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
1158 begin
1159 PressCount += 1;
1160 if PressTime = -1 then PressTime := tgcWait;
1161 if coolDown then TimeOut := 18 else TimeOut := 0;
1162 Result := True;
1163 end;
1165 TRIGGER_SECRET:
1166 if g_GetUIDType(ActivateUID) = UID_PLAYER then
1167 begin
1168 Enabled := False;
1169 Result := True;
1170 if gLMSRespawn = LMS_RESPAWN_NONE then
1171 begin
1172 g_Player_Get(ActivateUID).GetSecret();
1173 Inc(gCoopSecretsFound);
1174 if g_Game_IsNet then MH_SEND_GameStats();
1175 end;
1176 end;
1178 TRIGGER_LIFTUP:
1179 begin
1180 Result := tr_SetLift(trigPanelGUID, 0, tgcSilent, tgcD2d);
1181 TimeOut := 0;
1183 if (not tgcSilent) and Result then begin
1184 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1185 X + (Width div 2),
1186 Y + (Height div 2));
1187 if g_Game_IsServer and g_Game_IsNet then
1188 MH_SEND_Sound(X + (Width div 2),
1189 Y + (Height div 2),
1190 'SOUND_GAME_SWITCH0');
1191 end;
1192 end;
1194 TRIGGER_LIFTDOWN:
1195 begin
1196 Result := tr_SetLift(trigPanelGUID, 1, tgcSilent, tgcD2d);
1197 TimeOut := 0;
1199 if (not tgcSilent) and Result then begin
1200 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1201 X + (Width div 2),
1202 Y + (Height div 2));
1203 if g_Game_IsServer and g_Game_IsNet then
1204 MH_SEND_Sound(X + (Width div 2),
1205 Y + (Height div 2),
1206 'SOUND_GAME_SWITCH0');
1207 end;
1208 end;
1210 TRIGGER_LIFT:
1211 begin
1212 Result := tr_SetLift(trigPanelGUID, 3, tgcSilent, tgcD2d);
1214 if Result then
1215 begin
1216 TimeOut := 18;
1218 if (not tgcSilent) and Result then begin
1219 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1220 X + (Width div 2),
1221 Y + (Height div 2));
1222 if g_Game_IsServer and g_Game_IsNet then
1223 MH_SEND_Sound(X + (Width div 2),
1224 Y + (Height div 2),
1225 'SOUND_GAME_SWITCH0');
1226 end;
1227 end;
1228 end;
1230 TRIGGER_TEXTURE:
1231 begin
1232 if tgcActivateOnce then
1233 begin
1234 Enabled := False;
1235 TriggerType := TRIGGER_NONE;
1236 end
1237 else
1238 if coolDown then
1239 TimeOut := 6
1240 else
1241 TimeOut := 0;
1243 animonce := tgcAnimateOnce;
1244 Result := True;
1245 end;
1247 TRIGGER_SOUND:
1248 begin
1249 if Sound <> nil then
1250 begin
1251 if tgcSoundSwitch and Sound.IsPlaying() then
1252 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1253 Sound.Stop();
1254 SoundPlayCount := 0;
1255 Result := True;
1256 end
1257 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1258 if (tgcPlayCount > 0) or (not Sound.IsPlaying()) then
1259 begin
1260 if tgcPlayCount > 0 then
1261 SoundPlayCount := tgcPlayCount
1262 else // 0 - èãðàåì áåñêîíå÷íî
1263 SoundPlayCount := 1;
1264 Result := True;
1265 end;
1266 if g_Game_IsNet then MH_SEND_TriggerSound(Trigger);
1267 end;
1268 end;
1270 TRIGGER_SPAWNMONSTER:
1271 if (tgcSpawnMonsType in [MONSTER_DEMON..MONSTER_MAN]) then
1272 begin
1273 Result := False;
1274 if (tgcDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1275 begin
1276 AutoSpawn := not AutoSpawn;
1277 SpawnCooldown := 0;
1278 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1279 Result := True;
1280 end;
1282 if ((tgcDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1283 or ((tgcDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1284 for k := 1 to tgcMonsCount do
1285 begin
1286 if (actType = ACTIVATE_CUSTOM) and (tgcDelay > 0) then
1287 SpawnCooldown := tgcDelay;
1288 if (tgcMax > 0) and (SpawnedCount >= tgcMax) then
1289 Break;
1291 mon := g_Monsters_Create(tgcSpawnMonsType,
1292 tgcTX, tgcTY,
1293 TDirection(tgcDirection), True);
1295 Result := True;
1297 // Çäîðîâüå:
1298 if (tgcHealth > 0) then
1299 mon.SetHealth(tgcHealth);
1300 // Óñòàíàâëèâàåì ïîâåäåíèå:
1301 mon.MonsterBehaviour := tgcBehaviour;
1302 mon.FNoRespawn := True;
1303 if g_Game_IsNet then
1304 MH_SEND_MonsterSpawn(mon.UID);
1305 // Èäåì èñêàòü öåëü, åñëè íàäî:
1306 if tgcActive then
1307 mon.WakeUp();
1309 if tgcSpawnMonsType <> MONSTER_BARREL then Inc(gTotalMonsters);
1311 if g_Game_IsNet then
1312 begin
1313 SetLength(gMonstersSpawned, Length(gMonstersSpawned)+1);
1314 gMonstersSpawned[High(gMonstersSpawned)] := mon.UID;
1315 end;
1317 if tgcMax > 0 then
1318 begin
1319 mon.SpawnTrigger := ID;
1320 Inc(SpawnedCount);
1321 end;
1323 case tgcEffect of
1324 EFFECT_TELEPORT: begin
1325 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1326 begin
1327 Anim := TAnimation.Create(FramesID, False, 3);
1328 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX, tgcTY);
1329 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1330 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, Anim);
1331 Anim.Free();
1332 end;
1333 if g_Game_IsServer and g_Game_IsNet then
1334 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1335 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, 1,
1336 NET_GFX_TELE);
1337 end;
1338 EFFECT_RESPAWN: begin
1339 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1340 begin
1341 Anim := TAnimation.Create(FramesID, False, 4);
1342 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX, tgcTY);
1343 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1344 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, Anim);
1345 Anim.Free();
1346 end;
1347 if g_Game_IsServer and g_Game_IsNet then
1348 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1349 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, 1,
1350 NET_GFX_RESPAWN);
1351 end;
1352 EFFECT_FIRE: begin
1353 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1354 begin
1355 Anim := TAnimation.Create(FramesID, False, 4);
1356 g_Sound_PlayExAt('SOUND_FIRE', tgcTX, tgcTY);
1357 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1358 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, Anim);
1359 Anim.Free();
1360 end;
1361 if g_Game_IsServer and g_Game_IsNet then
1362 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1363 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, 1,
1364 NET_GFX_FIRE);
1365 end;
1366 end;
1367 end;
1368 if g_Game_IsNet then
1369 begin
1370 MH_SEND_GameStats();
1371 MH_SEND_CoopStats();
1372 end;
1374 if coolDown then
1375 TimeOut := 18
1376 else
1377 TimeOut := 0;
1378 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1379 if actType = ACTIVATE_CUSTOM then
1380 Result := False;
1381 end;
1383 TRIGGER_SPAWNITEM:
1384 if (tgcSpawnItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX]) then
1385 begin
1386 Result := False;
1387 if (tgcDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1388 begin
1389 AutoSpawn := not AutoSpawn;
1390 SpawnCooldown := 0;
1391 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1392 Result := True;
1393 end;
1395 if ((tgcDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1396 or ((tgcDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1397 if (not tgcDmonly) or
1398 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1399 for k := 1 to tgcItemCount do
1400 begin
1401 if (actType = ACTIVATE_CUSTOM) and (tgcDelay > 0) then
1402 SpawnCooldown := tgcDelay;
1403 if (tgcMax > 0) and (SpawnedCount >= tgcMax) then
1404 Break;
1406 iid := g_Items_Create(tgcTX, tgcTY,
1407 tgcSpawnItemType, tgcGravity, False, True);
1409 Result := True;
1411 if tgcMax > 0 then
1412 begin
1413 it := g_Items_ByIdx(iid);
1414 it.SpawnTrigger := ID;
1415 Inc(SpawnedCount);
1416 end;
1418 case tgcEffect of
1419 EFFECT_TELEPORT: begin
1420 it := g_Items_ByIdx(iid);
1421 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1422 begin
1423 Anim := TAnimation.Create(FramesID, False, 3);
1424 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', tgcTX, tgcTY);
1425 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1426 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, Anim);
1427 Anim.Free();
1428 end;
1429 if g_Game_IsServer and g_Game_IsNet then
1430 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1431 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, 1,
1432 NET_GFX_TELE);
1433 end;
1434 EFFECT_RESPAWN: begin
1435 it := g_Items_ByIdx(iid);
1436 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1437 begin
1438 Anim := TAnimation.Create(FramesID, False, 4);
1439 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', tgcTX, tgcTY);
1440 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1441 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, Anim);
1442 Anim.Free();
1443 end;
1444 if g_Game_IsServer and g_Game_IsNet then
1445 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1446 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, 1,
1447 NET_GFX_RESPAWN);
1448 end;
1449 EFFECT_FIRE: begin
1450 it := g_Items_ByIdx(iid);
1451 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1452 begin
1453 Anim := TAnimation.Create(FramesID, False, 4);
1454 g_Sound_PlayExAt('SOUND_FIRE', tgcTX, tgcTY);
1455 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1456 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, Anim);
1457 Anim.Free();
1458 end;
1459 if g_Game_IsServer and g_Game_IsNet then
1460 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1461 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, 1,
1462 NET_GFX_FIRE);
1463 end;
1464 end;
1466 if g_Game_IsNet then
1467 MH_SEND_ItemSpawn(True, iid);
1468 end;
1470 if coolDown then
1471 TimeOut := 18
1472 else
1473 TimeOut := 0;
1474 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1475 if actType = ACTIVATE_CUSTOM then
1476 Result := False;
1477 end;
1479 TRIGGER_MUSIC:
1480 begin
1481 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1482 if (Trigger.tgcMusicName <> '') then
1483 begin
1484 gMusic.SetByName(Trigger.tgcMusicName);
1485 gMusic.SpecPause := True;
1486 gMusic.Play();
1487 end;
1489 case Trigger.tgcMusicAction of
1490 TRIGGER_MUSIC_ACTION_STOP: // Âûêëþ÷èòü
1491 gMusic.SpecPause := True; // Ïàóçà
1492 TRIGGER_MUSIC_ACTION_PLAY: // Âêëþ÷èòü
1493 if gMusic.SpecPause then // Áûëà íà ïàóçå => èãðàòü
1494 gMusic.SpecPause := False
1495 else // Èãðàëà => ñíà÷àëà
1496 gMusic.SetPosition(0);
1497 end;
1499 if coolDown then
1500 TimeOut := 36
1501 else
1502 TimeOut := 0;
1503 Result := True;
1504 if g_Game_IsNet then MH_SEND_TriggerMusic;
1505 end;
1507 TRIGGER_PUSH:
1508 begin
1509 pAngle := -DegToRad(tgcAngle);
1510 Result := tr_Push(ActivateUID,
1511 Floor(Cos(pAngle)*tgcForce),
1512 Floor(Sin(pAngle)*tgcForce),
1513 tgcResetVelocity);
1514 TimeOut := 0;
1515 end;
1517 TRIGGER_SCORE:
1518 begin
1519 Result := False;
1520 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1521 if (tgcScoreAction in [TRIGGER_SCORE_ACTION_ADD, TRIGGER_SCORE_ACTION_SUB]) and (tgcScoreCount > 0) then
1522 begin
1523 // Ñâîåé èëè ÷óæîé êîìàíäå
1524 if (tgcScoreTeam in [TRIGGER_SCORE_TEAM_MINE_RED, TRIGGER_SCORE_TEAM_MINE_BLUE]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1525 begin
1526 p := g_Player_Get(ActivateUID);
1527 if ((tgcScoreAction = TRIGGER_SCORE_ACTION_ADD) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED))
1528 or ((tgcScoreAction = TRIGGER_SCORE_ACTION_ADD) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1529 begin
1530 Inc(gTeamStat[TEAM_RED].Goals, tgcScoreCount); // Red Scores
1532 if tgcScoreCon then
1533 begin
1534 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1535 begin
1536 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1537 if g_Game_IsServer and g_Game_IsNet then
1538 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '+r');
1539 end else
1540 begin
1541 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1542 if g_Game_IsServer and g_Game_IsNet then
1543 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '+re');
1544 end;
1545 end;
1547 if tgcScoreMsg then
1548 begin
1549 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1550 if g_Game_IsServer and g_Game_IsNet then
1551 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1552 end;
1553 end;
1554 if ((tgcScoreAction = TRIGGER_SCORE_ACTION_SUB) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED))
1555 or ((tgcScoreAction = TRIGGER_SCORE_ACTION_SUB) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1556 begin
1557 Dec(gTeamStat[TEAM_RED].Goals, tgcScoreCount); // Red Fouls
1559 if tgcScoreCon then
1560 begin
1561 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1562 begin
1563 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1564 if g_Game_IsServer and g_Game_IsNet then
1565 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '-r');
1566 end else
1567 begin
1568 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1569 if g_Game_IsServer and g_Game_IsNet then
1570 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '-re');
1571 end;
1572 end;
1574 if tgcScoreMsg then
1575 begin
1576 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1577 if g_Game_IsServer and g_Game_IsNet then
1578 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1579 end;
1580 end;
1581 if ((tgcScoreAction = TRIGGER_SCORE_ACTION_ADD) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE))
1582 or ((tgcScoreAction = TRIGGER_SCORE_ACTION_ADD) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1583 begin
1584 Inc(gTeamStat[TEAM_BLUE].Goals, tgcScoreCount); // Blue Scores
1586 if tgcScoreCon then
1587 begin
1588 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1589 begin
1590 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1591 if g_Game_IsServer and g_Game_IsNet then
1592 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '+b');
1593 end else
1594 begin
1595 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1596 if g_Game_IsServer and g_Game_IsNet then
1597 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '+be');
1598 end;
1599 end;
1601 if tgcScoreMsg then
1602 begin
1603 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1604 if g_Game_IsServer and g_Game_IsNet then
1605 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1606 end;
1607 end;
1608 if ((tgcScoreAction = TRIGGER_SCORE_ACTION_SUB) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE))
1609 or ((tgcScoreAction = TRIGGER_SCORE_ACTION_SUB) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1610 begin
1611 Dec(gTeamStat[TEAM_BLUE].Goals, tgcScoreCount); // Blue Fouls
1613 if tgcScoreCon then
1614 begin
1615 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1616 begin
1617 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1618 if g_Game_IsServer and g_Game_IsNet then
1619 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '-b');
1620 end else
1621 begin
1622 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, tgcScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1623 if g_Game_IsServer and g_Game_IsNet then
1624 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (tgcScoreCount shl 16), '-be');
1625 end;
1626 end;
1628 if tgcScoreMsg then
1629 begin
1630 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1631 if g_Game_IsServer and g_Game_IsNet then
1632 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1633 end;
1634 end;
1635 Result := (p.Team = TEAM_RED) or (p.Team = TEAM_BLUE);
1636 end;
1637 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1638 if tgcScoreTeam in [TRIGGER_SCORE_TEAM_FORCE_RED, TRIGGER_SCORE_TEAM_FORCE_BLUE] then
1639 begin
1640 if (tgcScoreAction = TRIGGER_SCORE_ACTION_ADD) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then
1641 begin
1642 Inc(gTeamStat[TEAM_RED].Goals, tgcScoreCount); // Red Scores
1644 if tgcScoreCon then
1645 begin
1646 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_RED], tgcScoreCount]), True);
1647 if g_Game_IsServer and g_Game_IsNet then
1648 MH_SEND_GameEvent(NET_EV_SCORE, tgcScoreCount shl 16, '+tr');
1649 end;
1651 if tgcScoreMsg then
1652 begin
1653 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1654 if g_Game_IsServer and g_Game_IsNet then
1655 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1656 end;
1657 end;
1658 if (tgcScoreAction = TRIGGER_SCORE_ACTION_SUB) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then
1659 begin
1660 Dec(gTeamStat[TEAM_RED].Goals, tgcScoreCount); // Red Fouls
1662 if tgcScoreCon then
1663 begin
1664 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_RED], tgcScoreCount]), True);
1665 if g_Game_IsServer and g_Game_IsNet then
1666 MH_SEND_GameEvent(NET_EV_SCORE, tgcScoreCount shl 16, '-tr');
1667 end;
1669 if tgcScoreMsg then
1670 begin
1671 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1672 if g_Game_IsServer and g_Game_IsNet then
1673 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1674 end;
1675 end;
1676 if (tgcScoreAction = TRIGGER_SCORE_ACTION_ADD) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then
1677 begin
1678 Inc(gTeamStat[TEAM_BLUE].Goals, tgcScoreCount); // Blue Scores
1680 if tgcScoreCon then
1681 begin
1682 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_BLUE], tgcScoreCount]), True);
1683 if g_Game_IsServer and g_Game_IsNet then
1684 MH_SEND_GameEvent(NET_EV_SCORE, tgcScoreCount shl 16, '+tb');
1685 end;
1687 if tgcScoreMsg then
1688 begin
1689 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1690 if g_Game_IsServer and g_Game_IsNet then
1691 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1692 end;
1693 end;
1694 if (tgcScoreAction = TRIGGER_SCORE_ACTION_SUB) and (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then
1695 begin
1696 Dec(gTeamStat[TEAM_BLUE].Goals, tgcScoreCount); // Blue Fouls
1698 if tgcScoreCon then
1699 begin
1700 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_BLUE], tgcScoreCount]), True);
1701 if g_Game_IsServer and g_Game_IsNet then
1702 MH_SEND_GameEvent(NET_EV_SCORE, tgcScoreCount shl 16, '-tb');
1703 end;
1705 if tgcScoreMsg then
1706 begin
1707 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1708 if g_Game_IsServer and g_Game_IsNet then
1709 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1710 end;
1711 end;
1712 Result := True;
1713 end;
1714 end;
1715 // Âûèãðûø
1716 if (tgcScoreAction = TRIGGER_SCORE_ACTION_WIN) and (gGameSettings.GoalLimit > 0) then
1717 begin
1718 // Ñâîåé èëè ÷óæîé êîìàíäû
1719 if (tgcScoreTeam in [TRIGGER_SCORE_TEAM_MINE_RED, TRIGGER_SCORE_TEAM_MINE_BLUE]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1720 begin
1721 p := g_Player_Get(ActivateUID);
1722 if ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED)) // Red Wins
1723 or ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1724 begin
1725 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1726 begin
1727 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1729 if tgcScoreCon then
1730 begin
1731 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1732 begin
1733 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1734 if g_Game_IsServer and g_Game_IsNet then
1735 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1736 end else
1737 begin
1738 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1739 if g_Game_IsServer and g_Game_IsNet then
1740 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1741 end;
1742 end;
1744 Result := True;
1745 end;
1746 end;
1747 if ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE)) // Blue Wins
1748 or ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1749 begin
1750 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1751 begin
1752 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1754 if tgcScoreCon then
1755 begin
1756 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) then
1757 begin
1758 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1759 if g_Game_IsServer and g_Game_IsNet then
1760 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1761 end else
1762 begin
1763 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1764 if g_Game_IsServer and g_Game_IsNet then
1765 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1766 end;
1767 end;
1769 Result := True;
1770 end;
1771 end;
1772 end;
1773 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1774 if tgcScoreTeam in [TRIGGER_SCORE_TEAM_FORCE_RED, TRIGGER_SCORE_TEAM_FORCE_BLUE] then
1775 begin
1776 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then // Red Wins
1777 begin
1778 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1779 begin
1780 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1781 Result := True;
1782 end;
1783 end;
1784 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then // Blue Wins
1785 begin
1786 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1787 begin
1788 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1789 Result := True;
1790 end;
1791 end;
1792 end;
1793 end;
1794 // Ïðîèãðûø
1795 if (tgcScoreAction = TRIGGER_SCORE_ACTION_LOOSE) and (gGameSettings.GoalLimit > 0) then
1796 begin
1797 // Ñâîåé èëè ÷óæîé êîìàíäû
1798 if (tgcScoreTeam in [TRIGGER_SCORE_TEAM_MINE_RED, TRIGGER_SCORE_TEAM_MINE_BLUE]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1799 begin
1800 p := g_Player_Get(ActivateUID);
1801 if ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_BLUE)) // Red Wins
1802 or ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_RED)) then
1803 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1804 begin
1805 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1807 if tgcScoreCon then
1808 if tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED then
1809 begin
1810 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1811 if g_Game_IsServer and g_Game_IsNet then
1812 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1813 end else
1814 begin
1815 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1816 if g_Game_IsServer and g_Game_IsNet then
1817 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1818 end;
1820 Result := True;
1821 end;
1822 if ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED) and (p.Team = TEAM_RED)) // Blue Wins
1823 or ((tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_BLUE) and (p.Team = TEAM_BLUE)) then
1824 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1825 begin
1826 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1828 if tgcScoreCon then
1829 if tgcScoreTeam = TRIGGER_SCORE_TEAM_MINE_RED then
1830 begin
1831 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1832 if g_Game_IsServer and g_Game_IsNet then
1833 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1834 end else
1835 begin
1836 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1837 if g_Game_IsServer and g_Game_IsNet then
1838 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1839 end;
1841 Result := True;
1842 end;
1843 end;
1844 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1845 if tgcScoreTeam in [TRIGGER_SCORE_TEAM_FORCE_BLUE, TRIGGER_SCORE_TEAM_FORCE_RED] then
1846 begin
1847 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_BLUE) then // Red Wins
1848 begin
1849 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1850 begin
1851 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1852 Result := True;
1853 end;
1854 end;
1855 if (tgcScoreTeam = TRIGGER_SCORE_TEAM_FORCE_RED) then // Blue Wins
1856 begin
1857 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1858 begin
1859 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1860 Result := True;
1861 end;
1862 end;
1863 end;
1864 end;
1865 if Result then begin
1866 if coolDown then
1867 TimeOut := 18
1868 else
1869 TimeOut := 0;
1870 if g_Game_IsServer and g_Game_IsNet then
1871 MH_SEND_GameStats;
1872 end;
1873 end;
1875 TRIGGER_MESSAGE:
1876 begin
1877 Result := tr_Message(tgcKind, tgcText,
1878 tgcMsgDest, tgcMsgTime,
1879 ActivateUID);
1880 TimeOut := 18;
1881 end;
1883 TRIGGER_DAMAGE, TRIGGER_HEALTH:
1884 begin
1885 Result := False;
1886 UIDType := g_GetUIDType(ActivateUID);
1887 if (UIDType = UID_PLAYER) or (UIDType = UID_MONSTER) then
1888 begin
1889 Result := True;
1890 k := -1;
1891 if coolDown then
1892 begin
1893 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1894 for idx := 0 to High(Activators) do
1895 if Activators[idx].UID = ActivateUID then
1896 begin
1897 k := idx;
1898 Break;
1899 end;
1900 if k = -1 then
1901 begin // Âèäèì åãî âïåðâûå
1902 // Çàïîìèíàåì åãî
1903 SetLength(Activators, Length(Activators) + 1);
1904 k := High(Activators);
1905 Activators[k].UID := ActivateUID;
1906 end else
1907 begin // Óæå âèäåëè åãî
1908 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1909 if (tgcInterval = 0) and (Activators[k].TimeOut > 0) then
1910 Activators[k].TimeOut := 65535;
1911 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1912 Result := Activators[k].TimeOut = 0;
1913 end;
1914 end;
1916 if Result then
1917 begin
1918 case UIDType of
1919 UID_PLAYER:
1920 begin
1921 p := g_Player_Get(ActivateUID);
1922 if p = nil then
1923 Exit;
1925 // Íàíîñèì óðîí èãðîêó
1926 if (TriggerType = TRIGGER_DAMAGE) and (tgcAmount > 0) then
1927 p.Damage(tgcAmount, 0, 0, 0, HIT_SOME);
1929 // Ëå÷èì èãðîêà
1930 if (TriggerType = TRIGGER_HEALTH) and (tgcAmount > 0) then
1931 if p.Heal(tgcAmount, not tgcHealMax) and (not tgcSilent) then
1932 begin
1933 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p.Obj.X, p.Obj.Y);
1934 if g_Game_IsServer and g_Game_IsNet then
1935 MH_SEND_Sound(p.Obj.X, p.Obj.Y, 'SOUND_ITEM_GETITEM');
1936 end;
1937 end;
1939 UID_MONSTER:
1940 begin
1941 m := g_Monsters_ByUID(ActivateUID);
1942 if m = nil then
1943 Exit;
1945 // Íàíîñèì óðîí ìîíñòðó
1946 if (TriggerType = TRIGGER_DAMAGE) and (tgcAmount > 0) then
1947 m.Damage(tgcAmount, 0, 0, 0, HIT_SOME);
1949 // Ëå÷èì ìîíñòðà
1950 if (TriggerType = TRIGGER_HEALTH) and (tgcAmount > 0) then
1951 if m.Heal(tgcAmount) and (not tgcSilent) then
1952 begin
1953 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m.Obj.X, m.Obj.Y);
1954 if g_Game_IsServer and g_Game_IsNet then
1955 MH_SEND_Sound(m.Obj.X, m.Obj.Y, 'SOUND_ITEM_GETITEM');
1956 end;
1957 end;
1958 end;
1959 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1960 idx := tgcInterval;
1961 if coolDown then
1962 if idx > 0 then
1963 Activators[k].TimeOut := idx
1964 else
1965 Activators[k].TimeOut := 65535;
1966 end;
1967 end;
1968 TimeOut := 0;
1969 end;
1971 TRIGGER_SHOT:
1972 begin
1973 if ShotSightTime > 0 then
1974 Exit;
1976 // put this at the beginning so it doesn't trigger itself
1977 TimeOut := tgcWait + 1;
1979 wx := tgcTX;
1980 wy := tgcTY;
1981 pAngle := -DegToRad(tgcAngle);
1982 xd := wx + Round(Cos(pAngle) * 32.0);
1983 yd := wy + Round(Sin(pAngle) * 32.0);
1984 TargetUID := 0;
1986 case tgcShotTarget of
1987 TRIGGER_SHOT_TARGET_MON: // monsters
1988 //TODO: accelerate this!
1989 g_Mons_ForEachAlive(monsShotTarget);
1991 TRIGGER_SHOT_TARGET_PLR: // players
1992 if gPlayers <> nil then
1993 for idx := Low(gPlayers) to High(gPlayers) do
1994 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
1995 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1996 begin
1997 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1998 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1999 TargetUID := gPlayers[idx].UID;
2000 break;
2001 end;
2003 TRIGGER_SHOT_TARGET_RED: // red team
2004 if gPlayers <> nil then
2005 for idx := Low(gPlayers) to High(gPlayers) do
2006 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2007 (gPlayers[idx].Team = TEAM_RED) and
2008 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2009 begin
2010 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2011 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2012 TargetUID := gPlayers[idx].UID;
2013 break;
2014 end;
2016 TRIGGER_SHOT_TARGET_BLUE: // blue team
2017 if gPlayers <> nil then
2018 for idx := Low(gPlayers) to High(gPlayers) do
2019 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2020 (gPlayers[idx].Team = TEAM_BLUE) and
2021 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2022 begin
2023 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2024 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2025 TargetUID := gPlayers[idx].UID;
2026 break;
2027 end;
2029 TRIGGER_SHOT_TARGET_MONPLR: // monsters then players
2030 begin
2031 //TODO: accelerate this!
2032 g_Mons_ForEachAlive(monsShotTargetMonPlr);
2034 if (TargetUID = 0) and (gPlayers <> nil) then
2035 for idx := Low(gPlayers) to High(gPlayers) do
2036 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2037 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2038 begin
2039 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2040 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2041 TargetUID := gPlayers[idx].UID;
2042 break;
2043 end;
2044 end;
2046 TRIGGER_SHOT_TARGET_PLRMON: // players then monsters
2047 begin
2048 if gPlayers <> nil then
2049 for idx := Low(gPlayers) to High(gPlayers) do
2050 if (gPlayers[idx] <> nil) and gPlayers[idx].alive and
2051 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2052 begin
2053 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2054 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2055 TargetUID := gPlayers[idx].UID;
2056 break;
2057 end;
2058 if TargetUID = 0 then
2059 begin
2060 //TODO: accelerate this!
2061 g_Mons_ForEachAlive(monShotTargetPlrMon);
2062 end;
2063 end;
2065 else begin
2066 if (tgcShotTarget <> TRIGGER_SHOT_TARGET_NONE) or
2067 (tgcShotType <> TRIGGER_SHOT_REV) then
2068 TargetUID := ActivateUID;
2069 end;
2070 end;
2072 if (tgcShotTarget = TRIGGER_SHOT_TARGET_NONE) or (TargetUID > 0) or
2073 ((tgcShotTarget > TRIGGER_SHOT_TARGET_NONE) and (TargetUID = 0)) then
2074 begin
2075 Result := True;
2076 if (tgcSight = 0) or
2077 (tgcShotTarget = TRIGGER_SHOT_TARGET_NONE) or
2078 (TargetUID = ShotSightTarget) then
2079 MakeShot(Trigger, wx, wy, xd, yd, TargetUID)
2080 else
2081 begin
2082 ShotSightTime := tgcSight;
2083 ShotSightTargetN := TargetUID;
2084 if tgcShotType = TRIGGER_SHOT_BFG then
2085 begin
2086 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx, wy);
2087 if g_Game_IsNet and g_Game_IsServer then
2088 MH_SEND_Sound(wx, wy, 'SOUND_WEAPON_STARTFIREBFG');
2089 end;
2090 end;
2091 end;
2092 end;
2094 TRIGGER_EFFECT:
2095 begin
2096 idx := tgcFXCount;
2098 while idx > 0 do
2099 begin
2100 case tgcFXPos of
2101 TRIGGER_EFFECT_POS_CENTER:
2102 begin
2103 wx := X + Width div 2;
2104 wy := Y + Height div 2;
2105 end;
2106 TRIGGER_EFFECT_POS_AREA:
2107 begin
2108 wx := X + Random(Width);
2109 wy := Y + Random(Height);
2110 end;
2111 else begin
2112 wx := X + Width div 2;
2113 wy := Y + Height div 2;
2114 end;
2115 end;
2116 xd := tgcVelX;
2117 yd := tgcVelY;
2118 if tgcSpreadL > 0 then xd -= Random(tgcSpreadL+1);
2119 if tgcSpreadR > 0 then xd += Random(tgcSpreadR+1);
2120 if tgcSpreadU > 0 then yd -= Random(tgcSpreadU+1);
2121 if tgcSpreadD > 0 then yd += Random(tgcSpreadD+1);
2122 tr_MakeEffect(wx, wy, xd, yd,
2123 tgcFXType, tgcFXSubType,
2124 tgcFXRed, tgcFXGreen, tgcFXBlue, True, False);
2125 Dec(idx);
2126 end;
2127 TimeOut := tgcWait;
2128 end;
2129 end;
2130 end;
2132 if Result {and (Trigger.TexturePanel <> -1)} then
2133 begin
2134 g_Map_SwitchTextureGUID(Trigger.TexturePanelType, Trigger.TexturePanelGUID, IfThen(animonce, 2, 1));
2135 end;
2136 end;
2139 function g_Triggers_CreateWithMapIndex (Trigger: TTrigger; arridx, mapidx: Integer): DWORD;
2140 var
2141 triggers: TDynField;
2142 begin
2143 triggers := gCurrentMap['trigger'];
2144 if (triggers = nil) then raise Exception.Create('LOAD: map has no triggers');
2145 if (mapidx < 0) or (mapidx >= triggers.count) then raise Exception.Create('LOAD: invalid map trigger index');
2146 Trigger.trigDataRec := triggers.itemAt[mapidx];
2147 if (Trigger.trigDataRec = nil) then raise Exception.Create('LOAD: internal error in trigger loader');
2148 Trigger.mapId := Trigger.trigDataRec.id;
2149 Trigger.mapIndex := mapidx;
2150 if (Trigger.trigDataRec.trigRec <> nil) then
2151 begin
2152 Trigger.trigDataRec := Trigger.trigDataRec.trigRec.clone(nil);
2153 end
2154 else
2155 begin
2156 Trigger.trigDataRec := nil;
2157 end;
2158 result := g_Triggers_Create(Trigger, arridx);
2159 end;
2162 function g_Triggers_Create(Trigger: TTrigger; forceInternalIndex: Integer=-1): DWORD;
2163 var
2164 find_id: DWORD;
2165 fn, mapw: AnsiString;
2166 f, olen: Integer;
2167 begin
2168 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà
2169 if (Trigger.TriggerType = TRIGGER_EXIT) and
2170 (not LongBool(gGameSettings.Options and GAME_OPTION_ALLOWEXIT)) then
2171 Trigger.TriggerType := TRIGGER_NONE;
2173 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð
2174 if (Trigger.TriggerType = TRIGGER_SPAWNMONSTER) and
2175 (not LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS)) and
2176 (gGameSettings.GameType <> GT_SINGLE) then
2177 Trigger.TriggerType := TRIGGER_NONE;
2179 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå
2180 if Trigger.TriggerType = TRIGGER_SECRET then gSecretsCount += 1;
2182 if (forceInternalIndex < 0) then
2183 begin
2184 find_id := FindTrigger();
2185 end
2186 else
2187 begin
2188 olen := Length(gTriggers);
2189 if (forceInternalIndex >= olen) then
2190 begin
2191 SetLength(gTriggers, forceInternalIndex+1);
2192 for f := olen to High(gTriggers) do gTriggers[f].TriggerType := TRIGGER_NONE;
2193 end;
2194 find_id := DWORD(forceInternalIndex);
2195 end;
2196 gTriggers[find_id] := Trigger;
2198 with gTriggers[find_id] do
2199 begin
2200 ID := find_id;
2201 // if this type of trigger exists both on the client and on the server
2202 // use an uniform numeration
2203 if Trigger.TriggerType = TRIGGER_SOUND then
2204 begin
2205 Inc(gTriggerClientID);
2206 ClientID := gTriggerClientID;
2207 end
2208 else
2209 begin
2210 ClientID := 0;
2211 end;
2212 TimeOut := 0;
2213 ActivateUID := 0;
2214 PlayerCollide := False;
2215 DoorTime := -1;
2216 PressTime := -1;
2217 PressCount := 0;
2218 SoundPlayCount := 0;
2219 Sound := nil;
2220 AutoSpawn := False;
2221 SpawnCooldown := 0;
2222 SpawnedCount := 0;
2223 end;
2225 // update cached trigger variables
2226 trigUpdateCacheData(gTriggers[find_id], gTriggers[find_id].trigDataRec);
2228 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê"
2229 if (Trigger.TriggerType = TRIGGER_SOUND) and (Trigger.tgcSoundName <> '') then
2230 begin
2231 // Åùå íåò òàêîãî çâóêà
2232 if not g_Sound_Exists(Trigger.tgcSoundName) then
2233 begin
2234 fn := g_ExtractWadName(Trigger.tgcSoundName);
2235 if fn = '' then
2236 begin // Çâóê â ôàéëå ñ êàðòîé
2237 mapw := g_ExtractWadName(gMapInfo.Map);
2238 fn := mapw+':'+g_ExtractFilePathName(Trigger.tgcSoundName);
2239 end
2240 else // Çâóê â îòäåëüíîì ôàéëå
2241 begin
2242 fn := GameDir + '/wads/' + Trigger.tgcSoundName;
2243 end;
2245 if not g_Sound_CreateWADEx(Trigger.tgcSoundName, fn) then
2246 begin
2247 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.tgcSoundName]));
2248 end;
2249 end;
2251 // Ñîçäàåì îáúåêò çâóêà
2252 with gTriggers[find_id] do
2253 begin
2254 Sound := TPlayableSound.Create();
2255 if not Sound.SetByName(Trigger.tgcSoundName) then
2256 begin
2257 Sound.Free();
2258 Sound := nil;
2259 end;
2260 end;
2261 end;
2263 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà"
2264 if (Trigger.TriggerType = TRIGGER_MUSIC) and (Trigger.tgcMusicName <> '') then
2265 begin
2266 // Åùå íåò òàêîé ìóçûêè
2267 if not g_Sound_Exists(Trigger.tgcMusicName) then
2268 begin
2269 fn := g_ExtractWadName(Trigger.tgcMusicName);
2271 if fn = '' then
2272 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2273 mapw := g_ExtractWadName(gMapInfo.Map);
2274 fn := mapw+':'+g_ExtractFilePathName(Trigger.tgcMusicName);
2275 end
2276 else // Ìóçûêà â ôàéëå ñ êàðòîé
2277 begin
2278 fn := GameDir+'/wads/'+Trigger.tgcMusicName;
2279 end;
2281 if not g_Sound_CreateWADEx(Trigger.tgcMusicName, fn, True) then
2282 begin
2283 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.tgcMusicName]));
2284 end;
2285 end;
2286 end;
2288 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü"
2289 if Trigger.TriggerType = TRIGGER_SHOT then
2290 begin
2291 with gTriggers[find_id] do
2292 begin
2293 ShotPanelTime := 0;
2294 ShotSightTime := 0;
2295 ShotSightTimeout := 0;
2296 ShotSightTarget := 0;
2297 ShotSightTargetN := 0;
2298 ShotAmmoCount := Trigger.tgcAmmo;
2299 ShotReloadTime := 0;
2300 end;
2301 end;
2303 Result := find_id;
2304 end;
2307 // sorry; grid doesn't support recursive queries, so we have to do this
2308 type
2309 TSimpleMonsterList = specialize TSimpleList<TMonster>;
2311 var
2312 tgMonsList: TSimpleMonsterList = nil;
2314 procedure g_Triggers_Update();
2315 var
2316 a, b, i: Integer;
2317 Affected: array of Integer;
2319 function monsNear (mon: TMonster): Boolean;
2320 begin
2321 result := false; // don't stop
2323 gTriggers[a].ActivateUID := mon.UID;
2324 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2326 tgMonsList.append(mon);
2327 end;
2329 var
2330 mon: TMonster;
2331 pan: TPanel;
2332 begin
2333 if (tgMonsList = nil) then tgMonsList := TSimpleMonsterList.Create();
2335 if gTriggers = nil then
2336 Exit;
2337 SetLength(Affected, 0);
2339 for a := 0 to High(gTriggers) do
2340 with gTriggers[a] do
2341 // Åñòü òðèããåð:
2342 if TriggerType <> TRIGGER_NONE then
2343 begin
2344 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè)
2345 if DoorTime > 0 then DoorTime := DoorTime - 1;
2346 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ
2347 if PressTime > 0 then PressTime := PressTime - 1;
2348 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2349 if (TriggerType = TRIGGER_DAMAGE) or (TriggerType = TRIGGER_HEALTH) then
2350 begin
2351 for b := 0 to High(Activators) do
2352 begin
2353 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2354 if Activators[b].TimeOut > 0 then
2355 begin
2356 Dec(Activators[b].TimeOut);
2357 end
2358 else
2359 begin
2360 continue;
2361 end;
2362 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2363 if (tgcInterval = 0) and (Activators[b].TimeOut < 65530) then Activators[b].TimeOut := 0;
2364 end;
2365 end;
2367 // Îáðàáàòûâàåì ñïàâíåðû
2368 if Enabled and AutoSpawn then
2369 begin
2370 if SpawnCooldown = 0 then
2371 begin
2372 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà
2373 if (TriggerType = TRIGGER_SPAWNMONSTER) and (tgcDelay > 0) then
2374 begin
2375 ActivateUID := 0;
2376 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2377 end;
2378 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò
2379 if (TriggerType = TRIGGER_SPAWNITEM) and (tgcDelay > 0) then
2380 begin
2381 ActivateUID := 0;
2382 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2383 end;
2384 end
2385 else
2386 begin
2387 // Óìåíüøàåì âðåìÿ îæèäàíèÿ
2388 Dec(SpawnCooldown);
2389 end;
2390 end;
2392 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü"
2393 if TriggerType = TRIGGER_SHOT then
2394 begin
2395 if ShotPanelTime > 0 then
2396 begin
2397 Dec(ShotPanelTime);
2398 if ShotPanelTime = 0 then g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID);
2399 end;
2400 if ShotSightTime > 0 then
2401 begin
2402 Dec(ShotSightTime);
2403 if ShotSightTime = 0 then ShotSightTarget := ShotSightTargetN;
2404 end;
2405 if ShotSightTimeout > 0 then
2406 begin
2407 Dec(ShotSightTimeout);
2408 if ShotSightTimeout = 0 then ShotSightTarget := 0;
2409 end;
2410 if ShotReloadTime > 0 then
2411 begin
2412 Dec(ShotReloadTime);
2413 if ShotReloadTime = 0 then ShotAmmoCount := tgcAmmo;
2414 end;
2415 end;
2417 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì
2418 if Enabled and (TriggerType = TRIGGER_SOUND) and (Sound <> nil) then
2419 begin
2420 if (SoundPlayCount > 0) and (not Sound.IsPlaying()) then
2421 begin
2422 if tgcPlayCount > 0 then SoundPlayCount -= 1; // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2423 if tgcLocal then
2424 begin
2425 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0);
2426 end
2427 else
2428 begin
2429 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2430 end;
2431 if Sound.IsPlaying() and g_Game_IsNet and g_Game_IsServer then MH_SEND_TriggerSound(gTriggers[a]);
2432 end;
2433 end;
2435 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü
2436 if (TriggerType = TRIGGER_TRAP) and (DoorTime = 0) and (g_Map_PanelByGUID(trigPanelGUID) <> nil) then
2437 begin
2438 tr_OpenDoor(trigPanelGUID, tgcSilent, tgcD2d);
2439 DoorTime := -1;
2440 end;
2442 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü
2443 if (TriggerType = TRIGGER_DOOR5) and (DoorTime = 0) and (g_Map_PanelByGUID(trigPanelGUID) <> nil) then
2444 begin
2445 pan := g_Map_PanelByGUID(trigPanelGUID);
2446 if (pan <> nil) and pan.isGWall then
2447 begin
2448 // Óæå çàêðûòà
2449 if {gWalls[trigPanelID].Enabled} pan.Enabled then
2450 begin
2451 DoorTime := -1;
2452 end
2453 else
2454 begin
2455 // Ïîêà îòêðûòà - çàêðûâàåì
2456 if tr_CloseDoor(trigPanelGUID, tgcSilent, tgcD2d) then DoorTime := -1;
2457 end;
2458 end;
2459 end;
2461 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2462 if (TriggerType in [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) and
2463 (PressTime = 0) and (PressCount >= tgcPressCount) then
2464 begin
2465 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2466 PressTime := -1;
2467 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2468 if tgcPressCount > 0 then PressCount -= tgcPressCount else PressCount := 0;
2470 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2471 for b := 0 to High(gTriggers) do
2472 begin
2473 if g_Collide(tgcTX, tgcTY, tgcTWidth, tgcTHeight, gTriggers[b].X, gTriggers[b].Y,
2474 gTriggers[b].Width, gTriggers[b].Height) and
2475 ((b <> a) or (tgcWait > 0)) then
2476 begin // Can be self-activated, if there is Data.Wait
2477 if (not tgcExtRandom) or gTriggers[b].Enabled then
2478 begin
2479 SetLength(Affected, Length(Affected) + 1);
2480 Affected[High(Affected)] := b;
2481 end;
2482 end;
2483 end;
2485 //HACK!
2486 // if we have panelid, assume that it will switch the moving platform
2487 pan := g_Map_PanelByGUID(trigPanelGUID);
2488 if (pan <> nil) then
2489 begin
2490 case TriggerType of
2491 TRIGGER_PRESS: pan.movingActive := true; // what to do here?
2492 TRIGGER_ON: pan.movingActive := true;
2493 TRIGGER_OFF: pan.movingActive := false;
2494 TRIGGER_ONOFF: pan.movingActive := not pan.movingActive;
2495 end;
2496 if not tgcSilent and (Length(tgcSound) > 0) then
2497 begin
2498 g_Sound_PlayExAt(tgcSound, X, Y);
2499 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, tgcSound);
2500 end;
2501 end;
2503 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2504 if (TriggerType = TRIGGER_PRESS) and tgcExtRandom then
2505 begin
2506 if (Length(Affected) > 0) then
2507 begin
2508 b := Affected[Random(Length(Affected))];
2509 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2510 ActivateTrigger(gTriggers[b], 0);
2511 end;
2512 end
2513 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2514 begin
2515 for i := 0 to High(Affected) do
2516 begin
2517 b := Affected[i];
2518 case TriggerType of
2519 TRIGGER_PRESS:
2520 begin
2521 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2522 ActivateTrigger(gTriggers[b], 0);
2523 end;
2524 TRIGGER_ON:
2525 begin
2526 gTriggers[b].Enabled := True;
2527 end;
2528 TRIGGER_OFF:
2529 begin
2530 gTriggers[b].Enabled := False;
2531 gTriggers[b].TimeOut := 0;
2532 if gTriggers[b].AutoSpawn then
2533 begin
2534 gTriggers[b].AutoSpawn := False;
2535 gTriggers[b].SpawnCooldown := 0;
2536 end;
2537 end;
2538 TRIGGER_ONOFF:
2539 begin
2540 gTriggers[b].Enabled := not gTriggers[b].Enabled;
2541 if not gTriggers[b].Enabled then
2542 begin
2543 gTriggers[b].TimeOut := 0;
2544 if gTriggers[b].AutoSpawn then
2545 begin
2546 gTriggers[b].AutoSpawn := False;
2547 gTriggers[b].SpawnCooldown := 0;
2548 end;
2549 end;
2550 end;
2551 end;
2552 end;
2553 end;
2554 SetLength(Affected, 0);
2555 end;
2557 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2558 if TimeOut > 0 then
2559 begin
2560 TimeOut := TimeOut - 1;
2561 Continue; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2562 end;
2564 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2565 if not Enabled then
2566 Continue;
2568 // "Èãðîê áëèçêî":
2569 if ByteBool(ActivateType and ACTIVATE_PLAYERCOLLIDE) and
2570 (TimeOut = 0) then
2571 if gPlayers <> nil then
2572 for b := 0 to High(gPlayers) do
2573 if gPlayers[b] <> nil then
2574 with gPlayers[b] do
2575 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2576 if alive and ((gTriggers[a].Keys and GetKeys) = gTriggers[a].Keys) and
2577 Collide(X, Y, Width, Height) then
2578 begin
2579 gTriggers[a].ActivateUID := UID;
2581 if (gTriggers[a].TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) and
2582 PlayerCollide then
2583 { Don't activate sound/music again if player is here }
2584 else
2585 ActivateTrigger(gTriggers[a], ACTIVATE_PLAYERCOLLIDE);
2586 end;
2588 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2590 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2591 ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2592 (TimeOut = 0) and (Keys = 0) then
2593 begin
2594 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2595 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2596 ActivateType := ActivateType and not (ACTIVATE_MONSTERCOLLIDE or ACTIVATE_NOMONSTER);
2597 gTriggers[a].ActivateUID := 0;
2598 ActivateTrigger(gTriggers[a], 0);
2599 end else
2600 begin
2601 // "Ìîíñòð áëèçêî"
2602 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2603 (TimeOut = 0) and (Keys = 0) then // Åñëè íå íóæíû êëþ÷è
2604 begin
2605 //g_Mons_ForEach(monsNear);
2606 //Alive?!
2607 tgMonsList.reset();
2608 g_Mons_ForEachAt(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height, monsNear);
2609 for mon in tgMonsList do
2610 begin
2611 gTriggers[a].ActivateUID := mon.UID;
2612 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2613 end;
2614 tgMonsList.reset(); // just in case
2615 end;
2617 // "Ìîíñòðîâ íåò"
2618 if ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2619 (TimeOut = 0) and (Keys = 0) then
2620 if not g_Mons_IsAnyAliveAt(X, Y, Width, Height) then
2621 begin
2622 gTriggers[a].ActivateUID := 0;
2623 ActivateTrigger(gTriggers[a], ACTIVATE_NOMONSTER);
2624 end;
2625 end;
2627 PlayerCollide := g_CollidePlayer(X, Y, Width, Height);
2628 end;
2629 end;
2631 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
2632 begin
2633 if (ID >= Length(gTriggers)) then exit;
2634 gTriggers[ID].ActivateUID := ActivateUID;
2635 ActivateTrigger(gTriggers[ID], ActivateType);
2636 end;
2638 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
2639 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
2640 var
2641 a: Integer;
2642 k: Byte;
2643 p: TPlayer;
2644 begin
2645 Result := nil;
2647 if gTriggers = nil then Exit;
2649 case g_GetUIDType(UID) of
2650 UID_GAME: k := 255;
2651 UID_PLAYER:
2652 begin
2653 p := g_Player_Get(UID);
2654 if p <> nil then
2655 k := p.GetKeys
2656 else
2657 k := 0;
2658 end;
2659 else k := 0;
2660 end;
2662 for a := 0 to High(gTriggers) do
2663 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2664 (gTriggers[a].TimeOut = 0) and
2665 (not InDWArray(a, IgnoreList)) and
2666 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2667 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2668 if g_Collide(X, Y, Width, Height,
2669 gTriggers[a].X, gTriggers[a].Y,
2670 gTriggers[a].Width, gTriggers[a].Height) then
2671 begin
2672 gTriggers[a].ActivateUID := UID;
2673 if ActivateTrigger(gTriggers[a], ActivateType) then
2674 begin
2675 SetLength(Result, Length(Result)+1);
2676 Result[High(Result)] := a;
2677 end;
2678 end;
2679 end;
2681 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
2682 var
2683 a: Integer;
2684 k: Byte;
2685 p: TPlayer;
2686 begin
2687 if gTriggers = nil then Exit;
2689 case g_GetUIDType(UID) of
2690 UID_GAME: k := 255;
2691 UID_PLAYER:
2692 begin
2693 p := g_Player_Get(UID);
2694 if p <> nil then
2695 k := p.GetKeys
2696 else
2697 k := 0;
2698 end;
2699 else k := 0;
2700 end;
2702 for a := 0 to High(gTriggers) do
2703 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2704 (gTriggers[a].TimeOut = 0) and
2705 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2706 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2707 if g_CollideLine(x1, y1, x2, y2, gTriggers[a].X, gTriggers[a].Y,
2708 gTriggers[a].Width, gTriggers[a].Height) then
2709 begin
2710 gTriggers[a].ActivateUID := UID;
2711 ActivateTrigger(gTriggers[a], ActivateType);
2712 end;
2713 end;
2715 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
2716 var
2717 a: Integer;
2718 k: Byte;
2719 rsq: Word;
2720 p: TPlayer;
2721 begin
2722 if gTriggers = nil then
2723 Exit;
2725 case g_GetUIDType(UID) of
2726 UID_GAME: k := 255;
2727 UID_PLAYER:
2728 begin
2729 p := g_Player_Get(UID);
2730 if p <> nil then
2731 k := p.GetKeys
2732 else
2733 k := 0;
2734 end;
2735 else k := 0;
2736 end;
2738 rsq := Radius * Radius;
2740 for a := 0 to High(gTriggers) do
2741 if (gTriggers[a].ID <> DWORD(IgnoreTrigger)) and
2742 (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2743 (gTriggers[a].TimeOut = 0) and
2744 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2745 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2746 with gTriggers[a] do
2747 if g_Collide(CX-Radius, CY-Radius, 2*Radius, 2*Radius,
2748 X, Y, Width, Height) then
2749 if ((Sqr(CX-X)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2750 ((Sqr(CX-X-Width)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2751 ((Sqr(CX-X-Width)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2752 ((Sqr(CX-X)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2753 ( (CX > (X-Radius)) and (CX < (X+Width+Radius)) and
2754 (CY > Y) and (CY < (Y+Height)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2755 ( (CY > (Y-Radius)) and (CY < (Y+Height+Radius)) and
2756 (CX > X) and (CX < (X+Width)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2757 begin
2758 ActivateUID := UID;
2759 ActivateTrigger(gTriggers[a], ActivateType);
2760 end;
2761 end;
2763 procedure g_Triggers_OpenAll();
2764 var
2765 a: Integer;
2766 b: Boolean;
2767 begin
2768 if gTriggers = nil then Exit;
2770 b := False;
2771 for a := 0 to High(gTriggers) do
2772 begin
2773 with gTriggers[a] do
2774 begin
2775 if (TriggerType = TRIGGER_OPENDOOR) or
2776 (TriggerType = TRIGGER_DOOR5) or
2777 (TriggerType = TRIGGER_DOOR) then
2778 begin
2779 tr_OpenDoor(trigPanelGUID, True, tgcD2d);
2780 if TriggerType = TRIGGER_DOOR5 then DoorTime := 180;
2781 b := True;
2782 end;
2783 end;
2784 end;
2786 if b then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2787 end;
2789 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
2790 begin
2791 if (gTriggers <> nil) then
2792 if gTriggers[ID].SpawnedCount > 0 then
2793 Dec(gTriggers[ID].SpawnedCount);
2794 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].tgcSoundName) then
2806 begin
2807 g_Sound_Delete(gTriggers[a].tgcSoundName);
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].trigDataRec.Free();
2816 end;
2818 gTriggers := nil;
2819 gSecretsCount := 0;
2820 SetLength(gMonstersSpawned, 0);
2821 end;
2824 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
2825 var
2826 count, actCount, i, j: Integer;
2827 dw: DWORD;
2828 sg: Single;
2829 b: Boolean;
2830 begin
2831 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ
2832 count := Length(gTriggers);
2833 Mem := TBinMemoryWriter.Create((count+1)*200);
2835 // Êîëè÷åñòâî òðèããåðîâ
2836 Mem.WriteInt(count);
2837 if (count = 0) then exit;
2839 for i := 0 to High(gTriggers) do
2840 begin
2841 // Ñèãíàòóðà òðèããåðà
2842 dw := TRIGGER_SIGNATURE; // 'TRGX'
2843 Mem.WriteDWORD(dw);
2844 // Òèï òðèããåðà
2845 Mem.WriteByte(gTriggers[i].TriggerType);
2846 if (gTriggers[i].TriggerType = TRIGGER_NONE) then continue; // empty one
2847 // Ñïåöèàëüíûå äàííûå òðèããåðà: ïîòîì èç êàðòû îïÿòü âûòàùèì; ñîõðàíèì òîëüêî èíäåêñ
2848 Mem.WriteInt(gTriggers[i].mapIndex);
2849 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà
2850 Mem.WriteInt(gTriggers[i].X);
2851 Mem.WriteInt(gTriggers[i].Y);
2852 // Ðàçìåðû
2853 Mem.WriteWord(gTriggers[i].Width);
2854 Mem.WriteWord(gTriggers[i].Height);
2855 // Âêëþ÷åí ëè òðèããåð
2856 Mem.WriteBoolean(gTriggers[i].Enabled);
2857 // Òèï àêòèâàöèè òðèããåðà
2858 Mem.WriteByte(gTriggers[i].ActivateType);
2859 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè
2860 Mem.WriteByte(gTriggers[i].Keys);
2861 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ
2862 Mem.WriteInt(gTriggers[i].TexturePanelGUID);
2863 // Òèï ýòîé ïàíåëè
2864 Mem.WriteWord(gTriggers[i].TexturePanelType);
2865 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2866 Mem.WriteInt(gTriggers[i].trigPanelGUID);
2867 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè
2868 Mem.WriteWord(gTriggers[i].TimeOut);
2869 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð
2870 Mem.WriteWord(gTriggers[i].ActivateUID);
2871 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì
2872 actCount := Length(gTriggers[i].Activators);
2873 Mem.WriteInt(actCount);
2874 for j := 0 to actCount-1 do
2875 begin
2876 // UID îáúåêòà
2877 Mem.WriteWord(gTriggers[i].Activators[j].UID);
2878 // Âðåìÿ îæèäàíèÿ
2879 Mem.WriteWord(gTriggers[i].Activators[j].TimeOut);
2880 end;
2881 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà
2882 Mem.WriteBoolean(gTriggers[i].PlayerCollide);
2883 // Âðåìÿ äî çàêðûòèÿ äâåðè
2884 Mem.WriteInt(gTriggers[i].DoorTime);
2885 // Çàäåðæêà àêòèâàöèè
2886 Mem.WriteInt(gTriggers[i].PressTime);
2887 // Ñ÷åò÷èê íàæàòèé
2888 Mem.WriteInt(gTriggers[i].PressCount);
2889 // Ñïàâíåð àêòèâåí
2890 Mem.WriteBoolean(gTriggers[i].AutoSpawn);
2891 // Çàäåðæêà ñïàâíåðà
2892 Mem.WriteInt(gTriggers[i].SpawnCooldown);
2893 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ
2894 Mem.WriteInt(gTriggers[i].SpawnedCount);
2895 // Ñêîëüêî ðàç ïðîèãðàí çâóê
2896 Mem.WriteInt(gTriggers[i].SoundPlayCount);
2897 // Ïðîèãðûâàåòñÿ ëè çâóê?
2898 if (gTriggers[i].Sound <> nil) then b := gTriggers[i].Sound.IsPlaying() else b := false;
2899 Mem.WriteBoolean(b);
2900 if b then
2901 begin
2902 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà
2903 dw := gTriggers[i].Sound.GetPosition();
2904 Mem.WriteDWORD(dw);
2905 // Ãðîìêîñòü çâóêà
2906 sg := gTriggers[i].Sound.GetVolume();
2907 sg := sg / (gSoundLevel/255.0);
2908 Mem.WriteSingle(sg);
2909 // Ñòåðåî ñìåùåíèå çâóêà
2910 sg := gTriggers[i].Sound.GetPan();
2911 Mem.WriteSingle(sg);
2912 end;
2913 end;
2914 end;
2917 procedure g_Triggers_LoadState (var Mem: TBinMemoryReader);
2918 var
2919 count, actCount, i, j, a: Integer;
2920 dw: DWORD;
2921 vol, pan: Single;
2922 b: Boolean;
2923 Trig: TTrigger;
2924 mapIndex: Integer;
2925 begin
2926 if (Mem = nil) then exit;
2928 g_Triggers_Free();
2930 // Êîëè÷åñòâî òðèããåðîâ
2931 Mem.ReadInt(count);
2932 if (count = 0) then exit;
2934 for a := 0 to count-1 do
2935 begin
2936 // Ñèãíàòóðà òðèããåðà
2937 Mem.ReadDWORD(dw); // 'TRGX'
2938 if (dw <> TRIGGER_SIGNATURE) then raise EBinSizeError.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2939 // Òèï òðèããåðà
2940 Mem.ReadByte(Trig.TriggerType);
2941 // Ñïåöèàëüíûå äàííûå òðèããåðà: èíäåêñ â gCurrentMap.field['triggers']
2942 if (Trig.TriggerType = TRIGGER_NONE) then continue; // empty one
2943 Mem.ReadInt(mapIndex);
2944 i := g_Triggers_CreateWithMapIndex(Trig, a, mapIndex);
2946 if (gTriggers[i].trigData <> nil) then
2947 begin
2948 tw := TStrTextWriter.Create();
2949 try
2950 gTriggers[i].trigData.writeTo(tw);
2951 e_LogWritefln('=== trigger #%s loaded ==='#10'%s'#10'---', [mapIndex, tw.str]);
2952 finally
2953 tw.Free();
2954 end;
2955 end;
2957 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2958 Mem.ReadInt(gTriggers[i].X);
2959 Mem.ReadInt(gTriggers[i].Y);
2960 // Ðàçìåðû:
2961 Mem.ReadWord(gTriggers[i].Width);
2962 Mem.ReadWord(gTriggers[i].Height);
2963 // Âêëþ÷åí ëè òðèããåð:
2964 Mem.ReadBoolean(gTriggers[i].Enabled);
2965 // Òèï àêòèâàöèè òðèããåðà:
2966 Mem.ReadByte(gTriggers[i].ActivateType);
2967 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2968 Mem.ReadByte(gTriggers[i].Keys);
2969 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2970 Mem.ReadInt(gTriggers[i].TexturePanelGUID);
2971 // Òèï ýòîé ïàíåëè:
2972 Mem.ReadWord(gTriggers[i].TexturePanelType);
2973 // Âíóòðåííèé íîìåð äðóãîé ïàíåëè (ïî ñ÷àñòëèâîé ñëó÷àéíîñòè îí áóäåò ñîâïàäàòü ñ òåì, ÷òî ñîçäàíî ïðè çàãðóçêå êàðòû)
2974 Mem.ReadInt(gTriggers[i].trigPanelGUID);
2975 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2976 Mem.ReadWord(gTriggers[i].TimeOut);
2977 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2978 Mem.ReadWord(gTriggers[i].ActivateUID);
2979 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2980 Mem.ReadInt(actCount);
2981 if actCount > 0 then
2982 begin
2983 SetLength(gTriggers[i].Activators, actCount);
2984 for j := 0 to actCount-1 do
2985 begin
2986 // UID îáúåêòà
2987 Mem.ReadWord(gTriggers[i].Activators[j].UID);
2988 // Âðåìÿ îæèäàíèÿ
2989 Mem.ReadWord(gTriggers[i].Activators[j].TimeOut);
2990 end;
2991 end;
2992 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2993 Mem.ReadBoolean(gTriggers[i].PlayerCollide);
2994 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2995 Mem.ReadInt(gTriggers[i].DoorTime);
2996 // Çàäåðæêà àêòèâàöèè:
2997 Mem.ReadInt(gTriggers[i].PressTime);
2998 // Ñ÷åò÷èê íàæàòèé:
2999 Mem.ReadInt(gTriggers[i].PressCount);
3000 // Ñïàâíåð àêòèâåí:
3001 Mem.ReadBoolean(gTriggers[i].AutoSpawn);
3002 // Çàäåðæêà ñïàâíåðà:
3003 Mem.ReadInt(gTriggers[i].SpawnCooldown);
3004 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
3005 Mem.ReadInt(gTriggers[i].SpawnedCount);
3006 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
3007 Mem.ReadInt(gTriggers[i].SoundPlayCount);
3008 // Ïðîèãðûâàåòñÿ ëè çâóê?
3009 Mem.ReadBoolean(b);
3010 if b then
3011 begin
3012 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
3013 Mem.ReadDWORD(dw);
3014 // Ãðîìêîñòü çâóêà:
3015 Mem.ReadSingle(vol);
3016 // Ñòåðåî ñìåùåíèå çâóêà:
3017 Mem.ReadSingle(pan);
3018 // Çàïóñêàåì çâóê, åñëè åñòü:
3019 if gTriggers[i].Sound <> nil then
3020 begin
3021 gTriggers[i].Sound.PlayPanVolume(pan, vol);
3022 gTriggers[i].Sound.Pause(True);
3023 gTriggers[i].Sound.SetPosition(dw);
3024 end
3025 end;
3026 end;
3027 end;
3029 end.