]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
item_key initial commit
authorprzemek <przemek@7bulls.com>
Sat, 8 Oct 2011 20:29:59 +0000 (22:29 +0200)
committerprzemek <przemek@7bulls.com>
Sat, 8 Oct 2011 20:29:59 +0000 (22:29 +0200)
models/keys/key.md3 [new file with mode: 0644]
models/keys/key.tga [new file with mode: 0644]
qcsrc/server/defs.qh
qcsrc/server/item_key.qc [new file with mode: 0644]
qcsrc/server/progs.src
qcsrc/server/t_plats.qc

diff --git a/models/keys/key.md3 b/models/keys/key.md3
new file mode 100644 (file)
index 0000000..097c90c
Binary files /dev/null and b/models/keys/key.md3 differ
diff --git a/models/keys/key.tga b/models/keys/key.tga
new file mode 100644 (file)
index 0000000..5e70fa3
Binary files /dev/null and b/models/keys/key.tga differ
index 9f4631a47c1195f5bf345f36f45c0a971c6fd31c..091866a06bf1954484fff7ddcd7f9c142d33daf6 100644 (file)
@@ -245,6 +245,14 @@ float alreadychangedlevel;
 
 .float runes;
 
+// Keys player is holding
+.float itemkeys;
+#define KEYS_GOLD_KEY  1
+#define KEYS_SILVER_KEY        2
+// spawnflags require key (for now only func_door)
+#define SPAWNFLAGS_GOLD_KEY 8
+#define SPAWNFLAGS_SILVER_KEY 16
+
 
 .float version;
 
diff --git a/qcsrc/server/item_key.qc b/qcsrc/server/item_key.qc
new file mode 100644 (file)
index 0000000..6a1ce53
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+Touch handler.
+*/
+void item_key_touch(void) {
+       if (other.classname != "player")
+               return;
+               
+       // player already picked up this key
+       if (other.itemkeys & self.itemkeys)
+               return;
+       
+       other.itemkeys |= self.itemkeys;
+       
+       if (self.message)
+               centerprint(other, self.message);
+}
+
+/*
+Spawn a key with given model, key code and color.
+*/
+void spawn_item_key(float key_code) {
+       self.itemkeys = key_code;
+       precache_model(self.model);
+       
+       if(self.spawnflags & 1)
+               self.noalign = 1;
+       if (self.noalign)
+               self.movetype = MOVETYPE_NONE;
+       else
+               self.movetype = MOVETYPE_TOSS;
+               
+       setsize(self, '-16 -16 -24', '16 16 32');
+       setmodel(self, self.model);
+       self.modelflags |= MF_ROTATE;
+       
+       if (!self.noalign)
+       {
+               // first nudge it off the floor a little bit to avoid math errors
+               setorigin(self, self.origin + '0 0 1');
+               // note droptofloor returns FALSE if stuck/or would fall too far
+               droptofloor();
+       }
+
+       self.touch = item_key_touch;
+}
+
+
+/*
+Spawn silver key.
+*/
+void spawnfunc_item_key1(void) {
+       if (!self.model)
+               self.model = "models/keys/key.md3";
+       
+       if (!self.colormod)
+               self.colormod = '.9 .9 .9';
+                       
+       if (!self.message)
+               self.message = "You've picked up the silver key!";
+               
+       spawn_item_key(KEYS_SILVER_KEY);
+}
+
+/*
+Spawn gold key.
+*/
+void spawnfunc_item_key2(void) {
+       if (!self.model)
+               self.model = "models/keys/key.md3";
+               
+       if (!self.colormod)
+               self.colormod = '1 .9 0';
+       
+       if (!self.message)
+               self.message = "You've picked up the gold key!";
+               
+       spawn_item_key(KEYS_GOLD_KEY);
+}
+
+
index c78b9f2fa5908c650ba76fd71cb0298146764599..87e66136ad677199293f13235160ddbadd801a1a 100644 (file)
@@ -110,6 +110,7 @@ w_all.qc
 t_items.qc
 cl_weapons.qc
 cl_impulse.qc
+item_key.qc
 
 ent_cs.qc
 
index ca87ede224ad45a1a67f401008ec253271c2a65f..25a25cdd1b1cee8a19db00f097697750cf3a6a6c 100644 (file)
@@ -971,11 +971,33 @@ void door_use()
 void door_trigger_touch()
 {
        if (other.health < 1)
-       if not(other.iscreature && other.deadflag == DEAD_NO)
-               return;
+               if not(other.iscreature && other.deadflag == DEAD_NO)
+                       return;
 
        if (time < self.attack_finished_single)
                return;
+       
+       if (self.spawnflags & (SPAWNFLAGS_GOLD_KEY | SPAWNFLAGS_SILVER_KEY)) {
+               // this door require a key
+               // only a player can have a key
+               if (other.classname != "player")
+                       return;
+               
+               // check gold key
+               if (self.spawnflags & SPAWNFLAGS_GOLD_KEY)
+                       if (!(other.itemkeys & KEYS_GOLD_KEY)) {
+                               centerprint(other, "You don't have the gold key");
+                               return;
+                       }
+                       
+               // check silver key
+               if (self.spawnflags & SPAWNFLAGS_SILVER_KEY)
+                       if (!(other.itemkeys & KEYS_SILVER_KEY)) {
+                               centerprint(other, "You don't have the silver key");
+                               return;
+                       }
+       }
+       
        self.attack_finished_single = time + 1;
 
        activator = other;
@@ -992,6 +1014,12 @@ void door_damage(entity inflictor, entity attacker, float damage, float deathtyp
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
        self.health = self.health - damage;
+       
+       if (self.spawnflags & SPAWNFLAGS_GOLD_KEY || self.spawnflags & SPAWNFLAGS_SILVER_KEY) {
+               // don't allow opening doors through damage if keys are required
+               return;
+       }
+       
        if (self.health <= 0)
        {
                oself = self;
@@ -1271,13 +1299,17 @@ void LinkDoors()
 };
 
 
-/*QUAKED spawnfunc_func_door (0 .5 .8) ? START_OPEN x DOOR_DONT_LINK x x TOGGLE
+/*QUAKED spawnfunc_func_door (0 .5 .8) ? START_OPEN x DOOR_DONT_LINK GOLD_KEY SILVER_KEY TOGGLE
 if two doors touch, they are assumed to be connected and operate as a unit.
 
 TOGGLE causes the door to wait in both the start and end states for a trigger event.
 
 START_OPEN causes the door to move to its destination when spawned, and operate in reverse.  It is used to temporarily or permanently close off an area when triggered (not useful for touch or takedamage doors).
 
+GOLD_KEY causes the door to open only if the activator holds a gold key.
+
+SILVER_KEY causes the door to open only if the activator holds a silver key.
+
 "message"      is printed when the door is touched if it is a trigger door and it hasn't been fired yet
 "angle"                determines the opening direction
 "targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.