]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into Mario/qc_physics_prehax
authorMario <zacjardine@y7mail.com>
Mon, 16 Mar 2015 14:00:45 +0000 (01:00 +1100)
committerMario <zacjardine@y7mail.com>
Mon, 16 Mar 2015 14:00:45 +0000 (01:00 +1100)
1  2 
qcsrc/client/effects.qc
qcsrc/common/triggers/func/breakable.qc
qcsrc/common/triggers/target/spawn.qc
qcsrc/server/cl_client.qc
qcsrc/server/defs.qh
qcsrc/server/g_world.qc

Simple merge
index 5ce34b5f471f68f531fccd2bbd96e96a77c98f81,0000000000000000000000000000000000000000..9c371b5d420ddd9e9c3c1deda7f13eb110de9de7
mode 100644,000000..100644
--- /dev/null
@@@ -1,289 -1,0 +1,315 @@@
-               self.model = "";
 +#ifdef SVQC
 +#include "../../../server/weapons/common.qh"
 +
 +.entity sprite;
 +
 +.float dmg;
 +.float dmg_edge;
 +.float dmg_radius;
 +.float dmg_force;
 +.float debrismovetype;
 +.float debrissolid;
 +.vector debrisvelocity;
 +.vector debrisvelocityjitter;
 +.vector debrisavelocityjitter;
 +.float debristime;
 +.float debristimejitter;
 +.float debrisfadetime;
 +.float debrisdamageforcescale;
 +.float debrisskin;
 +
 +.string mdl_dead; // or "" to hide when broken
 +.string debris; // space separated list of debris models
 +// other fields:
 +//   mdl = particle effect name
 +//   count = particle effect multiplier
 +//   targetname = target to trigger to unbreak the model
 +//   target = targets to trigger when broken
 +//   health = amount of damage it can take
 +//   spawnflags:
 +//     1 = start disabled (needs to be triggered to activate)
 +//     2 = indicate damage
 +// notes:
 +//   for mdl_dead to work, origin must be set (using a common/origin brush).
 +//   Otherwise mdl_dead will be displayed at the map origin, and nobody would
 +//   want that!
 +
 +void func_breakable_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force);
 +
 +//
 +// func_breakable
 +// - basically func_assault_destructible for general gameplay use
 +//
 +void LaunchDebris (string debrisname, vector force)
 +{
 +      entity dbr = spawn();
 +      setorigin(dbr, self.absmin
 +                 + '1 0 0' * random() * (self.absmax.x - self.absmin.x)
 +                 + '0 1 0' * random() * (self.absmax.y - self.absmin.y)
 +                 + '0 0 1' * random() * (self.absmax.z - self.absmin.z));
 +      setmodel (dbr, debrisname );
 +      dbr.skin = self.debrisskin;
 +      dbr.colormap = self.colormap; // inherit team colors
 +      dbr.owner = self; // do not be affected by our own explosion
 +      dbr.movetype = self.debrismovetype;
 +      dbr.solid = self.debrissolid;
 +      if(dbr.solid != SOLID_BSP) // SOLID_BSP has exact collision, MAYBE this works? TODO check this out
 +              setsize(dbr, '0 0 0', '0 0 0'); // needed for performance, until engine can deal better with it
 +      dbr.velocity_x = self.debrisvelocity.x + self.debrisvelocityjitter.x * crandom();
 +      dbr.velocity_y = self.debrisvelocity.y + self.debrisvelocityjitter.y * crandom();
 +      dbr.velocity_z = self.debrisvelocity.z + self.debrisvelocityjitter.z * crandom();
 +      self.velocity = self.velocity + force * self.debrisdamageforcescale;
 +      dbr.avelocity_x = random()*self.debrisavelocityjitter.x;
 +      dbr.avelocity_y = random()*self.debrisavelocityjitter.y;
 +      dbr.avelocity_z = random()*self.debrisavelocityjitter.z;
 +      dbr.damageforcescale = self.debrisdamageforcescale;
 +      if(dbr.damageforcescale)
 +              dbr.takedamage = DAMAGE_YES;
 +      SUB_SetFade(dbr, time + self.debristime + crandom() * self.debristimejitter, self.debrisfadetime);
 +}
 +
 +void func_breakable_colormod()
 +{
 +      float h;
 +      if (!(self.spawnflags & 2))
 +              return;
 +      h = self.health / self.max_health;
 +      if(h < 0.25)
 +              self.colormod = '1 0 0';
 +      else if(h <= 0.75)
 +              self.colormod = '1 0 0' + '0 1 0' * (2 * h - 0.5);
 +      else
 +              self.colormod = '1 1 1';
 +
 +      CSQCMODEL_AUTOUPDATE();
 +}
 +
 +void func_breakable_look_destroyed()
 +{
 +      float floorZ;
 +
 +      if(self.solid == SOLID_BSP) // in case a misc_follow moved me, save the current origin first
 +              self.dropped_origin = self.origin;
 +
 +      if(self.mdl_dead == "")
++              self.effects |= EF_NODRAW;
 +      else {
 +              if (self.origin == '0 0 0')     {       // probably no origin brush, so don't spawn in the middle of the map..
 +                      floorZ = self.absmin.z;
 +                      setorigin(self,((self.absmax+self.absmin)*.5));
 +                      self.origin_z = floorZ;
 +              }
 +              setmodel(self, self.mdl_dead);
++              self.effects &= ~EF_NODRAW;
 +      }
 +
++      CSQCMODEL_AUTOUPDATE();
++
 +      self.solid = SOLID_NOT;
 +}
 +
 +void func_breakable_look_restore()
 +{
 +      setmodel(self, self.mdl);
++      self.effects &= ~EF_NODRAW;
++
 +      if(self.mdl_dead != "") // only do this if we use mdl_dead, to behave better with misc_follow
 +              setorigin(self, self.dropped_origin);
++
++      CSQCMODEL_AUTOUPDATE();
++
 +      self.solid = SOLID_BSP;
 +}
 +
 +void func_breakable_behave_destroyed()
 +{
 +      self.health = self.max_health;
 +      self.takedamage = DAMAGE_NO;
 +      self.bot_attack = false;
 +      self.event_damage = func_null;
 +      self.state = 1;
 +      func_breakable_colormod();
++      if (self.noise1)
++              stopsound (self, CH_TRIGGER_SINGLE);
 +}
 +
 +void func_breakable_behave_restore()
 +{
 +      self.health = self.max_health;
 +      if(self.sprite)
 +      {
 +              WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
 +              WaypointSprite_UpdateHealth(self.sprite, self.health);
 +      }
 +      self.takedamage = DAMAGE_AIM;
 +      self.bot_attack = true;
 +      self.event_damage = func_breakable_damage;
 +      self.state = 0;
 +      self.nextthink = 0; // cancel auto respawn
 +      func_breakable_colormod();
++      if (self.noise1)
++              sound (self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
++}
++
++void func_breakable_init_for_player(entity player)
++{
++      if (self.noise1 && self.state == 0 && clienttype(player) == CLIENTTYPE_REAL)
++      {
++              msg_entity = player;
++              soundto (MSG_ONE, self, CH_TRIGGER_SINGLE, self.noise1, VOL_BASE, ATTEN_NORM);
++      }
 +}
 +
 +void func_breakable_destroyed()
 +{
 +      func_breakable_look_destroyed();
 +      func_breakable_behave_destroyed();
 +
 +      CSQCMODEL_AUTOUPDATE();
 +}
 +
 +void func_breakable_restore()
 +{
 +      func_breakable_look_restore();
 +      func_breakable_behave_restore();
 +
 +      CSQCMODEL_AUTOUPDATE();
 +}
 +
 +vector debrisforce; // global, set before calling this
 +void func_breakable_destroy() {
 +      float n, i;
 +      string oldmsg;
 +
 +      activator = self.owner;
 +      self.owner = world; // set by W_PrepareExplosionByDamage
 +
 +      // now throw around the debris
 +      n = tokenize_console(self.debris);
 +      for(i = 0; i < n; ++i)
 +              LaunchDebris(argv(i), debrisforce);
 +
 +      func_breakable_destroyed();
 +
 +      if(self.noise)
 +              sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
 +
 +      if(self.dmg)
 +              RadiusDamage(self, activator, self.dmg, self.dmg_edge, self.dmg_radius, self, world, self.dmg_force, DEATH_HURTTRIGGER, world);
 +
 +      if(self.cnt)
 +              pointparticles(self.cnt, self.absmin * 0.5 + self.absmax * 0.5, '0 0 0', self.count);
 +
 +      if(self.respawntime)
 +      {
 +              self.think = func_breakable_restore;
 +              self.nextthink = time + self.respawntime + crandom() * self.respawntimejitter;
 +      }
 +
 +      oldmsg = self.message;
 +      self.message = "";
 +      SUB_UseTargets();
 +      self.message = oldmsg;
 +}
 +
 +void func_breakable_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
 +{
 +      if(self.state == 1)
 +              return;
 +      if(self.spawnflags & DOOR_NOSPLASH)
 +              if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
 +                      return;
 +      if(self.team)
 +              if(attacker.team == self.team)
 +                      return;
 +      self.health = self.health - damage;
 +      if(self.sprite)
 +      {
 +              WaypointSprite_Ping(self.sprite);
 +              WaypointSprite_UpdateHealth(self.sprite, self.health);
 +      }
 +      func_breakable_colormod();
 +
 +      if(self.health <= 0)
 +      {
 +              debrisforce = force;
 +              W_PrepareExplosionByDamage(attacker, func_breakable_destroy);
 +      }
 +}
 +
 +void func_breakable_reset()
 +{
 +      self.team = self.team_saved;
 +      func_breakable_look_restore();
 +      if(self.spawnflags & 1)
 +              func_breakable_behave_destroyed();
 +      else
 +              func_breakable_behave_restore();
 +
 +      CSQCMODEL_AUTOUPDATE();
 +}
 +
 +// destructible walls that can be used to trigger target_objective_decrease
 +void spawnfunc_func_breakable()
 +{
 +      float n, i;
 +      if(!self.health)
 +              self.health = 100;
 +      self.max_health = self.health;
 +
 +      // yes, I know, MOVETYPE_NONE is not available here, not that one would want it here anyway
 +      if(!self.debrismovetype) self.debrismovetype = MOVETYPE_BOUNCE;
 +      if(!self.debrissolid) self.debrissolid = SOLID_NOT;
 +      if(self.debrisvelocity == '0 0 0') self.debrisvelocity = '0 0 140';
 +      if(self.debrisvelocityjitter == '0 0 0') self.debrisvelocityjitter = '70 70 70';
 +      if(self.debrisavelocityjitter == '0 0 0') self.debrisavelocityjitter = '600 600 600';
 +      if(!self.debristime) self.debristime = 3.5;
 +      if(!self.debristimejitter) self.debristime = 2.5;
 +
 +      if(self.mdl != "")
 +              self.cnt = particleeffectnum(self.mdl);
 +      if(self.count == 0)
 +              self.count = 1;
 +
 +      if(self.message == "")
 +              self.message = "got too close to an explosion";
 +      if(self.message2 == "")
 +              self.message2 = "was pushed into an explosion by";
 +      if(!self.dmg_radius)
 +              self.dmg_radius = 150;
 +      if(!self.dmg_force)
 +              self.dmg_force = 200;
 +
 +      self.mdl = self.model;
 +      SetBrushEntityModel();
 +
 +      self.use = func_breakable_restore;
 +
 +      // precache all the models
 +      if (self.mdl_dead)
 +              precache_model(self.mdl_dead);
 +      n = tokenize_console(self.debris);
 +      for(i = 0; i < n; ++i)
 +              precache_model(argv(i));
 +      if(self.noise)
 +              precache_sound(self.noise);
++      if(self.noise1)
++              precache_sound(self.noise1);
 +
 +      self.team_saved = self.team;
 +      self.dropped_origin = self.origin;
 +
 +      self.reset = func_breakable_reset;
 +      func_breakable_reset();
 +
++      self.init_for_player_needed = 1;
++      self.init_for_player = func_breakable_init_for_player;
++
 +      CSQCMODEL_AUTOINIT();
 +}
 +
 +// for use in maps with a "model" key set
 +void spawnfunc_misc_breakablemodel() {
 +      spawnfunc_func_breakable();
 +}
 +#endif
index 98a3209cc546e18af722de4799d41e5c831a71bc,0000000000000000000000000000000000000000..7b183553da1a8adc4c293d188c929886e9798ca1
mode 100644,000000..100644
--- /dev/null
@@@ -1,347 -1,0 +1,350 @@@
 +#if defined(CSQC)
 +#elif defined(MENUQC)
 +#elif defined(SVQC)
 +      #include "../../../dpdefs/progsdefs.qh"
 +    #include "../../../dpdefs/dpextensions.qh"
 +    #include "../../util.qh"
 +    #include "../../../server/defs.qh"
 +#endif
 +
 +#ifdef SVQC
 +
 +// spawner entity
 +// "classname" "target_spawn"
 +// "message" "fieldname value fieldname value ..."
 +// "spawnflags"
 +//   1 = call the spawn function
 +//   2 = trigger on map load
 +
 +float target_spawn_initialized;
 +.void() target_spawn_spawnfunc;
 +float target_spawn_spawnfunc_field;
 +.entity target_spawn_activator;
 +.float target_spawn_id;
 +float target_spawn_count;
 +
 +void target_spawn_helper_setmodel()
 +{
 +      setmodel(self, self.model);
 +}
 +
 +void target_spawn_helper_setsize()
 +{
 +      setsize(self, self.mins, self.maxs);
 +}
 +
 +void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity t3, entity t4, entity act)
 +{
 +      float i, n, valuefieldpos;
 +      string key, value, valuefield, valueoffset, valueoffsetrandom;
 +      entity valueent;
 +      vector data, data2;
 +      entity oldself;
 +      entity oldactivator;
 +
 +      n = tokenize_console(msg);
 +
 +      for(i = 0; i < n-1; i += 2)
 +      {
 +              key = argv(i);
 +              value = argv(i+1);
 +              if(key == "$")
 +              {
 +                      data.x = -1;
 +                      data.y = FIELD_STRING;
 +              }
 +              else
 +              {
 +                      data = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", key)));
 +                      if(data.y == 0) // undefined field, i.e., invalid type
 +                      {
 +                              print("target_spawn: invalid/unknown entity key ", key, " specified, ignored!\n");
 +                              continue;
 +                      }
 +              }
 +              if(substring(value, 0, 1) == "$")
 +              {
 +                      value = substring(value, 1, strlen(value) - 1);
 +                      if(substring(value, 0, 1) == "$")
 +                      {
 +                              // deferred replacement
 +                              // do nothing
 +                              // useful for creating target_spawns with this!
 +                      }
 +                      else
 +                      {
 +                              // replace me!
 +                              valuefieldpos = strstrofs(value, "+", 0);
 +                              valueoffset = "";
 +                              if(valuefieldpos != -1)
 +                              {
 +                                      valueoffset = substring(value, valuefieldpos + 1, strlen(value) - valuefieldpos - 1);
 +                                      value = substring(value, 0, valuefieldpos);
 +                              }
 +
 +                              valuefieldpos = strstrofs(valueoffset, "+", 0);
 +                              valueoffsetrandom = "";
 +                              if(valuefieldpos != -1)
 +                              {
 +                                      valueoffsetrandom = substring(valueoffset, valuefieldpos + 1, strlen(valueoffset) - valuefieldpos - 1);
 +                                      valueoffset = substring(valueoffset, 0, valuefieldpos);
 +                              }
 +
 +                              valuefieldpos = strstrofs(value, ".", 0);
 +                              valuefield = "";
 +                              if(valuefieldpos != -1)
 +                              {
 +                                      valuefield = substring(value, valuefieldpos + 1, strlen(value) - valuefieldpos - 1);
 +                                      value = substring(value, 0, valuefieldpos);
 +                              }
 +
 +                              if(value == "self")
 +                              {
 +                                      valueent = self;
 +                                      value = "";
 +                              }
 +                              else if(value == "activator")
 +                              {
 +                                      valueent = act;
 +                                      value = "";
 +                              }
 +                              else if(value == "other")
 +                              {
 +                                      valueent = other;
 +                                      value = "";
 +                              }
 +                              else if(value == "pusher")
 +                              {
 +                                      if(time < act.pushltime)
 +                                              valueent = act.pusher;
 +                                      else
 +                                              valueent = world;
 +                                      value = "";
 +                              }
 +                              else if(value == "target")
 +                              {
 +                                      valueent = e;
 +                                      value = "";
 +                              }
 +                              else if(value == "killtarget")
 +                              {
 +                                      valueent = kt;
 +                                      value = "";
 +                              }
 +                              else if(value == "target2")
 +                              {
 +                                      valueent = t2;
 +                                      value = "";
 +                              }
 +                              else if(value == "target3")
 +                              {
 +                                      valueent = t3;
 +                                      value = "";
 +                              }
 +                              else if(value == "target4")
 +                              {
 +                                      valueent = t4;
 +                                      value = "";
 +                              }
 +                              else if(value == "time")
 +                              {
 +                                      valueent = world;
 +                                      value = ftos(time);
 +                              }
 +                              else
 +                              {
 +                                      print("target_spawn: invalid/unknown variable replacement ", value, " specified, ignored!\n");
 +                                      continue;
 +                              }
 +
 +                              if(valuefield == "")
 +                              {
 +                                      if(value == "")
 +                                              value = ftos(num_for_edict(valueent));
 +                              }
 +                              else
 +                              {
 +                                      if(value != "")
 +                                      {
 +                                              print("target_spawn: try to get a field of a non-entity, ignored!\n");
 +                                              continue;
 +                                      }
 +                                      data2 = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", valuefield)));
 +                                      if(data2_y == 0) // undefined field, i.e., invalid type
 +                                      {
 +                                              print("target_spawn: invalid/unknown entity key replacement ", valuefield, " specified, ignored!\n");
 +                                              continue;
 +                                      }
 +                                      value = getentityfieldstring(data2_x, valueent);
 +                              }
 +
 +                              if(valueoffset != "")
 +                              {
 +                                      switch(data.y)
 +                                      {
 +                                              case FIELD_STRING:
 +                                                      value = strcat(value, valueoffset);
 +                                                      break;
 +                                              case FIELD_FLOAT:
 +                                                      value = ftos(stof(value) + stof(valueoffset));
 +                                                      break;
 +                                              case FIELD_VECTOR:
 +                                                      value = vtos(stov(value) + stov(valueoffset));
 +                                                      break;
 +                                              default:
 +                                                      print("target_spawn: only string, float and vector fields can do calculations, calculation ignored!\n");
 +                                                      break;
 +                                      }
 +                              }
 +
 +                              if(valueoffsetrandom != "")
 +                              {
 +                                      switch(data.y)
 +                                      {
 +                                              case FIELD_FLOAT:
 +                                                      value = ftos(stof(value) + random() * stof(valueoffsetrandom));
 +                                                      break;
 +                                              case FIELD_VECTOR:
 +                                                      data2 = stov(valueoffsetrandom);
 +                                                      value = vtos(stov(value) + random() * data2_x * '1 0 0' + random() * data2_y * '0 1 0' + random() * data2_z * '0 0 1');
 +                                                      break;
 +                                              default:
 +                                                      print("target_spawn: only float and vector fields can do random calculations, calculation ignored!\n");
 +                                                      break;
 +                                      }
 +                              }
 +                      }
 +              }
 +              if(key == "$")
 +              {
 +                      if(substring(value, 0, 1) == "_")
 +                              value = strcat("target_spawn_helper", value);
 +                      putentityfieldstring(target_spawn_spawnfunc_field, e, value);
 +
 +                      oldself = self;
 +                      oldactivator = activator;
 +
 +                      self = e;
 +                      activator = act;
 +
 +                      self.target_spawn_spawnfunc();
 +
 +                      self = oldself;
 +                      activator = oldactivator;
++
++                      // We called an external function, so we have to re-tokenize msg.
++                      n = tokenize_console(msg);
 +              }
 +              else
 +              {
 +                      if(data.y == FIELD_VECTOR)
 +                              value = strreplace("'", "", value); // why?!?
 +                      putentityfieldstring(data.x, e, value);
 +              }
 +      }
 +}
 +
 +void target_spawn_useon(entity e)
 +{
 +      self.target_spawn_activator = activator;
 +      target_spawn_edit_entity(
 +              e,
 +              self.message,
 +              find(world, targetname, self.killtarget),
 +              find(world, targetname, self.target2),
 +              find(world, targetname, self.target3),
 +              find(world, targetname, self.target4),
 +              activator
 +      );
 +}
 +
 +float target_spawn_cancreate()
 +{
 +      float c;
 +      entity e;
 +
 +      c = self.count;
 +      if(c == 0) // no limit?
 +              return 1;
 +
 +      ++c; // increase count to not include MYSELF
 +      for(e = world; (e = findfloat(e, target_spawn_id, self.target_spawn_id)); --c)
 +              ;
 +
 +      // if c now is 0, we have AT LEAST the given count (maybe more), so don't spawn any more
 +      if(c == 0)
 +              return 0;
 +      return 1;
 +}
 +
 +void target_spawn_use()
 +{
 +      entity e;
 +
 +      if(self.target == "")
 +      {
 +              // spawn new entity
 +              if(!target_spawn_cancreate())
 +                      return;
 +              e = spawn();
 +              target_spawn_useon(e);
 +              e.target_spawn_id = self.target_spawn_id;
 +      }
 +      else if(self.target == "*activator")
 +      {
 +              // edit entity
 +              if(activator)
 +                      target_spawn_useon(activator);
 +      }
 +      else
 +      {
 +              // edit entity
 +              for(e = world; (e = find(e, targetname, self.target)); )
 +                      target_spawn_useon(e);
 +      }
 +}
 +
 +void target_spawn_spawnfirst()
 +{
 +      activator = self.target_spawn_activator;
 +      if(self.spawnflags & 2)
 +              target_spawn_use();
 +}
 +
 +void initialize_field_db()
 +{
 +      if(!target_spawn_initialized)
 +      {
 +              float n, i;
 +              string fn;
 +              vector prev, new;
 +              float ft;
 +
 +              n = numentityfields();
 +              for(i = 0; i < n; ++i)
 +              {
 +                      fn = entityfieldname(i);
 +                      ft = entityfieldtype(i);
 +                      new = i * '1 0 0' + ft * '0 1 0' + '0 0 1';
 +                      prev = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", fn)));
 +                      if(prev.y == 0)
 +                      {
 +                              db_put(TemporaryDB, strcat("/target_spawn/field/", fn), vtos(new));
 +                              if(fn == "target_spawn_spawnfunc")
 +                                      target_spawn_spawnfunc_field = i;
 +                      }
 +              }
 +
 +              target_spawn_initialized = 1;
 +      }
 +}
 +
 +void spawnfunc_target_spawn()
 +{
 +      initialize_field_db();
 +      self.use = target_spawn_use;
 +      self.message = strzone(strreplace("'", "\"", self.message));
 +      self.target_spawn_id = ++target_spawn_count;
 +      InitializeEntity(self, target_spawn_spawnfirst, INITPRIO_LAST);
 +}
 +#endif
Simple merge
Simple merge
Simple merge