From 0efd74f114dad98c4fadc0318718f2e0203bca8b Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 18:54:54 +0100 Subject: This adds a function that allows you to 'shoot' a player towards a direction. --- src/Bindings/Bindings.cpp | 36 +++++++++++++++++++++++++++++++++++- src/Bindings/Bindings.h | 2 +- src/ClientHandle.cpp | 2 -- src/Entities/Player.cpp | 10 ++++++++++ src/Entities/Player.h | 3 +++ 5 files changed, 49 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Bindings/Bindings.cpp b/src/Bindings/Bindings.cpp index 46f8c8f40..219f7c31a 100644 --- a/src/Bindings/Bindings.cpp +++ b/src/Bindings/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/15/13 14:19:12. +** Generated automatically by tolua++-1.0.92 on 12/15/13 18:47:13. */ #ifndef __cplusplus @@ -9395,6 +9395,39 @@ static int tolua_AllToLua_cPlayer_GetIP00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: ShootTo of class cPlayer */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_ShootTo00 +static int tolua_AllToLua_cPlayer_ShootTo00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"Vector3d",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + Vector3d Vector = *((Vector3d*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ShootTo'", NULL); +#endif + { + self->ShootTo(Vector); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'ShootTo'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: MoveTo of class cPlayer */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_MoveTo00 static int tolua_AllToLua_cPlayer_MoveTo00(lua_State* tolua_S) @@ -31076,6 +31109,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"IsGameModeSurvival",tolua_AllToLua_cPlayer_IsGameModeSurvival00); tolua_function(tolua_S,"IsGameModeAdventure",tolua_AllToLua_cPlayer_IsGameModeAdventure00); tolua_function(tolua_S,"GetIP",tolua_AllToLua_cPlayer_GetIP00); + tolua_function(tolua_S,"ShootTo",tolua_AllToLua_cPlayer_ShootTo00); tolua_function(tolua_S,"MoveTo",tolua_AllToLua_cPlayer_MoveTo00); tolua_function(tolua_S,"GetWindow",tolua_AllToLua_cPlayer_GetWindow00); tolua_function(tolua_S,"CloseWindow",tolua_AllToLua_cPlayer_CloseWindow00); diff --git a/src/Bindings/Bindings.h b/src/Bindings/Bindings.h index 4805c260e..0b555e66c 100644 --- a/src/Bindings/Bindings.h +++ b/src/Bindings/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/15/13 14:19:13. +** Generated automatically by tolua++-1.0.92 on 12/15/13 18:47:14. */ /* Exported function */ diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d585eccf1..0d70b2a2b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1765,8 +1765,6 @@ void cClientHandle::SendEntityStatus(const cEntity & a_Entity, char a_Status) void cClientHandle::SendEntityVelocity(const cEntity & a_Entity) { - ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self - m_Protocol->SendEntityVelocity(a_Entity); } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c2a76342d..ab7075121 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1069,6 +1069,16 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const +void cPlayer::ShootTo(Vector3d a_Direction) +{ + SetSpeed(a_Direction); + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + void cPlayer::MoveTo( const Vector3d & a_NewPos ) { if ((a_NewPos.y < -990) && (GetPosY() > -100)) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index f3ee841e7..8dc6968ff 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -167,6 +167,9 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); + /// "Shoots" the player in the given direction. + void ShootTo(Vector3d a_Direction); // tolua_export + /// Tries to move to a new position, with attachment-related checks (y == -999) void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From 5e75408b3becd5de0ef88223c789fa6f95ff6619 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 20:19:58 +0100 Subject: Renamed ShootTo function to ForceSetSpeed. --- src/Entities/Player.cpp | 2 +- src/Entities/Player.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ab7075121..38b911fd2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1069,7 +1069,7 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const -void cPlayer::ShootTo(Vector3d a_Direction) +void cPlayer::ForceSetSpeed(Vector3d a_Direction) { SetSpeed(a_Direction); m_ClientHandle->SendEntityVelocity(*this); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 8dc6968ff..a09f7f489 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -167,8 +167,8 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /// "Shoots" the player in the given direction. - void ShootTo(Vector3d a_Direction); // tolua_export + /// Forces the player to move in the given direction. + void ForceSetSpeed(Vector3d a_Direction); // tolua_export /// Tries to move to a new position, with attachment-related checks (y == -999) void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From a2612fa68adacada92874c58b56f2646adda39eb Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 20:25:53 +0100 Subject: Exported to Lua --- src/Bindings/Bindings.cpp | 18 +++++++++--------- src/Bindings/Bindings.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Bindings/Bindings.cpp b/src/Bindings/Bindings.cpp index 219f7c31a..5536ab2b0 100644 --- a/src/Bindings/Bindings.cpp +++ b/src/Bindings/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/15/13 18:47:13. +** Generated automatically by tolua++-1.0.92 on 12/15/13 20:25:06. */ #ifndef __cplusplus @@ -9395,9 +9395,9 @@ static int tolua_AllToLua_cPlayer_GetIP00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: ShootTo of class cPlayer */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_ShootTo00 -static int tolua_AllToLua_cPlayer_ShootTo00(lua_State* tolua_S) +/* method: ForceSetSpeed of class cPlayer */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_ForceSetSpeed00 +static int tolua_AllToLua_cPlayer_ForceSetSpeed00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -9411,18 +9411,18 @@ static int tolua_AllToLua_cPlayer_ShootTo00(lua_State* tolua_S) #endif { cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); - Vector3d Vector = *((Vector3d*) tolua_tousertype(tolua_S,2,0)); + Vector3d a_Direction = *((Vector3d*) tolua_tousertype(tolua_S,2,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ShootTo'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ForceSetSpeed'", NULL); #endif { - self->ShootTo(Vector); + self->ForceSetSpeed(a_Direction); } } return 0; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'ShootTo'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'ForceSetSpeed'.",&tolua_err); return 0; #endif } @@ -31109,7 +31109,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"IsGameModeSurvival",tolua_AllToLua_cPlayer_IsGameModeSurvival00); tolua_function(tolua_S,"IsGameModeAdventure",tolua_AllToLua_cPlayer_IsGameModeAdventure00); tolua_function(tolua_S,"GetIP",tolua_AllToLua_cPlayer_GetIP00); - tolua_function(tolua_S,"ShootTo",tolua_AllToLua_cPlayer_ShootTo00); + tolua_function(tolua_S,"ForceSetSpeed",tolua_AllToLua_cPlayer_ForceSetSpeed00); tolua_function(tolua_S,"MoveTo",tolua_AllToLua_cPlayer_MoveTo00); tolua_function(tolua_S,"GetWindow",tolua_AllToLua_cPlayer_GetWindow00); tolua_function(tolua_S,"CloseWindow",tolua_AllToLua_cPlayer_CloseWindow00); diff --git a/src/Bindings/Bindings.h b/src/Bindings/Bindings.h index 0b555e66c..ef3b6b49e 100644 --- a/src/Bindings/Bindings.h +++ b/src/Bindings/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/15/13 18:47:14. +** Generated automatically by tolua++-1.0.92 on 12/15/13 20:25:06. */ /* Exported function */ -- cgit v1.2.3