]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/t_teleporters.c
Added savagex's telefragged code
[divverent/nexuiz.git] / qcsrc / gamec / t_teleporters.c
1 void Damage (entity targ, entity inflictor, entity attacker, float
2 damage, float deathtype, vector hitloc, vector force);
3
4 void() tdeath_touch =
5 {
6         if (other == self.owner)
7                 return;
8         // so teleporting shots etc can't telefrag
9         if (!self.owner.takedamage)
10                 return;
11         if (!other.takedamage)
12                 return;
13
14         if ((self.owner.classname == "player") && (self.owner.health >= 1))
15         {
16                 Damage (other, self, self.owner, 10000, WEP_TELEPORTER, other.origin,
17 '0 0 0');
18         }
19         else if (other.health < 1) // corpses gib
20                 Damage (other, self, self.owner, 10000, 0, other.origin, '0 0 0');
21         else // dead bodies and monsters gib themselves instead of telefragging
22                 Damage (self.owner, self, other, 10000, 0, self.owner.origin, '0 0 0');
23 };
24
25 // org2 is where they will return to if the teleport fails
26 void(vector org, entity death_owner, vector org2) spawn_tdeath =
27 {
28         local entity death;
29
30         death = spawn();
31 //      death.classname = "teledeath";
32         death.movetype = MOVETYPE_NONE;
33         death.solid = SOLID_TRIGGER;
34         death.angles = '0 0 0';
35         death.dest2 = org2;
36         setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
37         setorigin (death, org);
38         death.touch = tdeath_touch;
39         death.nextthink = time + 0.2;
40         death.think = SUB_Remove;
41         death.owner = death_owner;
42
43         force_retouch = 2;              // make sure even still objects get hit
44 };
45
46 void Teleport_Touch (void)
47 {
48         if (other.health < 1)
49                 return;
50         if (other.classname != "player")        // FIXME: Make missiles firable through the teleport too
51                 return;
52
53         // Make teleport effect where the player left
54         sound (other, CHAN_ITEM, "misc/teleport.wav", 1, ATTN_NORM);
55         te_teleport (other.origin);
56         
57         dest = find (world, targetname, self.target);
58         if (!dest)
59                 objerror ("Teleporter with nonexistant target");
60
61         // Make teleport effect where the player arrived
62         sound (other, CHAN_ITEM, "misc/teleport.wav", 1, ATTN_NORM);
63         makevectors (dest.mangle);
64         te_teleport (dest.origin + v_forward * 32);
65
66         spawn_tdeath(dest.origin, other, other.origin);
67
68         // Relocate the player
69         //setorigin (other, dest.origin);
70         setorigin (other, dest.origin + '0 0 1' * (1 - other.mins_z - 24));
71         other.angles = dest.mangle;
72         other.fixangle = TRUE;
73         
74         other.velocity = '0 0 0';
75         
76         other.flags = other.flags - (other.flags & FL_ONGROUND);
77 }
78
79 void info_teleport_destination (void)
80 {
81         self.mangle = self.angles;
82         self.angles = '0 0 0';
83
84         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake
85         setorigin (self, self.origin);
86
87         if (!self.targetname)
88                 objerror ("Teleport destination without a targetname");
89 }
90
91 void misc_teleporter_dest (void)
92 {
93         info_teleport_destination();
94 }
95
96 void trigger_teleport (void)
97 {
98         self.angles = '0 0 0';
99
100         self.solid = SOLID_TRIGGER;
101         self.movetype = MOVETYPE_NONE;
102         
103         setmodel (self, self.model);
104         
105         self.model = "";
106         self.modelindex = 0;
107         
108         self.touch = Teleport_Touch;
109         
110         if (!self.target)
111                 objerror ("Teleporter with no target");
112 }