]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/swamp.qc
Move swamps across (as with all physics related stuff, currently does not work)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / swamp.qc
1 #ifdef SVQC
2 void spawnfunc_trigger_swamp(void);
3 #endif
4 void swamp_touch(void);
5 void swampslug_think();
6
7
8 /*
9 * Uses a entity calld swampslug to handle players in the swamp
10 * It works like this: When the plyer enters teh swamp the spawnfunc_trigger_swamp
11 * attaches a new "swampslug" to the player. As long as the plyer is inside
12 * the swamp the swamp gives the slug new health. But the slug slowly kills itself
13 * so when the player goes outside the swamp, it dies and releases the player from the
14 * swamps curses (dmg/slowdown)
15 *
16 * I do it this way becuz there is no "untouch" event.
17 */
18 void swampslug_think(void)
19 {
20         //Slowly kill the slug
21         self.health = self.health - 1;
22
23         //Slug dead? then remove curses.
24         if(self.health <= 0)
25         {
26                 self.owner.in_swamp = 0;
27                 remove(self);
28                 //centerprint(self.owner,"Killing slug...\n");
29                 return;
30         }
31
32         // Slug still alive, so we are still in the swamp
33         // Or we have exited it very recently.
34         // Do the damage and renew the timer.
35 #ifdef SVQC
36         Damage (self.owner, self, self, self.dmg, DEATH_SWAMP, other.origin, '0 0 0');
37 #endif
38
39         self.nextthink = time + self.swamp_interval;
40 }
41
42 void swamp_touch(void)
43 {
44         // If whatever thats touching the swamp is not a player
45         // or if its a dead player, just dont care abt it.
46         if(!IS_PLAYER(other) || PHYS_DEAD(other))
47                 return;
48
49         EXACTTRIGGER_TOUCH;
50
51         // Chech if player alredy got a swampslug.
52         if(other.in_swamp != 1)
53         {
54                 // If not attach one.
55                 //centerprint(other,"Entering swamp!\n");
56                 other.swampslug = spawn();
57                 other.swampslug.health = 2;
58                 other.swampslug.think = swampslug_think;
59                 other.swampslug.nextthink = time;
60                 other.swampslug.owner = other;
61                 other.swampslug.dmg = self.dmg;
62                 other.swampslug.swamp_interval = self.swamp_interval;
63                 other.swamp_slowdown = self.swamp_slowdown;
64                 other.in_swamp = 1;
65                 return;
66         }
67
68         //other.in_swamp = 1;
69
70         //Revitalize players swampslug
71         other.swampslug.health = 2;
72 }
73
74 #ifdef SVQC
75 float swamp_send(entity to, float sf)
76 {
77         WriteByte(MSG_ENTITY, ENT_CLIENT_LADDER);
78
79         WriteByte(MSG_ENTITY, self.warpzone_isboxy);
80         WriteByte(MSG_ENTITY, self.scale);
81         WriteByte(MSG_ENTITY, self.dmg); // can probably get away with using a single byte here
82         WriteByte(MSG_ENTITY, self.swamp_slowdown);
83         WriteByte(MSG_ENTITY, self.swamp_interval);
84         WriteCoord(MSG_ENTITY, self.origin_x);
85         WriteCoord(MSG_ENTITY, self.origin_y);
86         WriteCoord(MSG_ENTITY, self.origin_z);
87
88         WriteCoord(MSG_ENTITY, self.mins_x);
89         WriteCoord(MSG_ENTITY, self.mins_y);
90         WriteCoord(MSG_ENTITY, self.mins_z);
91         WriteCoord(MSG_ENTITY, self.maxs_x);
92         WriteCoord(MSG_ENTITY, self.maxs_y);
93         WriteCoord(MSG_ENTITY, self.maxs_z);
94
95         WriteCoord(MSG_ENTITY, self.movedir_x);
96         WriteCoord(MSG_ENTITY, self.movedir_y);
97         WriteCoord(MSG_ENTITY, self.movedir_z);
98
99         WriteAngle(MSG_ENTITY, self.angles_x);
100         WriteAngle(MSG_ENTITY, self.angles_y);
101         WriteAngle(MSG_ENTITY, self.angles_z);
102
103         return TRUE;
104 }
105
106 void swamp_link()
107 {
108         Net_LinkEntity(self, FALSE, 0, func_ladder_send);
109 }
110
111 /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
112 Players gettin into the swamp will
113 get slowd down and damaged
114 */
115 void spawnfunc_trigger_swamp(void)
116 {
117         // Init stuff
118         EXACTTRIGGER_INIT;
119         self.touch = swamp_touch;
120
121         // Setup default keys, if missing
122         if(self.dmg <= 0)
123                 self.dmg = 5;
124         if(self.swamp_interval <= 0)
125                 self.swamp_interval = 1;
126         if(self.swamp_slowdown <= 0)
127                 self.swamp_slowdown = 0.5;
128
129         swamp_link();
130 }
131
132 #elif defined(CSQC)
133
134 void ent_swamp()
135 {
136         self.warpzone_isboxy = ReadByte();
137         self.scale = ReadByte();
138         self.dmg = ReadByte();
139         self.swamp_slowdown = ReadByte();
140         self.swamp_interval = ReadByte();
141
142         self.origin_x = ReadCoord();
143         self.origin_y = ReadCoord();
144         self.origin_z = ReadCoord();
145         setorigin(self, self.origin);
146
147         self.mins_x = ReadCoord();
148         self.mins_y = ReadCoord();
149         self.mins_z = ReadCoord();
150         self.maxs_x = ReadCoord();
151         self.maxs_y = ReadCoord();
152         self.maxs_z = ReadCoord();
153         setsize(self, self.mins, self.maxs);
154
155         self.movedir_x = ReadCoord();
156         self.movedir_y = ReadCoord();
157         self.movedir_z = ReadCoord();
158
159         self.angles_x = ReadAngle();
160         self.angles_y = ReadAngle();
161         self.angles_z = ReadAngle();
162
163         self.classname = "trigger_swamp";
164         self.solid = SOLID_TRIGGER;
165         self.draw = trigger_draw_generic;
166         self.trigger_touch = swamp_touch;
167         self.drawmask = MASK_NORMAL;
168         self.move_time = time;
169 }
170 #endif