DEADSOFTWARE

Holmes can draw triggers 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 TTrigger = record
31 ID: DWORD;
32 ClientID: DWORD;
33 TriggerType: Byte;
34 X, Y: Integer;
35 Width, Height: Word;
36 Enabled: Boolean;
37 ActivateType: Byte;
38 Keys: Byte;
39 TexturePanel: Integer;
40 TexturePanelType: Word;
42 TimeOut: Word;
43 ActivateUID: Word;
44 Activators: array of TActivator;
45 PlayerCollide: Boolean;
46 DoorTime: Integer;
47 PressTime: Integer;
48 PressCount: Integer;
49 SoundPlayCount: Integer;
50 Sound: TPlayableSound;
51 AutoSpawn: Boolean;
52 SpawnCooldown: Integer;
53 SpawnedCount: Integer;
54 ShotPanelType: Word;
55 ShotPanelTime: Integer;
56 ShotSightTime: Integer;
57 ShotSightTimeout: Integer;
58 ShotSightTarget: Word;
59 ShotSightTargetN: Word;
60 ShotAmmoCount: Word;
61 ShotReloadTime: Integer;
63 //trigShotPanelId: Integer;
64 trigPanelId: Integer;
66 //TrigData: TTriggerData;
67 trigData: TDynRecord; // triggerdata; owned by trigger
69 property trigShotPanelId: Integer read trigPanelId write trigPanelId;
70 end;
72 function g_Triggers_Create(Trigger: TTrigger): DWORD;
73 procedure g_Triggers_Update();
74 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
75 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
76 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
77 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
78 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
79 procedure g_Triggers_OpenAll();
80 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
81 procedure g_Triggers_Free();
82 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
83 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
85 function tr_Message(MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
87 function tr_CloseDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
88 function tr_OpenDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
89 procedure tr_CloseTrap(PanelID: Integer; NoSound: Boolean; d2d: Boolean);
90 function tr_SetLift(PanelID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
92 function tr_Teleport(ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
93 function tr_Push(ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
95 procedure tr_MakeEffect(X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
96 function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
98 var
99 gTriggerClientID: Integer = 0;
100 gTriggers: array of TTrigger;
101 gSecretsCount: Integer = 0;
102 gMonstersSpawned: array of LongInt = nil;
104 implementation
106 uses
107 g_player, g_map, Math, g_gfx, g_game, g_textures,
108 g_console, g_monsters, g_items, g_phys, g_weapons,
109 wadreader, g_main, SysUtils, e_log, g_language,
110 g_options, g_net, g_netmsg, utils;
112 const
113 TRIGGER_SIGNATURE = $52475254; // 'TRGR'
114 TRAP_DAMAGE = 1000;
116 function FindTrigger(): DWORD;
117 var
118 i: Integer;
119 begin
120 if gTriggers <> nil then
121 for i := 0 to High(gTriggers) do
122 if gTriggers[i].TriggerType = TRIGGER_NONE then
123 begin
124 Result := i;
125 Exit;
126 end;
128 if gTriggers = nil then
129 begin
130 SetLength(gTriggers, 8);
131 Result := 0;
132 end
133 else
134 begin
135 Result := High(gTriggers) + 1;
136 SetLength(gTriggers, Length(gTriggers) + 8);
137 end;
138 end;
140 function tr_CloseDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
141 var
142 a, b, c: Integer;
143 begin
144 Result := False;
146 if PanelID = -1 then Exit;
148 if not d2d then
149 begin
150 with gWalls[PanelID] do
151 begin
152 if g_CollidePlayer(X, Y, Width, Height) or
153 g_Mons_IsAnyAliveAt(X, Y, Width, Height) then Exit;
155 if not Enabled then
156 begin
157 if not NoSound then
158 begin
159 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
160 if g_Game_IsServer and g_Game_IsNet then
161 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
162 end;
163 g_Map_EnableWall(PanelID);
164 Result := True;
165 end;
166 end;
167 end
168 else
169 begin
170 if gDoorMap = nil then Exit;
172 c := -1;
173 for a := 0 to High(gDoorMap) do
174 begin
175 for b := 0 to High(gDoorMap[a]) do
176 if gDoorMap[a, b] = DWORD(PanelID) then
177 begin
178 c := a;
179 Break;
180 end;
182 if c <> -1 then Break;
183 end;
184 if c = -1 then Exit;
186 for b := 0 to High(gDoorMap[c]) do
187 with gWalls[gDoorMap[c, b]] do
188 begin
189 if g_CollidePlayer(X, Y, Width, Height) or
190 g_Mons_IsAnyAliveAt(X, Y, Width, Height) then Exit;
191 end;
193 if not NoSound then
194 for b := 0 to High(gDoorMap[c]) do
195 if not gWalls[gDoorMap[c, b]].Enabled then
196 begin
197 with gWalls[PanelID] do
198 begin
199 g_Sound_PlayExAt('SOUND_GAME_DOORCLOSE', X, Y);
200 if g_Game_IsServer and g_Game_IsNet then
201 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOORCLOSE');
202 end;
203 Break;
204 end;
206 for b := 0 to High(gDoorMap[c]) do
207 if not gWalls[gDoorMap[c, b]].Enabled then
208 begin
209 g_Map_EnableWall(gDoorMap[c, b]);
210 Result := True;
211 end;
212 end;
213 end;
215 procedure tr_CloseTrap(PanelID: Integer; NoSound: Boolean; d2d: Boolean);
216 var
217 a, b, c: Integer;
218 wx, wy, wh, ww: Integer;
220 function monsDamage (mon: TMonster): Boolean;
221 begin
222 result := false; // don't stop
223 if g_Obj_Collide(wx, wy, ww, wh, @mon.Obj) then mon.Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
224 end;
226 begin
227 if PanelID = -1 then Exit;
229 if not d2d then
230 begin
231 with gWalls[PanelID] do
232 begin
233 if (not NoSound) and (not Enabled) then
234 begin
235 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
236 if g_Game_IsServer and g_Game_IsNet then
237 MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
238 end;
239 end;
241 wx := gWalls[PanelID].X;
242 wy := gWalls[PanelID].Y;
243 ww := gWalls[PanelID].Width;
244 wh := gWalls[PanelID].Height;
246 with gWalls[PanelID] do
247 begin
248 if gPlayers <> nil then
249 for a := 0 to High(gPlayers) do
250 if (gPlayers[a] <> nil) and gPlayers[a].Live and
251 gPlayers[a].Collide(X, Y, Width, Height) then
252 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
254 //g_Mons_ForEach(monsDamage);
255 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
257 if not Enabled then g_Map_EnableWall(PanelID);
258 end;
259 end
260 else
261 begin
262 if gDoorMap = nil then Exit;
264 c := -1;
265 for a := 0 to High(gDoorMap) do
266 begin
267 for b := 0 to High(gDoorMap[a]) do
268 begin
269 if gDoorMap[a, b] = DWORD(PanelID) then
270 begin
271 c := a;
272 Break;
273 end;
274 end;
276 if c <> -1 then Break;
277 end;
278 if c = -1 then Exit;
280 if not NoSound then
281 begin
282 for b := 0 to High(gDoorMap[c]) do
283 begin
284 if not gWalls[gDoorMap[c, b]].Enabled then
285 begin
286 with gWalls[PanelID] do
287 begin
288 g_Sound_PlayExAt('SOUND_GAME_SWITCH1', X, Y);
289 if g_Game_IsServer and g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
290 end;
291 Break;
292 end;
293 end;
294 end;
296 for b := 0 to High(gDoorMap[c]) do
297 begin
298 wx := gWalls[gDoorMap[c, b]].X;
299 wy := gWalls[gDoorMap[c, b]].Y;
300 ww := gWalls[gDoorMap[c, b]].Width;
301 wh := gWalls[gDoorMap[c, b]].Height;
303 with gWalls[gDoorMap[c, b]] do
304 begin
305 if gPlayers <> nil then
306 for a := 0 to High(gPlayers) do
307 if (gPlayers[a] <> nil) and gPlayers[a].Live and
308 gPlayers[a].Collide(X, Y, Width, Height) then
309 gPlayers[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
311 //g_Mons_ForEach(monsDamage);
312 g_Mons_ForEachAliveAt(wx, wy, ww, wh, monsDamage);
313 (*
314 if gMonsters <> nil then
315 for a := 0 to High(gMonsters) do
316 if (gMonsters[a] <> nil) and gMonsters[a].Live and
317 g_Obj_Collide(X, Y, Width, Height, @gMonsters[a].Obj) then
318 gMonsters[a].Damage(TRAP_DAMAGE, 0, 0, 0, HIT_TRAP);
319 *)
321 if not Enabled then g_Map_EnableWall(gDoorMap[c, b]);
322 end;
323 end;
324 end;
325 end;
327 function tr_OpenDoor(PanelID: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
328 var
329 a, b, c: Integer;
330 begin
331 Result := False;
333 if PanelID = -1 then Exit;
335 if not d2d then
336 begin
337 with gWalls[PanelID] do
338 if Enabled then
339 begin
340 if not NoSound then
341 begin
342 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
343 if g_Game_IsServer and g_Game_IsNet then
344 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
345 end;
346 g_Map_DisableWall(PanelID);
347 Result := True;
348 end;
349 end
350 else
351 begin
352 if gDoorMap = nil then Exit;
354 c := -1;
355 for a := 0 to High(gDoorMap) do
356 begin
357 for b := 0 to High(gDoorMap[a]) do
358 if gDoorMap[a, b] = DWORD(PanelID) then
359 begin
360 c := a;
361 Break;
362 end;
364 if c <> -1 then Break;
365 end;
366 if c = -1 then Exit;
368 if not NoSound then
369 for b := 0 to High(gDoorMap[c]) do
370 if gWalls[gDoorMap[c, b]].Enabled then
371 begin
372 with gWalls[PanelID] do
373 begin
374 g_Sound_PlayExAt('SOUND_GAME_DOOROPEN', X, Y);
375 if g_Game_IsServer and g_Game_IsNet then
376 MH_SEND_Sound(X, Y, 'SOUND_GAME_DOOROPEN');
377 end;
378 Break;
379 end;
381 for b := 0 to High(gDoorMap[c]) do
382 if gWalls[gDoorMap[c, b]].Enabled then
383 begin
384 g_Map_DisableWall(gDoorMap[c, b]);
385 Result := True;
386 end;
387 end;
388 end;
390 function tr_SetLift(PanelID: Integer; d: Integer; NoSound: Boolean; d2d: Boolean): Boolean;
391 var
392 a, b, c, t: Integer;
393 begin
394 t := 0;
395 Result := False;
397 if PanelID = -1 then Exit;
399 if (gLifts[PanelID].PanelType = PANEL_LIFTUP) or
400 (gLifts[PanelID].PanelType = PANEL_LIFTDOWN) then
401 case d of
402 0: t := 0;
403 1: t := 1;
404 else t := IfThen(gLifts[PanelID].LiftType = 1, 0, 1);
405 end
406 else if (gLifts[PanelID].PanelType = PANEL_LIFTLEFT) or
407 (gLifts[PanelID].PanelType = PANEL_LIFTRIGHT) then
408 case d of
409 0: t := 2;
410 1: t := 3;
411 else t := IfThen(gLifts[PanelID].LiftType = 2, 3, 2);
412 end;
414 if not d2d then
415 begin
416 with gLifts[PanelID] do
417 if LiftType <> t then
418 begin
419 g_Map_SetLift(PanelID, t);
421 {if not NoSound then
422 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);}
423 Result := True;
424 end;
425 end
426 else // Êàê â D2d
427 begin
428 if gLiftMap = nil then Exit;
430 c := -1;
431 for a := 0 to High(gLiftMap) do
432 begin
433 for b := 0 to High(gLiftMap[a]) do
434 if gLiftMap[a, b] = DWORD(PanelID) then
435 begin
436 c := a;
437 Break;
438 end;
440 if c <> -1 then Break;
441 end;
442 if c = -1 then Exit;
444 {if not NoSound then
445 for b := 0 to High(gLiftMap[c]) do
446 if gLifts[gLiftMap[c, b]].LiftType <> t then
447 begin
448 with gLifts[PanelID] do
449 g_Sound_PlayExAt('SOUND_GAME_SWITCH0', X, Y);
450 Break;
451 end;}
453 for b := 0 to High(gLiftMap[c]) do
454 with gLifts[gLiftMap[c, b]] do
455 if LiftType <> t then
456 begin
457 g_Map_SetLift(gLiftMap[c, b], t);
459 Result := True;
460 end;
461 end;
462 end;
464 function tr_SpawnShot(ShotType: Integer; wx, wy, dx, dy: Integer; ShotSound: Boolean; ShotTarget: Word): Integer;
465 var
466 snd: string;
467 Projectile: Boolean;
468 TextureID: DWORD;
469 Anim: TAnimation;
470 begin
471 Result := -1;
472 TextureID := DWORD(-1);
473 snd := 'SOUND_WEAPON_FIREROCKET';
474 Projectile := True;
475 case ShotType of
476 TRIGGER_SHOT_PISTOL:
477 begin
478 g_Weapon_pistol(wx, wy, dx, dy, 0, True);
479 snd := 'SOUND_WEAPON_FIREPISTOL';
480 Projectile := False;
481 if ShotSound then
482 begin
483 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
484 if g_Game_IsNet then
485 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
486 end;
487 end;
489 TRIGGER_SHOT_BULLET:
490 begin
491 g_Weapon_mgun(wx, wy, dx, dy, 0, True);
492 if gSoundEffectsDF then snd := 'SOUND_WEAPON_FIRECGUN'
493 else snd := 'SOUND_WEAPON_FIREPISTOL';
494 Projectile := False;
495 if ShotSound then
496 begin
497 g_Player_CreateShell(wx, wy, 0, -2, SHELL_BULLET);
498 if g_Game_IsNet then
499 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL1);
500 end;
501 end;
503 TRIGGER_SHOT_SHOTGUN:
504 begin
505 g_Weapon_Shotgun(wx, wy, dx, dy, 0, True);
506 snd := 'SOUND_WEAPON_FIRESHOTGUN';
507 Projectile := False;
508 if ShotSound then
509 begin
510 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
511 if g_Game_IsNet then
512 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL2);
513 end;
514 end;
516 TRIGGER_SHOT_SSG:
517 begin
518 g_Weapon_DShotgun(wx, wy, dx, dy, 0, True);
519 snd := 'SOUND_WEAPON_FIRESHOTGUN2';
520 Projectile := False;
521 if ShotSound then
522 begin
523 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
524 g_Player_CreateShell(wx, wy, 0, -2, SHELL_SHELL);
525 if g_Game_IsNet then
526 MH_SEND_Effect(wx, wy, 0, NET_GFX_SHELL3);
527 end;
528 end;
530 TRIGGER_SHOT_IMP:
531 begin
532 g_Weapon_ball1(wx, wy, dx, dy, 0, -1, True);
533 snd := 'SOUND_WEAPON_FIREBALL';
534 end;
536 TRIGGER_SHOT_PLASMA:
537 begin
538 g_Weapon_Plasma(wx, wy, dx, dy, 0, -1, True);
539 snd := 'SOUND_WEAPON_FIREPLASMA';
540 end;
542 TRIGGER_SHOT_SPIDER:
543 begin
544 g_Weapon_aplasma(wx, wy, dx, dy, 0, -1, True);
545 snd := 'SOUND_WEAPON_FIREPLASMA';
546 end;
548 TRIGGER_SHOT_CACO:
549 begin
550 g_Weapon_ball2(wx, wy, dx, dy, 0, -1, True);
551 snd := 'SOUND_WEAPON_FIREBALL';
552 end;
554 TRIGGER_SHOT_BARON:
555 begin
556 g_Weapon_ball7(wx, wy, dx, dy, 0, -1, True);
557 snd := 'SOUND_WEAPON_FIREBALL';
558 end;
560 TRIGGER_SHOT_MANCUB:
561 begin
562 g_Weapon_manfire(wx, wy, dx, dy, 0, -1, True);
563 snd := 'SOUND_WEAPON_FIREBALL';
564 end;
566 TRIGGER_SHOT_REV:
567 begin
568 g_Weapon_revf(wx, wy, dx, dy, 0, ShotTarget, -1, True);
569 snd := 'SOUND_WEAPON_FIREREV';
570 end;
572 TRIGGER_SHOT_ROCKET:
573 begin
574 g_Weapon_Rocket(wx, wy, dx, dy, 0, -1, True);
575 snd := 'SOUND_WEAPON_FIREROCKET';
576 end;
578 TRIGGER_SHOT_BFG:
579 begin
580 g_Weapon_BFGShot(wx, wy, dx, dy, 0, -1, True);
581 snd := 'SOUND_WEAPON_FIREBFG';
582 end;
584 TRIGGER_SHOT_EXPL:
585 begin
586 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_ROCKET') then
587 begin
588 Anim := TAnimation.Create(TextureID, False, 6);
589 Anim.Blending := False;
590 g_GFX_OnceAnim(wx-64, wy-64, Anim);
591 Anim.Free();
592 end;
593 Projectile := False;
594 g_Weapon_Explode(wx, wy, 60, 0);
595 snd := 'SOUND_WEAPON_EXPLODEROCKET';
596 end;
598 TRIGGER_SHOT_BFGEXPL:
599 begin
600 if g_Frames_Get(TextureID, 'FRAMES_EXPLODE_BFG') then
601 begin
602 Anim := TAnimation.Create(TextureID, False, 6);
603 Anim.Blending := False;
604 g_GFX_OnceAnim(wx-64, wy-64, Anim);
605 Anim.Free();
606 end;
607 Projectile := False;
608 g_Weapon_BFG9000(wx, wy, 0);
609 snd := 'SOUND_WEAPON_EXPLODEBFG';
610 end;
612 else exit;
613 end;
615 if g_Game_IsNet and g_Game_IsServer then
616 case ShotType of
617 TRIGGER_SHOT_EXPL:
618 MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_EXPLODE);
619 TRIGGER_SHOT_BFGEXPL:
620 MH_SEND_Effect(wx, wy, Byte(ShotSound), NET_GFX_BFGEXPL);
621 else
622 begin
623 if Projectile then
624 MH_SEND_CreateShot(LastShotID);
625 if ShotSound then
626 MH_SEND_Sound(wx, wy, snd);
627 end;
628 end;
630 if ShotSound then
631 g_Sound_PlayExAt(snd, wx, wy);
633 if Projectile then
634 Result := LastShotID;
635 end;
637 procedure MakeShot(var Trigger: TTrigger; wx, wy, dx, dy: Integer; TargetUID: Word);
638 begin
639 with Trigger do
640 if (trigData.trigShotAmmo = 0) or
641 ((trigData.trigShotAmmo > 0) and (ShotAmmoCount > 0)) then
642 begin
643 if (trigShotPanelID <> -1) and (ShotPanelTime = 0) then
644 begin
645 g_Map_SwitchTexture(ShotPanelType, trigShotPanelID);
646 ShotPanelTime := 4; // òèêîâ íà âñïûøêó âûñòðåëà
647 end;
649 if trigData.trigShotIntSight > 0 then
650 ShotSightTimeout := 180; // ~= 5 ñåêóíä
652 if ShotAmmoCount > 0 then Dec(ShotAmmoCount);
654 dx := dx + Random(trigData.trigShotAccuracy) - Random(trigData.trigShotAccuracy);
655 dy := dy + Random(trigData.trigShotAccuracy) - Random(trigData.trigShotAccuracy);
657 tr_SpawnShot(trigData.trigShotType, wx, wy, dx, dy, trigData.trigShotSound, TargetUID);
658 end
659 else
660 if (trigData.trigShotIntReload > 0) and (ShotReloadTime = 0) then
661 ShotReloadTime := trigData.trigShotIntReload; // òèêîâ íà ïåðåçàðÿäêó ïóøêè
662 end;
664 procedure tr_MakeEffect(X, Y, VX, VY: Integer; T, ST, CR, CG, CB: Byte; Silent, Send: Boolean);
665 var
666 FramesID: DWORD;
667 Anim: TAnimation;
668 begin
669 if T = TRIGGER_EFFECT_PARTICLE then
670 case ST of
671 TRIGGER_EFFECT_SLIQUID:
672 begin
673 if (CR = 255) and (CG = 0) and (CB = 0) then
674 g_GFX_SimpleWater(X, Y, 1, VX, VY, 1, 0, 0, 0)
675 else if (CR = 0) and (CG = 255) and (CB = 0) then
676 g_GFX_SimpleWater(X, Y, 1, VX, VY, 2, 0, 0, 0)
677 else if (CR = 0) and (CG = 0) and (CB = 255) then
678 g_GFX_SimpleWater(X, Y, 1, VX, VY, 3, 0, 0, 0)
679 else
680 g_GFX_SimpleWater(X, Y, 1, VX, VY, 0, 0, 0, 0);
681 end;
682 TRIGGER_EFFECT_LLIQUID:
683 g_GFX_SimpleWater(X, Y, 1, VX, VY, 4, CR, CG, CB);
684 TRIGGER_EFFECT_DLIQUID:
685 g_GFX_SimpleWater(X, Y, 1, VX, VY, 5, CR, CG, CB);
686 TRIGGER_EFFECT_BLOOD:
687 g_GFX_Blood(X, Y, 1, VX, VY, 0, 0, CR, CG, CB);
688 TRIGGER_EFFECT_SPARK:
689 g_GFX_Spark(X, Y, 1, GetAngle2(VX, VY), 0, 0);
690 TRIGGER_EFFECT_BUBBLE:
691 g_GFX_Bubbles(X, Y, 1, 0, 0);
692 end;
693 if T = TRIGGER_EFFECT_ANIMATION then
694 case ST of
695 EFFECT_TELEPORT: begin
696 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
697 begin
698 Anim := TAnimation.Create(FramesID, False, 3);
699 if not Silent then
700 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
701 g_GFX_OnceAnim(X-32, Y-32, Anim);
702 Anim.Free();
703 end;
704 if Send and g_Game_IsServer and g_Game_IsNet then
705 MH_SEND_Effect(X, Y, Byte(not Silent), NET_GFX_TELE);
706 end;
707 EFFECT_RESPAWN: begin
708 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
709 begin
710 Anim := TAnimation.Create(FramesID, False, 4);
711 if not Silent then
712 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
713 g_GFX_OnceAnim(X-16, Y-16, Anim);
714 Anim.Free();
715 end;
716 if Send and g_Game_IsServer and g_Game_IsNet then
717 MH_SEND_Effect(X-16, Y-16, Byte(not Silent), NET_GFX_RESPAWN);
718 end;
719 EFFECT_FIRE: begin
720 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
721 begin
722 Anim := TAnimation.Create(FramesID, False, 4);
723 if not Silent then
724 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
725 g_GFX_OnceAnim(X-32, Y-128, Anim);
726 Anim.Free();
727 end;
728 if Send and g_Game_IsServer and g_Game_IsNet then
729 MH_SEND_Effect(X-32, Y-128, Byte(not Silent), NET_GFX_FIRE);
730 end;
731 end;
732 end;
734 function tr_Teleport(ActivateUID: Integer; TX, TY: Integer; TDir: Integer; Silent: Boolean; D2D: Boolean): Boolean;
735 var
736 p: TPlayer;
737 m: TMonster;
738 begin
739 Result := False;
740 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
741 case g_GetUIDType(ActivateUID) of
742 UID_PLAYER:
743 begin
744 p := g_Player_Get(ActivateUID);
745 if p = nil then
746 Exit;
748 if D2D then
749 begin
750 if p.TeleportTo(TX-(p.Obj.Rect.Width div 2),
751 TY-p.Obj.Rect.Height,
752 Silent,
753 TDir) then
754 Result := True;
755 end
756 else
757 if p.TeleportTo(TX, TY, Silent, TDir) then
758 Result := True;
759 end;
761 UID_MONSTER:
762 begin
763 m := g_Monsters_ByUID(ActivateUID);
764 if m = nil then
765 Exit;
767 if D2D then
768 begin
769 if m.TeleportTo(TX-(m.Obj.Rect.Width div 2),
770 TY-m.Obj.Rect.Height,
771 Silent,
772 TDir) then
773 Result := True;
774 end
775 else
776 if m.TeleportTo(TX, TY, Silent, TDir) then
777 Result := True;
778 end;
779 end;
780 end;
782 function tr_Push(ActivateUID: Integer; VX, VY: Integer; ResetVel: Boolean): Boolean;
783 var
784 p: TPlayer;
785 m: TMonster;
786 begin
787 Result := True;
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
794 Exit;
796 if ResetVel then
797 begin
798 p.GameVelX := 0;
799 p.GameVelY := 0;
800 p.GameAccelX := 0;
801 p.GameAccelY := 0;
802 end;
804 p.Push(VX, VY);
805 end;
807 UID_MONSTER:
808 begin
809 m := g_Monsters_ByUID(ActivateUID);
810 if m = nil then
811 Exit;
813 if ResetVel then
814 begin
815 m.GameVelX := 0;
816 m.GameVelY := 0;
817 m.GameAccelX := 0;
818 m.GameAccelY := 0;
819 end;
821 m.Push(VX, VY);
822 end;
823 end;
824 end;
826 function tr_Message(MKind: Integer; MText: string; MSendTo: Integer; MTime: Integer; ActivateUID: Integer): Boolean;
827 var
828 msg: string;
829 p: TPlayer;
830 i: Integer;
831 begin
832 Result := True;
833 if (ActivateUID < 0) or (ActivateUID > $FFFF) then Exit;
834 msg := b_Text_Format(MText);
835 case MSendTo of
836 0: // activator
837 begin
838 if g_GetUIDType(ActivateUID) = UID_PLAYER then
839 begin
840 if g_Game_IsWatchedPlayer(ActivateUID) then
841 begin
842 if MKind = 0 then
843 g_Console_Add(msg, True)
844 else if MKind = 1 then
845 g_Game_Message(msg, MTime);
846 end
847 else
848 begin
849 p := g_Player_Get(ActivateUID);
850 if g_Game_IsNet and (p.FClientID >= 0) then
851 if MKind = 0 then
852 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, p.FClientID)
853 else if MKind = 1 then
854 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, p.FClientID);
855 end;
856 end;
857 end;
859 1: // activator's team
860 begin
861 if g_GetUIDType(ActivateUID) = UID_PLAYER then
862 begin
863 p := g_Player_Get(ActivateUID);
864 if g_Game_IsWatchedTeam(p.Team) then
865 if MKind = 0 then
866 g_Console_Add(msg, True)
867 else if MKind = 1 then
868 g_Game_Message(msg, MTime);
870 if g_Game_IsNet then
871 begin
872 for i := Low(gPlayers) to High(gPlayers) do
873 if (gPlayers[i].Team = p.Team) and (gPlayers[i].FClientID >= 0) then
874 if MKind = 0 then
875 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
876 else if MKind = 1 then
877 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
878 end;
879 end;
880 end;
882 2: // activator's enemy team
883 begin
884 if g_GetUIDType(ActivateUID) = UID_PLAYER then
885 begin
886 p := g_Player_Get(ActivateUID);
887 if g_Game_IsWatchedTeam(p.Team) then
888 if MKind = 0 then
889 g_Console_Add(msg, True)
890 else if MKind = 1 then
891 g_Game_Message(msg, MTime);
893 if g_Game_IsNet then
894 begin
895 for i := Low(gPlayers) to High(gPlayers) do
896 if (gPlayers[i].Team <> p.Team) and (gPlayers[i].FClientID >= 0) then
897 if MKind = 0 then
898 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
899 else if MKind = 1 then
900 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
901 end;
902 end;
903 end;
905 3: // red team
906 begin
907 if g_Game_IsWatchedTeam(TEAM_RED) then
908 if MKind = 0 then
909 g_Console_Add(msg, True)
910 else if MKind = 1 then
911 g_Game_Message(msg, MTime);
913 if g_Game_IsNet then
914 begin
915 for i := Low(gPlayers) to High(gPlayers) do
916 if (gPlayers[i].Team = TEAM_RED) and (gPlayers[i].FClientID >= 0) then
917 if MKind = 0 then
918 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
919 else if MKind = 1 then
920 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
921 end;
922 end;
924 4: // blue team
925 begin
926 if g_Game_IsWatchedTeam(TEAM_BLUE) then
927 if MKind = 0 then
928 g_Console_Add(msg, True)
929 else if MKind = 1 then
930 g_Game_Message(msg, MTime);
932 if g_Game_IsNet then
933 begin
934 for i := Low(gPlayers) to High(gPlayers) do
935 if (gPlayers[i].Team = TEAM_BLUE) and (gPlayers[i].FClientID >= 0) then
936 if MKind = 0 then
937 MH_SEND_Chat(msg, NET_CHAT_SYSTEM, gPlayers[i].FClientID)
938 else if MKind = 1 then
939 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg, gPlayers[i].FClientID);
940 end;
941 end;
943 5: // everyone
944 begin
945 if MKind = 0 then
946 g_Console_Add(msg, True)
947 else if MKind = 1 then
948 g_Game_Message(msg, MTime);
950 if g_Game_IsNet then
951 begin
952 if MKind = 0 then
953 MH_SEND_Chat(msg, NET_CHAT_SYSTEM)
954 else if MKind = 1 then
955 MH_SEND_GameEvent(NET_EV_BIGTEXT, MTime, msg);
956 end;
957 end;
958 end;
959 end;
961 function tr_ShotAimCheck(var Trigger: TTrigger; Obj: PObj): Boolean;
962 begin
963 result := false;
964 with Trigger do
965 begin
966 if TriggerType <> TRIGGER_SHOT then
967 Exit;
968 Result := (trigData.trigShotAim and TRIGGER_SHOT_AIM_ALLMAP > 0)
969 or g_Obj_Collide(X, Y, Width, Height, Obj);
970 if Result and (trigData.trigShotAim and TRIGGER_SHOT_AIM_TRACE > 0) then
971 Result := g_TraceVector(trigData.trigShotPos.X,
972 trigData.trigShotPos.Y,
973 Obj^.X + Obj^.Rect.X + (Obj^.Rect.Width div 2),
974 Obj^.Y + Obj^.Rect.Y + (Obj^.Rect.Height div 2));
975 end;
976 end;
978 function ActivateTrigger(var Trigger: TTrigger; actType: Byte): Boolean;
979 var
980 animonce: Boolean;
981 p: TPlayer;
982 m: TMonster;
983 idx, k, wx, wy, xd, yd: Integer;
984 iid: LongWord;
985 coolDown: Boolean;
986 pAngle: Real;
987 FramesID: DWORD;
988 Anim: TAnimation;
989 UIDType: Byte;
990 TargetUID: Word;
991 it: PItem;
992 mon: TMonster;
994 function monsShotTarget (mon: TMonster): Boolean;
995 begin
996 result := false; // don't stop
997 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
998 begin
999 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1000 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1001 TargetUID := mon.UID;
1002 result := true; // stop
1003 end;
1004 end;
1006 function monsShotTargetMonPlr (mon: TMonster): Boolean;
1007 begin
1008 result := false; // don't stop
1009 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1010 begin
1011 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1012 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1013 TargetUID := mon.UID;
1014 result := true; // stop
1015 end;
1016 end;
1018 function monShotTargetPlrMon (mon: TMonster): Boolean;
1019 begin
1020 result := false; // don't stop
1021 if mon.Live and tr_ShotAimCheck(Trigger, @(mon.Obj)) then
1022 begin
1023 xd := mon.GameX + mon.Obj.Rect.Width div 2;
1024 yd := mon.GameY + mon.Obj.Rect.Height div 2;
1025 TargetUID := mon.UID;
1026 result := true; // stop
1027 end;
1028 end;
1030 begin
1031 Result := False;
1032 if g_Game_IsClient then
1033 Exit;
1035 if not Trigger.Enabled then
1036 Exit;
1037 if (Trigger.TimeOut <> 0) and (actType <> ACTIVATE_CUSTOM) then
1038 Exit;
1039 if gLMSRespawn = LMS_RESPAWN_WARMUP then
1040 Exit;
1042 animonce := False;
1044 coolDown := (actType <> 0);
1046 with Trigger do
1047 begin
1048 case TriggerType of
1049 TRIGGER_EXIT:
1050 begin
1051 g_Sound_PlayEx('SOUND_GAME_SWITCH0');
1052 if g_Game_IsNet then MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH0');
1053 gExitByTrigger := True;
1054 g_Game_ExitLevel(trigData.trigMapName);
1055 TimeOut := 18;
1056 Result := True;
1058 Exit;
1059 end;
1061 TRIGGER_TELEPORT:
1062 begin
1063 Result := tr_Teleport(ActivateUID,
1064 trigData.trigTargetPoint.X, trigData.trigTargetPoint.Y,
1065 trigData.trigTlpDir, trigData.trigsilent_teleport,
1066 trigData.trigd2d_teleport);
1067 TimeOut := 0;
1068 end;
1070 TRIGGER_OPENDOOR:
1071 begin
1072 Result := tr_OpenDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1073 TimeOut := 0;
1074 end;
1076 TRIGGER_CLOSEDOOR:
1077 begin
1078 Result := tr_CloseDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1079 TimeOut := 0;
1080 end;
1082 TRIGGER_DOOR, TRIGGER_DOOR5:
1083 begin
1084 if trigPanelID <> -1 then
1085 begin
1086 if gWalls[trigPanelID].Enabled then
1087 begin
1088 Result := tr_OpenDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1090 if TriggerType = TRIGGER_DOOR5 then
1091 DoorTime := 180;
1092 end
1093 else
1094 Result := tr_CloseDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1096 if Result then
1097 TimeOut := 18;
1098 end;
1099 end;
1101 TRIGGER_CLOSETRAP, TRIGGER_TRAP:
1102 begin
1103 tr_CloseTrap(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
1105 if TriggerType = TRIGGER_TRAP then
1106 begin
1107 DoorTime := 40;
1108 TimeOut := 76;
1109 end
1110 else
1111 begin
1112 DoorTime := -1;
1113 TimeOut := 0;
1114 end;
1116 Result := True;
1117 end;
1119 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF:
1120 begin
1121 PressCount := PressCount + 1;
1123 if PressTime = -1 then
1124 PressTime := trigData.trigWait;
1126 if coolDown then
1127 TimeOut := 18
1128 else
1129 TimeOut := 0;
1130 Result := True;
1131 end;
1133 TRIGGER_SECRET:
1134 if g_GetUIDType(ActivateUID) = UID_PLAYER then
1135 begin
1136 Enabled := False;
1137 Result := True;
1138 if gLMSRespawn = LMS_RESPAWN_NONE then
1139 begin
1140 g_Player_Get(ActivateUID).GetSecret();
1141 Inc(gCoopSecretsFound);
1142 if g_Game_IsNet then MH_SEND_GameStats();
1143 end;
1144 end;
1146 TRIGGER_LIFTUP:
1147 begin
1148 Result := tr_SetLift(trigPanelID, 0, trigData.trigNoSound, trigData.trigd2d_doors);
1149 TimeOut := 0;
1151 if (not trigData.trigNoSound) and Result then begin
1152 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1153 X + (Width div 2),
1154 Y + (Height div 2));
1155 if g_Game_IsServer and g_Game_IsNet then
1156 MH_SEND_Sound(X + (Width div 2),
1157 Y + (Height div 2),
1158 'SOUND_GAME_SWITCH0');
1159 end;
1160 end;
1162 TRIGGER_LIFTDOWN:
1163 begin
1164 Result := tr_SetLift(trigPanelID, 1, trigData.trigNoSound, trigData.trigd2d_doors);
1165 TimeOut := 0;
1167 if (not trigData.trigNoSound) and Result then begin
1168 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1169 X + (Width div 2),
1170 Y + (Height div 2));
1171 if g_Game_IsServer and g_Game_IsNet then
1172 MH_SEND_Sound(X + (Width div 2),
1173 Y + (Height div 2),
1174 'SOUND_GAME_SWITCH0');
1175 end;
1176 end;
1178 TRIGGER_LIFT:
1179 begin
1180 Result := tr_SetLift(trigPanelID, 3, trigData.trigNoSound, trigData.trigd2d_doors);
1182 if Result then
1183 begin
1184 TimeOut := 18;
1186 if (not trigData.trigNoSound) and Result then begin
1187 g_Sound_PlayExAt('SOUND_GAME_SWITCH0',
1188 X + (Width div 2),
1189 Y + (Height div 2));
1190 if g_Game_IsServer and g_Game_IsNet then
1191 MH_SEND_Sound(X + (Width div 2),
1192 Y + (Height div 2),
1193 'SOUND_GAME_SWITCH0');
1194 end;
1195 end;
1196 end;
1198 TRIGGER_TEXTURE:
1199 begin
1200 if trigData.trigActivateOnce then
1201 begin
1202 Enabled := False;
1203 TriggerType := TRIGGER_NONE;
1204 end
1205 else
1206 if coolDown then
1207 TimeOut := 6
1208 else
1209 TimeOut := 0;
1211 animonce := trigData.trigAnimOnce;
1212 Result := True;
1213 end;
1215 TRIGGER_SOUND:
1216 begin
1217 if Sound <> nil then
1218 begin
1219 if trigData.trigSoundSwitch and Sound.IsPlaying() then
1220 begin // Íóæíî âûêëþ÷èòü, åñëè èãðàë
1221 Sound.Stop();
1222 SoundPlayCount := 0;
1223 Result := True;
1224 end
1225 else // (not Data.SoundSwitch) or (not Sound.IsPlaying())
1226 if (trigData.trigPlayCount > 0) or (not Sound.IsPlaying()) then
1227 begin
1228 if trigData.trigPlayCount > 0 then
1229 SoundPlayCount := trigData.trigPlayCount
1230 else // 0 - èãðàåì áåñêîíå÷íî
1231 SoundPlayCount := 1;
1232 Result := True;
1233 end;
1234 if g_Game_IsNet then MH_SEND_TriggerSound(Trigger);
1235 end;
1236 end;
1238 TRIGGER_SPAWNMONSTER:
1239 if (trigData.trigMonType in [MONSTER_DEMON..MONSTER_MAN]) then
1240 begin
1241 Result := False;
1242 if (trigData.trigMonDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1243 begin
1244 AutoSpawn := not AutoSpawn;
1245 SpawnCooldown := 0;
1246 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1247 Result := True;
1248 end;
1250 if ((trigData.trigMonDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1251 or ((trigData.trigMonDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1252 for k := 1 to trigData.trigMonCount do
1253 begin
1254 if (actType = ACTIVATE_CUSTOM) and (trigData.trigMonDelay > 0) then
1255 SpawnCooldown := trigData.trigMonDelay;
1256 if (trigData.trigMonMax > 0) and (SpawnedCount >= trigData.trigMonMax) then
1257 Break;
1259 mon := g_Monsters_Create(trigData.trigMonType,
1260 trigData.trigMonPos.X, trigData.trigMonPos.Y,
1261 TDirection(trigData.trigMonDir), True);
1263 Result := True;
1265 // Çäîðîâüå:
1266 if (trigData.trigMonHealth > 0) then
1267 mon.SetHealth(trigData.trigMonHealth);
1268 // Óñòàíàâëèâàåì ïîâåäåíèå:
1269 mon.MonsterBehaviour := trigData.trigMonBehav;
1270 mon.FNoRespawn := True;
1271 if g_Game_IsNet then
1272 MH_SEND_MonsterSpawn(mon.UID);
1273 // Èäåì èñêàòü öåëü, åñëè íàäî:
1274 if trigData.trigMonActive then
1275 mon.WakeUp();
1277 if trigData.trigMonType <> MONSTER_BARREL then Inc(gTotalMonsters);
1279 if g_Game_IsNet then
1280 begin
1281 SetLength(gMonstersSpawned, Length(gMonstersSpawned)+1);
1282 gMonstersSpawned[High(gMonstersSpawned)] := mon.UID;
1283 end;
1285 if trigData.trigMonMax > 0 then
1286 begin
1287 mon.SpawnTrigger := ID;
1288 Inc(SpawnedCount);
1289 end;
1291 case trigData.trigMonEffect of
1292 EFFECT_TELEPORT: begin
1293 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1294 begin
1295 Anim := TAnimation.Create(FramesID, False, 3);
1296 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1297 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1298 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, Anim);
1299 Anim.Free();
1300 end;
1301 if g_Game_IsServer and g_Game_IsNet then
1302 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1303 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-32, 1,
1304 NET_GFX_TELE);
1305 end;
1306 EFFECT_RESPAWN: begin
1307 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1308 begin
1309 Anim := TAnimation.Create(FramesID, False, 4);
1310 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1311 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1312 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, Anim);
1313 Anim.Free();
1314 end;
1315 if g_Game_IsServer and g_Game_IsNet then
1316 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-16,
1317 mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2)-16, 1,
1318 NET_GFX_RESPAWN);
1319 end;
1320 EFFECT_FIRE: begin
1321 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1322 begin
1323 Anim := TAnimation.Create(FramesID, False, 4);
1324 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigMonPos.X, trigData.trigMonPos.Y);
1325 g_GFX_OnceAnim(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1326 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, Anim);
1327 Anim.Free();
1328 end;
1329 if g_Game_IsServer and g_Game_IsNet then
1330 MH_SEND_Effect(mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2)-32,
1331 mon.Obj.Y+mon.Obj.Rect.Y+mon.Obj.Rect.Height-128, 1,
1332 NET_GFX_FIRE);
1333 end;
1334 end;
1335 end;
1336 if g_Game_IsNet then
1337 begin
1338 MH_SEND_GameStats();
1339 MH_SEND_CoopStats();
1340 end;
1342 if coolDown then
1343 TimeOut := 18
1344 else
1345 TimeOut := 0;
1346 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1347 if actType = ACTIVATE_CUSTOM then
1348 Result := False;
1349 end;
1351 TRIGGER_SPAWNITEM:
1352 if (trigData.trigItemType in [ITEM_MEDKIT_SMALL..ITEM_MAX]) then
1353 begin
1354 Result := False;
1355 if (trigData.trigItemDelay > 0) and (actType <> ACTIVATE_CUSTOM) then
1356 begin
1357 AutoSpawn := not AutoSpawn;
1358 SpawnCooldown := 0;
1359 // Àâòîñïàâíåð ïåðåêëþ÷åí - ìåíÿåì òåêñòóðó
1360 Result := True;
1361 end;
1363 if ((trigData.trigItemDelay = 0) and (actType <> ACTIVATE_CUSTOM))
1364 or ((trigData.trigItemDelay > 0) and (actType = ACTIVATE_CUSTOM)) then
1365 if (not trigData.trigItemOnlyDM) or
1366 (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
1367 for k := 1 to trigData.trigItemCount do
1368 begin
1369 if (actType = ACTIVATE_CUSTOM) and (trigData.trigItemDelay > 0) then
1370 SpawnCooldown := trigData.trigItemDelay;
1371 if (trigData.trigItemMax > 0) and (SpawnedCount >= trigData.trigItemMax) then
1372 Break;
1374 iid := g_Items_Create(trigData.trigItemPos.X, trigData.trigItemPos.Y,
1375 trigData.trigItemType, trigData.trigItemFalls, False, True);
1377 Result := True;
1379 if trigData.trigItemMax > 0 then
1380 begin
1381 it := g_Items_ByIdx(iid);
1382 it.SpawnTrigger := ID;
1383 Inc(SpawnedCount);
1384 end;
1386 case trigData.trigItemEffect of
1387 EFFECT_TELEPORT: begin
1388 it := g_Items_ByIdx(iid);
1389 if g_Frames_Get(FramesID, 'FRAMES_TELEPORT') then
1390 begin
1391 Anim := TAnimation.Create(FramesID, False, 3);
1392 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1393 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1394 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, Anim);
1395 Anim.Free();
1396 end;
1397 if g_Game_IsServer and g_Game_IsNet then
1398 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1399 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-32, 1,
1400 NET_GFX_TELE);
1401 end;
1402 EFFECT_RESPAWN: begin
1403 it := g_Items_ByIdx(iid);
1404 if g_Frames_Get(FramesID, 'FRAMES_ITEM_RESPAWN') then
1405 begin
1406 Anim := TAnimation.Create(FramesID, False, 4);
1407 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1408 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1409 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, Anim);
1410 Anim.Free();
1411 end;
1412 if g_Game_IsServer and g_Game_IsNet then
1413 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-16,
1414 it.Obj.Y+it.Obj.Rect.Y+(it.Obj.Rect.Height div 2)-16, 1,
1415 NET_GFX_RESPAWN);
1416 end;
1417 EFFECT_FIRE: begin
1418 it := g_Items_ByIdx(iid);
1419 if g_Frames_Get(FramesID, 'FRAMES_FIRE') then
1420 begin
1421 Anim := TAnimation.Create(FramesID, False, 4);
1422 g_Sound_PlayExAt('SOUND_FIRE', trigData.trigItemPos.X, trigData.trigItemPos.Y);
1423 g_GFX_OnceAnim(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1424 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, Anim);
1425 Anim.Free();
1426 end;
1427 if g_Game_IsServer and g_Game_IsNet then
1428 MH_SEND_Effect(it.Obj.X+it.Obj.Rect.X+(it.Obj.Rect.Width div 2)-32,
1429 it.Obj.Y+it.Obj.Rect.Y+it.Obj.Rect.Height-128, 1,
1430 NET_GFX_FIRE);
1431 end;
1432 end;
1434 if g_Game_IsNet then
1435 MH_SEND_ItemSpawn(True, iid);
1436 end;
1438 if coolDown then
1439 TimeOut := 18
1440 else
1441 TimeOut := 0;
1442 // Åñëè àêòèâèðîâàí àâòîñïàâíåðîì, íå ìåíÿåì òåêñòóðó
1443 if actType = ACTIVATE_CUSTOM then
1444 Result := False;
1445 end;
1447 TRIGGER_MUSIC:
1448 begin
1449 // Ìåíÿåì ìóçûêó, åñëè åñòü íà ÷òî:
1450 if (Trigger.trigData.trigMusicName <> '') then
1451 begin
1452 gMusic.SetByName(Trigger.trigData.trigMusicName);
1453 gMusic.SpecPause := True;
1454 gMusic.Play();
1455 end;
1457 if Trigger.trigData.trigMusicAction = 1 then
1458 begin // Âêëþ÷èòü
1459 if gMusic.SpecPause then // Áûëà íà ïàóçå => èãðàòü
1460 gMusic.SpecPause := False
1461 else // Èãðàëà => ñíà÷àëà
1462 gMusic.SetPosition(0);
1463 end
1464 else // Âûêëþ÷èòü
1465 begin
1466 // Ïàóçà:
1467 gMusic.SpecPause := True;
1468 end;
1470 if coolDown then
1471 TimeOut := 36
1472 else
1473 TimeOut := 0;
1474 Result := True;
1475 if g_Game_IsNet then MH_SEND_TriggerMusic;
1476 end;
1478 TRIGGER_PUSH:
1479 begin
1480 pAngle := -DegToRad(trigData.trigPushAngle);
1481 Result := tr_Push(ActivateUID,
1482 Floor(Cos(pAngle)*trigData.trigPushForce),
1483 Floor(Sin(pAngle)*trigData.trigPushForce),
1484 trigData.trigResetVel);
1485 TimeOut := 0;
1486 end;
1488 TRIGGER_SCORE:
1489 begin
1490 Result := False;
1491 // Ïðèáàâèòü èëè îòíÿòü î÷êî
1492 if (trigData.trigScoreAction in [0..1]) and (trigData.trigScoreCount > 0) then
1493 begin
1494 // Ñâîåé èëè ÷óæîé êîìàíäå
1495 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1496 begin
1497 p := g_Player_Get(ActivateUID);
1498 if ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED))
1499 or ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1500 begin
1501 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1503 if trigData.trigScoreCon then
1504 if trigData.trigScoreTeam = 0 then
1505 begin
1506 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1507 if g_Game_IsServer and g_Game_IsNet then
1508 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+r');
1509 end else
1510 begin
1511 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1512 if g_Game_IsServer and g_Game_IsNet then
1513 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+re');
1514 end;
1516 if trigData.trigScoreMsg then
1517 begin
1518 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1519 if g_Game_IsServer and g_Game_IsNet then
1520 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1521 end;
1522 end;
1523 if ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED))
1524 or ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1525 begin
1526 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1528 if trigData.trigScoreCon then
1529 if trigData.trigScoreTeam = 0 then
1530 begin
1531 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1532 if g_Game_IsServer and g_Game_IsNet then
1533 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-r');
1534 end else
1535 begin
1536 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1537 if g_Game_IsServer and g_Game_IsNet then
1538 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-re');
1539 end;
1541 if trigData.trigScoreMsg then
1542 begin
1543 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1544 if g_Game_IsServer and g_Game_IsNet then
1545 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1546 end;
1547 end;
1548 if ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE))
1549 or ((trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1550 begin
1551 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1553 if trigData.trigScoreCon then
1554 if trigData.trigScoreTeam = 0 then
1555 begin
1556 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1557 if g_Game_IsServer and g_Game_IsNet then
1558 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+b');
1559 end else
1560 begin
1561 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1562 if g_Game_IsServer and g_Game_IsNet then
1563 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '+be');
1564 end;
1566 if trigData.trigScoreMsg then
1567 begin
1568 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1569 if g_Game_IsServer and g_Game_IsNet then
1570 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1571 end;
1572 end;
1573 if ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE))
1574 or ((trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1575 begin
1576 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1578 if trigData.trigScoreCon then
1579 if trigData.trigScoreTeam = 0 then
1580 begin
1581 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_OWN], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1582 if g_Game_IsServer and g_Game_IsNet then
1583 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-b');
1584 end else
1585 begin
1586 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_ENEMY], [p.Name, trigData.trigScoreCount, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1587 if g_Game_IsServer and g_Game_IsNet then
1588 MH_SEND_GameEvent(NET_EV_SCORE, p.UID or (trigData.trigScoreCount shl 16), '-be');
1589 end;
1591 if trigData.trigScoreMsg then
1592 begin
1593 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1594 if g_Game_IsServer and g_Game_IsNet then
1595 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1596 end;
1597 end;
1598 Result := (p.Team = TEAM_RED) or (p.Team = TEAM_BLUE);
1599 end;
1600 // Êàêîé-òî êîíêðåòíîé êîìàíäå
1601 if trigData.trigScoreTeam in [2..3] then
1602 begin
1603 if (trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 2) then
1604 begin
1605 Inc(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Scores
1607 if trigData.trigScoreCon then
1608 begin
1609 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1610 if g_Game_IsServer and g_Game_IsNet then
1611 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tr');
1612 end;
1614 if trigData.trigScoreMsg then
1615 begin
1616 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1617 if g_Game_IsServer and g_Game_IsNet then
1618 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_RED);
1619 end;
1620 end;
1621 if (trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 2) then
1622 begin
1623 Dec(gTeamStat[TEAM_RED].Goals, trigData.trigScoreCount); // Red Fouls
1625 if trigData.trigScoreCon then
1626 begin
1627 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_RED], trigData.trigScoreCount]), True);
1628 if g_Game_IsServer and g_Game_IsNet then
1629 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tr');
1630 end;
1632 if trigData.trigScoreMsg then
1633 begin
1634 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1635 if g_Game_IsServer and g_Game_IsNet then
1636 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_RED);
1637 end;
1638 end;
1639 if (trigData.trigScoreAction = 0) and (trigData.trigScoreTeam = 3) then
1640 begin
1641 Inc(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Scores
1643 if trigData.trigScoreCon then
1644 begin
1645 g_Console_Add(Format(_lc[I_PLAYER_SCORE_ADD_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1646 if g_Game_IsServer and g_Game_IsNet then
1647 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '+tb');
1648 end;
1650 if trigData.trigScoreMsg then
1651 begin
1652 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1653 if g_Game_IsServer and g_Game_IsNet then
1654 MH_SEND_GameEvent(NET_EV_SCORE_MSG, TEAM_BLUE);
1655 end;
1656 end;
1657 if (trigData.trigScoreAction = 1) and (trigData.trigScoreTeam = 3) then
1658 begin
1659 Dec(gTeamStat[TEAM_BLUE].Goals, trigData.trigScoreCount); // Blue Fouls
1661 if trigData.trigScoreCon then
1662 begin
1663 g_Console_Add(Format(_lc[I_PLAYER_SCORE_SUB_TEAM], [_lc[I_PLAYER_SCORE_BLUE], trigData.trigScoreCount]), True);
1664 if g_Game_IsServer and g_Game_IsNet then
1665 MH_SEND_GameEvent(NET_EV_SCORE, trigData.trigScoreCount shl 16, '-tb');
1666 end;
1668 if trigData.trigScoreMsg then
1669 begin
1670 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1671 if g_Game_IsServer and g_Game_IsNet then
1672 MH_SEND_GameEvent(NET_EV_SCORE_MSG, -TEAM_BLUE);
1673 end;
1674 end;
1675 Result := True;
1676 end;
1677 end;
1678 // Âûèãðûø
1679 if (trigData.trigScoreAction = 2) and (gGameSettings.GoalLimit > 0) then
1680 begin
1681 // Ñâîåé èëè ÷óæîé êîìàíäû
1682 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1683 begin
1684 p := g_Player_Get(ActivateUID);
1685 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED)) // Red Wins
1686 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1687 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1688 begin
1689 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1691 if trigData.trigScoreCon then
1692 if trigData.trigScoreTeam = 0 then
1693 begin
1694 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1695 if g_Game_IsServer and g_Game_IsNet then
1696 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1697 end else
1698 begin
1699 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1700 if g_Game_IsServer and g_Game_IsNet then
1701 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1702 end;
1704 Result := True;
1705 end;
1706 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE)) // Blue Wins
1707 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1708 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1709 begin
1710 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1712 if trigData.trigScoreCon then
1713 if trigData.trigScoreTeam = 0 then
1714 begin
1715 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1716 if g_Game_IsServer and g_Game_IsNet then
1717 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1718 end else
1719 begin
1720 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1721 if g_Game_IsServer and g_Game_IsNet then
1722 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1723 end;
1725 Result := True;
1726 end;
1727 end;
1728 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1729 if trigData.trigScoreTeam in [2..3] then
1730 begin
1731 if trigData.trigScoreTeam = 2 then // Red Wins
1732 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1733 begin
1734 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1735 Result := True;
1736 end;
1737 if trigData.trigScoreTeam = 3 then // Blue Wins
1738 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1739 begin
1740 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1741 Result := True;
1742 end;
1743 end;
1744 end;
1745 // Ïðîèãðûø
1746 if (trigData.trigScoreAction = 3) and (gGameSettings.GoalLimit > 0) then
1747 begin
1748 // Ñâîåé èëè ÷óæîé êîìàíäû
1749 if (trigData.trigScoreTeam in [0..1]) and (g_GetUIDType(ActivateUID) = UID_PLAYER) then
1750 begin
1751 p := g_Player_Get(ActivateUID);
1752 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_BLUE)) // Red Wins
1753 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_RED)) then
1754 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1755 begin
1756 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1758 if trigData.trigScoreCon then
1759 if trigData.trigScoreTeam = 0 then
1760 begin
1761 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1762 if g_Game_IsServer and g_Game_IsNet then
1763 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wre');
1764 end else
1765 begin
1766 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_RED]]), True);
1767 if g_Game_IsServer and g_Game_IsNet then
1768 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wr');
1769 end;
1771 Result := True;
1772 end;
1773 if ((trigData.trigScoreTeam = 0) and (p.Team = TEAM_RED)) // Blue Wins
1774 or ((trigData.trigScoreTeam = 1) and (p.Team = TEAM_BLUE)) then
1775 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1776 begin
1777 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1779 if trigData.trigScoreCon then
1780 if trigData.trigScoreTeam = 0 then
1781 begin
1782 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_ENEMY], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1783 if g_Game_IsServer and g_Game_IsNet then
1784 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wbe');
1785 end else
1786 begin
1787 g_Console_Add(Format(_lc[I_PLAYER_SCORE_WIN_OWN], [p.Name, _lc[I_PLAYER_SCORE_TO_BLUE]]), True);
1788 if g_Game_IsServer and g_Game_IsNet then
1789 MH_SEND_GameEvent(NET_EV_SCORE, p.UID, 'wb');
1790 end;
1792 Result := True;
1793 end;
1794 end;
1795 // Êàêîé-òî êîíêðåòíîé êîìàíäû
1796 if trigData.trigScoreTeam in [2..3] then
1797 begin
1798 if trigData.trigScoreTeam = 3 then // Red Wins
1799 if gTeamStat[TEAM_RED].Goals < SmallInt(gGameSettings.GoalLimit) then
1800 begin
1801 gTeamStat[TEAM_RED].Goals := gGameSettings.GoalLimit;
1802 Result := True;
1803 end;
1804 if trigData.trigScoreTeam = 2 then // Blue Wins
1805 if gTeamStat[TEAM_BLUE].Goals < SmallInt(gGameSettings.GoalLimit) then
1806 begin
1807 gTeamStat[TEAM_BLUE].Goals := gGameSettings.GoalLimit;
1808 Result := True;
1809 end;
1810 end;
1811 end;
1812 if Result then begin
1813 if coolDown then
1814 TimeOut := 18
1815 else
1816 TimeOut := 0;
1817 if g_Game_IsServer and g_Game_IsNet then
1818 MH_SEND_GameStats;
1819 end;
1820 end;
1822 TRIGGER_MESSAGE:
1823 begin
1824 Result := tr_Message(trigData.trigMessageKind, trigData.trigMessageText,
1825 trigData.trigMessageSendTo, trigData.trigMessageTime,
1826 ActivateUID);
1827 TimeOut := 18;
1828 end;
1830 TRIGGER_DAMAGE, TRIGGER_HEALTH:
1831 begin
1832 Result := False;
1833 UIDType := g_GetUIDType(ActivateUID);
1834 if (UIDType = UID_PLAYER) or (UIDType = UID_MONSTER) then
1835 begin
1836 Result := True;
1837 k := -1;
1838 if coolDown then
1839 begin
1840 // Âñïîìèíàåì, àêòèâèðîâàë ëè îí ìåíÿ ðàíüøå
1841 for idx := 0 to High(Activators) do
1842 if Activators[idx].UID = ActivateUID then
1843 begin
1844 k := idx;
1845 Break;
1846 end;
1847 if k = -1 then
1848 begin // Âèäèì åãî âïåðâûå
1849 // Çàïîìèíàåì åãî
1850 SetLength(Activators, Length(Activators) + 1);
1851 k := High(Activators);
1852 Activators[k].UID := ActivateUID;
1853 end else
1854 begin // Óæå âèäåëè åãî
1855 // Åñëè èíòåðâàë îòêëþ÷¸í, íî îí âñ¸ åù¸ â çîíå ïîðàæåíèÿ, äà¸ì åìó âðåìÿ
1856 if (trigData.trigDamageInterval = 0) and (Activators[k].TimeOut > 0) then
1857 Activators[k].TimeOut := 65535;
1858 // Òàéìàóò ïðîø¸ë - ðàáîòàåì
1859 Result := Activators[k].TimeOut = 0;
1860 end;
1861 end;
1863 if Result then
1864 begin
1865 case UIDType of
1866 UID_PLAYER:
1867 begin
1868 p := g_Player_Get(ActivateUID);
1869 if p = nil then
1870 Exit;
1872 // Íàíîñèì óðîí èãðîêó
1873 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigDamageValue > 0) then
1874 p.Damage(trigData.trigDamageValue, 0, 0, 0, HIT_SOME);
1876 // Ëå÷èì èãðîêà
1877 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigHealValue > 0) then
1878 if p.Heal(trigData.trigHealValue, not trigData.trigHealMax) and (not trigData.trigHealSilent) then
1879 begin
1880 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', p.Obj.X, p.Obj.Y);
1881 if g_Game_IsServer and g_Game_IsNet then
1882 MH_SEND_Sound(p.Obj.X, p.Obj.Y, 'SOUND_ITEM_GETITEM');
1883 end;
1884 end;
1886 UID_MONSTER:
1887 begin
1888 m := g_Monsters_ByUID(ActivateUID);
1889 if m = nil then
1890 Exit;
1892 // Íàíîñèì óðîí ìîíñòðó
1893 if (TriggerType = TRIGGER_DAMAGE) and (trigData.trigDamageValue > 0) then
1894 m.Damage(trigData.trigDamageValue, 0, 0, 0, HIT_SOME);
1896 // Ëå÷èì ìîíñòðà
1897 if (TriggerType = TRIGGER_HEALTH) and (trigData.trigHealValue > 0) then
1898 if m.Heal(trigData.trigHealValue) and (not trigData.trigHealSilent) then
1899 begin
1900 g_Sound_PlayExAt('SOUND_ITEM_GETITEM', m.Obj.X, m.Obj.Y);
1901 if g_Game_IsServer and g_Game_IsNet then
1902 MH_SEND_Sound(m.Obj.X, m.Obj.Y, 'SOUND_ITEM_GETITEM');
1903 end;
1904 end;
1905 end;
1906 // Íàçíà÷àåì âðåìÿ ñëåäóþùåãî âîçäåéñòâèÿ
1907 if TriggerType = TRIGGER_DAMAGE then
1908 idx := trigData.trigDamageInterval
1909 else
1910 idx := trigData.trigHealInterval;
1911 if coolDown then
1912 if idx > 0 then
1913 Activators[k].TimeOut := idx
1914 else
1915 Activators[k].TimeOut := 65535;
1916 end;
1917 end;
1918 TimeOut := 0;
1919 end;
1921 TRIGGER_SHOT:
1922 begin
1923 if ShotSightTime > 0 then
1924 Exit;
1926 // put this at the beginning so it doesn't trigger itself
1927 TimeOut := trigData.trigShotWait + 1;
1929 wx := trigData.trigShotPos.X;
1930 wy := trigData.trigShotPos.Y;
1931 pAngle := -DegToRad(trigData.trigShotAngle);
1932 xd := wx + Round(Cos(pAngle) * 32.0);
1933 yd := wy + Round(Sin(pAngle) * 32.0);
1934 TargetUID := 0;
1936 case trigData.trigShotTarget of
1937 TRIGGER_SHOT_TARGET_MON: // monsters
1938 //TODO: accelerate this!
1939 g_Mons_ForEachAlive(monsShotTarget);
1941 TRIGGER_SHOT_TARGET_PLR: // players
1942 if gPlayers <> nil then
1943 for idx := Low(gPlayers) to High(gPlayers) do
1944 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1945 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1946 begin
1947 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1948 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1949 TargetUID := gPlayers[idx].UID;
1950 break;
1951 end;
1953 TRIGGER_SHOT_TARGET_RED: // red team
1954 if gPlayers <> nil then
1955 for idx := Low(gPlayers) to High(gPlayers) do
1956 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1957 (gPlayers[idx].Team = TEAM_RED) and
1958 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1959 begin
1960 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1961 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1962 TargetUID := gPlayers[idx].UID;
1963 break;
1964 end;
1966 TRIGGER_SHOT_TARGET_BLUE: // blue team
1967 if gPlayers <> nil then
1968 for idx := Low(gPlayers) to High(gPlayers) do
1969 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1970 (gPlayers[idx].Team = TEAM_BLUE) and
1971 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1972 begin
1973 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1974 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1975 TargetUID := gPlayers[idx].UID;
1976 break;
1977 end;
1979 TRIGGER_SHOT_TARGET_MONPLR: // monsters then players
1980 begin
1981 //TODO: accelerate this!
1982 g_Mons_ForEachAlive(monsShotTargetMonPlr);
1984 if (TargetUID = 0) and (gPlayers <> nil) then
1985 for idx := Low(gPlayers) to High(gPlayers) do
1986 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
1987 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
1988 begin
1989 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
1990 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
1991 TargetUID := gPlayers[idx].UID;
1992 break;
1993 end;
1994 end;
1996 TRIGGER_SHOT_TARGET_PLRMON: // players then monsters
1997 begin
1998 if gPlayers <> nil then
1999 for idx := Low(gPlayers) to High(gPlayers) do
2000 if (gPlayers[idx] <> nil) and gPlayers[idx].Live and
2001 tr_ShotAimCheck(Trigger, @(gPlayers[idx].Obj)) then
2002 begin
2003 xd := gPlayers[idx].GameX + PLAYER_RECT_CX;
2004 yd := gPlayers[idx].GameY + PLAYER_RECT_CY;
2005 TargetUID := gPlayers[idx].UID;
2006 break;
2007 end;
2008 if TargetUID = 0 then
2009 begin
2010 //TODO: accelerate this!
2011 g_Mons_ForEachAlive(monShotTargetPlrMon);
2012 end;
2013 end;
2015 else begin
2016 if (trigData.trigShotTarget <> TRIGGER_SHOT_TARGET_NONE) or
2017 (trigData.trigShotType <> TRIGGER_SHOT_REV) then
2018 TargetUID := ActivateUID;
2019 end;
2020 end;
2022 if (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or (TargetUID > 0) or
2023 ((trigData.trigShotTarget > TRIGGER_SHOT_TARGET_NONE) and (TargetUID = 0)) then
2024 begin
2025 Result := True;
2026 if (trigData.trigShotIntSight = 0) or
2027 (trigData.trigShotTarget = TRIGGER_SHOT_TARGET_NONE) or
2028 (TargetUID = ShotSightTarget) then
2029 MakeShot(Trigger, wx, wy, xd, yd, TargetUID)
2030 else
2031 begin
2032 ShotSightTime := trigData.trigShotIntSight;
2033 ShotSightTargetN := TargetUID;
2034 if trigData.trigShotType = TRIGGER_SHOT_BFG then
2035 begin
2036 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', wx, wy);
2037 if g_Game_IsNet and g_Game_IsServer then
2038 MH_SEND_Sound(wx, wy, 'SOUND_WEAPON_STARTFIREBFG');
2039 end;
2040 end;
2041 end;
2042 end;
2044 TRIGGER_EFFECT:
2045 begin
2046 idx := trigData.trigFXCount;
2048 while idx > 0 do
2049 begin
2050 case trigData.trigFXPos of
2051 TRIGGER_EFFECT_POS_CENTER:
2052 begin
2053 wx := X + Width div 2;
2054 wy := Y + Height div 2;
2055 end;
2056 TRIGGER_EFFECT_POS_AREA:
2057 begin
2058 wx := X + Random(Width);
2059 wy := Y + Random(Height);
2060 end;
2061 else begin
2062 wx := X + Width div 2;
2063 wy := Y + Height div 2;
2064 end;
2065 end;
2066 xd := trigData.trigFXVelX;
2067 yd := trigData.trigFXVelY;
2068 if trigData.trigFXSpreadL > 0 then xd := xd - Random(trigData.trigFXSpreadL + 1);
2069 if trigData.trigFXSpreadR > 0 then xd := xd + Random(trigData.trigFXSpreadR + 1);
2070 if trigData.trigFXSpreadU > 0 then yd := yd - Random(trigData.trigFXSpreadU + 1);
2071 if trigData.trigFXSpreadD > 0 then yd := yd + Random(trigData.trigFXSpreadD + 1);
2072 tr_MakeEffect(wx, wy, xd, yd,
2073 trigData.trigFXType, trigData.trigFXSubType,
2074 trigData.trigFXColorR, trigData.trigFXColorG, trigData.trigFXColorB, True, False);
2075 Dec(idx);
2076 end;
2077 TimeOut := trigData.trigFXWait;
2078 end;
2079 end;
2080 end;
2082 if Result and (Trigger.TexturePanel <> -1) then
2083 g_Map_SwitchTexture(Trigger.TexturePanelType, Trigger.TexturePanel, IfThen(animonce, 2, 1));
2084 end;
2086 function g_Triggers_Create(Trigger: TTrigger): DWORD;
2087 var
2088 find_id: DWORD;
2089 fn, mapw: String;
2090 begin
2091 // Íå ñîçäàâàòü âûõîä, åñëè èãðà áåç âûõîäà:
2092 if (Trigger.TriggerType = TRIGGER_EXIT) and
2093 (not LongBool(gGameSettings.Options and GAME_OPTION_ALLOWEXIT)) then
2094 Trigger.TriggerType := TRIGGER_NONE;
2096 // Åñëè ìîíñòðû çàïðåùåíû, îòìåíÿåì òðèããåð:
2097 if (Trigger.TriggerType = TRIGGER_SPAWNMONSTER) and
2098 (not LongBool(gGameSettings.Options and GAME_OPTION_MONSTERS)) and
2099 (gGameSettings.GameType <> GT_SINGLE) then
2100 Trigger.TriggerType := TRIGGER_NONE;
2102 // Ñ÷èòàåì êîëè÷åñòâî ñåêðåòîâ íà êàðòå:
2103 if Trigger.TriggerType = TRIGGER_SECRET then
2104 gSecretsCount := gSecretsCount + 1;
2106 find_id := FindTrigger();
2107 gTriggers[find_id] := Trigger;
2109 writeln('trigger #', find_id, ': pos=(', Trigger.x, ',', Trigger.y, ')-(', Trigger.width, 'x', Trigger.height, ')',
2110 '; TexturePanel=', Trigger.TexturePanel,
2111 '; TexturePanelType=', Trigger.TexturePanelType,
2112 '; ShotPanelType=', Trigger.ShotPanelType,
2113 '; TriggerType=', Trigger.TriggerType,
2114 '; ActivateType=', Trigger.ActivateType,
2115 '; Keys=', Trigger.Keys,
2116 '; trigPanelId=', Trigger.trigPanelId,
2117 '; trigShotPanelId=', Trigger.trigShotPanelId
2118 );
2120 with gTriggers[find_id] do
2121 begin
2122 ID := find_id;
2123 // if this type of trigger exists both on the client and on the server
2124 // use an uniform numeration
2125 if Trigger.TriggerType = TRIGGER_SOUND then
2126 begin
2127 Inc(gTriggerClientID);
2128 ClientID := gTriggerClientID;
2129 end
2130 else
2131 ClientID := 0;
2132 TimeOut := 0;
2133 ActivateUID := 0;
2134 PlayerCollide := False;
2135 DoorTime := -1;
2136 PressTime := -1;
2137 PressCount := 0;
2138 SoundPlayCount := 0;
2139 Sound := nil;
2140 AutoSpawn := False;
2141 SpawnCooldown := 0;
2142 SpawnedCount := 0;
2143 end;
2145 // Çàãðóæàåì çâóê, åñëè ýòî òðèããåð "Çâóê":
2146 if (Trigger.TriggerType = TRIGGER_SOUND) and
2147 (Trigger.trigData.trigSoundName <> '') then
2148 begin
2149 // Åùå íåò òàêîãî çâóêà:
2150 if not g_Sound_Exists(Trigger.trigData.trigSoundName) then
2151 begin
2152 fn := g_ExtractWadName(Trigger.trigData.trigSoundName);
2154 if fn = '' then
2155 begin // Çâóê â ôàéëå ñ êàðòîé
2156 mapw := g_ExtractWadName(gMapInfo.Map);
2157 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigSoundName);
2158 end
2159 else // Çâóê â îòäåëüíîì ôàéëå
2160 fn := GameDir + '/wads/' + Trigger.trigData.trigSoundName;
2162 if not g_Sound_CreateWADEx(Trigger.trigData.trigSoundName, fn) then
2163 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigSoundName]));
2164 end;
2166 // Ñîçäàåì îáúåêò çâóêà:
2167 with gTriggers[find_id] do
2168 begin
2169 Sound := TPlayableSound.Create();
2170 if not Sound.SetByName(Trigger.trigData.trigSoundName) then
2171 begin
2172 Sound.Free();
2173 Sound := nil;
2174 end;
2175 end;
2176 end;
2178 // Çàãðóæàåì ìóçûêó, åñëè ýòî òðèããåð "Ìóçûêà":
2179 if (Trigger.TriggerType = TRIGGER_MUSIC) and
2180 (Trigger.trigData.trigMusicName <> '') then
2181 begin
2182 // Åùå íåò òàêîé ìóçûêè:
2183 if not g_Sound_Exists(Trigger.trigData.trigMusicName) then
2184 begin
2185 fn := g_ExtractWadName(Trigger.trigData.trigMusicName);
2187 if fn = '' then
2188 begin // Ìóçûêà â ôàéëå ñ êàðòîé
2189 mapw := g_ExtractWadName(gMapInfo.Map);
2190 fn := mapw+':'+g_ExtractFilePathName(Trigger.trigData.trigMusicName);
2191 end
2192 else // Ìóçûêà â ôàéëå ñ êàðòîé
2193 fn := GameDir+'/wads/'+Trigger.trigData.trigMusicName;
2195 if not g_Sound_CreateWADEx(Trigger.trigData.trigMusicName, fn, True) then
2196 g_FatalError(Format(_lc[I_GAME_ERROR_TR_SOUND], [fn, Trigger.trigData.trigMusicName]));
2197 end;
2198 end;
2200 // Çàãðóæàåì äàííûå òðèããåðà "Òóðåëü":
2201 if Trigger.TriggerType = TRIGGER_SHOT then
2202 with gTriggers[find_id] do
2203 begin
2204 ShotPanelTime := 0;
2205 ShotSightTime := 0;
2206 ShotSightTimeout := 0;
2207 ShotSightTarget := 0;
2208 ShotSightTargetN := 0;
2209 ShotAmmoCount := Trigger.trigData.trigShotAmmo;
2210 ShotReloadTime := 0;
2211 end;
2213 Result := find_id;
2214 end;
2217 // sorry; grid doesn't support recursive queries, so we have to do this
2218 type
2219 TSimpleMonsterList = specialize TSimpleList<TMonster>;
2221 var
2222 tgMonsList: TSimpleMonsterList = nil;
2224 procedure g_Triggers_Update();
2225 var
2226 a, b, i: Integer;
2227 Affected: array of Integer;
2229 function monsNear (mon: TMonster): Boolean;
2230 begin
2231 result := false; // don't stop
2233 gTriggers[a].ActivateUID := mon.UID;
2234 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2236 tgMonsList.append(mon);
2237 end;
2239 var
2240 mon: TMonster;
2241 begin
2242 if (tgMonsList = nil) then tgMonsList := TSimpleMonsterList.Create();
2244 if gTriggers = nil then
2245 Exit;
2246 SetLength(Affected, 0);
2248 for a := 0 to High(gTriggers) do
2249 with gTriggers[a] do
2250 // Åñòü òðèããåð:
2251 if TriggerType <> TRIGGER_NONE then
2252 begin
2253 // Óìåíüøàåì âðåìÿ äî çàêðûòèÿ äâåðè (îòêðûòèÿ ëîâóøêè):
2254 if DoorTime > 0 then
2255 DoorTime := DoorTime - 1;
2256 // Óìåíüøàåì âðåìÿ îæèäàíèÿ ïîñëå íàæàòèÿ:
2257 if PressTime > 0 then
2258 PressTime := PressTime - 1;
2259 // Ïðîâåðÿåì èãðîêîâ è ìîíñòðîâ, êîòîðûõ ðàíåå çàïîìíèëè:
2260 if (TriggerType = TRIGGER_DAMAGE) or (TriggerType = TRIGGER_HEALTH) then
2261 for b := 0 to High(Activators) do
2262 begin
2263 // Óìåíüøàåì âðåìÿ äî ïîâòîðíîãî âîçäåéñòâèÿ:
2264 if Activators[b].TimeOut > 0 then
2265 Dec(Activators[b].TimeOut)
2266 else
2267 Continue;
2268 // Ñ÷èòàåì, ÷òî îáúåêò ïîêèíóë çîíó äåéñòâèÿ òðèããåðà
2269 if (trigData.trigDamageInterval = 0) and (Activators[b].TimeOut < 65530) then
2270 Activators[b].TimeOut := 0;
2271 end;
2273 // Îáðàáàòûâàåì ñïàâíåðû:
2274 if Enabled and AutoSpawn then
2275 if SpawnCooldown = 0 then
2276 begin
2277 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ìîíñòðà:
2278 if (TriggerType = TRIGGER_SPAWNMONSTER) and (trigData.trigMonDelay > 0) then
2279 begin
2280 ActivateUID := 0;
2281 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2282 end;
2283 // Åñëè ïðèøëî âðåìÿ, ñïàâíèì ïðåäìåò:
2284 if (TriggerType = TRIGGER_SPAWNITEM) and (trigData.trigItemDelay > 0) then
2285 begin
2286 ActivateUID := 0;
2287 ActivateTrigger(gTriggers[a], ACTIVATE_CUSTOM);
2288 end;
2289 end else // Óìåíüøàåì âðåìÿ îæèäàíèÿ:
2290 Dec(SpawnCooldown);
2292 // Îáðàáàòûâàåì ñîáûòèÿ òðèããåðà "Òóðåëü":
2293 if TriggerType = TRIGGER_SHOT then
2294 begin
2295 if ShotPanelTime > 0 then
2296 begin
2297 Dec(ShotPanelTime);
2298 if ShotPanelTime = 0 then
2299 g_Map_SwitchTexture(ShotPanelType, trigShotPanelID);
2300 end;
2301 if ShotSightTime > 0 then
2302 begin
2303 Dec(ShotSightTime);
2304 if ShotSightTime = 0 then
2305 ShotSightTarget := ShotSightTargetN;
2306 end;
2307 if ShotSightTimeout > 0 then
2308 begin
2309 Dec(ShotSightTimeout);
2310 if ShotSightTimeout = 0 then
2311 ShotSightTarget := 0;
2312 end;
2313 if ShotReloadTime > 0 then
2314 begin
2315 Dec(ShotReloadTime);
2316 if ShotReloadTime = 0 then
2317 ShotAmmoCount := trigData.trigShotAmmo;
2318 end;
2319 end;
2321 // Òðèããåð "Çâóê" óæå îòûãðàë, åñëè íóæíî åùå - ïåðåçàïóñêàåì:
2322 if Enabled and (TriggerType = TRIGGER_SOUND) and (Sound <> nil) then
2323 if (SoundPlayCount > 0) and (not Sound.IsPlaying()) then
2324 begin
2325 if trigData.trigPlayCount > 0 then // Åñëè 0 - èãðàåì çâóê áåñêîíå÷íî
2326 SoundPlayCount := SoundPlayCount - 1;
2327 if trigData.trigLocal then
2328 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), trigData.trigVolume/255.0)
2329 else
2330 Sound.PlayPanVolume((trigData.trigPan-127.0)/128.0, trigData.trigVolume/255.0);
2331 if Sound.IsPlaying() and g_Game_IsNet and g_Game_IsServer then
2332 MH_SEND_TriggerSound(gTriggers[a]);
2333 end;
2335 // Òðèããåð "Ëîâóøêà" - ïîðà îòêðûâàòü:
2336 if (TriggerType = TRIGGER_TRAP) and (DoorTime = 0) and (trigPanelID <> -1) then
2337 begin
2338 tr_OpenDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors);
2339 DoorTime := -1;
2340 end;
2342 // Òðèããåð "Äâåðü 5 ñåê" - ïîðà çàêðûâàòü:
2343 if (TriggerType = TRIGGER_DOOR5) and (DoorTime = 0) and (trigPanelID <> -1) then
2344 begin
2345 // Óæå çàêðûòà:
2346 if gWalls[trigPanelID].Enabled then
2347 DoorTime := -1
2348 else // Ïîêà îòêðûòà - çàêðûâàåì
2349 if tr_CloseDoor(trigPanelID, trigData.trigNoSound, trigData.trigd2d_doors) then
2350 DoorTime := -1;
2351 end;
2353 // Òðèããåð - ðàñøèðèòåëü èëè ïåðåêëþ÷àòåëü, è ïðîøëà çàäåðæêà, è íàæàëè íóæíîå ÷èñëî ðàç:
2354 if (TriggerType in [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF]) and
2355 (PressTime = 0) and (PressCount >= trigData.trigCount) then
2356 begin
2357 // Ñáðàñûâàåì çàäåðæêó àêòèâàöèè:
2358 PressTime := -1;
2359 // Ñáðàñûâàåì ñ÷åò÷èê íàæàòèé:
2360 if trigData.trigCount > 0 then
2361 PressCount := PressCount - trigData.trigCount
2362 else
2363 PressCount := 0;
2365 // Îïðåäåëÿåì èçìåíÿåìûå èì òðèããåðû:
2366 for b := 0 to High(gTriggers) do
2367 if g_Collide(trigData.trigtX, trigData.trigtY, trigData.trigtWidth, trigData.trigtHeight, gTriggers[b].X, gTriggers[b].Y,
2368 gTriggers[b].Width, gTriggers[b].Height) and
2369 ((b <> a) or (trigData.trigWait > 0)) then
2370 begin // Can be self-activated, if there is Data.Wait
2371 if (not trigData.trigExtRandom) or gTriggers[b].Enabled then
2372 begin
2373 SetLength(Affected, Length(Affected) + 1);
2374 Affected[High(Affected)] := b;
2375 end;
2376 end;
2377 // Âûáèðàåì îäèí èç òðèããåðîâ äëÿ ðàñøèðèòåëÿ, åñëè âêëþ÷åí ðàíäîì:
2378 if (TriggerType = TRIGGER_PRESS) and trigData.trigExtRandom then
2379 begin
2380 if (Length(Affected) > 0) then
2381 begin
2382 b := Affected[Random(Length(Affected))];
2383 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2384 ActivateTrigger(gTriggers[b], 0);
2385 end;
2386 end
2387 else //  ïðîòèâíîì ñëó÷àå ðàáîòàåì êàê îáû÷íî:
2388 for i := 0 to High(Affected) do
2389 begin
2390 b := Affected[i];
2391 case TriggerType of
2392 TRIGGER_PRESS:
2393 begin
2394 gTriggers[b].ActivateUID := gTriggers[a].ActivateUID;
2395 ActivateTrigger(gTriggers[b], 0);
2396 end;
2397 TRIGGER_ON:
2398 begin
2399 gTriggers[b].Enabled := True;
2400 end;
2401 TRIGGER_OFF:
2402 begin
2403 gTriggers[b].Enabled := False;
2404 gTriggers[b].TimeOut := 0;
2405 if gTriggers[b].AutoSpawn then
2406 begin
2407 gTriggers[b].AutoSpawn := False;
2408 gTriggers[b].SpawnCooldown := 0;
2409 end;
2410 end;
2411 TRIGGER_ONOFF:
2412 begin
2413 gTriggers[b].Enabled := not gTriggers[b].Enabled;
2414 if not gTriggers[b].Enabled then
2415 begin
2416 gTriggers[b].TimeOut := 0;
2417 if gTriggers[b].AutoSpawn then
2418 begin
2419 gTriggers[b].AutoSpawn := False;
2420 gTriggers[b].SpawnCooldown := 0;
2421 end;
2422 end;
2423 end;
2424 end;
2425 end;
2426 SetLength(Affected, 0);
2427 end;
2429 // Óìåíüøàåì âðåìÿ äî âîçìîæíîñòè ïîâòîðíîé àêòèâàöèè:
2430 if TimeOut > 0 then
2431 begin
2432 TimeOut := TimeOut - 1;
2433 Continue; // ×òîáû íå ïîòåðÿòü 1 åäèíèöó çàäåðæêè
2434 end;
2436 // Íèæå èäóò òèïû àêòèâàöèè, åñëè òðèããåð îòêëþ÷¸í - èä¸ì äàëüøå
2437 if not Enabled then
2438 Continue;
2440 // "Èãðîê áëèçêî":
2441 if ByteBool(ActivateType and ACTIVATE_PLAYERCOLLIDE) and
2442 (TimeOut = 0) then
2443 if gPlayers <> nil then
2444 for b := 0 to High(gPlayers) do
2445 if gPlayers[b] <> nil then
2446 with gPlayers[b] do
2447 // Æèâ, åñòü íóæíûå êëþ÷è è îí ðÿäîì:
2448 if Live and ((gTriggers[a].Keys and GetKeys) = gTriggers[a].Keys) and
2449 Collide(X, Y, Width, Height) then
2450 begin
2451 gTriggers[a].ActivateUID := UID;
2453 if (gTriggers[a].TriggerType in [TRIGGER_SOUND, TRIGGER_MUSIC]) and
2454 PlayerCollide then
2455 { Don't activate sound/music again if player is here }
2456 else
2457 ActivateTrigger(gTriggers[a], ACTIVATE_PLAYERCOLLIDE);
2458 end;
2460 { TODO 5 : àêòèâàöèÿ ìîíñòðàìè òðèããåðîâ ñ êëþ÷àìè }
2462 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2463 ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2464 (TimeOut = 0) and (Keys = 0) then
2465 begin
2466 // Åñëè "Ìîíñòð áëèçêî" è "Ìîíñòðîâ íåò",
2467 // çàïóñêàåì òðèããåð íà ñòàðòå êàðòû è ñíèìàåì îáà ôëàãà
2468 ActivateType := ActivateType and not (ACTIVATE_MONSTERCOLLIDE or ACTIVATE_NOMONSTER);
2469 gTriggers[a].ActivateUID := 0;
2470 ActivateTrigger(gTriggers[a], 0);
2471 end else
2472 begin
2473 // "Ìîíñòð áëèçêî"
2474 if ByteBool(ActivateType and ACTIVATE_MONSTERCOLLIDE) and
2475 (TimeOut = 0) and (Keys = 0) then // Åñëè íå íóæíû êëþ÷è
2476 begin
2477 //g_Mons_ForEach(monsNear);
2478 //Alive?!
2479 tgMonsList.reset();
2480 g_Mons_ForEachAt(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height, monsNear);
2481 for mon in tgMonsList do
2482 begin
2483 gTriggers[a].ActivateUID := mon.UID;
2484 ActivateTrigger(gTriggers[a], ACTIVATE_MONSTERCOLLIDE);
2485 end;
2486 tgMonsList.reset(); // just in case
2487 end;
2489 // "Ìîíñòðîâ íåò"
2490 if ByteBool(ActivateType and ACTIVATE_NOMONSTER) and
2491 (TimeOut = 0) and (Keys = 0) then
2492 if not g_Mons_IsAnyAliveAt(X, Y, Width, Height) then
2493 begin
2494 gTriggers[a].ActivateUID := 0;
2495 ActivateTrigger(gTriggers[a], ACTIVATE_NOMONSTER);
2496 end;
2497 end;
2499 PlayerCollide := g_CollidePlayer(X, Y, Width, Height);
2500 end;
2501 end;
2503 procedure g_Triggers_Press(ID: DWORD; ActivateType: Byte; ActivateUID: Word = 0);
2504 begin
2505 gTriggers[ID].ActivateUID := ActivateUID;
2506 ActivateTrigger(gTriggers[ID], ActivateType);
2507 end;
2509 function g_Triggers_PressR(X, Y: Integer; Width, Height: Word; UID: Word;
2510 ActivateType: Byte; IgnoreList: DWArray = nil): DWArray;
2511 var
2512 a: Integer;
2513 k: Byte;
2514 p: TPlayer;
2515 begin
2516 Result := nil;
2518 if gTriggers = nil then Exit;
2520 case g_GetUIDType(UID) of
2521 UID_GAME: k := 255;
2522 UID_PLAYER:
2523 begin
2524 p := g_Player_Get(UID);
2525 if p <> nil then
2526 k := p.GetKeys
2527 else
2528 k := 0;
2529 end;
2530 else k := 0;
2531 end;
2533 for a := 0 to High(gTriggers) do
2534 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2535 (gTriggers[a].TimeOut = 0) and
2536 (not InDWArray(a, IgnoreList)) and
2537 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2538 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2539 if g_Collide(X, Y, Width, Height,
2540 gTriggers[a].X, gTriggers[a].Y,
2541 gTriggers[a].Width, gTriggers[a].Height) then
2542 begin
2543 gTriggers[a].ActivateUID := UID;
2544 if ActivateTrigger(gTriggers[a], ActivateType) then
2545 begin
2546 SetLength(Result, Length(Result)+1);
2547 Result[High(Result)] := a;
2548 end;
2549 end;
2550 end;
2552 procedure g_Triggers_PressL(X1, Y1, X2, Y2: Integer; UID: DWORD; ActivateType: Byte);
2553 var
2554 a: Integer;
2555 k: Byte;
2556 p: TPlayer;
2557 begin
2558 if gTriggers = nil then Exit;
2560 case g_GetUIDType(UID) of
2561 UID_GAME: k := 255;
2562 UID_PLAYER:
2563 begin
2564 p := g_Player_Get(UID);
2565 if p <> nil then
2566 k := p.GetKeys
2567 else
2568 k := 0;
2569 end;
2570 else k := 0;
2571 end;
2573 for a := 0 to High(gTriggers) do
2574 if (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2575 (gTriggers[a].TimeOut = 0) and
2576 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2577 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2578 if g_CollideLine(x1, y1, x2, y2, gTriggers[a].X, gTriggers[a].Y,
2579 gTriggers[a].Width, gTriggers[a].Height) then
2580 begin
2581 gTriggers[a].ActivateUID := UID;
2582 ActivateTrigger(gTriggers[a], ActivateType);
2583 end;
2584 end;
2586 procedure g_Triggers_PressC(CX, CY: Integer; Radius: Word; UID: Word; ActivateType: Byte; IgnoreTrigger: Integer = -1);
2587 var
2588 a: Integer;
2589 k: Byte;
2590 rsq: Word;
2591 p: TPlayer;
2592 begin
2593 if gTriggers = nil then
2594 Exit;
2596 case g_GetUIDType(UID) of
2597 UID_GAME: k := 255;
2598 UID_PLAYER:
2599 begin
2600 p := g_Player_Get(UID);
2601 if p <> nil then
2602 k := p.GetKeys
2603 else
2604 k := 0;
2605 end;
2606 else k := 0;
2607 end;
2609 rsq := Radius * Radius;
2611 for a := 0 to High(gTriggers) do
2612 if (gTriggers[a].ID <> DWORD(IgnoreTrigger)) and
2613 (gTriggers[a].TriggerType <> TRIGGER_NONE) and
2614 (gTriggers[a].TimeOut = 0) and
2615 ((gTriggers[a].Keys and k) = gTriggers[a].Keys) and
2616 ByteBool(gTriggers[a].ActivateType and ActivateType) then
2617 with gTriggers[a] do
2618 if g_Collide(CX-Radius, CY-Radius, 2*Radius, 2*Radius,
2619 X, Y, Width, Height) then
2620 if ((Sqr(CX-X)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ëåâîìó óãëó
2621 ((Sqr(CX-X-Width)+Sqr(CY-Y)) < rsq) or // Öåíòð êðóãà áëèçîê ê âåðõíåìó ïðàâîìó óãëó
2622 ((Sqr(CX-X-Width)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ïðàâîìó óãëó
2623 ((Sqr(CX-X)+Sqr(CY-Y-Height)) < rsq) or // Öåíòð êðóãà áëèçîê ê íèæíåìó ëåâîìó óãëó
2624 ( (CX > (X-Radius)) and (CX < (X+Width+Radius)) and
2625 (CY > Y) and (CY < (Y+Height)) ) or // Öåíòð êðóãà íåäàëåêî îò âåðòèêàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2626 ( (CY > (Y-Radius)) and (CY < (Y+Height+Radius)) and
2627 (CX > X) and (CX < (X+Width)) ) then // Öåíòð êðóãà íåäàëåêî îò ãîðèçîíòàëüíûõ ãðàíèö ïðÿìîóãîëüíèêà
2628 begin
2629 ActivateUID := UID;
2630 ActivateTrigger(gTriggers[a], ActivateType);
2631 end;
2632 end;
2634 procedure g_Triggers_OpenAll();
2635 var
2636 a: Integer;
2637 b: Boolean;
2638 begin
2639 if gTriggers = nil then Exit;
2641 b := False;
2642 for a := 0 to High(gTriggers) do
2643 with gTriggers[a] do
2644 if (TriggerType = TRIGGER_OPENDOOR) or
2645 (TriggerType = TRIGGER_DOOR5) or
2646 (TriggerType = TRIGGER_DOOR) then
2647 begin
2648 tr_OpenDoor(trigPanelID, True, trigData.trigd2d_doors);
2649 if TriggerType = TRIGGER_DOOR5 then DoorTime := 180;
2650 b := True;
2651 end;
2653 if b then g_Sound_PlayEx('SOUND_GAME_DOOROPEN');
2654 end;
2656 procedure g_Triggers_DecreaseSpawner(ID: DWORD);
2657 begin
2658 if (gTriggers <> nil) then
2659 if gTriggers[ID].SpawnedCount > 0 then
2660 Dec(gTriggers[ID].SpawnedCount);
2661 end;
2663 procedure g_Triggers_Free();
2664 var
2665 a: Integer;
2666 begin
2667 for a := 0 to High(gTriggers) do
2668 begin
2669 gTriggers[a].trigData.Free();
2670 if (gTriggers[a].TriggerType = TRIGGER_SOUND) then
2671 begin
2672 if g_Sound_Exists(gTriggers[a].trigData.trigSoundName) then
2673 begin
2674 g_Sound_Delete(gTriggers[a].trigData.trigSoundName);
2675 end;
2676 gTriggers[a].Sound.Free();
2677 end;
2678 if (gTriggers[a].Activators <> nil) then
2679 begin
2680 SetLength(gTriggers[a].Activators, 0);
2681 end;
2682 end;
2684 gTriggers := nil;
2685 gSecretsCount := 0;
2686 SetLength(gMonstersSpawned, 0);
2687 end;
2689 procedure g_Triggers_SaveState(var Mem: TBinMemoryWriter);
2690 var
2691 count, act_count, i, j: Integer;
2692 dw: DWORD;
2693 sg: Single;
2694 b: Boolean;
2695 //p: Pointer;
2696 begin
2697 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðèããåðîâ:
2698 count := 0;
2699 if gTriggers <> nil then
2700 for i := 0 to High(gTriggers) do
2701 count := count + 1;
2703 Mem := TBinMemoryWriter.Create((count+1) * 200);
2705 // Êîëè÷åñòâî òðèããåðîâ:
2706 Mem.WriteInt(count);
2708 if count = 0 then
2709 Exit;
2711 for i := 0 to High(gTriggers) do
2712 begin
2713 // Ñèãíàòóðà òðèããåðà:
2714 dw := TRIGGER_SIGNATURE; // 'TRGR'
2715 Mem.WriteDWORD(dw);
2716 // Òèï òðèããåðà:
2717 Mem.WriteByte(gTriggers[i].TriggerType);
2718 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2719 //!!!FIXME!!!
2720 //p := @gTriggers[i].Data;
2721 //Mem.WriteMemory(p, SizeOf(TTriggerData));
2722 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2723 Mem.WriteInt(gTriggers[i].X);
2724 Mem.WriteInt(gTriggers[i].Y);
2725 // Ðàçìåðû:
2726 Mem.WriteWord(gTriggers[i].Width);
2727 Mem.WriteWord(gTriggers[i].Height);
2728 // Âêëþ÷åí ëè òðèããåð:
2729 Mem.WriteBoolean(gTriggers[i].Enabled);
2730 // Òèï àêòèâàöèè òðèããåðà:
2731 Mem.WriteByte(gTriggers[i].ActivateType);
2732 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2733 Mem.WriteByte(gTriggers[i].Keys);
2734 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2735 Mem.WriteInt(gTriggers[i].TexturePanel);
2736 // Òèï ýòîé ïàíåëè:
2737 Mem.WriteWord(gTriggers[i].TexturePanelType);
2738 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2739 Mem.WriteWord(gTriggers[i].TimeOut);
2740 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2741 Mem.WriteWord(gTriggers[i].ActivateUID);
2742 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2743 act_count := Length(gTriggers[i].Activators);
2744 Mem.WriteInt(act_count);
2745 for j := 0 to act_count-1 do
2746 begin
2747 // UID îáúåêòà
2748 Mem.WriteWord(gTriggers[i].Activators[j].UID);
2749 // Âðåìÿ îæèäàíèÿ
2750 Mem.WriteWord(gTriggers[i].Activators[j].TimeOut);
2751 end;
2752 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2753 Mem.WriteBoolean(gTriggers[i].PlayerCollide);
2754 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2755 Mem.WriteInt(gTriggers[i].DoorTime);
2756 // Çàäåðæêà àêòèâàöèè:
2757 Mem.WriteInt(gTriggers[i].PressTime);
2758 // Ñ÷åò÷èê íàæàòèé:
2759 Mem.WriteInt(gTriggers[i].PressCount);
2760 // Ñïàâíåð àêòèâåí:
2761 Mem.WriteBoolean(gTriggers[i].AutoSpawn);
2762 // Çàäåðæêà ñïàâíåðà:
2763 Mem.WriteInt(gTriggers[i].SpawnCooldown);
2764 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2765 Mem.WriteInt(gTriggers[i].SpawnedCount);
2766 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2767 Mem.WriteInt(gTriggers[i].SoundPlayCount);
2768 // Ïðîèãðûâàåòñÿ ëè çâóê?
2769 if gTriggers[i].Sound <> nil then
2770 b := gTriggers[i].Sound.IsPlaying()
2771 else
2772 b := False;
2773 Mem.WriteBoolean(b);
2774 if b then
2775 begin
2776 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2777 dw := gTriggers[i].Sound.GetPosition();
2778 Mem.WriteDWORD(dw);
2779 // Ãðîìêîñòü çâóêà:
2780 sg := gTriggers[i].Sound.GetVolume();
2781 sg := sg / (gSoundLevel/255.0);
2782 Mem.WriteSingle(sg);
2783 // Ñòåðåî ñìåùåíèå çâóêà:
2784 sg := gTriggers[i].Sound.GetPan();
2785 Mem.WriteSingle(sg);
2786 end;
2787 end;
2788 end;
2790 procedure g_Triggers_LoadState(var Mem: TBinMemoryReader);
2791 var
2792 count, act_count, i, j, a: Integer;
2793 dw: DWORD;
2794 vol, pan: Single;
2795 b: Boolean;
2796 //p: Pointer;
2797 Trig: TTrigger;
2798 begin
2799 if Mem = nil then
2800 Exit;
2802 g_Triggers_Free();
2804 // Êîëè÷åñòâî òðèããåðîâ:
2805 Mem.ReadInt(count);
2807 if count = 0 then
2808 Exit;
2810 for a := 0 to count-1 do
2811 begin
2812 // Ñèãíàòóðà òðèããåðà:
2813 Mem.ReadDWORD(dw);
2814 if dw <> TRIGGER_SIGNATURE then // 'TRGR'
2815 begin
2816 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong Trigger Signature');
2817 end;
2818 // Òèï òðèããåðà:
2819 Mem.ReadByte(Trig.TriggerType);
2820 // Ñïåöèàëüíûå äàííûå òðèããåðà:
2821 //!!!FIXME!!!
2823 Mem.ReadMemory(p, dw);
2824 if dw <> SizeOf(TTriggerData) then
2825 begin
2826 raise EBinSizeError.Create('g_Triggers_LoadState: Wrong TriggerData Size');
2827 end;
2828 Trig.Data := TTriggerData(p^);
2830 // Ñîçäàåì òðèããåð:
2831 i := g_Triggers_Create(Trig);
2832 // Êîîðäèíàòû ëåâîãî âåðõíåãî óãëà:
2833 Mem.ReadInt(gTriggers[i].X);
2834 Mem.ReadInt(gTriggers[i].Y);
2835 // Ðàçìåðû:
2836 Mem.ReadWord(gTriggers[i].Width);
2837 Mem.ReadWord(gTriggers[i].Height);
2838 // Âêëþ÷åí ëè òðèããåð:
2839 Mem.ReadBoolean(gTriggers[i].Enabled);
2840 // Òèï àêòèâàöèè òðèããåðà:
2841 Mem.ReadByte(gTriggers[i].ActivateType);
2842 // Êëþ÷è, íåîáõîäèìûå äëÿ àêòèâàöèè:
2843 Mem.ReadByte(gTriggers[i].Keys);
2844 // ID ïàíåëè, òåêñòóðà êîòîðîé èçìåíèòñÿ:
2845 Mem.ReadInt(gTriggers[i].TexturePanel);
2846 // Òèï ýòîé ïàíåëè:
2847 Mem.ReadWord(gTriggers[i].TexturePanelType);
2848 // Âðåìÿ äî âîçìîæíîñòè àêòèâàöèè:
2849 Mem.ReadWord(gTriggers[i].TimeOut);
2850 // UID òîãî, êòî àêòèâèðîâàë ýòîò òðèããåð:
2851 Mem.ReadWord(gTriggers[i].ActivateUID);
2852 // Ñïèñîê UID-îâ îáúåêòîâ, êîòîðûå íàõîäèëèñü ïîä âîçäåéñòâèåì:
2853 Mem.ReadInt(act_count);
2854 if act_count > 0 then
2855 begin
2856 SetLength(gTriggers[i].Activators, act_count);
2857 for j := 0 to act_count-1 do
2858 begin
2859 // UID îáúåêòà
2860 Mem.ReadWord(gTriggers[i].Activators[j].UID);
2861 // Âðåìÿ îæèäàíèÿ
2862 Mem.ReadWord(gTriggers[i].Activators[j].TimeOut);
2863 end;
2864 end;
2865 // Ñòîèò ëè èãðîê â îáëàñòè òðèããåðà:
2866 Mem.ReadBoolean(gTriggers[i].PlayerCollide);
2867 // Âðåìÿ äî çàêðûòèÿ äâåðè:
2868 Mem.ReadInt(gTriggers[i].DoorTime);
2869 // Çàäåðæêà àêòèâàöèè:
2870 Mem.ReadInt(gTriggers[i].PressTime);
2871 // Ñ÷åò÷èê íàæàòèé:
2872 Mem.ReadInt(gTriggers[i].PressCount);
2873 // Ñïàâíåð àêòèâåí:
2874 Mem.ReadBoolean(gTriggers[i].AutoSpawn);
2875 // Çàäåðæêà ñïàâíåðà:
2876 Mem.ReadInt(gTriggers[i].SpawnCooldown);
2877 // Ñ÷åò÷èê ñîçäàíèÿ îáúåêòîâ:
2878 Mem.ReadInt(gTriggers[i].SpawnedCount);
2879 // Ñêîëüêî ðàç ïðîèãðàí çâóê:
2880 Mem.ReadInt(gTriggers[i].SoundPlayCount);
2881 // Ïðîèãðûâàåòñÿ ëè çâóê?
2882 Mem.ReadBoolean(b);
2883 if b then
2884 begin
2885 // Ïîçèöèÿ ïðîèãðûâàíèÿ çâóêà:
2886 Mem.ReadDWORD(dw);
2887 // Ãðîìêîñòü çâóêà:
2888 Mem.ReadSingle(vol);
2889 // Ñòåðåî ñìåùåíèå çâóêà:
2890 Mem.ReadSingle(pan);
2891 // Çàïóñêàåì çâóê, åñëè åñòü:
2892 if gTriggers[i].Sound <> nil then
2893 begin
2894 gTriggers[i].Sound.PlayPanVolume(pan, vol);
2895 gTriggers[i].Sound.Pause(True);
2896 gTriggers[i].Sound.SetPosition(dw);
2897 end
2898 end;
2899 end;
2900 end;
2902 end.