]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/swamp.qc
Merge branch 'master' into Mario/stats_eloranking
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / 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 support routines for nexuiz 1.2.1+ and xonotic
14 *               Author tZork (Jakob MG)
15 *               jakob@games43.se
16 *               2005 11 29
17 */
18
19
20 /*
21 * Uses a entity calld swampslug to handle players in the swamp
22 * It works like this: When the plyer enters teh swamp the spawnfunc_trigger_swamp
23 * attaches a new "swampslug" to the player. As long as the plyer is inside
24 * the swamp the swamp gives the slug new health. But the slug slowly kills itself
25 * so when the player goes outside the swamp, it dies and releases the player from the
26 * swamps curses (dmg/slowdown)
27 *
28 * I do it this way becuz there is no "untouch" event.
29 */
30 void swampslug_think(entity this)
31 {
32         //Slowly kill the slug
33         this.swamp_lifetime -= 1;
34
35         //Slug dead? then remove curses.
36         if(GetResource(this, RES_HEALTH) <= 0)
37         {
38                 if(this.owner.swampslug == this)
39                 {
40                         this.owner.in_swamp = false;
41                         this.owner.swampslug = NULL;
42                 }
43                 delete(this);
44                 //centerprint(this.owner,"Killing slug...\n");
45                 return;
46         }
47
48         // Slug still alive, so we are still in the swamp
49         // Or we have exited it very recently.
50         // Do the damage and renew the timer.
51 #ifdef SVQC
52         Damage (this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, DMG_NOWEP, this.owner.origin, '0 0 0');
53 #endif
54
55         this.nextthink = time + this.swamp_interval;
56 }
57
58 void swamp_touch(entity this, entity toucher)
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(!IS_PLAYER(toucher) || IS_DEAD(toucher))
63                 return;
64
65         EXACTTRIGGER_TOUCH(this, toucher);
66
67         // Chech if player alredy got a swampslug.
68         if(!toucher.in_swamp)
69         {
70                 // If not attach one.
71                 //centerprint(toucher,"Entering swamp!\n");
72                 if(!toucher.swampslug) // just incase
73                         toucher.swampslug = spawn();
74                 toucher.swampslug.swamp_lifetime = 2;
75                 setthink(toucher.swampslug, swampslug_think);
76                 toucher.swampslug.nextthink = time;
77                 toucher.swampslug.owner = toucher;
78                 toucher.swampslug.dmg = this.dmg;
79                 toucher.swampslug.swamp_interval = this.swamp_interval;
80                 toucher.swamp_slowdown = this.swamp_slowdown;
81                 toucher.in_swamp = true;
82                 return;
83         }
84
85         //toucher.in_swamp = true;
86
87         //Revitalize players swampslug
88         toucher.swampslug.swamp_lifetime = 2;
89 }
90
91 REGISTER_NET_LINKED(ENT_CLIENT_SWAMP)
92
93 #ifdef SVQC
94 float swamp_send(entity this, entity to, float sf)
95 {
96         WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP);
97
98         WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here
99         WriteByte(MSG_ENTITY, this.swamp_slowdown);
100         WriteByte(MSG_ENTITY, this.swamp_interval);
101
102         trigger_common_write(this, false);
103
104         return true;
105 }
106
107 void swamp_link(entity this)
108 {
109         trigger_link(this, swamp_send);
110 }
111
112 /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
113 Players in the swamp will be
114 slowed down and damaged over time
115 */
116 spawnfunc(trigger_swamp)
117 {
118         // Init stuff
119         trigger_init(this);
120         settouch(this, swamp_touch);
121
122         // Setup default keys, if missing
123         if(this.dmg <= 0)
124                 this.dmg = 5;
125         if(this.swamp_interval <= 0)
126                 this.swamp_interval = 1;
127         if(this.swamp_slowdown <= 0)
128                 this.swamp_slowdown = 0.5;
129
130         swamp_link(this);
131 }
132
133 #elif defined(CSQC)
134
135 NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
136 {
137         this.dmg = ReadByte();
138         this.swamp_slowdown = ReadByte();
139         this.swamp_interval = ReadByte();
140
141         trigger_common_read(this, false);
142
143         return = true;
144
145         this.classname = "trigger_swamp";
146         this.solid = SOLID_TRIGGER;
147         settouch(this, swamp_touch);
148         this.drawmask = MASK_NORMAL;
149         this.move_time = time;
150         this.entremove = trigger_remove_generic;
151 }
152 #endif