forked from teamnwah/openmw-tes3coop
		
	[General] Implement PlayerMomentum packet & associated script functions
This commit is contained in:
		
							parent
							
								
									273179fd5a
								
							
						
					
					
						commit
						099f85be0a
					
				
					 7 changed files with 58 additions and 3 deletions
				
			
		| 
						 | 
					@ -118,6 +118,16 @@ void PositionFunctions::SetRot(unsigned short pid, double x, double z) noexcept
 | 
				
			||||||
    player->position.rot[2] = z;
 | 
					    player->position.rot[2] = z;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void PositionFunctions::SetMomentum(unsigned short pid, double x, double y, double z) noexcept
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Player *player;
 | 
				
			||||||
 | 
					    GET_PLAYER(pid, player, );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    player->momentum.pos[0] = x;
 | 
				
			||||||
 | 
					    player->momentum.pos[1] = y;
 | 
				
			||||||
 | 
					    player->momentum.pos[2] = z;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PositionFunctions::SendPos(unsigned short pid) noexcept
 | 
					void PositionFunctions::SendPos(unsigned short pid) noexcept
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Player *player;
 | 
					    Player *player;
 | 
				
			||||||
| 
						 | 
					@ -126,3 +136,12 @@ void PositionFunctions::SendPos(unsigned short pid) noexcept
 | 
				
			||||||
    mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->setPlayer(player);
 | 
					    mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->setPlayer(player);
 | 
				
			||||||
    mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->Send(false);
 | 
					    mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->Send(false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void PositionFunctions::SendMomentum(unsigned short pid) noexcept
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Player *player;
 | 
				
			||||||
 | 
					    GET_PLAYER(pid, player, );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MOMENTUM)->setPlayer(player);
 | 
				
			||||||
 | 
					    mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MOMENTUM)->Send(false);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,8 +19,10 @@
 | 
				
			||||||
    \
 | 
					    \
 | 
				
			||||||
    {"SetPos",              PositionFunctions::SetPos},\
 | 
					    {"SetPos",              PositionFunctions::SetPos},\
 | 
				
			||||||
    {"SetRot",              PositionFunctions::SetRot},\
 | 
					    {"SetRot",              PositionFunctions::SetRot},\
 | 
				
			||||||
 | 
					    {"SetMomentum",         PositionFunctions::SetMomentum},\
 | 
				
			||||||
    \
 | 
					    \
 | 
				
			||||||
    {"SendPos",             PositionFunctions::SendPos}
 | 
					    {"SendPos",             PositionFunctions::SendPos},\
 | 
				
			||||||
 | 
					    {"SendMomentum",        PositionFunctions::SendMomentum}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PositionFunctions
 | 
					class PositionFunctions
 | 
				
			||||||
| 
						 | 
					@ -144,6 +146,20 @@ public:
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
    static void SetRot(unsigned short pid, double x, double z) noexcept;
 | 
					    static void SetRot(unsigned short pid, double x, double z) noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					    * \brief Set the momentum of a player.
 | 
				
			||||||
 | 
					    *
 | 
				
			||||||
 | 
					    * This changes the coordinates recorded for that player's momentum in the server memory, but
 | 
				
			||||||
 | 
					    * does not by itself send a packet.
 | 
				
			||||||
 | 
					    *
 | 
				
			||||||
 | 
					    * \param pid The player ID.
 | 
				
			||||||
 | 
					    * \param x The X momentum.
 | 
				
			||||||
 | 
					    * \param y The Y momentum.
 | 
				
			||||||
 | 
					    * \param z The Z momentum.
 | 
				
			||||||
 | 
					    * \return void
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    static void SetMomentum(unsigned short pid, double x, double y, double z) noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
    * \brief Send a PlayerPosition packet about a player.
 | 
					    * \brief Send a PlayerPosition packet about a player.
 | 
				
			||||||
    *
 | 
					    *
 | 
				
			||||||
| 
						 | 
					@ -153,6 +169,16 @@ public:
 | 
				
			||||||
    * \return void
 | 
					    * \return void
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
    static void SendPos(unsigned short pid) noexcept;
 | 
					    static void SendPos(unsigned short pid) noexcept;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					    * \brief Send a PlayerMomentum packet about a player.
 | 
				
			||||||
 | 
					    *
 | 
				
			||||||
 | 
					    * It is only sent to the affected player.
 | 
				
			||||||
 | 
					    *
 | 
				
			||||||
 | 
					    * \param pid The player ID.
 | 
				
			||||||
 | 
					    * \return void
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    static void SendMomentum(unsigned short pid) noexcept;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif //OPENMW_POSITIONAPI_HPP
 | 
					#endif //OPENMW_POSITIONAPI_HPP
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1002,6 +1002,13 @@ void LocalPlayer::setPosition()
 | 
				
			||||||
    updateAnimFlags(true);
 | 
					    updateAnimFlags(true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void LocalPlayer::setMomentum()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    MWBase::World *world = MWBase::Environment::get().getWorld();
 | 
				
			||||||
 | 
					    MWWorld::Ptr ptrPlayer = world->getPlayerPtr();
 | 
				
			||||||
 | 
					    world->setInertialForce(ptrPlayer, momentum.asVec3());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void LocalPlayer::setCell()
 | 
					void LocalPlayer::setCell()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MWBase::World *world = MWBase::Environment::get().getWorld();
 | 
					    MWBase::World *world = MWBase::Environment::get().getWorld();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,6 +54,7 @@ namespace mwmp
 | 
				
			||||||
        void setBounty();
 | 
					        void setBounty();
 | 
				
			||||||
        void setReputation();
 | 
					        void setReputation();
 | 
				
			||||||
        void setPosition();
 | 
					        void setPosition();
 | 
				
			||||||
 | 
					        void setMomentum();
 | 
				
			||||||
        void setCell();
 | 
					        void setCell();
 | 
				
			||||||
        void setClass();
 | 
					        void setClass();
 | 
				
			||||||
        void setEquipment();
 | 
					        void setEquipment();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,7 @@ namespace mwmp
 | 
				
			||||||
            if (!isRequest())
 | 
					            if (!isRequest())
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
 | 
					                LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
 | 
				
			||||||
                //localPlayer.setMomentum();
 | 
					                localPlayer.setMomentum();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -294,6 +294,7 @@ namespace mwmp
 | 
				
			||||||
        ESM::Position position;
 | 
					        ESM::Position position;
 | 
				
			||||||
        ESM::Position direction;
 | 
					        ESM::Position direction;
 | 
				
			||||||
        ESM::Position previousCellPosition;
 | 
					        ESM::Position previousCellPosition;
 | 
				
			||||||
 | 
					        ESM::Position momentum;
 | 
				
			||||||
        ESM::Cell cell;
 | 
					        ESM::Cell cell;
 | 
				
			||||||
        ESM::NPC npc;
 | 
					        ESM::NPC npc;
 | 
				
			||||||
        ESM::NpcStats npcStats;
 | 
					        ESM::NpcStats npcStats;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,5 +12,6 @@ PacketPlayerMomentum::PacketPlayerMomentum(RakNet::RakPeerInterface *peer) : Pla
 | 
				
			||||||
void PacketPlayerMomentum::Packet(RakNet::BitStream *bs, bool send)
 | 
					void PacketPlayerMomentum::Packet(RakNet::BitStream *bs, bool send)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PlayerPacket::Packet(bs, send);
 | 
					    PlayerPacket::Packet(bs, send);
 | 
				
			||||||
    // Placeholder
 | 
					    
 | 
				
			||||||
 | 
					    RW(player->momentum.pos, send, 1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue