View Single Post
Is there a better way to do these ?
Old
  (#1)
Rifleman
This user broke our rules and has been BANNED
 
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
Default Is there a better way to do these ? - 08-11-2004

Here's some messy code ....

Code:
   if (pBot->strafe_left_time > gpGlobals->time)
   {
	pBot->f_move_speed = 0.0;
	pBot->f_sidemove_speed = -pBot->f_max_speed;
   }
   if (pBot->strafe_right_time > gpGlobals->time)
   {
	pBot->f_move_speed = 0.0;
	pBot->f_sidemove_speed = pBot->f_max_speed;
   }
   if (pBot->move_front_time > gpGlobals->time)
   {
	pBot->f_move_speed = pBot->f_max_speed;
	pBot->f_sidemove_speed = 0.0;
   }
   if (pBot->move_back_time > gpGlobals->time)
   {
	pBot->f_move_speed = -pBot->f_max_speed;
	pBot->f_sidemove_speed = 0.0;
   }
   if (pBot->north_east_time > gpGlobals->time)
   {
	pBot->f_move_speed = pBot->f_max_speed;
	pBot->f_sidemove_speed = pBot->f_max_speed;
   }
   if (pBot->south_east_time > gpGlobals->time)
   {
	pBot->f_move_speed = -pBot->f_max_speed;
	pBot->f_sidemove_speed = pBot->f_max_speed;
   }
   if (pBot->north_west_time > gpGlobals->time)
   {
	pBot->f_move_speed = pBot->f_max_speed;
	pBot->f_sidemove_speed = -pBot->f_max_speed;
   }
   if (pBot->south_west_time > gpGlobals->time)
   {
	pBot->f_move_speed = -pBot->f_max_speed;
	pBot->f_sidemove_speed = -pBot->f_max_speed;
   }
I think these dont need to explain

And the real messy ...

Code:
   Vector v_direction = pBot->waypoint_origin - pEdict->v.origin;
 
   Vector bot_angles = UTIL_VecToAngles(v_direction);
 
   int yaw = pEdict->v.ideal_yaw;
 
   while (yaw <= 0)
	yaw += 360;
 
   while (bot_angles.y <= 0)
	bot_angles.y += 360;
 
   int angle = yaw - bot_angles.y;
 
   while (angle > 180)
	angle -= 360;
 
	 bot_angles = UTIL_VecToAngles( v_direction );
 
	  UTIL_MakeVectors( pEdict->v.v_angle );
   
   // Check for correct angle and strafe for the correct direction
   // Waypoint at front 
   if ((angle >= 0) && (angle < 22.5) ||
	(angle <= 0) && (angle > -22.5))
   {
	pBot->move_front_time = gpGlobals->time + 1.0;
   }
   // Waypoint at north-east
   else if ((angle >= 22.5) && (angle < 67.5))
   {
	pBot->north_east_time = gpGlobals->time + 1.0;
   }
   // Waypoint at right
   else if ((angle >= 67.5) && (angle < 112.5))
   {
	pBot->strafe_right_time = gpGlobals->time + 1.0;
   }
   // Waypoint at south-east
   else if ((angle >= 112.5) && (angle < 157.5))
   {
	pBot->south_east_time = gpGlobals->time + 1.0;
   }
   // Waypoint at back
   else if ((angle >= 0) && (angle > 157.5) ||
	(angle <= 0) && (angle < -157.5))
   {
	pBot->move_back_time = gpGlobals->time + 1.0;
   }
   // Waypoint at north-west
   else if ((angle <= -22.5) && (angle > -67.5))
   {
	pBot->north_west_time = gpGlobals->time + 1.0;
   }
   // Waypoint at left
   else if ((angle <= -67.5) && (angle > -112.5))
   {
	pBot->strafe_left_time = gpGlobals->time + 1.0;
   }
   // Waypoint at south-west
   else if ((angle <= -112.5) && (angle > -157.5))
   {
	pBot->south_west_time = gpGlobals->time + 1.0;
   }
   BotFixIdealYaw(pEdict);
These code is quite easy to understand , but , Is there a better way to do all these stuff ?
  
Reply With Quote