]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/swamp.qc
Merge branch 'master' into terencehill/bot_ai
[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 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 .float swamp_lifetime;  // holds the points remaining until slug dies (not quite health!) 
22 .entity swampslug;
23
24 #ifdef SVQC
25 spawnfunc(trigger_swamp);
26 #endif
27 void swamp_touch(entity this, entity toucher);
28 void swampslug_think(entity this);
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(entity this)
42 {
43         //Slowly kill the slug
44         this.swamp_lifetime -= 1;
45
46         //Slug dead? then remove curses.
47         if(GetResourceAmount(this, RESOURCE_HEALTH) <= 0)
48         {
49                 this.owner.in_swamp = 0;
50                 delete(this);
51                 //centerprint(this.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 (this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, DMG_NOWEP, this.owner.origin, '0 0 0');
60 #endif
61
62         this.nextthink = time + this.swamp_interval;
63 }
64
65 void swamp_touch(entity this, entity toucher)
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(toucher) || IS_DEAD(toucher))
70                 return;
71
72         EXACTTRIGGER_TOUCH(this, toucher);
73
74         // Chech if player alredy got a swampslug.
75         if(toucher.in_swamp != 1)
76         {
77                 // If not attach one.
78                 //centerprint(toucher,"Entering swamp!\n");
79                 toucher.swampslug = spawn();
80                 toucher.swampslug.swamp_lifetime = 2;
81                 setthink(toucher.swampslug, swampslug_think);
82                 toucher.swampslug.nextthink = time;
83                 toucher.swampslug.owner = toucher;
84                 toucher.swampslug.dmg = this.dmg;
85                 toucher.swampslug.swamp_interval = this.swamp_interval;
86                 toucher.swamp_slowdown = this.swamp_slowdown;
87                 toucher.in_swamp = 1;
88                 return;
89         }
90
91         //toucher.in_swamp = 1;
92
93         //Revitalize players swampslug
94         toucher.swampslug.swamp_lifetime = 2;
95 }
96
97 REGISTER_NET_LINKED(ENT_CLIENT_SWAMP)
98
99 #ifdef SVQC
100 float swamp_send(entity this, entity to, float sf)
101 {
102         WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP);
103
104         WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here
105         WriteByte(MSG_ENTITY, this.swamp_slowdown);
106         WriteByte(MSG_ENTITY, this.swamp_interval);
107
108         trigger_common_write(this, false);
109
110         return true;
111 }
112
113 void swamp_link(entity this)
114 {
115         trigger_link(this, swamp_send);
116 }
117
118 /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
119 Players gettin into the swamp will
120 get slowd down and damaged
121 */
122 spawnfunc(trigger_swamp)
123 {
124         // Init stuff
125         trigger_init(this);
126         settouch(this, swamp_touch);
127
128         // Setup default keys, if missing
129         if(this.dmg <= 0)
130                 this.dmg = 5;
131         if(this.swamp_interval <= 0)
132                 this.swamp_interval = 1;
133         if(this.swamp_slowdown <= 0)
134                 this.swamp_slowdown = 0.5;
135
136         swamp_link(this);
137 }
138
139 #elif defined(CSQC)
140
141 NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
142 {
143         this.dmg = ReadByte();
144         this.swamp_slowdown = ReadByte();
145         this.swamp_interval = ReadByte();
146
147         trigger_common_read(this, false);
148
149         return = true;
150
151         this.classname = "trigger_swamp";
152         this.solid = SOLID_TRIGGER;
153         settouch(this, swamp_touch);
154         this.drawmask = MASK_NORMAL;
155         this.move_time = time;
156         this.entremove = trigger_remove_generic;
157 }
158 #endif