示例#1
0
void AGameObject::Walk( float t )
{
  CheckWaypoint();

  // Alter destination based on locations of other units.
  FVector ToDest = Dest - Pos;
  
  // Clamp travel length so that we can't overshoot destination
  if( float Len = ToDest.Size() )
  {
    Dir = ToDest / Len; // normalize
    if( !Stats.SpeedMax )  error( FS("%s had 0 speed", *GetName()) );
    
    // I am maxing out the speed here.
    Speed = Stats.SpeedMax;

    // The direction of travel is modified by repulsion forces
    FVector repulsionForces = GetRepulsionForcesFromOverlappedUnits();
    FVector modDir = Dir + repulsionForces;
    modDir.Normalize();
    FVector Vel = modDir*Speed;
    //Game->flycam->DrawDebug( Pos, Pos + Vel, 5.f, FLinearColor::Red, 0.f );
    FVector travel = Vel*t;

    // If travel exceeds destination, then jump to dest,
    // so we don't jitter over the final position.
    if( Len < travel.Size() )
    {
      // snap to position & stop moving.
      Pos = Dest; // we are @ destination.
      travel = ToDest; // This is the displacement we actually moved.
      Speed = 0;
    }
    else
    {
      Pos += travel;
      if( Grounds )
      {
        FVector newPos = Pos + UnitZ * 10.f;
        // Travel in direction plus some amount straight up.
        // The straight up amount ensures that the unit doesn't sink underground
        if( Game->flycam->SetOnGround( newPos ) )  Pos = newPos;
        else  error( FS( "%s Object was trying to leave the ground plane.", *GetName() ) );
      }
      SetRot( Dir.Rotation() );
    }
  }
  else
  {
    // We're at the destination, so the velocity becomes 0
    Speed = 0.f;
  }
}
示例#2
0
ZObject* ZCore::ProcessWaypointData(char *data, int size, bool is_server, int ok_team)
{
	int expected_packet_size;
	int waypoint_amount;
	int ref_id;
	ZObject *our_object;

	//does it hold the header info?
	if(size < 8) return NULL;

	//get header
	ref_id = ((int*)data)[0];
	waypoint_amount = ((int*)data)[1];

	expected_packet_size = 8 + (waypoint_amount * sizeof(waypoint));

	//should we toss this packet for bad data?
	if(size != expected_packet_size) return NULL;

	//find our object
	our_object = GetObjectFromID(ref_id, object_list);

	//not found?
	if(!our_object) return NULL;

	//ok team?
	if(is_server && our_object->GetOwner() == NULL_TEAM) return NULL;
	if(is_server && our_object->GetOwner() != ok_team) return NULL;

	//can set waypoints?
	if(is_server && !our_object->CanSetWaypoints()) return NULL;

	//is this object currently doing a forced move wp?
	//if(is_server && our_object->GetWayPointList().size() && our_object->GetWayPointList().begin()->mode == FORCE_MOVE_WP) return NULL;

	//this a crane repair or forced move wp (or etc)?
	//if(is_server && !our_object->CanOverwriteWP()) return NULL;

	//is this object a minion?
	if(is_server && our_object->IsMinion()) return NULL;

	//clear this objects waypoint list
	if(is_server && !our_object->CanOverwriteWP())
	{
		//keep the first one because we are not allowed to 
		//write over it
		if(our_object->GetWayPointList().size())
		{
			waypoint first_waypoint;
			first_waypoint = *our_object->GetWayPointList().begin();
			our_object->GetWayPointList().clear();
			our_object->GetWayPointList().push_back(first_waypoint);
		}
	}
	else
		our_object->GetWayPointList().clear();

	//begin the waypoint push
	data += 8;
	for(int i=0;i<waypoint_amount;i++)
	{
		waypoint new_waypoint;

		memcpy(&new_waypoint, data, sizeof(waypoint));

		//printf("ZServer:pushing waypoint... (%d,%d) id:%d mode:%d\n", new_waypoint.x, new_waypoint.y, new_waypoint.ref_id, new_waypoint.mode);

		if(!is_server || CheckWaypoint(our_object, &new_waypoint))
			our_object->GetWayPointList().push_back(new_waypoint);

		data += sizeof(waypoint);
	}

	//do we need to clone the waypoints?
	if(is_server)
	{
		
	}

	return our_object;
}