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
24spawnfunc(trigger_swamp);
25#endif
26void swamp_touch(entity this, entity toucher);
27void 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*/
40void 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	{
48		this.owner.in_swamp = 0;
49		delete(this);
50		//centerprint(this.owner,"Killing slug...\n");
51		return;
52	}
53
54	// Slug still alive, so we are still in the swamp
55	// Or we have exited it very recently.
56	// Do the damage and renew the timer.
57#ifdef SVQC
58	Damage (this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, this.owner.origin, '0 0 0');
59#endif
60
61	this.nextthink = time + this.swamp_interval;
62}
63
64void swamp_touch(entity this, entity toucher)
65{
66	// If whatever thats touching the swamp is not a player
67	// or if its a dead player, just dont care abt it.
68	if(!IS_PLAYER(toucher) || IS_DEAD(toucher))
69		return;
70
71	EXACTTRIGGER_TOUCH(this, toucher);
72
73	// Chech if player alredy got a swampslug.
74	if(toucher.in_swamp != 1)
75	{
76		// If not attach one.
77		//centerprint(toucher,"Entering swamp!\n");
78		toucher.swampslug = spawn();
79		toucher.swampslug.health = 2;
80		setthink(toucher.swampslug, swampslug_think);
81		toucher.swampslug.nextthink = time;
82		toucher.swampslug.owner = toucher;
83		toucher.swampslug.dmg = this.dmg;
84		toucher.swampslug.swamp_interval = this.swamp_interval;
85		toucher.swamp_slowdown = this.swamp_slowdown;
86		toucher.in_swamp = 1;
87		return;
88	}
89
90	//toucher.in_swamp = 1;
91
92	//Revitalize players swampslug
93	toucher.swampslug.health = 2;
94}
95
96REGISTER_NET_LINKED(ENT_CLIENT_SWAMP)
97
98#ifdef SVQC
99float swamp_send(entity this, entity to, float sf)
100{
101	WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP);
102
103	WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here
104	WriteByte(MSG_ENTITY, this.swamp_slowdown);
105	WriteByte(MSG_ENTITY, this.swamp_interval);
106
107	trigger_common_write(this, false);
108
109	return true;
110}
111
112void swamp_link(entity this)
113{
114	trigger_link(this, swamp_send);
115}
116
117/*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ?
118Players gettin into the swamp will
119get slowd down and damaged
120*/
121spawnfunc(trigger_swamp)
122{
123	// Init stuff
124	trigger_init(this);
125	settouch(this, swamp_touch);
126
127	// Setup default keys, if missing
128	if(this.dmg <= 0)
129		this.dmg = 5;
130	if(this.swamp_interval <= 0)
131		this.swamp_interval = 1;
132	if(this.swamp_slowdown <= 0)
133		this.swamp_slowdown = 0.5;
134
135	swamp_link(this);
136}
137
138#elif defined(CSQC)
139
140NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew)
141{
142	this.dmg = ReadByte();
143	this.swamp_slowdown = ReadByte();
144	this.swamp_interval = ReadByte();
145
146	trigger_common_read(this, false);
147
148	return = true;
149
150	this.classname = "trigger_swamp";
151	this.solid = SOLID_TRIGGER;
152	settouch(this, swamp_touch);
153	this.drawmask = MASK_NORMAL;
154	this.move_time = time;
155	this.entremove = trigger_remove_generic;
156}
157#endif
158