]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/t_teleporters.c
add g_navnodeedit
[divverent/nexuiz.git] / data / qcsrc / server / 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.ogg", 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.ogg", 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         // reset tracking of oldvelocity for impact damage (sudden velocity changes)
75         other.oldvelocity = other.velocity;
76         // reset tracking of who pushed you into a hazard (for kill credit)
77         other.pushltime = 0;
78 }
79
80 void info_teleport_destination (void)
81 {
82         self.mangle = self.angles;
83         self.angles = '0 0 0';
84
85         //setorigin (self, self.origin + '0 0 27');     // To fix a mappers' habit as old as Quake
86         setorigin (self, self.origin);
87
88         if (!self.targetname)
89                 objerror ("Teleport destination without a targetname");
90 }
91
92 void misc_teleporter_dest (void)
93 {
94         info_teleport_destination();
95 }
96
97 void trigger_teleport (void)
98 {
99         self.angles = '0 0 0';
100
101         self.solid = SOLID_TRIGGER;
102         self.movetype = MOVETYPE_NONE;
103
104         setmodel (self, self.model);
105
106         self.model = "";
107         self.modelindex = 0;
108
109         self.touch = Teleport_Touch;
110
111         if (!self.target)
112                 objerror ("Teleporter with no target");
113 }