]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/swamp.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / swamp.qc
1 #include "swamp.qh"
2 #if defined(CSQC)
3 #elif defined(MENUQC)
4 #elif defined(SVQC)
5 #include <lib/warpzone/util_server.qh>
6 #include <common/weapons/_all.qh>
7 #include <server/defs.qh>
8 #include <common/deathtypes/all.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(entity this, entity toucher);
27 void swampslug_think(entity this);
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(entity this)
41 {
42         // Slowly kill the slug
43         this.health = this.health - 1;
44
45         // Slug dead? then remove curses.
46         if (this.health <= 0) {
47                 this.owner.in_swamp = 0;
48                 delete(this);
49                 // centerprint(this.owner,"Killing slug...\n");
50                 return;
51         }
52
53         // Slug still alive, so we are still in the swamp
54         // Or we have exited it very recently.
55         // Do the damage and renew the timer.
56 #ifdef SVQC
57         Damage(this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, this.owner.origin, '0 0 0');
58 #endif
59
60         this.nextthink = time + this.swamp_interval;
61 }
62
63 void swamp_touch(entity this, entity toucher)
64 {
65         // If whatever thats touching the swamp is not a player
66         // or if its a dead player, just dont care abt it.
67         if (!IS_PLAYER(toucher) || IS_DEAD(toucher)) {
68                 return;
69         }
70
71         EXACTTRIGGER_TOUCH(this, toucher);
72
73         // Chech if player alredy got a swampslug.
74         if (toucher.in_swamp != 1) {
75                 // If not attach one.
76                 // centerprint(toucher,"Entering swamp!\n");
77                 toucher.swampslug = spawn();
78                 toucher.swampslug.health = 2;
79                 setthink(toucher.swampslug, swampslug_think);
80                 toucher.swampslug.nextthink = time;
81                 toucher.swampslug.owner = toucher;
82                 toucher.swampslug.dmg = this.dmg;
83                 toucher.swampslug.swamp_interval = this.swamp_interval;
84                 toucher.swamp_slowdown = this.swamp_slowdown;
85                 toucher.in_swamp = 1;
86                 return;
87         }
88
89         // toucher.in_swamp = 1;
90
91         // Revitalize players swampslug
92         toucher.swampslug.health = 2;
93 }
94
95 REGISTER_NET_LINKED(ENT_CLIENT_SWAMP)
96
97 #ifdef SVQC
98 float swamp_send(entity this, entity to, float sf)
99 {
100         WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP);
101
102         WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here
103         WriteByte(MSG_ENTITY, this.swamp_slowdown);
104         WriteByte(MSG_ENTITY, this.swamp_interval);
105
106         trigger_common_write(this, false);
107
108         return true;
109 }
110
111 void swamp_link(entity this)
112 {
113         trigger_link(this, swamp_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 spawnfunc(trigger_swamp)
121 {
122         // Init stuff
123         trigger_init(this);
124         settouch(this, swamp_touch);
125
126         // Setup default keys, if missing
127         if (this.dmg <= 0) {
128                 this.dmg = 5;
129         }
130         if (this.swamp_interval <= 0) {
131                 this.swamp_interval = 1;
132         }
133         if (this.swamp_slowdown <= 0) {
134                 this.swamp_slowdown = 0.5;
135         }
136
137         swamp_link(this);
138 }
139
140 #elif defined(CSQC)
141
142 NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
143 {
144         this.dmg = ReadByte();
145         this.swamp_slowdown = ReadByte();
146         this.swamp_interval = ReadByte();
147
148         trigger_common_read(this, false);
149
150         return = true;
151
152         this.classname = "trigger_swamp";
153         this.solid = SOLID_TRIGGER;
154         settouch(this, swamp_touch);
155         this.drawmask = MASK_NORMAL;
156         this.move_time = time;
157         this.entremove = trigger_remove_generic;
158 }
159 #endif