Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/speedtiles2 #2

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/game/client/components/mapimages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static bool IsValidTile(int LayerType, bool EntitiesAreMasked, EMapImageModType

if(EntitiesModType == MAP_IMAGE_MOD_TYPE_DDNET || EntitiesModType == MAP_IMAGE_MOD_TYPE_DDRACE)
{
if(EntitiesModType == MAP_IMAGE_MOD_TYPE_DDNET || TileIndex != TILE_BOOST)
if(EntitiesModType == MAP_IMAGE_MOD_TYPE_DDNET || TileIndex != TILE_SPEED_BOOST_OLD || TileIndex != TILE_SPEED_BOOST)
{
if(LayerType == MAP_IMAGE_ENTITY_LAYER_TYPE_ALL_EXCEPT_SWITCH &&
!IsValidGameTile(TileIndex) &&
Expand Down
109 changes: 66 additions & 43 deletions src/game/client/prediction/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,56 +641,79 @@ void CCharacter::HandleSkippableTiles(int Index)
if(Collision()->IsSpeedup(Index))
{
vec2 Direction, TempVel = m_Core.m_Vel;
int Force, MaxSpeed = 0;
float TeeAngle, SpeederAngle, DiffAngle, SpeedLeft, TeeSpeed;
Collision()->GetSpeedup(Index, &Direction, &Force, &MaxSpeed);
if(Force == 255 && MaxSpeed)
{
m_Core.m_Vel = Direction * (MaxSpeed / 5);
}
else
int Force, Type, MaxSpeed = 0;
Collision()->GetSpeedup(Index, &Direction, &Force, &MaxSpeed, &Type);

if(Type == TILE_SPEED_BOOST_OLD) // old buggy shitty spaghetti behavior
{
if(MaxSpeed > 0 && MaxSpeed < 5)
MaxSpeed = 5;
if(MaxSpeed > 0)
float TeeAngle, SpeederAngle, DiffAngle, SpeedLeft, TeeSpeed;
if(Force == 255 && MaxSpeed)
{
m_Core.m_Vel = Direction * (MaxSpeed / 5);
}
else
{
if(Direction.x > 0.0000001f)
SpeederAngle = -std::atan(Direction.y / Direction.x);
else if(Direction.x < 0.0000001f)
SpeederAngle = std::atan(Direction.y / Direction.x) + 2.0f * std::asin(1.0f);
else if(Direction.y > 0.0000001f)
SpeederAngle = std::asin(1.0f);
if(MaxSpeed > 0 && MaxSpeed < 5)
MaxSpeed = 5;
if(MaxSpeed > 0)
{
if(Direction.x > 0.0000001f)
SpeederAngle = -std::atan(Direction.y / Direction.x);
else if(Direction.x < 0.0000001f)
SpeederAngle = std::atan(Direction.y / Direction.x) + 2.0f * std::asin(1.0f);
else if(Direction.y > 0.0000001f)
SpeederAngle = std::asin(1.0f);
else
SpeederAngle = std::asin(-1.0f);

if(SpeederAngle < 0)
SpeederAngle = 4.0f * std::asin(1.0f) + SpeederAngle;

if(TempVel.x > 0.0000001f)
TeeAngle = -std::atan(TempVel.y / TempVel.x);
else if(TempVel.x < 0.0000001f)
TeeAngle = std::atan(TempVel.y / TempVel.x) + 2.0f * std::asin(1.0f);
else if(TempVel.y > 0.0000001f)
TeeAngle = std::asin(1.0f);
else
TeeAngle = std::asin(-1.0f);

if(TeeAngle < 0)
TeeAngle = 4.0f * std::asin(1.0f) + TeeAngle;

TeeSpeed = std::sqrt(std::pow(TempVel.x, 2) + std::pow(TempVel.y, 2));

DiffAngle = SpeederAngle - TeeAngle;
SpeedLeft = MaxSpeed / 5.0f - std::cos(DiffAngle) * TeeSpeed;
if(absolute((int)SpeedLeft) > Force && SpeedLeft > 0.0000001f)
TempVel += Direction * Force;
else if(absolute((int)SpeedLeft) > Force)
TempVel += Direction * -Force;
else
TempVel += Direction * SpeedLeft;
}
else
SpeederAngle = std::asin(-1.0f);

if(SpeederAngle < 0)
SpeederAngle = 4.0f * std::asin(1.0f) + SpeederAngle;
TempVel += Direction * Force;

if(TempVel.x > 0.0000001f)
TeeAngle = -std::atan(TempVel.y / TempVel.x);
else if(TempVel.x < 0.0000001f)
TeeAngle = std::atan(TempVel.y / TempVel.x) + 2.0f * std::asin(1.0f);
else if(TempVel.y > 0.0000001f)
TeeAngle = std::asin(1.0f);
m_Core.m_Vel = ClampVel(m_MoveRestrictions, TempVel);
}
}
else if(Type == TILE_SPEED_BOOST)
{
if(MaxSpeed == 0)
{
TempVel += Direction * Force;
}
else
{
// hardest to understand
float CurrentDirectionalSpeed = dot(Direction, m_Core.m_Vel);
float TempMaxSpeed = MaxSpeed / 5.0f;
if(CurrentDirectionalSpeed + Force > TempMaxSpeed)
TempVel += Direction * (TempMaxSpeed - CurrentDirectionalSpeed);
else
TeeAngle = std::asin(-1.0f);

if(TeeAngle < 0)
TeeAngle = 4.0f * std::asin(1.0f) + TeeAngle;

TeeSpeed = std::sqrt(std::pow(TempVel.x, 2) + std::pow(TempVel.y, 2));

DiffAngle = SpeederAngle - TeeAngle;
SpeedLeft = MaxSpeed / 5.0f - std::cos(DiffAngle) * TeeSpeed;
if(absolute((int)SpeedLeft) > Force && SpeedLeft > 0.0000001f)
TempVel += Direction * Force;
else if(absolute((int)SpeedLeft) > Force)
TempVel += Direction * -Force;
else
TempVel += Direction * SpeedLeft;
}
else
TempVel += Direction * Force;
m_Core.m_Vel = ClampVel(m_MoveRestrictions, TempVel);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/game/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,13 @@ int CCollision::IsTune(int Index) const
return 0;
}

void CCollision::GetSpeedup(int Index, vec2 *pDir, int *pForce, int *pMaxSpeed) const
void CCollision::GetSpeedup(int Index, vec2 *pDir, int *pForce, int *pMaxSpeed, int *pType) const
{
if(Index < 0 || !m_pSpeedup)
return;
float Angle = m_pSpeedup[Index].m_Angle * (pi / 180.0f);
*pForce = m_pSpeedup[Index].m_Force;
*pType = m_pSpeedup[Index].m_Type;
*pDir = direction(Angle);
if(pMaxSpeed)
*pMaxSpeed = m_pSpeedup[Index].m_MaxSpeed;
Expand Down
2 changes: 1 addition & 1 deletion src/game/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CCollision
int IsTeleCheckpoint(int Index) const;
int IsSpeedup(int Index) const;
int IsTune(int Index) const;
void GetSpeedup(int Index, vec2 *pDir, int *pForce, int *pMaxSpeed) const;
void GetSpeedup(int Index, vec2 *pDir, int *pForce, int *pMaxSpeed, int *pType) const;
int GetSwitchType(int Index) const;
int GetSwitchNumber(int Index) const;
int GetSwitchDelay(int Index) const;
Expand Down
8 changes: 5 additions & 3 deletions src/game/editor/explanations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ const char *CEditor::ExplainDDNet(int Tile, int Layer)
if(Layer == LAYER_TELE)
return "TELEPORT TO: Destination tile for FROMs, WEAPON & HOOK TELEPORTs with the same numbers.";
break;
case TILE_BOOST:
case TILE_SPEED_BOOST_OLD:
if(Layer == LAYER_SPEEDUP)
return "SPEEDUP: Gives tee defined speed. Arrow shows direction and angle.";
return "OLD SPEEDUP: Gives tee defined speed. Arrow shows direction and angle. Deprecated.";
break;
case TILE_TELECHECK:
case TILE_TELECHECK: // also TILE_SPEED_BOOST
if(Layer == LAYER_TELE)
return "CHECKPOINT TELEPORT: After having touched this tile, any CFRM will teleport you to CTO with the same number.";
if(Layer == LAYER_SPEEDUP)
return "SPEEDUP: Gives tee defined speed. Arrow shows direction and angle.";
break;
case TILE_TELECHECKOUT:
if(Layer == LAYER_TELE)
Expand Down
2 changes: 1 addition & 1 deletion src/game/mapitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool IsTeleTileNumberUsedAny(int Index)

bool IsValidSpeedupTile(int Index)
{
return Index == TILE_BOOST;
return Index == TILE_SPEED_BOOST_OLD || Index == TILE_SPEED_BOOST;
}

bool IsValidSwitchTile(int Index)
Expand Down
5 changes: 3 additions & 2 deletions src/game/mapitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ enum
TILE_SWITCHCLOSE,
TILE_TELEIN,
TILE_TELEOUT,
TILE_BOOST,
TILE_TELECHECK,
TILE_SPEED_BOOST_OLD = 28,
TILE_SPEED_BOOST,
TILE_TELECHECK = 29,
TILE_TELECHECKOUT,
TILE_TELECHECKIN,
TILE_REFILL_JUMPS = 32,
Expand Down
110 changes: 66 additions & 44 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,57 +1417,79 @@ void CCharacter::HandleSkippableTiles(int Index)
if(Collision()->IsSpeedup(Index))
{
vec2 Direction, TempVel = m_Core.m_Vel;
int Force, MaxSpeed = 0;
float TeeAngle, SpeederAngle, DiffAngle, SpeedLeft, TeeSpeed;
Collision()->GetSpeedup(Index, &Direction, &Force, &MaxSpeed);
if(Force == 255 && MaxSpeed)
{
m_Core.m_Vel = Direction * (MaxSpeed / 5);
}
else
int Force, Type, MaxSpeed = 0;
Collision()->GetSpeedup(Index, &Direction, &Force, &MaxSpeed, &Type);

if(Type == TILE_SPEED_BOOST_OLD)
{
if(MaxSpeed > 0 && MaxSpeed < 5)
MaxSpeed = 5;
if(MaxSpeed > 0)
float TeeAngle, SpeederAngle, DiffAngle, SpeedLeft, TeeSpeed;
if(Force == 255 && MaxSpeed)
{
m_Core.m_Vel = Direction * (MaxSpeed / 5);
}
else
{
if(Direction.x > 0.0000001f)
SpeederAngle = -std::atan(Direction.y / Direction.x);
else if(Direction.x < 0.0000001f)
SpeederAngle = std::atan(Direction.y / Direction.x) + 2.0f * std::asin(1.0f);
else if(Direction.y > 0.0000001f)
SpeederAngle = std::asin(1.0f);
if(MaxSpeed > 0 && MaxSpeed < 5)
MaxSpeed = 5;
if(MaxSpeed > 0)
{
if(Direction.x > 0.0000001f)
SpeederAngle = -std::atan(Direction.y / Direction.x);
else if(Direction.x < 0.0000001f)
SpeederAngle = std::atan(Direction.y / Direction.x) + 2.0f * std::asin(1.0f);
else if(Direction.y > 0.0000001f)
SpeederAngle = std::asin(1.0f);
else
SpeederAngle = std::asin(-1.0f);

if(SpeederAngle < 0)
SpeederAngle = 4.0f * std::asin(1.0f) + SpeederAngle;

if(TempVel.x > 0.0000001f)
TeeAngle = -std::atan(TempVel.y / TempVel.x);
else if(TempVel.x < 0.0000001f)
TeeAngle = std::atan(TempVel.y / TempVel.x) + 2.0f * std::asin(1.0f);
else if(TempVel.y > 0.0000001f)
TeeAngle = std::asin(1.0f);
else
TeeAngle = std::asin(-1.0f);

if(TeeAngle < 0)
TeeAngle = 4.0f * std::asin(1.0f) + TeeAngle;

TeeSpeed = std::sqrt(std::pow(TempVel.x, 2) + std::pow(TempVel.y, 2));

DiffAngle = SpeederAngle - TeeAngle;
SpeedLeft = MaxSpeed / 5.0f - std::cos(DiffAngle) * TeeSpeed;
if(absolute((int)SpeedLeft) > Force && SpeedLeft > 0.0000001f)
TempVel += Direction * Force;
else if(absolute((int)SpeedLeft) > Force)
TempVel += Direction * -Force;
else
TempVel += Direction * SpeedLeft;
}
else
SpeederAngle = std::asin(-1.0f);

if(SpeederAngle < 0)
SpeederAngle = 4.0f * std::asin(1.0f) + SpeederAngle;
TempVel += Direction * Force;

if(TempVel.x > 0.0000001f)
TeeAngle = -std::atan(TempVel.y / TempVel.x);
else if(TempVel.x < 0.0000001f)
TeeAngle = std::atan(TempVel.y / TempVel.x) + 2.0f * std::asin(1.0f);
else if(TempVel.y > 0.0000001f)
TeeAngle = std::asin(1.0f);
m_Core.m_Vel = ClampVel(m_MoveRestrictions, TempVel);
}
}
else if(Type == TILE_SPEED_BOOST)
{
if(MaxSpeed == 0)
{
TempVel += Direction * Force;
}
else
{
// hardest to understand
float CurrentDirectionalSpeed = dot(Direction, m_Core.m_Vel);
float TempMaxSpeed = MaxSpeed / 5.0f;
if(CurrentDirectionalSpeed + Force > TempMaxSpeed)
TempVel += Direction * (TempMaxSpeed - CurrentDirectionalSpeed);
else
TeeAngle = std::asin(-1.0f);

if(TeeAngle < 0)
TeeAngle = 4.0f * std::asin(1.0f) + TeeAngle;

TeeSpeed = std::sqrt(std::pow(TempVel.x, 2) + std::pow(TempVel.y, 2));

DiffAngle = SpeederAngle - TeeAngle;
SpeedLeft = MaxSpeed / 5.0f - std::cos(DiffAngle) * TeeSpeed;
if(absolute((int)SpeedLeft) > Force && SpeedLeft > 0.0000001f)
TempVel += Direction * Force;
else if(absolute((int)SpeedLeft) > Force)
TempVel += Direction * -Force;
else
TempVel += Direction * SpeedLeft;
}
else
TempVel += Direction * Force;

m_Core.m_Vel = ClampVel(m_MoveRestrictions, TempVel);
}
}
Expand Down
Loading