Skip to content

Commit

Permalink
[11754] Implement jump (parabolic movement) effect
Browse files Browse the repository at this point in the history
Also correct destination calculation in Unit::KnockBackFrom - now spline knockback effect works similar to client's effect (same amplitude, speed etc)
  • Loading branch information
SilverIce committed Jul 26, 2011
1 parent 6e1c903 commit bc2ef4b
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 25 deletions.
3 changes: 2 additions & 1 deletion sql/mangos.sql
Expand Up @@ -24,7 +24,7 @@ CREATE TABLE `db_version` (
`version` varchar(120) default NULL,
`creature_ai_version` varchar(120) default NULL,
`cache_id` int(10) default '0',
`required_11733_01_mangos_spell_proc_event` bit(1) default NULL
`required_11754_mangos_mangos_string` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';

--
Expand Down Expand Up @@ -3589,6 +3589,7 @@ INSERT INTO `mangos_string` VALUES
(535,' Home movement to (X:%f Y:%f Z:%f)',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(536,' Home movement used for player?!?',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(537,' Taxi flight',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(1192,' Effect movement',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(538,' Unknown movement generator (%u)',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(539,'Player selected: %s.\nFaction: %u.\nnpcFlags: %u.\nEntry: %u.\nDisplayID: %u (Native: %u).',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(540,'Level: %u.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
Expand Down
5 changes: 5 additions & 0 deletions sql/updates/11754_mangos_mangos_string.sql
@@ -0,0 +1,5 @@
ALTER TABLE db_version CHANGE COLUMN required_11733_01_mangos_spell_proc_event required_11754_mangos_mangos_string bit;

DELETE FROM mangos_string WHERE entry IN (1192);

INSERT INTO mangos_string VALUES (1192,'Effect movement',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
3 changes: 2 additions & 1 deletion src/game/Language.h
Expand Up @@ -937,7 +937,8 @@ enum MangosStrings
LANG_AHBOT_QUALITY_YELLOW = 1189,
LANG_AHBOT_ITEMS_AMOUNT = 1190,
LANG_AHBOT_ITEMS_RATIO = 1191,
// Room for more level 3 1192-1199 not used
LANG_MOVEGENS_EFFECT = 1192,
// Room for more level 3 1193-1199 not used

// Debug commands
LANG_CINEMATIC_NOT_EXIST = 1200,
Expand Down
1 change: 1 addition & 0 deletions src/game/Level3.cpp
Expand Up @@ -6178,6 +6178,7 @@ bool ChatHandler::HandleMovegensCommand(char* /*args*/)
}
case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
case EFFECT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_EFFECT); break;
default:
PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
break;
Expand Down
34 changes: 34 additions & 0 deletions src/game/MotionMaster.cpp
Expand Up @@ -28,6 +28,7 @@
#include "WaypointMovementGenerator.h"
#include "RandomMovementGenerator.h"
#include "movement/MoveSpline.h"
#include "movement/MoveSplineInit.h"

#include <cassert>

Expand Down Expand Up @@ -415,6 +416,7 @@ void MotionMaster::Mutate(MovementGenerator *m)
case HOME_MOTION_TYPE:
// DistractMovement interrupted by any other movement
case DISTRACT_MOTION_TYPE:
case EFFECT_MOTION_TYPE:
MovementExpired(false);
default:
break;
Expand Down Expand Up @@ -462,3 +464,35 @@ void MotionMaster::UpdateFinalDistanceToTarget(float fDistance)
if (!empty())
top()->UpdateFinalDistance(fDistance);
}

// Does almost nothing - just doesn't allows previous movegen interrupt current effect. Can be reused for charge effect
class EffectMovementGenerator : public MovementGenerator
{
public:
void Initialize(Unit &) {}
void Finalize(Unit &unit)
{
// Since we have no proper states system need restore previous movement.
if (unit.GetTypeId() != TYPEID_PLAYER && unit.isAlive() && !unit.hasUnitState(UNIT_STAT_CONFUSED|UNIT_STAT_FLEEING))
{
if (Unit * victim = unit.getVictim())
unit.GetMotionMaster()->MoveChase(victim);
else
unit.GetMotionMaster()->Initialize();
}
}
void Interrupt(Unit &) {}
void Reset(Unit &) {}
bool Update(Unit &u, const uint32 &) { return !u.movespline->Finalized(); }
MovementGeneratorType GetMovementGeneratorType() const { return EFFECT_MOTION_TYPE; }
};

void MotionMaster::MoveJump(float x, float y, float z, float horizontalSpeed, float max_height)
{
Movement::MoveSplineInit init(*m_owner);
init.MoveTo(x,y,z);
init.SetParabolic(max_height,0,false);
init.SetVelocity(horizontalSpeed);
init.Launch();
Mutate(new EffectMovementGenerator());
}
2 changes: 2 additions & 0 deletions src/game/MotionMaster.h
Expand Up @@ -48,6 +48,7 @@ enum MovementGeneratorType
ASSISTANCE_DISTRACT_MOTION_TYPE = 12, // IdleMovementGenerator.h (second part of flee for assistance)
TIMED_FLEEING_MOTION_TYPE = 13, // FleeingMovementGenerator.h (alt.second part of flee for assistance)
FOLLOW_MOTION_TYPE = 14, // TargetedMovementGenerator.h
EFFECT_MOTION_TYPE = 15,
};

enum MMCleanFlag
Expand Down Expand Up @@ -107,6 +108,7 @@ class MANGOS_DLL_SPEC MotionMaster : private std::stack<MovementGenerator *>
void MoveWaypoint();
void MoveTaxiFlight(uint32 path, uint32 pathnode);
void MoveDistract(uint32 timeLimit);
void MoveJump(float x, float y, float z, float horizontalSpeed, float max_height);

MovementGeneratorType GetCurrentMovementGeneratorType() const;

Expand Down
17 changes: 6 additions & 11 deletions src/game/Unit.cpp
Expand Up @@ -10496,10 +10496,9 @@ void Unit::KnockBackFrom(Unit* target, float horizontalSpeed, float verticalSpee
float vsin = sin(angle);
float vcos = cos(angle);

// Effect properly implemented only for players
if(GetTypeId()==TYPEID_PLAYER)
if (GetTypeId() == TYPEID_PLAYER)
{
WorldPacket data(SMSG_MOVE_KNOCK_BACK, 8+4+4+4+4+4);
WorldPacket data(SMSG_MOVE_KNOCK_BACK, 9+4+4+4+4+4);
data << GetPackGUID();
data << uint32(0); // Sequence
data << float(vcos); // x direction
Expand All @@ -10510,28 +10509,24 @@ void Unit::KnockBackFrom(Unit* target, float horizontalSpeed, float verticalSpee
}
else
{
float dis = horizontalSpeed;
float moveTimeHalf = verticalSpeed / Movement::gravity;
float max_height = -Movement::computeFallElevation(moveTimeHalf,false,-verticalSpeed);

float dis = 2 * moveTimeHalf * horizontalSpeed;
float ox, oy, oz;
GetPosition(ox, oy, oz);

float fx = ox + dis * vcos;
float fy = oy + dis * vsin;
float fz = oz;

float fx2, fy2, fz2; // getObjectHitPos overwrite last args in any result case
if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox,oy,oz+0.5f, fx,fy,oz+0.5f,fx2,fy2,fz2, -0.5f))
{
fx = fx2;
fy = fy2;
fz = fz2;
}

UpdateAllowedPositionZ(fx, fy, fz);

//FIXME: this mostly hack, must exist some packet for proper creature move at client side
// with CreatureRelocation at server side
NearTeleportTo(fx, fy, fz, GetOrientation(), this == target);
GetMotionMaster()->MoveJump(fx,fy,fz,horizontalSpeed,max_height);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/WaypointMovementGenerator.cpp
Expand Up @@ -312,7 +312,7 @@ void FlightPathMovementGenerator::Reset(Player & player)

bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff)
{
int32 pointId = player.movespline->currentPathIdx();
uint32 pointId = (uint32)player.movespline->currentPathIdx();
// currentPathIdx returns lastIdx + 1 at arrive
while (i_currentNode < pointId)
{
Expand Down
9 changes: 0 additions & 9 deletions src/game/movement/MoveSplineInit.h
Expand Up @@ -102,15 +102,6 @@ namespace Movement
MoveSplineInitArgs args;
Unit& unit;
};

inline void MoveJumpInit(Unit& st, const Vector3& dest, float velocity, float parabolic_heigth = 0.5f)
{
MoveSplineInit init(st);
init.MoveTo(dest);
init.SetParabolic(parabolic_heigth,0,false);
init.SetVelocity(velocity);
init.Launch();
}

inline void MoveSplineInit::SetFly() { args.flags.EnableFlying();}
inline void MoveSplineInit::SetWalk(bool enable) { args.flags.walkmode = enable;}
Expand Down
3 changes: 3 additions & 0 deletions src/game/movement/typedefs.h
Expand Up @@ -73,6 +73,9 @@ namespace Movement
};

typedef counter<uint32, 0xFFFFFFFF> UInt32Counter;

extern double gravity;
extern float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity);
}

#endif // MANGOSSERVER_TYPEDEFS_H
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11753"
#define REVISION_NR "11754"
#endif // __REVISION_NR_H__
2 changes: 1 addition & 1 deletion src/shared/revision_sql.h
@@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_11716_10_characters_mail"
#define REVISION_DB_MANGOS "required_11733_01_mangos_spell_proc_event"
#define REVISION_DB_MANGOS "required_11754_mangos_mangos_string"
#define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version"
#endif // __REVISION_SQL_H__

5 comments on commit bc2ef4b

@LordJZ
Copy link
Contributor

@LordJZ LordJZ commented on bc2ef4b Jul 26, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoa. great job!

@rsa
Copy link
Contributor

@rsa rsa commented on bc2ef4b Jul 26, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big thx.

@MaxXx2021
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, big thanks!

@Schmoozerd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah nice :)
it is possible that you have the part already working but this is hidden in other parts of code: Is there some MovementInform call when the jump movement finishes?
Also possible for scripting uses it might be helpfull (but likely not really needed) to get a "pointId" for the JumpMovement as well
(I have Forgemaster Garfrost as example where there are two different jump-movements needed (with different action as result - but this can be stored in the phase system)

@SilverIce
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some MovementInform call when the jump movement finishes?

@Schmoozerd this has been added with my last commit

Please sign in to comment.