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

Fix Issue #144 - Entity isSwimming function #171

Open
wants to merge 19 commits into
base: barony-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
70 changes: 20 additions & 50 deletions src/acthudweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,33 +214,18 @@ void actHudWeapon(Entity* my)
throwGimpTimer--;
}

// check levitating value
bool levitating = isLevitating(stats[clientnum]);

// water walking boots
bool waterwalkingboots = false;
if (stats[clientnum]->shoes != nullptr)
if ( stats[clientnum]->shoes->type == IRON_BOOTS_WATERWALKING )
{
waterwalkingboots = true;
}

// swimming
if (players[clientnum] && players[clientnum]->entity)
// Check to make sure the Player is not swimming
if ( players[clientnum] && players[clientnum]->entity )
{
if (!levitating && !waterwalkingboots)
if ( IsSwimming(players[clientnum]->entity) )
{
int x = std::min<unsigned>(std::max<int>(0, floor(players[clientnum]->entity->x / 16)), map.width - 1);
int y = std::min<unsigned>(std::max<int>(0, floor(players[clientnum]->entity->y / 16)), map.height - 1);
if (animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]])
// Player is swimming, hide their weapon
my->flags[INVISIBLE] = true;
if ( parent )
{
my->flags[INVISIBLE] = true;
if (parent)
{
parent->flags[INVISIBLE] = true;
}
return;
parent->flags[INVISIBLE] = true;
}
return;
}
}

Expand Down Expand Up @@ -1333,17 +1318,6 @@ void actHudShield(Entity* my)
return;
}

// check levitating value
bool levitating = isLevitating(stats[clientnum]);

// water walking boots
bool waterwalkingboots = false;
if (stats[clientnum]->shoes != nullptr)
if (stats[clientnum]->shoes->type == IRON_BOOTS_WATERWALKING)
{
waterwalkingboots = true;
}

// select model
bool wearingring = false;
if ( stats[clientnum]->ring != nullptr )
Expand Down Expand Up @@ -1392,24 +1366,20 @@ void actHudShield(Entity* my)
}
}

// swimming
bool swimming = false;
if (players[clientnum] && players[clientnum]->entity)
// Check to make sure the Player is not swimming
bool bIsPlayerSwimming = false;
if ( players[clientnum] && players[clientnum]->entity )
{
if (!levitating && !waterwalkingboots) //TODO: Swimming capstone?
if ( IsSwimming(players[clientnum]->entity) )
{
int x = std::min<int>(std::max<int>(0, floor(players[clientnum]->entity->x / 16)), map.width - 1);
int y = std::min<int>(std::max<int>(0, floor(players[clientnum]->entity->y / 16)), map.height - 1);
if (animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]])
// Player is swimming, hide their shield
my->flags[INVISIBLE] = true;
Entity* parent = uidToEntity(my->parent);
if ( parent )
{
my->flags[INVISIBLE] = true;
Entity* parent = uidToEntity(my->parent);
if (parent)
{
parent->flags[INVISIBLE] = true;
}
swimming = true;
parent->flags[INVISIBLE] = true;
}
bIsPlayerSwimming = true;
}
}

Expand All @@ -1419,7 +1389,7 @@ void actHudShield(Entity* my)
}

bool defending = false;
if (!command && !swimming)
if ( !command && bIsPlayerSwimming )
{
if (stats[clientnum]->shield)
{
Expand Down Expand Up @@ -1578,7 +1548,7 @@ void actHudShield(Entity* my)

// torch/lantern flames
my->flags[BRIGHT] = false;
if (stats[clientnum]->shield && !swimming && players[clientnum]->entity->skill[3] == 0 && !cast_animation.active && !shieldSwitch)
if ( stats[clientnum]->shield && bIsPlayerSwimming && players[clientnum]->entity->skill[3] == 0 && !cast_animation.active && !shieldSwitch )
{
if (itemCategory(stats[clientnum]->shield) == TOOL)
{
Expand Down
120 changes: 63 additions & 57 deletions src/actplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,76 +882,80 @@ void actPlayer(Entity* my)
}
}

// swimming
bool waterwalkingboots = false;
if ( stats[PLAYER_NUM]->shoes != NULL )
if ( stats[PLAYER_NUM]->shoes->type == IRON_BOOTS_WATERWALKING )
{
waterwalkingboots = true;
}
bool swimming = false;
// Check to make sure the Player is not swimming
bool bIsPlayerSwimming = false;
if ( PLAYER_NUM == clientnum || multiplayer == SERVER )
{
if ( !levitating && !waterwalkingboots && !noclip && !skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) )
if ( IsSwimming(players[PLAYER_NUM]->entity) && noclip && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) )
{
int x = std::min(std::max<unsigned int>(0, floor(my->x / 16)), map.width - 1);
int y = std::min(std::max<unsigned int>(0, floor(my->y / 16)), map.height - 1);
if ( animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] )
// Player is swimming, lower them into the water
bIsPlayerSwimming = true;
my->z = 7;

// Store their map position for future checks
int playerMapX = std::min(std::max<unsigned int>(0, floor(my->x / 16)), map.width - 1);
int playerMapY = std::min(std::max<unsigned int>(0, floor(my->y / 16)), map.height - 1);

// Check to increase their swimming level
if ( rand() % 400 == 0 && multiplayer != CLIENT )
{
my->increaseSkill(PRO_SWIMMING);
}

// Process initial step into swimming tile
if ( !PLAYER_INWATER && PLAYER_NUM == clientnum )
{
if ( rand() % 400 == 0 && multiplayer != CLIENT )
PLAYER_INWATER = 1;
if ( lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] )
{
my->increaseSkill(PRO_SWIMMING);
messagePlayer(PLAYER_NUM, language[573]); // "You've fallen in boiling lava!"
}
swimming = true;
my->z = 7;
if ( !PLAYER_INWATER && PLAYER_NUM == clientnum )
else
{
PLAYER_INWATER = 1;
if ( lavatiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] )
{
messagePlayer(PLAYER_NUM, language[573]);
}
else
{
playSound(136, 128);
}
playSound(136, 128); // "Splash1V1.ogg"
}
if ( multiplayer != CLIENT )
}

// Check to remove Fire status if stepping in water
if ( multiplayer != CLIENT )
{
if ( !lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] )
{
if ( !lavatiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] )
if ( my->flags[BURNING] )
{
if ( my->flags[BURNING] )
my->flags[BURNING] = false;
messagePlayer(PLAYER_NUM, language[574]); // "The water extinguishes the flames!"
if ( PLAYER_NUM > 0 )
{
my->flags[BURNING] = false;
messagePlayer(PLAYER_NUM, language[574]);
if ( PLAYER_NUM > 0 )
{
serverUpdateEntityFlag(my, BURNING);
}
serverUpdateEntityFlag(my, BURNING);
}
}
else if ( ticks % 10 == 0 )
}
else if ( ticks % 10 == 0 ) // Player is in lava, burn them
{
my->modHP(-2 - rand() % 2);
my->setObituary(language[1506]); // "goes for a swim in some lava."
if ( !my->flags[BURNING] )
{
my->modHP(-2 - rand() % 2);
my->setObituary(language[1506]);
if ( !my->flags[BURNING] )
my->flags[BURNING] = true;
if ( PLAYER_NUM > 0 )
{
my->flags[BURNING] = true;
if ( PLAYER_NUM > 0 )
{
serverUpdateEntityFlag(my, BURNING);
}
serverUpdateEntityFlag(my, BURNING);
}
}
}
}
}
}
if (!swimming)
if (PLAYER_INWATER)

// Update PLAYER_INWATER flag
if ( !(bIsPlayerSwimming) )
{
if ( PLAYER_INWATER )
{
PLAYER_INWATER = 0;
}
}

if (PLAYER_NUM == clientnum)
{
Expand All @@ -960,7 +964,7 @@ void actPlayer(Entity* my)
// camera bobbing
if (bobbing)
{
if ( swimming )
if ( bIsPlayerSwimming )
{
if ( PLAYER_BOBMODE )
{
Expand All @@ -971,7 +975,7 @@ void actPlayer(Entity* my)
PLAYER_BOBMOVE -= .03;
}
}
if ( (*inputPressed(impulses[IN_FORWARD]) || *inputPressed(impulses[IN_BACK])) || (*inputPressed(impulses[IN_RIGHT]) - *inputPressed(impulses[IN_LEFT])) || (game_controller && (game_controller->getLeftXPercent() || game_controller->getLeftYPercent())) && !command && !swimming)
if ( (*inputPressed(impulses[IN_FORWARD]) || *inputPressed(impulses[IN_BACK])) || (*inputPressed(impulses[IN_RIGHT]) - *inputPressed(impulses[IN_LEFT])) || (game_controller && (game_controller->getLeftXPercent() || game_controller->getLeftYPercent())) && !command && (bIsPlayerSwimming) )
{
if (!stats[clientnum]->defending)
{
Expand All @@ -996,13 +1000,13 @@ void actPlayer(Entity* my)
}
}
}
else if ( !swimming )
else if ( (bIsPlayerSwimming) )
{
PLAYER_BOBMOVE = 0;
PLAYER_BOB = 0;
PLAYER_BOBMODE = 0;
}
if ( !swimming && !stats[clientnum]->defending )
if ( (bIsPlayerSwimming) && !stats[clientnum]->defending )
{
if ( PLAYER_BOBMOVE > .2 )
{
Expand All @@ -1015,7 +1019,7 @@ void actPlayer(Entity* my)
PLAYER_BOBMODE = 1;
}
}
else if ( swimming )
else if ( bIsPlayerSwimming )
{
if ( PLAYER_BOBMOVE > .3 )
{
Expand Down Expand Up @@ -1625,14 +1629,16 @@ void actPlayer(Entity* my)
}
}

// swimming slows you down
// Swimming slows the Player down
bool amuletwaterbreathing = false;
if ( stats[PLAYER_NUM]->amulet != NULL )
{
if ( stats[PLAYER_NUM]->amulet->type == AMULET_WATERBREATHING )
{
amuletwaterbreathing = true;
}
if ( swimming && !amuletwaterbreathing )
}
if ( bIsPlayerSwimming && !amuletwaterbreathing )
{
PLAYER_VELX *= (((stats[PLAYER_NUM]->PROFICIENCIES[PRO_SWIMMING] / 100.f) * 50.f) + 50) / 100.f;
PLAYER_VELY *= (((stats[PLAYER_NUM]->PROFICIENCIES[PRO_SWIMMING] / 100.f) * 50.f) + 50) / 100.f;
Expand Down Expand Up @@ -1941,7 +1947,7 @@ void actPlayer(Entity* my)
if ( entity->pitch < -PI / 4.0 )
{
entity->pitch = -PI / 4.0;
if (bodypart == 2 && dist > .4 && !levitating && !swimming)
if ( bodypart == 2 && dist > .4 && !levitating && (!bIsPlayerSwimming) )
{
node_t* tempNode = list_Node(&my->children, 2);
if ( tempNode )
Expand Down Expand Up @@ -1969,7 +1975,7 @@ void actPlayer(Entity* my)
if ( entity->pitch > PI / 4.0 )
{
entity->pitch = PI / 4.0;
if (bodypart == 2 && dist > .4 && !levitating && !swimming)
if ( bodypart == 2 && dist > .4 && !levitating && (!bIsPlayerSwimming) )
{
node_t* tempNode = list_Node(&my->children, 2);
if ( tempNode )
Expand Down Expand Up @@ -2447,7 +2453,7 @@ void actPlayer(Entity* my)
case 6:
if ( multiplayer != CLIENT )
{
if ( swimming )
if ( bIsPlayerSwimming )
{
entity->flags[INVISIBLE] = true;
}
Expand Down Expand Up @@ -2556,7 +2562,7 @@ void actPlayer(Entity* my)
case 7:
if ( multiplayer != CLIENT )
{
if ( swimming )
if ( bIsPlayerSwimming )
{
entity->flags[INVISIBLE] = true;
}
Expand Down
Loading