From 978a0dd865663f3fcd49554b123d6fb56b396588 Mon Sep 17 00:00:00 2001
From: Marco Hladik <marco@icculus.org>
Date: Sun, 1 Sep 2019 22:39:56 +0200
Subject: [PATCH] Added initial func_guntarget and trigger_autosave.

---
 src/client/cstrike/draw.c                  |   1 -
 src/defs.h                                 |   2 +-
 src/gs-entbase/client/env_glow.cpp         |  12 +-
 src/gs-entbase/server.src                  |   2 +
 src/gs-entbase/server/func_guntarget.cpp   | 146 ++++++++
 src/gs-entbase/server/func_train.cpp       |   3 +-
 src/gs-entbase/server/trigger_autosave.cpp |  70 ++++
 src/server/valve/client.c                  |   1 -
 src/server/valve/server.c                  |   2 +-
 src/shared/pmove.c                         | 387 +++++++++------------
 src/shared/valve/items.h                   |  14 +-
 11 files changed, 409 insertions(+), 231 deletions(-)
 create mode 100644 src/gs-entbase/server/func_guntarget.cpp
 create mode 100644 src/gs-entbase/server/trigger_autosave.cpp

diff --git a/src/client/cstrike/draw.c b/src/client/cstrike/draw.c
index 83c6caf4..d77321fb 100644
--- a/src/client/cstrike/draw.c
+++ b/src/client/cstrike/draw.c
@@ -23,7 +23,6 @@ Entry point for drawing on the client
 */
 void Cstrike_PreDraw(void)
 {
-
 	Nightvision_PreDraw();
 }
 
diff --git a/src/defs.h b/src/defs.h
index 6e6524ef..ec8b769a 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -59,7 +59,7 @@ const vector VEC_PLAYER_CVIEWPOS = [0,0,12];
 #define FLQW_LAGGEDMOVE		(1<<16)
 
 // FreeCS flags
-#define FL_FLASHLIGHT           (1<<17)
+#define FL_FLASHLIGHT		(1<<17)
 #define FL_REMOVEME		(1<<18)
 #define FL_CROUCHING 		(1<<19)
 #define FL_SEMI_TOGGLED		(1<<20)
diff --git a/src/gs-entbase/client/env_glow.cpp b/src/gs-entbase/client/env_glow.cpp
index 08c87a02..674034b7 100644
--- a/src/gs-entbase/client/env_glow.cpp
+++ b/src/gs-entbase/client/env_glow.cpp
@@ -58,10 +58,14 @@ float env_glow::predraw(void)
 		/* Project it, always facing the player */
 		makevectors(view_angles);
 		R_BeginPolygon(m_strSprite, 1, 0);
-		R_PolygonVertex(forg + v_right * fsize[0] - v_up * fsize[1], [1,1], m_vecColor, falpha);
-		R_PolygonVertex(forg - v_right * fsize[0] - v_up * fsize[1], [0,1], m_vecColor, falpha);
-		R_PolygonVertex(forg - v_right * fsize[0] + v_up * fsize[1], [0,0], m_vecColor, falpha);
-		R_PolygonVertex(forg + v_right * fsize[0] + v_up * fsize[1], [1,0], m_vecColor, falpha);
+		R_PolygonVertex(forg + v_right * fsize[0] - v_up * fsize[1],
+			[1,1], m_vecColor, falpha);
+		R_PolygonVertex(forg - v_right * fsize[0] - v_up * fsize[1],
+			[0,1], m_vecColor, falpha);
+		R_PolygonVertex(forg - v_right * fsize[0] + v_up * fsize[1],
+			[0,0], m_vecColor, falpha);
+		R_PolygonVertex(forg + v_right * fsize[0] + v_up * fsize[1],
+			[1,0], m_vecColor, falpha);
 		R_EndPolygon();
 		addentity(this);
 	}
diff --git a/src/gs-entbase/server.src b/src/gs-entbase/server.src
index acd026b6..21ad8042 100644
--- a/src/gs-entbase/server.src
+++ b/src/gs-entbase/server.src
@@ -25,6 +25,7 @@ server/func_door_rotating.cpp
 server/func_illusionary.cpp
 server/func_ladder.cpp
 server/func_train.cpp
+server/func_guntarget.cpp
 server/func_tracktrain.cpp
 server/func_pushable.cpp
 server/func_wall.cpp
@@ -35,6 +36,7 @@ server/light.cpp
 server/stubs.cpp
 server/infodecal.cpp
 server/trigger_auto.cpp
+server/trigger_autosave.cpp
 server/trigger_cdaudio.cpp
 server/trigger_camera.cpp
 server/trigger_hurt.cpp
diff --git a/src/gs-entbase/server/func_guntarget.cpp b/src/gs-entbase/server/func_guntarget.cpp
new file mode 100644
index 00000000..eadcee27
--- /dev/null
+++ b/src/gs-entbase/server/func_guntarget.cpp
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2016-2019 Marco Hladik <marco@icculus.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define SF_GUNTARGET_ON
+
+class func_guntarget:CBaseTrigger
+{
+	float m_flSpeed;
+
+	void() func_guntarget;
+	
+	virtual void() Respawn;
+	virtual void() NextPath;
+	virtual void() Move;
+	virtual void() Stop;
+	virtual void() Trigger;
+	virtual void(int) vDeath;
+};
+
+void func_guntarget::Move(void)
+{
+	float flTravelTime;
+	vector vel_to_pos;
+	entity f;
+
+	f = find(world, CBaseTrigger::m_strTargetName, m_strTarget);
+
+	if (!f) {
+		print("^1func_guntarget^7: Path node not found!\n");
+		return;
+	}
+
+	vector vecWorldPos;
+	vecWorldPos[0] = absmin[0] + (0.5 * (absmax[0] - absmin[0]));
+	vecWorldPos[1] = absmin[1] + (0.5 * (absmax[1] - absmin[1]));
+	vecWorldPos[2] = absmin[2] + (0.5 * (absmax[2] - absmin[2]));
+
+	vel_to_pos = (f.origin - vecWorldPos);
+	flTravelTime = (vlen(vel_to_pos) / m_flSpeed);
+
+	if (!flTravelTime) {
+		NextPath();
+		return;
+	}
+
+	velocity = (vel_to_pos * (1 / flTravelTime));
+	think = NextPath;
+	nextthink = (ltime + flTravelTime);
+}
+
+void func_guntarget::NextPath(void)
+{
+	CBaseTrigger current_target;
+
+	print(sprintf("^2func_guntarget^7: Talking to current target %s... ", m_strTarget));
+	current_target = (CBaseTrigger)find(world, CBaseTrigger::m_strTargetName, m_strTarget);
+
+	if (!current_target) {
+		print("^1FAILED.\n");
+	} else {
+		print("^2SUCCESS.\n");
+	}
+
+	m_strTarget = current_target.m_strTarget;
+	velocity = [0,0,0];
+
+	if (m_strTarget) {
+		Move();
+	}
+}
+
+void func_guntarget::vDeath(int iHitBody)
+{
+	Stop();
+}
+
+void func_guntarget::Stop(void)
+{
+	takedamage = DAMAGE_NO;
+	velocity = [0,0,0];
+	nextthink = 0;
+	think = __NULL__;
+}
+
+void func_guntarget::Trigger(void)
+{
+	flags = (1<<FL_FROZEN) | flags;
+
+	if (flags & FL_FROZEN) {
+		takedamage = DAMAGE_NO;
+		Stop();
+	} else {
+		takedamage = DAMAGE_YES;
+		NextPath();
+	}
+}
+
+void func_guntarget::Respawn(void)
+{
+	solid = SOLID_BSP;
+	movetype = MOVETYPE_PUSH;
+
+	setmodel(this, m_oldModel);
+	setorigin(this, m_oldOrigin);
+
+	if (spawnflags & 1) {
+		think = Trigger;
+		nextthink = time + 0.1f;
+	}
+}
+
+void func_guntarget::func_guntarget(void)
+{
+	for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
+		switch (argv(i)) {
+		case "health":
+			health = stof(argv(i+1));
+			break;
+		case "speed":
+			m_flSpeed = stof(argv(i+1));
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (!m_flSpeed) {
+		m_flSpeed = 100;
+	}
+
+	CBaseTrigger::CBaseTrigger();
+	Respawn();
+}
diff --git a/src/gs-entbase/server/func_train.cpp b/src/gs-entbase/server/func_train.cpp
index 74d93313..1bc842e2 100644
--- a/src/gs-entbase/server/func_train.cpp
+++ b/src/gs-entbase/server/func_train.cpp
@@ -55,7 +55,7 @@ void func_train::GoToTarget(void)
 
 	velocity = (vel_to_pos * (1 / flTravelTime));
 	think = NextPath;
-	nextthink = (time + flTravelTime);
+	nextthink = (ltime + flTravelTime);
 }
 
 void func_train::NextPath(void)
@@ -84,7 +84,6 @@ void func_train::Trigger(void)
 	GoToTarget();
 }
 
-
 void func_train::Find(void)
 {
 	entity f = find(world, CBaseTrigger::m_strTargetName, m_strTarget);
diff --git a/src/gs-entbase/server/trigger_autosave.cpp b/src/gs-entbase/server/trigger_autosave.cpp
new file mode 100644
index 00000000..20f8fcd0
--- /dev/null
+++ b/src/gs-entbase/server/trigger_autosave.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2016-2019 Marco Hladik <marco@icculus.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+class trigger_autosave:CBaseTrigger
+{
+	float m_flDelay;
+	void() trigger_autosave;
+	virtual void() touch;
+	virtual void() Respawn;
+};
+
+void trigger_autosave::touch(void)
+{
+	eActivator = other;
+
+	localcmd("save autosave");
+	Hide();
+
+	if (m_flDelay > 0) {
+		CBaseTrigger::UseTargets_Delay(m_flDelay);
+	} else {
+		CBaseTrigger::UseTargets();
+	}
+	solid = SOLID_NOT;
+#ifdef GS_DEVELOPER
+	alpha = 0.001f;
+#endif
+}
+
+/* TODO: Make this redundant */
+void trigger_autosave::Respawn(void)
+{
+	solid = SOLID_TRIGGER;
+#ifdef GS_DEVELOPER
+	alpha = 0.5f;
+#endif
+}
+
+void trigger_autosave::trigger_autosave(void)
+{	
+	if (cvar("sv_playerslots") > 1) {
+		remove(this);
+		return;
+	}
+	for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
+		switch (argv(i)) {
+		case "delay":
+			m_flDelay = stof(argv(i + 1));
+			break;
+		default:
+			break;
+		}
+	}
+	CBaseEntity::CBaseEntity();
+	CBaseTrigger::InitBrushTrigger();
+	trigger_autosave::Respawn();
+}
diff --git a/src/server/valve/client.c b/src/server/valve/client.c
index 61d78785..7ff16c4f 100644
--- a/src/server/valve/client.c
+++ b/src/server/valve/client.c
@@ -189,7 +189,6 @@ void Game_ParseClientCommand(string cmd)
 		return;
 	}
 
-	// Players talk to players, spectators to spectators.
 	if (argv(0) == "say") {
 		localcmd(sprintf("echo [SERVER] %s: %s\n", self.netname, argv(1)));
 		SV_SendChat(self, argv(1), world, 0);
diff --git a/src/server/valve/server.c b/src/server/valve/server.c
index 45992971..d4e592e8 100644
--- a/src/server/valve/server.c
+++ b/src/server/valve/server.c
@@ -41,6 +41,6 @@ void Game_Worldspawn(void)
 	precache_model("models/player/zombie/zombie.mdl");
 	precache_model("models/player/helmet/helmet.mdl");
 	precache_model("models/player/recon/recon.mdl");
-    precache_model("models/player/robo/robo.mdl");	
+	precache_model("models/player/robo/robo.mdl");	
 	Weapons_Init();
 }
diff --git a/src/shared/pmove.c b/src/shared/pmove.c
index 54d0fa1f..df2f9135 100644
--- a/src/shared/pmove.c
+++ b/src/shared/pmove.c
@@ -14,13 +14,12 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define AIRCONTROL
-
 #define PHY_JUMP_CHAINWINDOW	0.5
-#define PHY_JUMP_CHAIN	100
+#define PHY_JUMP_CHAIN		100
 #define PHY_JUMP_CHAINDECAY	50
 
-/*FIXME: jumptime should use the time global, as time intervals are not predictable - decrement it based upon input_timelength*/
+/* FIXME: jumptime should use the time global, as time intervals are not
+ * predictable - decrement it based upon input_timelength */
 .float waterlevel;
 .float watertype;
 .float maxspeed;
@@ -34,12 +33,12 @@ int Items_CheckItem(entity pl, int i) {
 }
 #endif
 
-/*
-=================
-PMove_Init
-=================
-*/
-void PMove_Init(void) {
+/* serverinfo keys are the only way both client and server are kept in sync
+ * about physics variables. so none of the traditional cvars will work.
+ * otherwise we could not have reliable prediction code for player movement.
+ */
+void
+PMove_Init(void) {
 #ifdef SSQC
 	localcmd("serverinfo phy_stepheight 18\n");
 	localcmd("serverinfo phy_airstepheight 18\n");
@@ -61,14 +60,11 @@ void PMove_Init(void) {
 #endif
 }
 
-/*
-=================
-PMove_Contents
-
-Wrapper that emulates pointcontents' behaviour
-=================
-*/
-int PMove_Contents(vector org)
+/* pointcontents reimplementation, only way we can effectively trace 
+ * against ladders and liquids that are defined in the game-logic.
+ */
+int
+PMove_Contents(vector org)
 {
 	int oldhitcontents = self.hitcontentsmaski;
 	self.hitcontentsmaski = -1;
@@ -77,7 +73,9 @@ int PMove_Contents(vector org)
 	return trace_endcontentsi;
 }
 
-float PMove_Gravity(entity ent)
+/* used for trigger_gravity type entities */
+float
+PMove_Gravity(entity ent)
 {
 	if (ent.gravity) {
 		return serverkeyfloat("phy_gravity") * ent.gravity; 
@@ -86,15 +84,9 @@ float PMove_Gravity(entity ent)
 	}
 }
 
-/*
-=================
-PMove_Categorize
-
-	Figures out where we are in the game world.
-	Whether we are in water, on the ground etc.
-=================
-*/
-void PMove_Categorize(void)
+/* figure out where we are in the geometry. void, solid, liquid, etc. */
+void
+PMove_Categorize(void)
 {
 	int contents;
 
@@ -108,7 +100,8 @@ void PMove_Categorize(void)
 		self.view_ofs = VEC_PLAYER_VIEWPOS;
 	}
 
-	tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 0.25', FALSE, self);
+	tracebox(self.origin, self.mins, self.maxs, self.origin - [0,0,0.25],
+		FALSE, self);
 
 	if (!trace_startsolid) {
 		if ((trace_fraction < 1) && (trace_plane_normal[2] > 0.7)) {
@@ -118,10 +111,10 @@ void PMove_Categorize(void)
 		}
 	}
 
-	// Ladder content testing
+	/* ladder content testing */
 	int oldhitcontents = self.hitcontentsmaski;
 	self.hitcontentsmaski = CONTENTBIT_FTELADDER;
-	tracebox( self.origin, self.mins, self.maxs, self.origin, FALSE, self );
+	tracebox(self.origin, self.mins, self.maxs, self.origin, FALSE, self);
 	self.hitcontentsmaski = oldhitcontents;
 
 	if (trace_endcontentsi & CONTENTBIT_FTELADDER) {
@@ -140,10 +133,15 @@ void PMove_Categorize(void)
 		contents = CONTENT_LAVA;
 	}
 
+	/* how far underwater are we? */
 	if (contents < CONTENT_SOLID && !(self.flags & FL_ONLADDER)) {
 		self.watertype = contents;
-		if (PMove_Contents(self.origin + (self.mins + self.maxs) * 0.5) & CONTENTBITS_FLUID) {
-			if (PMove_Contents(self.origin + self.maxs - '0 0 1') & CONTENTBITS_FLUID) {
+		if (PMove_Contents(self.origin + (self.mins + self.maxs) * 0.5) 
+			& CONTENTBITS_FLUID)
+		{
+			if (PMove_Contents(self.origin + self.maxs - '0 0 1')
+				& CONTENTBITS_FLUID)
+			{
 				self.waterlevel = 3;
 			} else {
 				self.waterlevel = 2;
@@ -157,12 +155,9 @@ void PMove_Categorize(void)
 	}
 }
 
-/*
-===========
-PMove_WaterMove
-============
-*/
-void PMove_WaterMove(void)
+/* this is technically run every frame, not just when we're in water */
+void
+PMove_WaterMove(void)
 {
 	if (self.movetype == MOVETYPE_NOCLIP) {
 		return;
@@ -231,7 +226,9 @@ void PMove_WaterMove(void)
 	}
 }
 
-void PMove_CheckWaterJump(void)
+/* spammed whenever we're near a ledge, getting out of a pool or something */
+void
+PMove_CheckWaterJump(void)
 {
 	vector vStart;
 	vector vEnd;
@@ -259,28 +256,29 @@ void PMove_CheckWaterJump(void)
 	}
 }
 
-int QPMove_IsStuck(entity eTarget, vector vOffset, vector vecMins, vector vecMaxs)
+/* simple bounds check */
+int
+QPMove_IsStuck(entity eTarget, vector vOffset, vector vecMins, vector vecMaxs)
 {
+	vector bound;
+
 	if (eTarget.solid != SOLID_SLIDEBOX) {
 		return FALSE;
 	}
-	tracebox(eTarget.origin + vOffset, vecMins, vecMaxs, eTarget.origin + vOffset, FALSE, eTarget);
+
+	bound = eTarget.origin + vOffset;
+	tracebox(bound, vecMins, vecMaxs, bound, FALSE, eTarget);
 	return trace_startsolid;
 }
 
-/*
-=================
-PMove_Run_Acceleration
-
-	This function applies the velocity changes the player wishes to apply
-=================
-*/
-void PMove_Run_Acceleration(float flMovetime, float flBefore)
+/* two-pass acceleration */
+void
+PMove_Run_Acceleration(float move_time, float premove)
 {
 	vector vecWishVel;
-	vector vecWishDir;
+	vector wish_dir;
 	vector vecTemp;
-	float flWishSpeed;
+	float wish_speed;
 	float flFriction;
 	float flJumptimeDelta;
 	float flChainBonus;
@@ -289,12 +287,12 @@ void PMove_Run_Acceleration(float flMovetime, float flBefore)
 	PMove_Categorize();
 
 	// Update the timer
-	self.jumptime -= flMovetime;
-	self.teleport_time -= flMovetime;
+	self.jumptime -= move_time;
+	self.teleport_time -= move_time;
 
 	// Corpses
 	if (self.movetype == MOVETYPE_TOSS) {
-		self.velocity[2] = self.velocity[2] - (PMove_Gravity(self) * flMovetime);
+		self.velocity[2] = self.velocity[2] - (PMove_Gravity(self) * move_time);
 		return;
 	}
 
@@ -347,17 +345,17 @@ void PMove_Run_Acceleration(float flMovetime, float flBefore)
 				vecWishVel += v_up * input_movevalues[2];
 			}
 
-			flWishSpeed = vlen(vecWishVel);
+			wish_speed = vlen(vecWishVel);
 
-			if (flWishSpeed > self.maxspeed) {
-				flWishSpeed = self.maxspeed;
+			if (wish_speed > self.maxspeed) {
+				wish_speed = self.maxspeed;
 			}
 
-			flWishSpeed = flWishSpeed * 0.7;
+			wish_speed = wish_speed * 0.7;
 
 			// water friction
 			if (self.velocity != [0,0,0]) {
-				flFriction = vlen(self.velocity) * (1 - flMovetime * serverkeyfloat("phy_friction"));
+				flFriction = vlen(self.velocity) * (1 - move_time * serverkeyfloat("phy_friction"));
 				if (flFriction > 0) {
 					self.velocity = normalize(self.velocity) * flFriction;
 				} else {
@@ -368,11 +366,11 @@ void PMove_Run_Acceleration(float flMovetime, float flBefore)
 			}
 
 			// water acceleration
-			if (flWishSpeed <= flFriction) {
+			if (wish_speed <= flFriction) {
 				return;
 			}
 
-			flFriction = min(flWishSpeed - flFriction, serverkeyfloat("phy_accelerate") * flWishSpeed * flMovetime);
+			flFriction = min(wish_speed - flFriction, serverkeyfloat("phy_accelerate") * wish_speed * move_time);
 			self.velocity = self.velocity + normalize(vecWishVel) * flFriction;
 			return;
 		}
@@ -396,22 +394,22 @@ void PMove_Run_Acceleration(float flMovetime, float flBefore)
 		vecWishVel[2] = 0;
 	}
 
-	vecWishDir = normalize(vecWishVel);
-	flWishSpeed = vlen(vecWishVel);
+	wish_dir = normalize(vecWishVel);
+	wish_speed = vlen(vecWishVel);
 	
-	if (flWishSpeed > self.maxspeed) {
-		flWishSpeed = self.maxspeed;
+	if (wish_speed > self.maxspeed) {
+		wish_speed = self.maxspeed;
 	}
 
 	if (self.movetype == MOVETYPE_NOCLIP) {
 		self.flags &= ~FL_ONGROUND;
-		self.velocity = vecWishDir * flWishSpeed;
+		self.velocity = wish_dir * wish_speed;
 	} else {
 		/*FIXME: pogostick*/
 		if (self.flags & FL_ONGROUND)
 		if (!(self.flags & FL_WATERJUMP))
 		if (self.flags & FL_JUMPRELEASED)
-		if (input_buttons & INPUT_BUTTON2 && flBefore) {
+		if (input_buttons & INPUT_BUTTON2 && premove) {
 			if (self.velocity[2] < 0) {
 				self.velocity[2] = 0;
 			}
@@ -445,6 +443,7 @@ void PMove_Run_Acceleration(float flMovetime, float flBefore)
 			self.flags &= ~FL_ONGROUND;
 			self.flags &= ~FL_JUMPRELEASED;
 		}
+
 		// not pressing jump, set released flag
 		if (!(input_buttons & INPUT_BUTTON2)) {
 			self.flags |= FL_JUMPRELEASED;
@@ -471,21 +470,20 @@ void PMove_Run_Acceleration(float flMovetime, float flBefore)
 
 				// if the leading edge is over a dropoff, increase friction
 				vecTemp = self.origin + normalize(vecTemp) * 16 + '0 0 1' * VEC_HULL_MIN[2];
-
 				traceline(vecTemp, vecTemp + '0 0 -34', TRUE, self);
 
 				// apply friction
 				if (trace_fraction == 1.0) {
 					if (flFriction < serverkeyfloat("phy_stopspeed")) {
-						flFriction = 1 - flMovetime * (serverkeyfloat("phy_stopspeed") / flFriction) * serverkeyfloat("phy_friction") * serverkeyfloat("phy_edgefriction");
+						flFriction = 1 - move_time * (serverkeyfloat("phy_stopspeed") / flFriction) * serverkeyfloat("phy_friction") * serverkeyfloat("phy_edgefriction");
 					} else {
-						flFriction = 1 - flMovetime * serverkeyfloat("phy_friction") * serverkeyfloat("phy_edgefriction");
+						flFriction = 1 - move_time * serverkeyfloat("phy_friction") * serverkeyfloat("phy_edgefriction");
 					}
 				} else {
 					if (flFriction < serverkeyfloat("phy_stopspeed")) {
-						flFriction = 1 - flMovetime * (serverkeyfloat("phy_stopspeed") / flFriction) * serverkeyfloat("phy_friction");
+						flFriction = 1 - move_time * (serverkeyfloat("phy_stopspeed") / flFriction) * serverkeyfloat("phy_friction");
 					} else {
-						flFriction = 1 - flMovetime * serverkeyfloat("phy_friction");
+						flFriction = 1 - move_time * serverkeyfloat("phy_friction");
 					}
 				}
 
@@ -496,49 +494,32 @@ void PMove_Run_Acceleration(float flMovetime, float flBefore)
 				}
 			}
 
-			/*if (self.flags & FL_ONLADDER) {
-				vector vPlayerVector;
-
-				makevectors(input_angles);
-				vPlayerVector = v_forward;
-				vPlayerVector = (vPlayerVector * 240);
-
-				if (input_movevalues[0] > 0) {
-					self.velocity = vPlayerVector;
-				} else {
-					self.velocity = [0,0,0];
-				}
-			}*/
-
 			// acceleration
-			flFriction = flWishSpeed - (self.velocity * vecWishDir);
+			flFriction = wish_speed - (self.velocity * wish_dir);
 			if (flFriction > 0) {
-				self.velocity = self.velocity + vecWishDir * min(flFriction, serverkeyfloat("phy_accelerate") * flMovetime * flWishSpeed);
+				self.velocity = self.velocity + wish_dir * min(flFriction, serverkeyfloat("phy_accelerate") * move_time * wish_speed);
 			}
 		} else {
 			/* apply gravity */
-			self.velocity[2] = self.velocity[2] - (PMove_Gravity(self) * flMovetime);
+			self.velocity[2] = self.velocity[2] - (PMove_Gravity(self) * move_time);
 
-			if (flWishSpeed < 30) {
-				flFriction = flWishSpeed - (self.velocity * vecWishDir);
+			if (wish_speed < 30) {
+				flFriction = wish_speed - (self.velocity * wish_dir);
 			} else {
-				flFriction = 30 - (self.velocity * vecWishDir);
+				flFriction = 30 - (self.velocity * wish_dir);
 			}
 
 			if (flFriction > 0) {
-				self.velocity = self.velocity + vecWishDir * (min(flFriction, serverkeyfloat("phy_airaccelerate")) * flWishSpeed * flMovetime);
+				float fric;
+				fric = min(flFriction, serverkeyfloat("phy_airaccelerate") * wish_speed * move_time);
+				self.velocity += wish_dir * fric;
 			}
 		}
 	}
 }
-/*
-=================
-PMove_Rebound
 
-	Calls somethings touch() function upon hit.
-=================
-*/
-void PMove_DoTouch(entity tother)
+void
+PMove_DoTouch(entity tother)
 {
 	entity oself = self;
 	if (tother.touch) {
@@ -549,31 +530,20 @@ void PMove_DoTouch(entity tother)
 	self = oself;
 }
 
-/*
-=================
-PMove_Rebound
-
-	This function 'bounces' off any surfaces that were hit
-=================
-*/
-static void PMove_Rebound(vector vecNormal)
+/* bounce us back off a place normal */
+static void
+PMove_Rebound(vector normal)
 {
-	self.velocity = self.velocity - vecNormal * (self.velocity * vecNormal);
+	self.velocity = self.velocity - normal * (self.velocity * normal);
 }
 
-/*
-=================
-PMove_Fix_Origin
-
-	Incase BSP precision messes up, this function will attempt
-	to correct the origin to stop it from being invalid.
-=================
-*/
-float PMove_Fix_Origin(void)
+/* brute force unstuck function */
+float
+PMove_Fix_Origin(void)
 {
 	float x, y, z;
 	vector norg, oorg = self.origin;
-	
+
 	for (z = 0; z < 3; z++) {
 		norg[2] = oorg[2] + ((z==2)?-1:z)*0.0125;
 		for (x = 0; x < 3; x++) {
@@ -583,42 +553,37 @@ float PMove_Fix_Origin(void)
 
 				tracebox(norg, self.mins, self.maxs, norg, FALSE, self);
 				if (!trace_startsolid) {
-					//dprint("[PHYSICS] Unstuck\n");
 					self.origin = norg;
 					return TRUE;
 				}
 			}
 		}
 	}
-	//dprint("[PHYSICS] Stuck\n");
 	return FALSE;
 }
 
-/*
-=================
-PMove_Run_Move
-
-	This function is responsible for moving the entity 
-	forwards according to the various inputs/state.
-=================
-*/
-void PMove_Run_Move(void)
+/* move the player based on the given acceleration */
+void
+PMove_Run_Move(void)
 {
-	vector vecDestPos;
-	vector vecSavePlane;
-	float flStepped;
-	float flMoveTime;
-	int iAttempts;
+	vector dest;
+	vector saved_plane;
+	float stepped;
+	float move_time;
+	int i;
 
+	/* no friction for the deceased */
 	if (self.movetype == MOVETYPE_NOCLIP) {
 		self.origin = self.origin + self.velocity * input_timelength;
 		return;
 	}
 
-	// we need to bounce off surfaces (in order to slide along them), so we need at 2 attempts
-	for (iAttempts = 3, flMoveTime = input_timelength; flMoveTime > 0 && iAttempts; iAttempts--) {
-		vecDestPos = self.origin + (self.velocity * flMoveTime);
-		tracebox(self.origin, self.mins, self.maxs, vecDestPos, FALSE, self);
+	/* we need to bounce off surfaces (in order to slide along them), 
+	 * so we need at 2 attempts
+	 */
+	for (i = 3, move_time = input_timelength; move_time > 0 && i; i--) {
+		dest = self.origin + (self.velocity * move_time);
+		tracebox(self.origin, self.mins, self.maxs, dest, FALSE, self);
 
 		if (trace_startsolid) {
 			if (!PMove_Fix_Origin()) {
@@ -629,73 +594,71 @@ void PMove_Run_Move(void)
 
 		self.origin = trace_endpos;
 
-		if (trace_fraction < 1) {
-			vecSavePlane = trace_plane_normal;
-			flMoveTime -= flMoveTime * trace_fraction;
-
-			if (flMoveTime) {
-				// step up if we can
-				trace_endpos = self.origin;
-
-				if (self.flags & FL_ONGROUND) {
-					trace_endpos[2] += serverkeyfloat("phy_stepheight");
-				} else {
-					trace_endpos[2] += serverkeyfloat("phy_airstepheight");
-				}
-
-				tracebox(self.origin, self.mins, self.maxs, trace_endpos, FALSE, self);
-				flStepped = trace_endpos[2] - self.origin[2];
-
-				float roof_fraction = trace_fraction;
-				vector roof_plane_normal = trace_plane_normal;
-
-				vecDestPos = trace_endpos + self.velocity*flMoveTime;
-				vecDestPos[2] = trace_endpos[2]; /*only horizontally*/
-
-				// move forwards
-				tracebox(trace_endpos, self.mins, self.maxs, vecDestPos, FALSE, self);
-
-				// if we got anywhere, make this raised-step move count
-				if (trace_fraction != 0) {
-					float fwfrac = trace_fraction;
-					vector fwplane = trace_plane_normal;
-
-					// move down
-					vecDestPos = trace_endpos;
-					vecDestPos[2] -= flStepped + 1;
-					tracebox(trace_endpos, self.mins, self.maxs, vecDestPos, FALSE, self);
-
-					if (trace_fraction < 1 && trace_plane_normal[2] > 0.7f) {
-						flMoveTime -= flMoveTime * fwfrac;
-						/* bounce off the ceiling if we hit it while airstepping */
-						if (roof_fraction < 1) {
-							PMove_Rebound(roof_plane_normal);
-						}
-						/* FIXME: you probably want this: && self.velocity[2] < 0 */
-						if (trace_fraction < 1) {
-							PMove_Rebound(trace_plane_normal);
-						} else if (fwfrac < 1) {
-							PMove_Rebound(fwplane);
-						}
-						self.origin = trace_endpos;
-						continue;
-					}
-				}
-			}
-
-			//stepping failed, just bounce off
-			PMove_Rebound(vecSavePlane);
-			PMove_DoTouch(trace_ent);
-		} else {
+		if (trace_fraction > 1) {
 			break;
 		}
+		saved_plane = trace_plane_normal;
+		move_time -= move_time * trace_fraction;
+
+		if (move_time) {
+			/* step up if we can */
+			trace_endpos = self.origin;
+
+			if (self.flags & FL_ONGROUND) {
+				trace_endpos[2] += serverkeyfloat("phy_stepheight");
+			} else {
+				trace_endpos[2] += serverkeyfloat("phy_airstepheight");
+			}
+
+			tracebox(self.origin, self.mins, self.maxs, trace_endpos, FALSE, self);
+			stepped = trace_endpos[2] - self.origin[2];
+
+			float roof_fraction = trace_fraction;
+			vector roof_plane_normal = trace_plane_normal;
+
+			dest = trace_endpos + self.velocity*move_time;
+			dest[2] = trace_endpos[2]; /*only horizontally*/
+
+			/* move forwards */
+			tracebox(trace_endpos, self.mins, self.maxs, dest, FALSE, self);
+
+			/* if we got anywhere, make this raised-step move count */
+			if (trace_fraction != 0) {
+				float fwfrac = trace_fraction;
+				vector fwplane = trace_plane_normal;
+
+				/* move down */
+				dest = trace_endpos;
+				dest[2] -= stepped + 1;
+				tracebox(trace_endpos, self.mins, self.maxs, dest, FALSE, self);
+
+				if (trace_fraction < 1 && trace_plane_normal[2] > 0.7f) {
+					move_time -= move_time * fwfrac;
+					/* bounce off the ceiling */
+					if (roof_fraction < 1) {
+						PMove_Rebound(roof_plane_normal);
+					}
+					if (trace_fraction < 1) {
+						PMove_Rebound(trace_plane_normal);
+					} else if (fwfrac < 1) {
+						PMove_Rebound(fwplane);
+					}
+					self.origin = trace_endpos;
+					continue;
+				}
+			}
+		}
+
+		/* stepping failed, just bounce off */
+		PMove_Rebound(saved_plane);
+		PMove_DoTouch(trace_ent);
 	}
 
 	/* touch whatever is below */
 	if (self.flags & FL_ONGROUND) {
-		vecDestPos = self.origin;
-		vecDestPos[2] -= serverkeyfloat("phy_stepheight");
-		tracebox(self.origin, self.mins, self.maxs, vecDestPos, FALSE, self);
+		dest = self.origin;
+		dest[2] -= serverkeyfloat("phy_stepheight");
+		tracebox(self.origin, self.mins, self.maxs, dest, FALSE, self);
 		if (trace_fraction >= 1) {
 			return;
 		}
@@ -708,14 +671,9 @@ void PMove_Run_Move(void)
 	}
 }
 
-/*
-=================
-PMove_Run
-
-	Runs the physics for one input frame.
-=================
-*/
-void PMove_Run(void)
+/* it all starts here */
+void
+PMove_Run(void)
 {
 #ifdef VALVE
 	self.maxspeed = (self.flags & FL_CROUCHING) ? 135 : 270;
@@ -737,9 +695,10 @@ void PMove_Run(void)
 		input_movevalues[2] = -240;
 	}
 
-	/* Call accelerate before and after the actual move, 
-	 * with half the move each time. 
-	 * This reduces framerate dependance. */
+	/* call accelerate before and after the actual move, 
+	 * with half the move each time. this reduces framerate dependence. 
+	 * and makes controlling jumps slightly easier
+	 */
 	PMove_Run_Acceleration(input_timelength / 2, TRUE);
 	PMove_Run_Move();
 	PMove_Run_Acceleration(input_timelength / 2, FALSE);
@@ -752,8 +711,8 @@ void PMove_Run(void)
 
 	player pl = (player)self;
 #ifdef VALVE
-	pl.w_attack_next = max(0, pl.w_attack_next-input_timelength);
-	pl.w_idle_next = max(0, pl.w_idle_next-input_timelength);
+	pl.w_attack_next = max(0, pl.w_attack_next - input_timelength);
+	pl.w_idle_next = max(0, pl.w_idle_next - input_timelength);
 #endif
 	pl.weapontime += input_timelength;
 	Game_Input();
diff --git a/src/shared/valve/items.h b/src/shared/valve/items.h
index 2eb51482..f1af8869 100644
--- a/src/shared/valve/items.h
+++ b/src/shared/valve/items.h
@@ -15,21 +15,21 @@
  */
 
 #define ITEM_CROWBAR		0x00000001
-#define ITEM_GLOCK			0x00000002
+#define ITEM_GLOCK		0x00000002
 #define ITEM_PYTHON		0x00000004
-#define ITEM_MP5			0x00000008
+#define ITEM_MP5		0x00000008
 #define ITEM_CROSSBOW		0x00000010
 #define ITEM_SHOTGUN		0x00000020
-#define ITEM_RPG			0x00000040
-#define ITEM_GAUSS			0x00000080
+#define ITEM_RPG		0x00000040
+#define ITEM_GAUSS		0x00000080
 
-#define ITEM_EGON			0x00000100
+#define ITEM_EGON		0x00000100
 #define ITEM_HORNETGUN		0x00000200
 #define ITEM_HANDGRENADE	0x00000400
 #define ITEM_TRIPMINE		0x00000800
 #define ITEM_SATCHEL		0x00001000
-#define ITEM_SNARK			0x00002000
-#define ITEM_SUIT			0x00004000
+#define ITEM_SNARK		0x00002000
+#define ITEM_SUIT		0x00004000
 #define ITEM_LONGJUMP		0x00008000
 
 #define ITEM_HEALTHKIT		0x00010000