]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/swamp.qc
A few trillion lines of untested junk, committing now so it doesn't become quadrillions
[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 "../../../dpdefs/progsdefs.qh"
5     #include "../../../warpzonelib/util_server.qh"
6     #include "../../weapons/weapons.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 void spawnfunc_trigger_swamp(void);
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 {
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 {
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 {
99         WriteByte(MSG_ENTITY, ENT_CLIENT_LADDER);
100
101         WriteByte(MSG_ENTITY, self.warpzone_isboxy);
102         WriteByte(MSG_ENTITY, self.scale);
103         WriteByte(MSG_ENTITY, self.dmg); // can probably get away with using a single byte here
104         WriteByte(MSG_ENTITY, self.swamp_slowdown);
105         WriteByte(MSG_ENTITY, self.swamp_interval);
106         WriteCoord(MSG_ENTITY, self.origin_x);
107         WriteCoord(MSG_ENTITY, self.origin_y);
108         WriteCoord(MSG_ENTITY, self.origin_z);
109
110         WriteCoord(MSG_ENTITY, self.mins_x);
111         WriteCoord(MSG_ENTITY, self.mins_y);
112         WriteCoord(MSG_ENTITY, self.mins_z);
113         WriteCoord(MSG_ENTITY, self.maxs_x);
114         WriteCoord(MSG_ENTITY, self.maxs_y);
115         WriteCoord(MSG_ENTITY, self.maxs_z);
116
117         WriteCoord(MSG_ENTITY, self.movedir_x);
118         WriteCoord(MSG_ENTITY, self.movedir_y);
119         WriteCoord(MSG_ENTITY, self.movedir_z);
120
121         WriteAngle(MSG_ENTITY, self.angles_x);
122         WriteAngle(MSG_ENTITY, self.angles_y);
123         WriteAngle(MSG_ENTITY, self.angles_z);
124
125         return true;
126 }
127
128 void swamp_link()
129 {
130         Net_LinkEntity(self, false, 0, func_ladder_send);
131 }
132
133 /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
134 Players gettin into the swamp will
135 get slowd down and damaged
136 */
137 void spawnfunc_trigger_swamp(void)
138 {
139         // Init stuff
140         EXACTTRIGGER_INIT;
141         self.touch = swamp_touch;
142
143         // Setup default keys, if missing
144         if(self.dmg <= 0)
145                 self.dmg = 5;
146         if(self.swamp_interval <= 0)
147                 self.swamp_interval = 1;
148         if(self.swamp_slowdown <= 0)
149                 self.swamp_slowdown = 0.5;
150
151         swamp_link();
152 }
153
154 #elif defined(CSQC)
155
156 void ent_swamp()
157 {
158         self.warpzone_isboxy = ReadByte();
159         self.scale = ReadByte();
160         self.dmg = ReadByte();
161         self.swamp_slowdown = ReadByte();
162         self.swamp_interval = ReadByte();
163
164         self.origin_x = ReadCoord();
165         self.origin_y = ReadCoord();
166         self.origin_z = ReadCoord();
167         setorigin(self, self.origin);
168
169         self.mins_x = ReadCoord();
170         self.mins_y = ReadCoord();
171         self.mins_z = ReadCoord();
172         self.maxs_x = ReadCoord();
173         self.maxs_y = ReadCoord();
174         self.maxs_z = ReadCoord();
175         setsize(self, self.mins, self.maxs);
176
177         self.movedir_x = ReadCoord();
178         self.movedir_y = ReadCoord();
179         self.movedir_z = ReadCoord();
180
181         self.angles_x = ReadAngle();
182         self.angles_y = ReadAngle();
183         self.angles_z = ReadAngle();
184
185         self.classname = "trigger_swamp";
186         self.solid = SOLID_TRIGGER;
187         self.draw = trigger_draw_generic;
188         self.trigger_touch = swamp_touch;
189         self.drawmask = MASK_NORMAL;
190         self.move_time = time;
191 }
192 #endif