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