about summary refs log tree commit diff
path: root/src/game/server
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-12-09 17:15:18 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-12-09 17:15:18 +0000
commit6b2fa3403cf144276fc73fc3344e1a5c36f7aeac (patch)
treea876beda8da762e998356c81d528a62162eaf0aa /src/game/server
parent7366995539f60d4dd3bd1cde99cfc4ce4292cbbe (diff)
downloadzcatch-6b2fa3403cf144276fc73fc3344e1a5c36f7aeac.tar.gz
zcatch-6b2fa3403cf144276fc73fc3344e1a5c36f7aeac.zip
fixed weapon queuing
Diffstat (limited to 'src/game/server')
-rw-r--r--src/game/server/game_server.cpp47
-rw-r--r--src/game/server/srv_common.h1
2 files changed, 26 insertions, 22 deletions
diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp
index ebd5dff3..378a00ab 100644
--- a/src/game/server/game_server.cpp
+++ b/src/game/server/game_server.cpp
@@ -501,6 +501,7 @@ void player::try_respawn()
 
 	active_weapon = WEAPON_GUN;
 	last_weapon = WEAPON_HAMMER;
+	wanted_weapon = WEAPON_GUN;
 
 	reload_timer = 0;
 
@@ -720,42 +721,44 @@ int player::handle_weapons()
 		reload_timer--;
 		return 0;
 	}
+	
 	if (active_weapon == WEAPON_NINJA)
 	{
 		// don't update other weapons while ninja is active
 		return handle_ninja();
 	}
 
-	// switch weapon if wanted
-	if(data->weapons[active_weapon].duration <= 0)
+	// select weapon
+	int next = count_input(previnput.next_weapon, input.next_weapon).presses;
+	int prev = count_input(previnput.prev_weapon, input.prev_weapon).presses;
+	while(next) // next weapon selection
 	{
-		int new_weapon = active_weapon;
-		int next = count_input(previnput.next_weapon, input.next_weapon).presses;
-		int prev = count_input(previnput.prev_weapon, input.prev_weapon).presses;
-		while(next) // next weapon selection
-		{
-			new_weapon = (new_weapon+1)%NUM_WEAPONS;
-			if(weapons[new_weapon].got)
-				next--;
-		}
+		wanted_weapon = (wanted_weapon+1)%NUM_WEAPONS;
+		if(weapons[wanted_weapon].got)
+			next--;
+	}
 
-		while(prev) // prev weapon selection
-		{
-			new_weapon = (new_weapon-1)<0?NUM_WEAPONS-1:new_weapon-1;
-			if(weapons[new_weapon].got)
-				prev--;
-		}
+	while(prev) // prev weapon selection
+	{
+		wanted_weapon = (wanted_weapon-1)<0?NUM_WEAPONS-1:wanted_weapon-1;
+		if(weapons[wanted_weapon].got)
+			prev--;
+	}
+
+	if(input.wanted_weapon) // direct weapon selection
+		wanted_weapon = input.wanted_weapon-1;
 
-		if(input.wanted_weapon) // direct weapon selection
-			new_weapon = input.wanted_weapon-1;
 
-		if(new_weapon != active_weapon && new_weapon >= 0 && new_weapon < NUM_WEAPONS && weapons[new_weapon].got)
+	// switch weapon if wanted
+	if(data->weapons[active_weapon].duration <= 0)
+	{
+		if(wanted_weapon != active_weapon && wanted_weapon >= 0 && wanted_weapon < NUM_WEAPONS && weapons[wanted_weapon].got)
 		{
-			if(active_weapon != new_weapon)
+			if(active_weapon != wanted_weapon)
 				create_sound(pos, SOUND_WEAPON_SWITCH);
 
 			last_weapon = active_weapon;
-			active_weapon = new_weapon;
+			active_weapon = wanted_weapon;
 		}
 	}
 
diff --git a/src/game/server/srv_common.h b/src/game/server/srv_common.h
index 80a5260b..25af52b0 100644
--- a/src/game/server/srv_common.h
+++ b/src/game/server/srv_common.h
@@ -240,6 +240,7 @@ public:
 	} weapons[NUM_WEAPONS];
 	int active_weapon;
 	int last_weapon;
+	int wanted_weapon;
 	int reload_timer;
 	int attack_tick;