示例#1
0
//------------------------------------------------------------------------------
void Missile::readStateFromBitstream(RakNet::BitStream & stream, unsigned type, uint32_t timestamp)
{
    if (type == OST_BOTH)
    {
        Projectile::readStateFromBitstream(stream, type, timestamp);
    } else
    {
        Vector v;
        stream.ReadVector(v.x_,v.y_,v.z_);
        setPosition(v);
        
        stream.ReadVector(v.x_,v.y_,v.z_);
        setGlobalLinearVel(v);
    }
    
    stream.ReadVector(target_.x_, target_.y_, target_.z_);
}
示例#2
0
void CFlag::Unserialize( RakNet::BitStream& bt )
{
    int stringLength = 0;
    char* inString = NULL;
    vector3df vScale;
    f32 fMass;
    int iBody;

    UNLOAD_STRING
    String modelname = inString;    delete[] inString; inString = NULL;

    UNLOAD_STRING
    String texname = inString;  delete[] inString; inString = NULL;

    bt.ReadVector( vScale.X, vScale.Y, vScale.Z );
    bt.Read( fMass );
    bt.Read( iBody );
    bt.Read( team );

    assemblePhysics( modelname.c_str(), ( BodyType )iBody, vScale, vector3df( 0, 0, 0 ), fMass, false );

    if ( ( !node ) || ( !body ) )
    {
      bInvalidEntity = true;
      return;
    }

    //bFix2DPos = bFix2DRot = false;

    node->setMaterialTexture( 0, IRR.video->getTexture( texname.c_str() ) );

    // upvector joint
    vector3df upDirection( -1.0f, 0.0f, 0.0f );
    m_upVector = NewtonConstraintCreateUpVector( WORLD.GetPhysics()->nWorld, &upDirection.X, body );

    // continuous collision
    NewtonBodySetContinuousCollisionMode( body, 1 );

    //setRotation( vector3df(0, 0, 90 ) );
}
示例#3
0
//------------------------------------------------------------------------------
void SoccerBall::readStateFromBitstream(RakNet::BitStream & stream, unsigned type, uint32_t timestamp)
{
    RigidBody::readStateFromBitstream(stream, type, timestamp);

//    return;
    
    bool rel_pos_given;
    stream.Read(rel_pos_given);

    if (rel_pos_given && game_state_)
    {
        stream.Read(rel_object_id_);

        stream.ReadVector(rel_pos_.x_,
                          rel_pos_.y_,
                          rel_pos_.z_);
        
        RigidBody * body = (RigidBody*)game_state_->getGameObject(rel_object_id_);
        if (body)
        {

//            getTarget()->setGlobalLinearVel(body->getGlobalLinearVel());
//            getProxy()->setGlobalLinearVel(2*body->getGlobalLinearVel());
            
            
            Vector new_pos = body->getTransform().transformPoint(rel_pos_);


//             uint32_t cur_time = RakNet::GetTime();
//             if (cur_time <= timestamp) return;
//             float dt = (float)(cur_time - timestamp) * 0.001f;

//              rel_pos_ += body->getLocalLinearVel() * dt;
            
//            new_pos += body->getGlobalLinearVel() / 10.0f;


//             new_pos *= 0.1f;
//             new_pos += getPosition() * 0.9;
            
            setPosition(new_pos);

            // setting the target only has nicer results for low lag,
            // but breaks things with higher ping.
//            getTarget()->setPosition(new_pos);


/*
            // correct position
            uint32_t cur_time = RakNet::GetTime();
            if (cur_time <= timestamp) return;
            float dt = (float)(cur_time - timestamp) * 0.001f;

            getTarget()->setPosition(getTarget()->getPosition() + 5*dt*body->getGlobalLinearVel());
*/
        }

//        getProxy()->enableGravity(true);
//        enableProxyInterpolation(false);
    } else
    {
        rel_object_id_ = INVALID_GAMEOBJECT_ID;
//        enableProxyInterpolation(true);
//        getProxy()->enableGravity(false);
    }
}
//------------------------------------------------------------------------------
void GameLogicClientSoccer::onGoalScored(RakNet::BitStream & args)
{

    int score_team_a, score_team_b;
    unsigned type_of_goal;
    TEAM_ID goal_scoring_team;
    Vector goal_pos;
    SystemAddress goalgetter;
    SystemAddress assist;

    args.Read(goal_scoring_team);
    args.Read(goalgetter);

    args.Read(assist);
    args.Read(type_of_goal);

    args.ReadVector(goal_pos.x_,
                    goal_pos.y_,
                    goal_pos.z_);
    
    args.Read(score_team_a);
    args.Read(score_team_b);
    
    std::string game_info_label = score_.getTeam(goal_scoring_team)->getName() + " scored! ";

    Player * p_goalgetter = puppet_master_->getLocalOrRemotePlayer(goalgetter);
    Player * p_assist     = puppet_master_->getLocalOrRemotePlayer(assist);

    if(type_of_goal == GTS_NORMAL_GOAL)
    {
        if(p_goalgetter)
        {        
            game_info_label += "Goal: " + p_goalgetter->getName() + " ";
        }
       
        if(p_assist)
        {        
            game_info_label += "Assist: " + p_assist->getName() + " ";
        }
    }
    else if(type_of_goal == GTS_OWN_GOAL)
    {
        if(p_goalgetter)
        {        
            game_info_label += "Own Goal: " + p_goalgetter->getName() + " ";
        }
    }
    else if(type_of_goal == GTS_DEFLECTED_GOAL)
    {
        if(p_assist) ///< due to deflection nominate assistant as goal getter
        {        
            game_info_label += "Goal: " + p_assist->getName() + " ";
        }
    }

    puppet_master_->getHud()->addMessage(game_info_label, Color(1.0f,1.0f,0.0f));

    // add goal score particle effect
    s_effect_manager.createEffect("soccer_goal", goal_pos, Vector(0,1,0), false, s_scene_manager.getRootNode());


    // There currently is no mechanism to set overheating over the
    // network. Cooldown all weapons here.
    Tank * own_tank = dynamic_cast<Tank*>(puppet_master_->getLocalPlayer()->getControllable());
    if (own_tank)
    {
        for (unsigned w=0; w<NUM_WEAPON_SLOTS; ++w)
        {
            WeaponSystem * ws = own_tank->getWeaponSystems()[w];
            if (ws) ws->setCooldownStatus(0.0f);
        }        
    }
}