]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/t_swamp.qc
renamed and moved all gamec/*.[ch] files to *.q[ch]
[divverent/nexuiz.git] / data / qcsrc / server / t_swamp.qc
1 /*
2 *               t_swamp.c
3 *               Adds trigger_swamp and suppoart routines for nexuiz 1.2.1+
4 *               Author tZork (Jakob MG) 
5 *               jakob@games43.se
6 *               2005 11 29
7 */
8
9 .float swamp_interval;  //Hurt players in swamp with this interval
10 .float swamp_slowdown;  //Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?)
11 .float swamp_ticker;    //Used localy by the swampslug to calculate when to hurt the player and check the slug.
12 .entity swampslug;
13
14 void trigger_swamp(void);
15 void swamp_touch(void);
16 void swampslug_think();
17
18
19 /*
20 * Uses a entity calld swampslug to handle players in the swamp
21 * It works like this: When the plyer enters teh swamp the trigger_swamp
22 * attaches a new "swampslug" to the player. As long as the plyer is inside
23 * the swamp the swamp gives the slug new health. But the slug slowly kills itself
24 * so when the player goes outside the swamp, it dies and releases the player from the 
25 * swamps curses (dmg/slowdown) 
26
27 * I do it this way becuz there is no "untouch" event.
28 *
29 * --NOTE-- 
30 * THE ACCTUAL slowdown is done in cl_physics.c on line 57-60
31 * --NOTE--
32 */
33 void swampslug_think(void) 
34 {
35
36         //Slowly kill the slug
37         self.health = self.health - 1;
38
39         //Slug dead? then remove curses.
40         if(self.health <= 0) {
41                 self.owner.in_swamp = 0;
42                 remove(self);
43                 //centerprint(self.owner,"Killing slug...\n");
44                 return;
45         }
46         
47         // Slug still alive, so we are still in the swamp
48         // Or we have exited it very recently.
49         // Do the damage and renew the timer.
50         Damage (self.owner, self, self, self.dmg, DEATH_SWAMP, other.origin, '0 0 0');
51         self.swamp_ticker = time + self.swamp_interval;
52
53         self.nextthink = time + self.swamp_interval;
54
55 }
56
57 void swamp_touch(void) 
58 {
59         
60         // If whatever thats touching the swamp is not a player
61         // or if its a dead player, just dont care abt it.
62         if((other.classname != "player")||(other.deadflag != DEAD_NO))
63                 return;
64
65         // Chech if player alredy got a swampslug.
66         if(other.in_swamp != 1) {
67                 // If not attach one.
68                 //centerprint(other,"Entering swamp!\n");
69                 other.swampslug = spawn();
70                 other.swampslug.health = 2;
71                 other.swampslug.think = swampslug_think;
72                 other.swampslug.nextthink = time;
73                 other.swampslug.owner = other;
74                 other.swampslug.dmg = self.dmg;
75                 other.swampslug.swamp_interval = self.swamp_interval;
76                 other.swamp_slowdown = self.swamp_slowdown;
77                 other.in_swamp = 1;
78                 return;
79         }
80
81         //other.in_swamp = 1;
82
83         //Revitalize players swampslug
84         other.swampslug.health = 2;
85 }
86
87 /*QUAKED trigger_swamp (.5 .5 .5) ?
88 Players gettin into the swamp will 
89 get slowd down and damaged
90 */
91 void trigger_swamp(void)
92 {
93         // Init stuff
94         InitTrigger ();
95         self.touch = swamp_touch;       
96
97         // Setup default keys, if missing
98         if(self.dmg <= 0) 
99                 self.dmg = 5;
100         if(self.swamp_interval <= 0) 
101                 self.swamp_interval = 1;
102         if(self.swamp_slowdown <= 0) 
103                 self.swamp_slowdown = 0.5;
104 };