]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/swamp.qc
Spawnfunc whitelist
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / swamp.qc
1 #if defined(CSQC)
2 #elif defined(MENUQC)
3 #elif defined(SVQC)
4         #include "../../../server/_all.qh"
5     #include "../../../warpzonelib/util_server.qh"
6     #include "../../weapons/all.qh"
7     #include "../../../server/defs.qh"
8     #include "../../deathtypes.qh"
9 #endif
10
11 /*
12 *               t_swamp.c
13 *               Adds spawnfunc_trigger_swamp and suppoart routines for xonotic 1.2.1+
14 *               Author tZork (Jakob MG)
15 *               jakob@games43.se
16 *               2005 11 29
17 */
18
19 .float swamp_interval;  //Hurt players in swamp with this interval
20 .float swamp_slowdown;  //Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?)
21 .entity swampslug;
22
23 #ifdef SVQC
24 spawnfunc(trigger_swamp);
25 #endif
26 void swamp_touch(void);
27 void swampslug_think();
28
29
30 /*
31 * Uses a entity calld swampslug to handle players in the swamp
32 * It works like this: When the plyer enters teh swamp the spawnfunc_trigger_swamp
33 * attaches a new "swampslug" to the player. As long as the plyer is inside
34 * the swamp the swamp gives the slug new health. But the slug slowly kills itself
35 * so when the player goes outside the swamp, it dies and releases the player from the
36 * swamps curses (dmg/slowdown)
37 *
38 * I do it this way becuz there is no "untouch" event.
39 */
40 void swampslug_think(void)
41 {SELFPARAM();
42         //Slowly kill the slug
43         self.health = self.health - 1;
44
45         //Slug dead? then remove curses.
46         if(self.health <= 0)
47         {
48                 self.owner.in_swamp = 0;
49                 remove(self);
50                 //centerprint(self.owner,"Killing slug...\n");
51                 return;
52         }
53
54         // Slug still alive, so we are still in the swamp
55         // Or we have exited it very recently.
56         // Do the damage and renew the timer.
57 #ifdef SVQC
58         Damage (self.owner, self, self, self.dmg, DEATH_SWAMP, other.origin, '0 0 0');
59 #endif
60
61         self.nextthink = time + self.swamp_interval;
62 }
63
64 void swamp_touch(void)
65 {SELFPARAM();
66         // If whatever thats touching the swamp is not a player
67         // or if its a dead player, just dont care abt it.
68         if(!IS_PLAYER(other) || PHYS_DEAD(other))
69                 return;
70
71         EXACTTRIGGER_TOUCH;
72
73         // Chech if player alredy got a swampslug.
74         if(other.in_swamp != 1)
75         {
76                 // If not attach one.
77                 //centerprint(other,"Entering swamp!\n");
78                 other.swampslug = spawn();
79                 other.swampslug.health = 2;
80                 other.swampslug.think = swampslug_think;
81                 other.swampslug.nextthink = time;
82                 other.swampslug.owner = other;
83                 other.swampslug.dmg = self.dmg;
84                 other.swampslug.swamp_interval = self.swamp_interval;
85                 other.swamp_slowdown = self.swamp_slowdown;
86                 other.in_swamp = 1;
87                 return;
88         }
89
90         //other.in_swamp = 1;
91
92         //Revitalize players swampslug
93         other.swampslug.health = 2;
94 }
95
96 #ifdef SVQC
97 float swamp_send(entity to, float sf)
98 {SELFPARAM();
99         WriteByte(MSG_ENTITY, ENT_CLIENT_LADDER);
100
101         WriteByte(MSG_ENTITY, self.dmg); // can probably get away with using a single byte here
102         WriteByte(MSG_ENTITY, self.swamp_slowdown);
103         WriteByte(MSG_ENTITY, self.swamp_interval);
104
105         trigger_common_write(false);
106
107         return true;
108 }
109
110 void swamp_link()
111 {SELFPARAM();
112         Net_LinkEntity(self, false, 0, func_ladder_send);
113 }
114
115 /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
116 Players gettin into the swamp will
117 get slowd down and damaged
118 */
119 spawnfunc(trigger_swamp)
120 {
121         // Init stuff
122         EXACTTRIGGER_INIT;
123         self.touch = swamp_touch;
124
125         // Setup default keys, if missing
126         if(self.dmg <= 0)
127                 self.dmg = 5;
128         if(self.swamp_interval <= 0)
129                 self.swamp_interval = 1;
130         if(self.swamp_slowdown <= 0)
131                 self.swamp_slowdown = 0.5;
132
133         swamp_link();
134 }
135
136 #elif defined(CSQC)
137
138 void ent_swamp()
139 {SELFPARAM();
140         self.dmg = ReadByte();
141         self.swamp_slowdown = ReadByte();
142         self.swamp_interval = ReadByte();
143
144         trigger_common_read(false);
145
146         self.classname = "trigger_swamp";
147         self.solid = SOLID_TRIGGER;
148         self.draw = trigger_draw_generic;
149         self.trigger_touch = swamp_touch;
150         self.drawmask = MASK_NORMAL;
151         self.move_time = time;
152         self.entremove = trigger_remove_generic;
153 }
154 #endif