From 536dbdf122983831fd10a89478c84c86d592047d Mon Sep 17 00:00:00 2001 From: vermeulenl Date: Tue, 15 Feb 2005 22:11:19 +0000 Subject: [PATCH] Added Urre's light code Added Sparks git-svn-id: svn://svn.icculus.org/nexuiz/trunk@302 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- qcsrc/gamec/g_lights.c | 120 +++++++++++++++++++++++++++++++++++++++ qcsrc/gamec/g_triggers.c | 35 ++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 qcsrc/gamec/g_lights.c diff --git a/qcsrc/gamec/g_lights.c b/qcsrc/gamec/g_lights.c new file mode 100644 index 000000000..810ceba99 --- /dev/null +++ b/qcsrc/gamec/g_lights.c @@ -0,0 +1,120 @@ +float LOOP = 1; + +float DNOSHADOW = 2; +float DFOLLOW = 4; +.float light_lev; +.float lefty; +.vector color; +.string dtagname; + +/*QUAKED dynlight (0 1 0) (-8 -8 -8) (8 8 8) START_OFF NOSHADOW FOLLOW +Dynamic light. +Can do one of these things: sit still and be just a silly light, travel along a path, follow an entity around, attach to a tag on an entity. +It can spin around it's own axis in all the above cases. +If targeted, it will toggle between on or off. +keys: +"light_lev" light radius, default 200 +"color" light color in rgb and brightness, 1 1 1 produces bright white, up to 255 255 255 (nuclear blast), recommended values up to 1 1 1, default 1 1 1 +"style" lightstyle, same as for static lights +"angles" initial orientation +"avelocity" a vector value, the direction and speed it rotates in +"skin" cubemap number, must be 16 or above +"dtagname" will attach to this tag on the entity which "targetname" matches "target". If the "target" is either not an md3 model or is missing tags, it will attach to the targets origin. Note that the "target" must be visible to the light +"targetname" will toggle on and off when triggered +"target" if issued with a target, preferrably path_corner, it will move along the path. If also issued with the FOLLOW spawnflag, then this is the entity it will follow. If issued with the "tagname" key it will attach it to this targets tag called "tagname", does not work together with FOLLOW or path movement +"speed" the speed it will travel along the path, default 100 +flags: +"START_OFF" light will be in off state until targeted +"NOSHADOW" will not cast shadows in realtime lighting mode +"FOLLOW" will follow the entity which "targetname" matches "target" +*/ +void() dynlight_think = +{ + if(!self.owner) + remove(self); + + self.nextthink = 0.1; +}; +void() dynlight_find_aiment = +{ + local entity targ; + + targ = find(world, targetname, self.target); + self.movetype = MOVETYPE_FOLLOW; + self.aiment = targ; + self.owner = targ; + self.punchangle = targ.angles; + self.view_ofs = self.origin - targ.origin; + self.v_angle = self.angles - targ.angles; + self.nextthink = 0.1; + self.think = dynlight_think; +}; +void() dynlight_find_path = +{ + local entity targ; + + targ = find(world, targetname, self.target); + self.target = targ.target; + setorigin (self, targ.origin); + self.nextthink = self.ltime + 0.1; + self.think = train_next; +}; +void() dynlight_use = +{ + if (self.light_lev == 0) + self.light_lev = self.lefty; + else + self.light_lev = 0; +}; +void() dynlight = +{ + local entity targ; + + if (!self.light_lev) + self.light_lev = 200; + if (!self.color) + self.color = '1 1 1'; + self.lefty = self.light_lev; + self.use = dynlight_use; + setsize (self, '0 0 0', '0 0 0'); + setorigin (self, self.origin); + //self.pflags = PFLAGS_FULLDYNAMIC; + self.solid = SOLID_NOT; + //self.blocked = SUB_Null; + //if (self.spawnflags & DNOSHADOW) + // self.pflags = self.pflags + PFLAGS_NOSHADOW; + //if (self.spawnflags & START_OFF) + // self.light_lev = 0; + +//tag attaching + if (self.dtagname) + { + if (!self.target) + objerror ("dynlight: no target to follow"); + targ = find(world, targetname, self.target); + setattachment(self, targ, self.dtagname); + self.owner = targ; + self.think = dynlight_think; + return; + } + +// entity following + if (self.spawnflags & DFOLLOW) + { + if (!self.target) + objerror ("dynlight: no target to follow"); + self.nextthink = time + 0.1; + self.think = dynlight_find_aiment; + return; + } +// path following + if (self.target) +// if (!(self.spawnflags & DFOLLOW)) + { + self.movetype = MOVETYPE_PUSH; + if (!self.speed) + self.speed = 100; + self.nextthink = self.ltime + 0.1; + self.think = dynlight_find_path; + } +}; \ No newline at end of file diff --git a/qcsrc/gamec/g_triggers.c b/qcsrc/gamec/g_triggers.c index 79d2ecddf..24f49e5e3 100644 --- a/qcsrc/gamec/g_triggers.c +++ b/qcsrc/gamec/g_triggers.c @@ -390,3 +390,38 @@ if(self.noise) { //remove(self); }; + + +void() sparksthink = +{ + local float tmp; + self.nextthink = time + 0.1; + + if(random() < self.wait) { + te_spark(self.origin,'0 0 -1',self.cnt); + } +} + + +void() func_sparks = +{ + self.think = sparksthink; + self.nextthink = time + 0.2; + + // self.cnt is the amount of sparks that one burst will spawn + if(self.cnt < 1) { + self.cnt = 25.0; // nice default value + } + + // self.wait is the probability that a sparkthink will spawn a spark shower + // range: 0 - 1, but 0 makes little sense, so... + if(self.wait < 0.05) { + self.wait = 0.25; // nice default value + } + + // sound + if(self.noise) { + precache_sound (self.noise); + ambientsound (self.origin, self.noise, 1, ATTN_STATIC); + } +} -- 2.39.2