X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fmapobjects%2Ftrigger%2Fswamp.qc;h=495deb7988693b565c3d5e9eec12816ec5d22853;hb=14aef0c52085bf8fce7b76b10d8862aabc43c6e4;hp=0717f4beadd4eeb4aa0ae1c2a7cfcc94af38a0f9;hpb=45d8904a100765555e622598a39967963733df1d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/mapobjects/trigger/swamp.qc b/qcsrc/common/mapobjects/trigger/swamp.qc index 0717f4bea..495deb798 100644 --- a/qcsrc/common/mapobjects/trigger/swamp.qc +++ b/qcsrc/common/mapobjects/trigger/swamp.qc @@ -10,149 +10,74 @@ /* * t_swamp.c -* Adds spawnfunc_trigger_swamp and suppoart routines for xonotic 1.2.1+ +* Adds spawnfunc_trigger_swamp and support routines for nexuiz 1.2.1+ and xonotic * Author tZork (Jakob MG) * jakob@games43.se * 2005 11 29 */ -.float swamp_interval; //Hurt players in swamp with this interval -.float swamp_slowdown; //Players in swamp get slowd down by this mutch 0-1 is slowdown 1-~ is speedup (!?) -.float swamp_lifetime; // holds the points remaining until slug dies (not quite health!) -.entity swampslug; - #ifdef SVQC -spawnfunc(trigger_swamp); -#endif -void swamp_touch(entity this, entity toucher); -void swampslug_think(entity this); - - -/* -* Uses a entity calld swampslug to handle players in the swamp -* It works like this: When the plyer enters teh swamp the spawnfunc_trigger_swamp -* attaches a new "swampslug" to the player. As long as the plyer is inside -* the swamp the swamp gives the slug new health. But the slug slowly kills itself -* so when the player goes outside the swamp, it dies and releases the player from the -* swamps curses (dmg/slowdown) -* -* I do it this way becuz there is no "untouch" event. -*/ -void swampslug_think(entity this) +void swamp_think(entity this) { - //Slowly kill the slug - this.swamp_lifetime -= 1; - - //Slug dead? then remove curses. - if(GetResource(this, RES_HEALTH) <= 0) + // set myself as current swampslug where possible + IL_EACH(g_swamped, it.swampslug == this, { - this.owner.in_swamp = 0; - delete(this); - //centerprint(this.owner,"Killing slug...\n"); - return; - } - - // Slug still alive, so we are still in the swamp - // Or we have exited it very recently. - // Do the damage and renew the timer. -#ifdef SVQC - Damage (this.owner, this, this, this.dmg, DEATH_SWAMP.m_id, DMG_NOWEP, this.owner.origin, '0 0 0'); -#endif + it.swampslug = NULL; + IL_REMOVE(g_swamped, it); + }); - this.nextthink = time + this.swamp_interval; -} - -void swamp_touch(entity this, entity toucher) -{ - // If whatever thats touching the swamp is not a player - // or if its a dead player, just dont care abt it. - if(!IS_PLAYER(toucher) || IS_DEAD(toucher)) - return; - - EXACTTRIGGER_TOUCH(this, toucher); - - // Chech if player alredy got a swampslug. - if(toucher.in_swamp != 1) + if(this.active == ACTIVE_ACTIVE) { - // If not attach one. - //centerprint(toucher,"Entering swamp!\n"); - toucher.swampslug = spawn(); - toucher.swampslug.swamp_lifetime = 2; - setthink(toucher.swampslug, swampslug_think); - toucher.swampslug.nextthink = time; - toucher.swampslug.owner = toucher; - toucher.swampslug.dmg = this.dmg; - toucher.swampslug.swamp_interval = this.swamp_interval; - toucher.swamp_slowdown = this.swamp_slowdown; - toucher.in_swamp = 1; - return; + FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, it.swampslug.active == ACTIVE_NOT && IS_PLAYER(it) && !IS_DEAD(it), + { + vector emin = it.absmin; + vector emax = it.absmax; + if(this.solid == SOLID_BSP) + { + emin -= '1 1 1'; + emax += '1 1 1'; + } + if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick + if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate + { + if(!it.swampslug) + IL_PUSH(g_swamped, it); + it.swampslug = this; + } + }); + + IL_EACH(g_swamped, it.swampslug == this, + { + if(time > it.swamp_interval) + { + Damage (it, this, this, this.dmg, DEATH_SWAMP.m_id, DMG_NOWEP, it.origin, '0 0 0'); + it.swamp_interval = time + this.swamp_interval; + } + }); } - //toucher.in_swamp = 1; - - //Revitalize players swampslug - toucher.swampslug.swamp_lifetime = 2; -} - -REGISTER_NET_LINKED(ENT_CLIENT_SWAMP) - -#ifdef SVQC -float swamp_send(entity this, entity to, float sf) -{ - WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP); - - WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here - WriteByte(MSG_ENTITY, this.swamp_slowdown); - WriteByte(MSG_ENTITY, this.swamp_interval); - - trigger_common_write(this, false); - - return true; -} - -void swamp_link(entity this) -{ - trigger_link(this, swamp_send); + this.nextthink = time; } /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ? -Players gettin into the swamp will -get slowd down and damaged +Players in the swamp will be +slowed down and damaged over time */ spawnfunc(trigger_swamp) { // Init stuff - trigger_init(this); - settouch(this, swamp_touch); + EXACTTRIGGER_INIT; + this.active = ACTIVE_ACTIVE; + //trigger_init(this); + setthink(this, swamp_think); + this.nextthink = time; // Setup default keys, if missing - if(this.dmg <= 0) + if(!this.dmg) this.dmg = 5; - if(this.swamp_interval <= 0) + if(!this.swamp_interval) this.swamp_interval = 1; - if(this.swamp_slowdown <= 0) + if(!this.swamp_slowdown) this.swamp_slowdown = 0.5; - - swamp_link(this); -} - -#elif defined(CSQC) - -NET_HANDLE(ENT_CLIENT_SWAMP, bool isnew) -{ - this.dmg = ReadByte(); - this.swamp_slowdown = ReadByte(); - this.swamp_interval = ReadByte(); - - trigger_common_read(this, false); - - return = true; - - this.classname = "trigger_swamp"; - this.solid = SOLID_TRIGGER; - settouch(this, swamp_touch); - this.drawmask = MASK_NORMAL; - this.move_time = time; - this.entremove = trigger_remove_generic; } #endif