]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/t_plats.qc
Use the proper time offset for turning. The train still won't turn in the right direc...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_plats.qc
index 9ac9df289243bd36ba3028cec515d4f5394117cb..6ac02df66f04e0433885853cd845909aca1eb757 100644 (file)
@@ -57,7 +57,17 @@ void plat_spawn_inside_trigger()
                tmax_y = tmin_y + 1;
        }
 
-       setsize (trigger, tmin, tmax);
+       if(tmin_x < tmax_x)
+               if(tmin_y < tmax_y)
+                       if(tmin_z < tmax_z)
+                       {
+                               setsize (trigger, tmin, tmax);
+                               return;
+                       }
+
+       // otherwise, something is fishy...
+       remove(trigger);
+       objerror("plat_spawn_inside_trigger: platform has odd size or lip, can't spawn");
 }
 
 void plat_hit_top()
@@ -78,14 +88,14 @@ void plat_go_down()
 {
        sound (self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTN_NORM);
        self.state = 3;
-       SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom);
+       SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, plat_hit_bottom);
 }
 
 void plat_go_up()
 {
        sound (self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTN_NORM);
        self.state = 4;
-       SUB_CalcMove (self.pos1, self.speed, plat_hit_top);
+       SUB_CalcMove (self.pos1, TSPEED_LINEAR, self.speed, plat_hit_top);
 }
 
 void plat_center_touch()
@@ -175,11 +185,6 @@ void plat_reset()
 void spawnfunc_path_corner() { }
 void spawnfunc_func_plat()
 {
-       if (!self.t_length)
-               self.t_length = 80;
-       if (!self.t_width)
-               self.t_width = 10;
-
        if (self.sounds == 0)
                self.sounds = 2;
 
@@ -231,26 +236,49 @@ void spawnfunc_func_plat()
 
        if (!self.speed)
                self.speed = 150;
+       if (!self.lip)
+               self.lip = 16;
+       if (!self.height)
+               self.height = self.size_z - self.lip;
 
        self.pos1 = self.origin;
        self.pos2 = self.origin;
-       self.pos2_z = self.origin_z - self.size_z + 8;
-
-       plat_spawn_inside_trigger ();   // the "start moving" trigger
+       self.pos2_z = self.origin_z - self.height;
 
        self.reset = plat_reset;
        plat_reset();
-}
 
+       plat_spawn_inside_trigger ();   // the "start moving" trigger
+}
 
+.float train_wait_turning;
 void() train_next;
 void train_wait()
 {
+       entity oldself;
+       oldself = self;
+       self = self.enemy;
+       SUB_UseTargets();
+       self = oldself;
+       self.enemy = world;
+
+       // if using bezier curves and turning is enabled, the train will turn toward the next point while waiting
+       if(!self.train_wait_turning)
+       if(self.spawnflags & 1 && self.bezier_turn && self.wait >= 0)
+       {
+               entity targ;
+               targ = find(world, targetname, self.target);
+               SUB_CalcAngleMove(targ.origin, TSPEED_TIME, self.ltime - time + self.wait, train_wait);
+               self.train_wait_turning = TRUE;
+               return;
+       }
+
        if(self.noise != "")
                stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
 
-       if(self.wait < 0)
+       if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
        {
+               self.train_wait_turning = FALSE;
                train_next();
        }
        else
@@ -258,21 +286,24 @@ void train_wait()
                self.think = train_next;
                self.nextthink = self.ltime + self.wait;
        }
-
-       entity oldself;
-       oldself = self;
-       self = self.enemy;
-       SUB_UseTargets();
-       self = oldself;
-       self.enemy = world;
 }
 
 void train_next()
 {
-       entity targ;
+       entity targ, cp;
+       vector cp_org;
+
        targ = find(world, targetname, self.target);
-       self.enemy = targ;
        self.target = targ.target;
+       if (self.spawnflags & 1)
+       {
+               cp = find(world, target, targ.targetname); // get the previous corner first
+               cp = find(world, targetname, cp.curve); // now get its second target (the control point)
+               if(cp.targetname == "")
+                       cp_org = targ.origin - self.mins; // no control point found, assume a straight line to the destination
+               else
+                       cp_org = cp.origin - self.mins;
+       }
        if (!self.target)
                objerror("train_next: no next target");
        self.wait = targ.wait;
@@ -280,9 +311,19 @@ void train_next()
                self.wait = 0.1;
 
        if (targ.speed)
-               SUB_CalcMove(targ.origin - self.mins, targ.speed, train_wait);
+       {
+               if (self.spawnflags & 1)
+                       SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, TSPEED_LINEAR, targ.speed, train_wait);
+               else
+                       SUB_CalcMove(targ.origin - self.mins, TSPEED_LINEAR, targ.speed, train_wait);
+       }
        else
-               SUB_CalcMove(targ.origin - self.mins, self.speed, train_wait);
+       {
+               if (self.spawnflags & 1)
+                       SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, TSPEED_LINEAR, self.speed, train_wait);
+               else
+                       SUB_CalcMove(targ.origin - self.mins, TSPEED_LINEAR, self.speed, train_wait);
+       }
 
        if(self.noise != "")
                sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTN_IDLE);
@@ -314,6 +355,8 @@ void spawnfunc_func_train()
                objerror("func_train without a target");
        if (!self.speed)
                self.speed = 100;
+       if (self.spawnflags & 2)
+               self.bezier_turn = TRUE;
 
        if not(InitMovingBrushTrigger())
                return;
@@ -593,7 +636,7 @@ void button_done()
 void button_return()
 {
        self.state = STATE_DOWN;
-       SUB_CalcMove (self.pos1, self.speed, button_done);
+       SUB_CalcMove (self.pos1, TSPEED_LINEAR, self.speed, button_done);
        self.frame = 0;                 // use normal textures
        if (self.health)
                self.takedamage = DAMAGE_YES;   // can be shot again
@@ -618,7 +661,7 @@ void button_fire()
                sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
 
        self.state = STATE_UP;
-       SUB_CalcMove (self.pos2, self.speed, button_wait);
+       SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, button_wait);
 }
 
 void button_reset()
@@ -858,7 +901,7 @@ void door_go_down()
        }
 
        self.state = STATE_DOWN;
-       SUB_CalcMove (self.pos1, self.speed, door_hit_bottom);
+       SUB_CalcMove (self.pos1, TSPEED_LINEAR, self.speed, door_hit_bottom);
 }
 
 void door_go_up()
@@ -875,7 +918,7 @@ void door_go_up()
        if (self.noise2 != "")
                sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
        self.state = STATE_UP;
-       SUB_CalcMove (self.pos2, self.speed, door_hit_top);
+       SUB_CalcMove (self.pos2, TSPEED_LINEAR, self.speed, door_hit_top);
 
        string oldmessage;
        oldmessage = self.message;
@@ -885,6 +928,7 @@ void door_go_up()
 }
 
 
+
 /*
 =============================================================================
 
@@ -893,6 +937,50 @@ ACTIVATION FUNCTIONS
 =============================================================================
 */
 
+float door_check_keys(void) {
+       local entity door;
+       
+       
+       if (self.owner)
+               door = self.owner;
+       else
+               door = self;
+       
+       // no key needed
+       if not(door.itemkeys)
+               return TRUE;
+
+       // this door require a key
+       // only a player can have a key
+       if (other.classname != "player")
+               return FALSE;
+       
+       if (item_keys_usekey(door, other)) {
+               // some keys were used
+               if (other.key_door_messagetime <= time) {
+                       play2(other, "misc/talk.wav");
+                       centerprint(other, strcat("You also need ", item_keys_keylist(door.itemkeys), "!"));
+                       other.key_door_messagetime = time + 2;
+               }
+       } else {
+               // no keys were used
+               if (other.key_door_messagetime <= time) {
+                       play2(other, "misc/talk.wav");
+                       centerprint(other, strcat("You need ", item_keys_keylist(door.itemkeys), "!"));
+                       other.key_door_messagetime = time + 2;
+               }
+       }
+
+       if (door.itemkeys) {
+               // door is now unlocked
+               play2(other, "misc/talk.wav");
+               centerprint(other, "Door unlocked!");
+               return TRUE;
+       } else
+               return FALSE;
+}
+
+
 void door_fire()
 {
        entity  oself;
@@ -958,6 +1046,7 @@ void door_use()
        entity oself;
 
        //dprint("door_use (model: ");dprint(self.model);dprint(")\n");
+       
        if (self.owner)
        {
                oself = self;
@@ -971,11 +1060,16 @@ 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;
+       
+       // check if door is locked
+       if (!door_check_keys())
+               return;
+       
        self.attack_finished_single = time + 1;
 
        activator = other;
@@ -992,6 +1086,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.itemkeys) {
+               // don't allow opening doors through damage if keys are required
+               return;
+       }
+       
        if (self.health <= 0)
        {
                oself = self;
@@ -1103,7 +1203,7 @@ void door_rotating_go_down()
        }
 
        self.state = STATE_DOWN;
-       SUB_CalcAngleMove (self.pos1, self.speed, door_rotating_hit_bottom);
+       SUB_CalcAngleMove (self.pos1, TSPEED_LINEAR, self.speed, door_rotating_hit_bottom);
 }
 
 void door_rotating_go_up()
@@ -1119,7 +1219,7 @@ void door_rotating_go_up()
        if (self.noise2 != "")
                sound (self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
        self.state = STATE_UP;
-       SUB_CalcAngleMove (self.pos2, self.speed, door_rotating_hit_top);
+       SUB_CalcAngleMove (self.pos2, TSPEED_LINEAR, self.speed, door_rotating_hit_top);
 
        string oldmessage;
        oldmessage = self.message;
@@ -1271,13 +1371,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.
@@ -1311,8 +1415,17 @@ void door_reset()
        self.think = SUB_Null;
 }
 
+// spawnflags require key (for now only func_door)
+#define SPAWNFLAGS_GOLD_KEY 8
+#define SPAWNFLAGS_SILVER_KEY 16
 void spawnfunc_func_door()
 {
+       // Quake 1 keys compatibility
+       if (self.spawnflags & SPAWNFLAGS_GOLD_KEY)
+               self.itemkeys |= ITEM_KEY_BIT(0);
+       if (self.spawnflags & SPAWNFLAGS_SILVER_KEY)
+               self.itemkeys |= ITEM_KEY_BIT(1);
+               
        //if (!self.deathtype) // map makers can override this
        //      self.deathtype = " got in the way";
        SetMovedir ();
@@ -1326,8 +1439,9 @@ void spawnfunc_func_door()
        self.blocked = door_blocked;
        self.use = door_use;
 
-    if(self.spawnflags & 8)
-        self.dmg = 10000;
+       // FIXME: undocumented flag 8, originally (Q1) GOLD_KEY
+       // if(self.spawnflags & 8)
+       //      self.dmg = 10000;
 
     if(self.dmg && (!self.message))
                self.message = "was squished";
@@ -1569,7 +1683,7 @@ void fd_secret_use()
                self.dest1 = self.origin + v_right * (self.t_width * temp);
 
        self.dest2 = self.dest1 + v_forward * self.t_length;
-       SUB_CalcMove(self.dest1, self.speed, fd_secret_move1);
+       SUB_CalcMove(self.dest1, TSPEED_LINEAR, self.speed, fd_secret_move1);
        if (self.noise2 != "")
                sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
 }
@@ -1588,7 +1702,7 @@ void fd_secret_move2()
 {
        if (self.noise2 != "")
                sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
-       SUB_CalcMove(self.dest2, self.speed, fd_secret_move3);
+       SUB_CalcMove(self.dest2, TSPEED_LINEAR, self.speed, fd_secret_move3);
 }
 
 // Wait here until time to go back...
@@ -1608,7 +1722,7 @@ void fd_secret_move4()
 {
        if (self.noise2 != "")
                sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
-       SUB_CalcMove(self.dest1, self.speed, fd_secret_move5);
+       SUB_CalcMove(self.dest1, TSPEED_LINEAR, self.speed, fd_secret_move5);
 }
 
 // Wait 1 second...
@@ -1624,7 +1738,7 @@ void fd_secret_move6()
 {
        if (self.noise2 != "")
                sound(self, CH_TRIGGER_SINGLE, self.noise2, VOL_BASE, ATTN_NORM);
-       SUB_CalcMove(self.oldorigin, self.speed, fd_secret_done);
+       SUB_CalcMove(self.oldorigin, TSPEED_LINEAR, self.speed, fd_secret_done);
 }
 
 void fd_secret_done()
@@ -1984,3 +2098,91 @@ void spawnfunc_func_vectormamamam()
 
        InitializeEntity(self, func_vectormamamam_findtarget, INITPRIO_FINDTARGET);
 }
+
+void conveyor_think()
+{
+       entity e;
+
+       // set myself as current conveyor where possible
+       for(e = world; (e = findentity(e, conveyor, self)); )
+               e.conveyor = world;
+
+       if(self.state)
+       {
+               for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain)
+                       if(!e.conveyor.state)
+                               if(isPushable(e))
+                               {
+                                       vector emin = e.absmin;
+                                       vector emax = e.absmax;
+                                       if(self.solid == SOLID_BSP)
+                                       {
+                                               emin -= '1 1 1';
+                                               emax += '1 1 1';
+                                       }
+                                       if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick
+                                               if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate
+                                                       e.conveyor = self;
+                               }
+
+               for(e = world; (e = findentity(e, conveyor, self)); )
+               {
+                       if(e.flags & FL_CLIENT) // doing it via velocity has quite some advantages
+                               continue; // done in SV_PlayerPhysics
+
+                       setorigin(e, e.origin + self.movedir * sys_frametime);
+                       move_out_of_solid(e);
+                       UpdateCSQCProjectile(e);
+                       /*
+                       // stupid conveyor code
+                       tracebox(e.origin, e.mins, e.maxs, e.origin + self.movedir * sys_frametime, MOVE_NORMAL, e);
+                       if(trace_fraction > 0)
+                               setorigin(e, trace_endpos);
+                       */
+               }
+       }
+
+       self.nextthink = time;
+}
+
+void conveyor_use()
+{
+       self.state = !self.state;
+}
+
+void conveyor_reset()
+{
+       self.state = (self.spawnflags & 1);
+}
+
+void conveyor_init()
+{
+       if (!self.speed)
+               self.speed = 200;
+       self.movedir = self.movedir * self.speed;
+       self.think = conveyor_think;
+       self.nextthink = time;
+       IFTARGETED
+       {
+               self.use = conveyor_use;
+               self.reset = conveyor_reset;
+               conveyor_reset();
+       }
+       else
+               self.state = 1;
+}
+
+void spawnfunc_trigger_conveyor()
+{
+       SetMovedir();
+       EXACTTRIGGER_INIT;
+       conveyor_init();
+}
+
+void spawnfunc_func_conveyor()
+{
+       SetMovedir();
+       InitMovingBrushTrigger();
+       self.movetype = MOVETYPE_NONE;
+       conveyor_init();
+}