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