From e32735b87ce0d650a0fd8a62ce67b209bd400a36 Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 25 Aug 2017 23:43:17 -0500 Subject: [PATCH 01/15] + Added function 'isSwimming()' to return Entity swimming status --- src/entity.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/entity.hpp | 1 + 2 files changed, 48 insertions(+) diff --git a/src/entity.cpp b/src/entity.cpp index f017a97a5..4acbfcb39 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -6127,6 +6127,53 @@ bool isLevitating(Stat* mystats) /*------------------------------------------------------------------------------- +isSwimming + +Returns true if the given Entity is swimming, or false if it is not + +-------------------------------------------------------------------------------*/ + +bool isSwimming(Entity* entity) +{ + if ( entity == nullptr ) + { + return false; + } + + Stat* entityStats = entity->getStats(); + if ( entityStats == nullptr ) + { + return false; + } + + // If the Entity is levitating, they are not swimming + if ( isLevitating(entityStats) ) + { + return false; + } + + // If the Entity has waterwalking boots, they are not swimming + if ( entityStats->shoes != nullptr ) + { + if ( entityStats->shoes->type == IRON_BOOTS_WATERWALKING ) + { + return false; + } + } + + // If both cases are false, the Entity could potentially be swimming + int x = std::min(std::max(0, floor(entity->x / 16)), map.width - 1); + int y = std::min(std::max(0, floor(entity->y / 16)), map.height - 1); + if ( animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) + { + return true; // The Entity is in a water tile, so must be swimming + } + + return false; +} + +/*------------------------------------------------------------------------------- + getWeaponSkill returns the proficiency for the weapon equipped. diff --git a/src/entity.hpp b/src/entity.hpp index d6cfa8582..da43e37d4 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -518,6 +518,7 @@ static const int SPRITE_BOOT_LEFT_OFFSET = 2; int setGloveSprite(Stat * myStats, Entity* ent, int spriteOffset); bool isLevitating(Stat * myStats); +bool isSwimming(Entity* entity); int getWeaponSkill(Item* weapon); int getStatForProficiency(int skill); void setSpriteAttributes(Entity* entityToSet, Entity* entityToCopy, Entity* entityStatToCopy); From d817a667bed1fbb2e66e532ceb6f9f6b9283ce4f Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 25 Aug 2017 23:53:28 -0500 Subject: [PATCH 02/15] * Replaced swimming check with new 'isSwimming()' --- src/magic/castSpell.cpp | 58 +++++++++++------------------------------ 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index 8c06ae15a..5dea1ac25 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -204,6 +204,21 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool } } + // Check to make sure the Caster is not swimming + // This check prevents situations where the Caster starts swimming after starting to cast + if ( !trap ) + { + if ( isSwimming(caster) == true ) + { + // If the Caster is a Player, tell them they cannot cast while swimming + if ( player >= 0 ) + { + messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" + } + return nullptr; + } + } + bool newbie = false; if ( !using_magicstaff && !trap) { @@ -262,49 +277,6 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool } } - //Check if the bugger is levitating. - bool levitating = false; - if (!trap) - { - levitating = isLevitating(stat); - } - - //Water walking boots - bool waterwalkingboots = false; - if (!trap) - { - if (stat->shoes != NULL) - if (stat->shoes->type == IRON_BOOTS_WATERWALKING ) - { - waterwalkingboots = true; - } - } - - node_t* node2; //For traversing the map looking for...liquids? - //Check if swimming. - if (!waterwalkingboots && !levitating && !trap && player >= 0) - { - bool swimming = false; - if (players[player] && players[player]->entity) - { - int x = std::min(std::max(0, floor(caster->x / 16)), map.width - 1); - int y = std::min(std::max(0, floor(caster->y / 16)), map.height - 1); - if (animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]]) - { - swimming = true; - } - } - if (swimming) - { - //Can't cast spells while swimming if not levitating or water walking. - if (player >= 0) - { - messagePlayer(player, language[410]); - } - return nullptr; - } - } - //Right. First, grab the root element, which is what determines the delivery system. //spellElement_t *element = (spellElement_t *)spell->elements->first->element; spellElement_t* element = (spellElement_t*)node->element; From 7211d695daef525fba9f03457618061d3b78141f Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 25 Aug 2017 23:54:18 -0500 Subject: [PATCH 03/15] + Added 'isSwimming()' check to fix issue #43 --- src/magic/castSpell.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index 5dea1ac25..ef8c08b8a 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -110,6 +110,17 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) return; } + // Check to make sure the Caster is not swimming + if ( isSwimming(caster) == true ) + { + // If the Caster is a Player, tell them they cannot cast while swimming + if ( player >= 0 ) + { + messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" + } + return; + } + if ( stat->EFFECTS[EFF_PARALYZED] ) { return; From 478c03a0d9a813b88f3c83e3d34e078565959c5c Mon Sep 17 00:00:00 2001 From: Lutz Date: Fri, 25 Aug 2017 23:58:45 -0500 Subject: [PATCH 04/15] * Replaced swimming check with 'isSwimming()' --- src/acthudweapon.cpp | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/acthudweapon.cpp b/src/acthudweapon.cpp index aadc03af7..ed2db6ffa 100644 --- a/src/acthudweapon.cpp +++ b/src/acthudweapon.cpp @@ -214,35 +214,20 @@ 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) - { - if (!levitating && !waterwalkingboots) - { - int x = std::min(std::max(0, floor(players[clientnum]->entity->x / 16)), map.width - 1); - int y = std::min(std::max(0, floor(players[clientnum]->entity->y / 16)), map.height - 1); - if (animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]]) - { - my->flags[INVISIBLE] = true; - if (parent) - { - parent->flags[INVISIBLE] = true; - } - return; - } - } - } + // Check to make sure the Player is not swimming + if ( players[clientnum] && players[clientnum]->entity ) + { + if ( isSwimming(players[clientnum]->entity) == true ) + { + // Player is swimming, hide their arms + my->flags[INVISIBLE] = true; + if ( parent ) + { + parent->flags[INVISIBLE] = true; + } + return; + } + } // select model if ( stats[clientnum]->ring != nullptr ) From 5d8f2615733beefcd493ffc84aaad573b5e8b7f2 Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 26 Aug 2017 00:02:29 -0500 Subject: [PATCH 05/15] * Replaced swimming check with 'isSwimming()' --- src/acthudweapon.cpp | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/acthudweapon.cpp b/src/acthudweapon.cpp index ed2db6ffa..87f9eff29 100644 --- a/src/acthudweapon.cpp +++ b/src/acthudweapon.cpp @@ -219,7 +219,7 @@ void actHudWeapon(Entity* my) { if ( isSwimming(players[clientnum]->entity) == true ) { - // Player is swimming, hide their arms + // Player is swimming, hide their weapon my->flags[INVISIBLE] = true; if ( parent ) { @@ -1377,26 +1377,22 @@ void actHudShield(Entity* my) } } - // swimming - bool swimming = false; - if (players[clientnum] && players[clientnum]->entity) - { - if (!levitating && !waterwalkingboots) //TODO: Swimming capstone? - { - int x = std::min(std::max(0, floor(players[clientnum]->entity->x / 16)), map.width - 1); - int y = std::min(std::max(0, floor(players[clientnum]->entity->y / 16)), map.height - 1); - if (animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]]) - { - my->flags[INVISIBLE] = true; - Entity* parent = uidToEntity(my->parent); - if (parent) - { - parent->flags[INVISIBLE] = true; - } - swimming = true; - } - } - } + // Check to make sure the Player is not swimming + bool isPlayerSwimming = false; + if ( players[clientnum] && players[clientnum]->entity ) + { + if ( isSwimming(players[clientnum]->entity) == true ) + { + // Player is swimming, hide their shield + my->flags[INVISIBLE] = true; + Entity* parent = uidToEntity(my->parent); + if ( parent ) + { + parent->flags[INVISIBLE] = true; + } + isPlayerSwimming = true; + } + } if (cast_animation.active) { @@ -1404,7 +1400,7 @@ void actHudShield(Entity* my) } bool defending = false; - if (!command && !swimming) + if ( !command && isPlayerSwimming == false ) { if (stats[clientnum]->shield) { @@ -1563,7 +1559,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 && isPlayerSwimming == false && players[clientnum]->entity->skill[3] == 0 && !cast_animation.active && !shieldSwitch) { if (itemCategory(stats[clientnum]->shield) == TOOL) { From 3b5d64f82f47d75269ff0ffe15838561cdfeb457 Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 26 Aug 2017 00:22:12 -0500 Subject: [PATCH 06/15] * Replaced swimming check with 'isSwimming()' --- src/actplayer.cpp | 152 ++++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 74 deletions(-) diff --git a/src/actplayer.cpp b/src/actplayer.cpp index d9bce48db..dd5761277 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -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; - if ( PLAYER_NUM == clientnum || multiplayer == SERVER ) - { - if ( !levitating && !waterwalkingboots && !noclip && !skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) ) - { - int x = std::min(std::max(0, floor(my->x / 16)), map.width - 1); - int y = std::min(std::max(0, floor(my->y / 16)), map.height - 1); - if ( animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) - { - if ( rand() % 400 == 0 && multiplayer != CLIENT ) - { - my->increaseSkill(PRO_SWIMMING); - } - swimming = true; - my->z = 7; - if ( !PLAYER_INWATER && PLAYER_NUM == clientnum ) - { - PLAYER_INWATER = 1; - if ( lavatiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) - { - messagePlayer(PLAYER_NUM, language[573]); - } - else - { - playSound(136, 128); - } - } - if ( multiplayer != CLIENT ) - { - if ( !lavatiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) - { - if ( my->flags[BURNING] ) - { - my->flags[BURNING] = false; - messagePlayer(PLAYER_NUM, language[574]); - if ( PLAYER_NUM > 0 ) - { - serverUpdateEntityFlag(my, BURNING); - } - } - } - else if ( ticks % 10 == 0 ) - { - my->modHP(-2 - rand() % 2); - my->setObituary(language[1506]); - if ( !my->flags[BURNING] ) - { - my->flags[BURNING] = true; - if ( PLAYER_NUM > 0 ) - { - serverUpdateEntityFlag(my, BURNING); - } - } - } - } - } - } - } - if (!swimming) - if (PLAYER_INWATER) - { - PLAYER_INWATER = 0; - } + // Check to make sure the Player is not swimming + bool isPlayerSwimming = false; + if ( PLAYER_NUM == clientnum || multiplayer == SERVER ) + { + if ( isSwimming(players[clientnum]->entity) == true && noclip == false && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) == false ) + { + // Player is swimming, lower them into the water + isPlayerSwimming = true; + my->z = 7; + + // Store their map position for future checks + int playerMapX = std::min(std::max(0, floor(my->x / 16)), map.width - 1); + int playerMapY = std::min(std::max(0, floor(my->y / 16)), map.height - 1); + + // Check to increase their swimming level + if ( rand() % 400 == 0 && multiplayer != CLIENT ) + { + my->increaseSkill(PRO_SWIMMING); + } + + // Check if they are in lava + if ( !PLAYER_INWATER && PLAYER_NUM == clientnum ) + { + PLAYER_INWATER = 1; + if ( lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] ) + { + messagePlayer(PLAYER_NUM, language[573]); // "You've fallen in boiling lava!" + } + else + { + playSound(136, 128); // "Splash1V1.ogg" + } + } + + // Check to remove Fire status if stepping in water + if ( multiplayer != CLIENT ) + { + if ( !lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] ) + { + if ( my->flags[BURNING] ) + { + my->flags[BURNING] = false; + messagePlayer(PLAYER_NUM, language[574]); // "The water extinguishes the flames!" + if ( PLAYER_NUM > 0 ) + { + serverUpdateEntityFlag(my, BURNING); + } + } + } + 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->flags[BURNING] = true; + if ( PLAYER_NUM > 0 ) + { + serverUpdateEntityFlag(my, BURNING); + } + } + } + } + } + } + + // Update PLAYER_INWATER flag + if ( isPlayerSwimming != true ) + { + if ( PLAYER_INWATER ) + { + PLAYER_INWATER = 0; + } + } if (PLAYER_NUM == clientnum) { @@ -960,7 +964,7 @@ void actPlayer(Entity* my) // camera bobbing if (bobbing) { - if ( swimming ) + if ( isPlayerSwimming == true ) { if ( PLAYER_BOBMODE ) { @@ -996,13 +1000,13 @@ void actPlayer(Entity* my) } } } - else if ( !swimming ) + else if ( isPlayerSwimming != true ) { PLAYER_BOBMOVE = 0; PLAYER_BOB = 0; PLAYER_BOBMODE = 0; } - if ( !swimming && !stats[clientnum]->defending ) + if ( isPlayerSwimming != true && !stats[clientnum]->defending ) { if ( PLAYER_BOBMOVE > .2 ) { @@ -1015,7 +1019,7 @@ void actPlayer(Entity* my) PLAYER_BOBMODE = 1; } } - else if ( swimming ) + else if ( isPlayerSwimming == true ) { if ( PLAYER_BOBMOVE > .3 ) { From 6e4ed90a2caa862b7d72a4d6965c5cc40c917d51 Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 26 Aug 2017 00:25:22 -0500 Subject: [PATCH 07/15] * Replaced 'swimming' with 'isPlayerSwimming' for swim speed check --- src/actplayer.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/actplayer.cpp b/src/actplayer.cpp index dd5761277..5bc9139a7 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -975,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 && isPlayerSwimming != true) { if (!stats[clientnum]->defending) { @@ -1631,12 +1631,14 @@ void actPlayer(Entity* my) // swimming slows you down bool amuletwaterbreathing = false; - if ( stats[PLAYER_NUM]->amulet != NULL ) - if ( stats[PLAYER_NUM]->amulet->type == AMULET_WATERBREATHING ) - { - amuletwaterbreathing = true; - } - if ( swimming && !amuletwaterbreathing ) + if ( stats[PLAYER_NUM]->amulet != NULL ) + { + if ( stats[PLAYER_NUM]->amulet->type == AMULET_WATERBREATHING ) + { + amuletwaterbreathing = true; + } + } + if ( isPlayerSwimming == true && !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; From 0c2fdc828b6ea7bd09ab9083f744228d31ab74ff Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 26 Aug 2017 00:27:23 -0500 Subject: [PATCH 08/15] * Replaced 'swimming' with 'isPlayerSwimming' for body part movement --- src/actplayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actplayer.cpp b/src/actplayer.cpp index 5bc9139a7..827c675e7 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -1947,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 && isPlayerSwimming != true ) { node_t* tempNode = list_Node(&my->children, 2); if ( tempNode ) @@ -1975,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 && isPlayerSwimming != true ) { node_t* tempNode = list_Node(&my->children, 2); if ( tempNode ) From e638432a490551868365b642f5712b7fe1022586 Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 26 Aug 2017 00:28:57 -0500 Subject: [PATCH 09/15] * Replaced 'swimming' with 'isPlayerSwimming' for weapon and shield movement --- src/actplayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actplayer.cpp b/src/actplayer.cpp index 827c675e7..9bfb22308 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -2453,7 +2453,7 @@ void actPlayer(Entity* my) case 6: if ( multiplayer != CLIENT ) { - if ( swimming ) + if ( isPlayerSwimming == true ) { entity->flags[INVISIBLE] = true; } @@ -2562,7 +2562,7 @@ void actPlayer(Entity* my) case 7: if ( multiplayer != CLIENT ) { - if ( swimming ) + if ( isPlayerSwimming == true ) { entity->flags[INVISIBLE] = true; } From 514ea867329f9cb11bb9679ba6470d6cea5ec68e Mon Sep 17 00:00:00 2001 From: Lutz Date: Sat, 26 Aug 2017 23:32:54 -0500 Subject: [PATCH 10/15] * Commented out debug message --- src/entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entity.cpp b/src/entity.cpp index 4acbfcb39..90cfb54b5 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -7408,7 +7408,7 @@ void Entity::giveClientStats() void Entity::monsterAcquireAttackTarget(const Entity& target, Sint32 state) { - messagePlayer(clientnum, "Entity acquired target!"); + //messagePlayer(clientnum, "Entity acquired target!"); monsterState = state; monsterTarget = target.getUID(); From 8786ed8f6c67967cf3fff60cffa35bba265db5a9 Mon Sep 17 00:00:00 2001 From: Lutz Date: Sun, 27 Aug 2017 01:14:04 -0500 Subject: [PATCH 11/15] * Fixed which Entity was being passed to 'isSwimming()' --- src/actplayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actplayer.cpp b/src/actplayer.cpp index 9bfb22308..703bdcdae 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -886,7 +886,7 @@ void actPlayer(Entity* my) bool isPlayerSwimming = false; if ( PLAYER_NUM == clientnum || multiplayer == SERVER ) { - if ( isSwimming(players[clientnum]->entity) == true && noclip == false && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) == false ) + if ( isSwimming(players[PLAYER_NUM]->entity) == true && noclip == false && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) == false ) { // Player is swimming, lower them into the water isPlayerSwimming = true; @@ -902,7 +902,7 @@ void actPlayer(Entity* my) my->increaseSkill(PRO_SWIMMING); } - // Check if they are in lava + // Process initial step into swimming tile if ( !PLAYER_INWATER && PLAYER_NUM == clientnum ) { PLAYER_INWATER = 1; From 9ef08b73988355268386ab533548699dc1f65e48 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 29 Aug 2017 22:45:29 -0500 Subject: [PATCH 12/15] + Added a checl to 'isSwimming()' in the magic animation manager to prevent #143 --- src/magic/act_HandMagic.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/magic/act_HandMagic.cpp b/src/magic/act_HandMagic.cpp index 2e81eece1..1e55df75f 100644 --- a/src/magic/act_HandMagic.cpp +++ b/src/magic/act_HandMagic.cpp @@ -271,6 +271,15 @@ void actLeftHandMagic(Entity* my) entity->vel_z = -.15; entity->fskill[3] = 0.01; } + + // Check to make sure the Player is not swimming + if ( isSwimming(players[clientnum]->entity) == true ) + { + // The Player is swimming, cancel the cast + spellcastingAnimationManager_deactivate(&cast_animation); + return; + } + cast_animation.consume_timer--; if ( cast_animation.consume_timer < 0 && cast_animation.mana_left > 0 ) { From e6c51b9d799f01ef8ac77894a83b2a2e17ab3a92 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 26 Sep 2017 15:33:21 -0500 Subject: [PATCH 13/15] * Fixed formatting (spaces -> tabs) --- src/acthudweapon.cpp | 62 ++++++------- src/actplayer.cpp | 168 ++++++++++++++++++------------------ src/entity.cpp | 74 ++++++++-------- src/magic/act_HandMagic.cpp | 14 +-- src/magic/castSpell.cpp | 48 +++++------ 5 files changed, 183 insertions(+), 183 deletions(-) diff --git a/src/acthudweapon.cpp b/src/acthudweapon.cpp index 87f9eff29..f58430880 100644 --- a/src/acthudweapon.cpp +++ b/src/acthudweapon.cpp @@ -214,20 +214,20 @@ void actHudWeapon(Entity* my) throwGimpTimer--; } - // Check to make sure the Player is not swimming - if ( players[clientnum] && players[clientnum]->entity ) - { - if ( isSwimming(players[clientnum]->entity) == true ) - { - // Player is swimming, hide their weapon - my->flags[INVISIBLE] = true; - if ( parent ) - { - parent->flags[INVISIBLE] = true; - } - return; - } - } + // Check to make sure the Player is not swimming + if ( players[clientnum] && players[clientnum]->entity ) + { + if ( isSwimming(players[clientnum]->entity) == true ) + { + // Player is swimming, hide their weapon + my->flags[INVISIBLE] = true; + if ( parent ) + { + parent->flags[INVISIBLE] = true; + } + return; + } + } // select model if ( stats[clientnum]->ring != nullptr ) @@ -1377,22 +1377,22 @@ void actHudShield(Entity* my) } } - // Check to make sure the Player is not swimming - bool isPlayerSwimming = false; - if ( players[clientnum] && players[clientnum]->entity ) - { - if ( isSwimming(players[clientnum]->entity) == true ) - { - // Player is swimming, hide their shield - my->flags[INVISIBLE] = true; - Entity* parent = uidToEntity(my->parent); - if ( parent ) - { - parent->flags[INVISIBLE] = true; - } - isPlayerSwimming = true; - } - } + // Check to make sure the Player is not swimming + bool isPlayerSwimming = false; + if ( players[clientnum] && players[clientnum]->entity ) + { + if ( isSwimming(players[clientnum]->entity) == true ) + { + // Player is swimming, hide their shield + my->flags[INVISIBLE] = true; + Entity* parent = uidToEntity(my->parent); + if ( parent ) + { + parent->flags[INVISIBLE] = true; + } + isPlayerSwimming = true; + } + } if (cast_animation.active) { @@ -1559,7 +1559,7 @@ void actHudShield(Entity* my) // torch/lantern flames my->flags[BRIGHT] = false; - if (stats[clientnum]->shield && isPlayerSwimming == false && players[clientnum]->entity->skill[3] == 0 && !cast_animation.active && !shieldSwitch) + if ( stats[clientnum]->shield && isPlayerSwimming == false && players[clientnum]->entity->skill[3] == 0 && !cast_animation.active && !shieldSwitch ) { if (itemCategory(stats[clientnum]->shield) == TOOL) { diff --git a/src/actplayer.cpp b/src/actplayer.cpp index 703bdcdae..e247c69e2 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -882,80 +882,80 @@ void actPlayer(Entity* my) } } - // Check to make sure the Player is not swimming - bool isPlayerSwimming = false; - if ( PLAYER_NUM == clientnum || multiplayer == SERVER ) - { - if ( isSwimming(players[PLAYER_NUM]->entity) == true && noclip == false && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) == false ) - { - // Player is swimming, lower them into the water - isPlayerSwimming = true; - my->z = 7; - - // Store their map position for future checks - int playerMapX = std::min(std::max(0, floor(my->x / 16)), map.width - 1); - int playerMapY = std::min(std::max(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 ) - { - PLAYER_INWATER = 1; - if ( lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] ) - { - messagePlayer(PLAYER_NUM, language[573]); // "You've fallen in boiling lava!" - } - else - { - playSound(136, 128); // "Splash1V1.ogg" - } - } - - // Check to remove Fire status if stepping in water - if ( multiplayer != CLIENT ) - { - if ( !lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] ) - { - if ( my->flags[BURNING] ) - { - my->flags[BURNING] = false; - messagePlayer(PLAYER_NUM, language[574]); // "The water extinguishes the flames!" - if ( PLAYER_NUM > 0 ) - { - serverUpdateEntityFlag(my, BURNING); - } - } - } - 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->flags[BURNING] = true; - if ( PLAYER_NUM > 0 ) - { - serverUpdateEntityFlag(my, BURNING); - } - } - } - } - } - } - - // Update PLAYER_INWATER flag - if ( isPlayerSwimming != true ) - { - if ( PLAYER_INWATER ) - { - PLAYER_INWATER = 0; - } - } + // Check to make sure the Player is not swimming + bool isPlayerSwimming = false; + if ( PLAYER_NUM == clientnum || multiplayer == SERVER ) + { + if ( isSwimming(players[PLAYER_NUM]->entity) == true && noclip == false && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) == false ) + { + // Player is swimming, lower them into the water + isPlayerSwimming = true; + my->z = 7; + + // Store their map position for future checks + int playerMapX = std::min(std::max(0, floor(my->x / 16)), map.width - 1); + int playerMapY = std::min(std::max(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 ) + { + PLAYER_INWATER = 1; + if ( lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] ) + { + messagePlayer(PLAYER_NUM, language[573]); // "You've fallen in boiling lava!" + } + else + { + playSound(136, 128); // "Splash1V1.ogg" + } + } + + // Check to remove Fire status if stepping in water + if ( multiplayer != CLIENT ) + { + if ( !lavatiles[map.tiles[playerMapY * MAPLAYERS + playerMapX * MAPLAYERS * map.height]] ) + { + if ( my->flags[BURNING] ) + { + my->flags[BURNING] = false; + messagePlayer(PLAYER_NUM, language[574]); // "The water extinguishes the flames!" + if ( PLAYER_NUM > 0 ) + { + serverUpdateEntityFlag(my, BURNING); + } + } + } + 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->flags[BURNING] = true; + if ( PLAYER_NUM > 0 ) + { + serverUpdateEntityFlag(my, BURNING); + } + } + } + } + } + } + + // Update PLAYER_INWATER flag + if ( isPlayerSwimming != true ) + { + if ( PLAYER_INWATER ) + { + PLAYER_INWATER = 0; + } + } if (PLAYER_NUM == clientnum) { @@ -975,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 && isPlayerSwimming != true) + 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 && isPlayerSwimming != true ) { if (!stats[clientnum]->defending) { @@ -1006,7 +1006,7 @@ void actPlayer(Entity* my) PLAYER_BOB = 0; PLAYER_BOBMODE = 0; } - if ( isPlayerSwimming != true && !stats[clientnum]->defending ) + if ( isPlayerSwimming != true && !stats[clientnum]->defending ) { if ( PLAYER_BOBMOVE > .2 ) { @@ -1629,15 +1629,15 @@ 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 ( stats[PLAYER_NUM]->amulet != NULL ) + { + if ( stats[PLAYER_NUM]->amulet->type == AMULET_WATERBREATHING ) + { + amuletwaterbreathing = true; + } + } if ( isPlayerSwimming == true && !amuletwaterbreathing ) { PLAYER_VELX *= (((stats[PLAYER_NUM]->PROFICIENCIES[PRO_SWIMMING] / 100.f) * 50.f) + 50) / 100.f; diff --git a/src/entity.cpp b/src/entity.cpp index 90cfb54b5..853636d31 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -6081,7 +6081,7 @@ bool Entity::setBootSprite(Entity* leg, int spriteOffset) /*------------------------------------------------------------------------------- -sLevitating +isLevitating returns true if the given entity is levitating, or false if it cannot @@ -6135,41 +6135,41 @@ Returns true if the given Entity is swimming, or false if it is not bool isSwimming(Entity* entity) { - if ( entity == nullptr ) - { - return false; - } - - Stat* entityStats = entity->getStats(); - if ( entityStats == nullptr ) - { - return false; - } - - // If the Entity is levitating, they are not swimming - if ( isLevitating(entityStats) ) - { - return false; - } - - // If the Entity has waterwalking boots, they are not swimming - if ( entityStats->shoes != nullptr ) - { - if ( entityStats->shoes->type == IRON_BOOTS_WATERWALKING ) - { - return false; - } - } - - // If both cases are false, the Entity could potentially be swimming - int x = std::min(std::max(0, floor(entity->x / 16)), map.width - 1); - int y = std::min(std::max(0, floor(entity->y / 16)), map.height - 1); - if ( animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) - { - return true; // The Entity is in a water tile, so must be swimming - } - - return false; + if ( entity == nullptr ) + { + return false; + } + + Stat* entityStats = entity->getStats(); + if ( entityStats == nullptr ) + { + return false; + } + + // If the Entity is levitating, they are not swimming + if ( isLevitating(entityStats) ) + { + return false; + } + + // If the Entity has waterwalking boots, they are not swimming + if ( entityStats->shoes != nullptr ) + { + if ( entityStats->shoes->type == IRON_BOOTS_WATERWALKING ) + { + return false; + } + } + + // If both cases are false, the Entity could potentially be swimming + int x = std::min(std::max(0, floor(entity->x / 16)), map.width - 1); + int y = std::min(std::max(0, floor(entity->y / 16)), map.height - 1); + if ( animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) + { + return true; // The Entity is in a water tile, so must be swimming + } + + return false; } /*------------------------------------------------------------------------------- @@ -7408,7 +7408,7 @@ void Entity::giveClientStats() void Entity::monsterAcquireAttackTarget(const Entity& target, Sint32 state) { - //messagePlayer(clientnum, "Entity acquired target!"); + messagePlayer(clientnum, "Entity acquired target!"); monsterState = state; monsterTarget = target.getUID(); diff --git a/src/magic/act_HandMagic.cpp b/src/magic/act_HandMagic.cpp index 1e55df75f..49c6c9a86 100644 --- a/src/magic/act_HandMagic.cpp +++ b/src/magic/act_HandMagic.cpp @@ -272,13 +272,13 @@ void actLeftHandMagic(Entity* my) entity->fskill[3] = 0.01; } - // Check to make sure the Player is not swimming - if ( isSwimming(players[clientnum]->entity) == true ) - { - // The Player is swimming, cancel the cast - spellcastingAnimationManager_deactivate(&cast_animation); - return; - } + // Check to make sure the Player is not swimming + if ( isSwimming(players[clientnum]->entity) == true ) + { + // The Player is swimming, cancel the cast + spellcastingAnimationManager_deactivate(&cast_animation); + return; + } cast_animation.consume_timer--; if ( cast_animation.consume_timer < 0 && cast_animation.mana_left > 0 ) diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index ef8c08b8a..66a77cbb4 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -110,16 +110,16 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) return; } - // Check to make sure the Caster is not swimming - if ( isSwimming(caster) == true ) - { - // If the Caster is a Player, tell them they cannot cast while swimming - if ( player >= 0 ) - { - messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" - } - return; - } + // Check to make sure the Caster is not swimming + if ( isSwimming(caster) == true ) + { + // If the Caster is a Player, tell them they cannot cast while swimming + if ( player >= 0 ) + { + messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" + } + return; + } if ( stat->EFFECTS[EFF_PARALYZED] ) { @@ -215,20 +215,20 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool } } - // Check to make sure the Caster is not swimming - // This check prevents situations where the Caster starts swimming after starting to cast - if ( !trap ) - { - if ( isSwimming(caster) == true ) - { - // If the Caster is a Player, tell them they cannot cast while swimming - if ( player >= 0 ) - { - messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" - } - return nullptr; - } - } + // Check to make sure the Caster is not swimming + // This check prevents situations where the Caster starts swimming after starting to cast + if ( !trap ) + { + if ( isSwimming(caster) == true ) + { + // If the Caster is a Player, tell them they cannot cast while swimming + if ( player >= 0 ) + { + messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" + } + return nullptr; + } + } bool newbie = false; if ( !using_magicstaff && !trap) From c3cb42d2b32135c2715617298c649f381b672a12 Mon Sep 17 00:00:00 2001 From: Lutz Date: Tue, 26 Sep 2017 15:33:49 -0500 Subject: [PATCH 14/15] - Removed unused variables that are replaced by isSwimming() --- src/acthudweapon.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/acthudweapon.cpp b/src/acthudweapon.cpp index f58430880..4522c83b4 100644 --- a/src/acthudweapon.cpp +++ b/src/acthudweapon.cpp @@ -1318,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 ) From bc4c31e7c83a1066f73c454e1e5b1b81047e01e3 Mon Sep 17 00:00:00 2001 From: Lutz Date: Wed, 27 Sep 2017 13:23:58 -0500 Subject: [PATCH 15/15] * Fixed formatting (explicit bool checks -> bIsBool) Added comments and renamed function to "IsSwimming()" --- src/acthudweapon.cpp | 12 ++++++------ src/actplayer.cpp | 28 ++++++++++++++-------------- src/entity.cpp | 12 ++++++++++-- src/entity.hpp | 9 ++++++++- src/magic/act_HandMagic.cpp | 2 +- src/magic/castSpell.cpp | 4 ++-- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/acthudweapon.cpp b/src/acthudweapon.cpp index 4522c83b4..898fe7b7b 100644 --- a/src/acthudweapon.cpp +++ b/src/acthudweapon.cpp @@ -217,7 +217,7 @@ void actHudWeapon(Entity* my) // Check to make sure the Player is not swimming if ( players[clientnum] && players[clientnum]->entity ) { - if ( isSwimming(players[clientnum]->entity) == true ) + if ( IsSwimming(players[clientnum]->entity) ) { // Player is swimming, hide their weapon my->flags[INVISIBLE] = true; @@ -1367,10 +1367,10 @@ void actHudShield(Entity* my) } // Check to make sure the Player is not swimming - bool isPlayerSwimming = false; + bool bIsPlayerSwimming = false; if ( players[clientnum] && players[clientnum]->entity ) { - if ( isSwimming(players[clientnum]->entity) == true ) + if ( IsSwimming(players[clientnum]->entity) ) { // Player is swimming, hide their shield my->flags[INVISIBLE] = true; @@ -1379,7 +1379,7 @@ void actHudShield(Entity* my) { parent->flags[INVISIBLE] = true; } - isPlayerSwimming = true; + bIsPlayerSwimming = true; } } @@ -1389,7 +1389,7 @@ void actHudShield(Entity* my) } bool defending = false; - if ( !command && isPlayerSwimming == false ) + if ( !command && bIsPlayerSwimming ) { if (stats[clientnum]->shield) { @@ -1548,7 +1548,7 @@ void actHudShield(Entity* my) // torch/lantern flames my->flags[BRIGHT] = false; - if ( stats[clientnum]->shield && isPlayerSwimming == false && 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) { diff --git a/src/actplayer.cpp b/src/actplayer.cpp index e247c69e2..fdab60b85 100644 --- a/src/actplayer.cpp +++ b/src/actplayer.cpp @@ -883,13 +883,13 @@ void actPlayer(Entity* my) } // Check to make sure the Player is not swimming - bool isPlayerSwimming = false; + bool bIsPlayerSwimming = false; if ( PLAYER_NUM == clientnum || multiplayer == SERVER ) { - if ( isSwimming(players[PLAYER_NUM]->entity) == true && noclip == false && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) == false ) + if ( IsSwimming(players[PLAYER_NUM]->entity) && noclip && skillCapstoneUnlocked(PLAYER_NUM, PRO_SWIMMING) ) { // Player is swimming, lower them into the water - isPlayerSwimming = true; + bIsPlayerSwimming = true; my->z = 7; // Store their map position for future checks @@ -949,7 +949,7 @@ void actPlayer(Entity* my) } // Update PLAYER_INWATER flag - if ( isPlayerSwimming != true ) + if ( !(bIsPlayerSwimming) ) { if ( PLAYER_INWATER ) { @@ -964,7 +964,7 @@ void actPlayer(Entity* my) // camera bobbing if (bobbing) { - if ( isPlayerSwimming == true ) + if ( bIsPlayerSwimming ) { if ( PLAYER_BOBMODE ) { @@ -975,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 && isPlayerSwimming != true ) + 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) { @@ -1000,13 +1000,13 @@ void actPlayer(Entity* my) } } } - else if ( isPlayerSwimming != true ) + else if ( (bIsPlayerSwimming) ) { PLAYER_BOBMOVE = 0; PLAYER_BOB = 0; PLAYER_BOBMODE = 0; } - if ( isPlayerSwimming != true && !stats[clientnum]->defending ) + if ( (bIsPlayerSwimming) && !stats[clientnum]->defending ) { if ( PLAYER_BOBMOVE > .2 ) { @@ -1019,7 +1019,7 @@ void actPlayer(Entity* my) PLAYER_BOBMODE = 1; } } - else if ( isPlayerSwimming == true ) + else if ( bIsPlayerSwimming ) { if ( PLAYER_BOBMOVE > .3 ) { @@ -1638,7 +1638,7 @@ void actPlayer(Entity* my) amuletwaterbreathing = true; } } - if ( isPlayerSwimming == true && !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; @@ -1947,7 +1947,7 @@ void actPlayer(Entity* my) if ( entity->pitch < -PI / 4.0 ) { entity->pitch = -PI / 4.0; - if ( bodypart == 2 && dist > .4 && !levitating && isPlayerSwimming != true ) + if ( bodypart == 2 && dist > .4 && !levitating && (!bIsPlayerSwimming) ) { node_t* tempNode = list_Node(&my->children, 2); if ( tempNode ) @@ -1975,7 +1975,7 @@ void actPlayer(Entity* my) if ( entity->pitch > PI / 4.0 ) { entity->pitch = PI / 4.0; - if ( bodypart == 2 && dist > .4 && !levitating && isPlayerSwimming != true ) + if ( bodypart == 2 && dist > .4 && !levitating && (!bIsPlayerSwimming) ) { node_t* tempNode = list_Node(&my->children, 2); if ( tempNode ) @@ -2453,7 +2453,7 @@ void actPlayer(Entity* my) case 6: if ( multiplayer != CLIENT ) { - if ( isPlayerSwimming == true ) + if ( bIsPlayerSwimming ) { entity->flags[INVISIBLE] = true; } @@ -2562,7 +2562,7 @@ void actPlayer(Entity* my) case 7: if ( multiplayer != CLIENT ) { - if ( isPlayerSwimming == true ) + if ( bIsPlayerSwimming ) { entity->flags[INVISIBLE] = true; } diff --git a/src/entity.cpp b/src/entity.cpp index 853636d31..c673b6133 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -6127,13 +6127,21 @@ bool isLevitating(Stat* mystats) /*------------------------------------------------------------------------------- -isSwimming +IsSwimming Returns true if the given Entity is swimming, or false if it is not +TODOR: This function should be replaced by a flag on Entities after a refactor -------------------------------------------------------------------------------*/ -bool isSwimming(Entity* entity) +/* entity.cpp + * @param entity - The Entity being checked if it is swimming or not + * @returns true - If the Entity is in a water tile, is not levitating, and is not wearing water walking boots + * @returns false - Any other case + * Returns whether or not the given Entity, @entity, is currently swimming. Calculated by if they are in a water tile, and are not levitating or water walking + * TODOR: This function should be replaced by a flag on Entities after a refactor + */ +bool IsSwimming(Entity* entity) { if ( entity == nullptr ) { diff --git a/src/entity.hpp b/src/entity.hpp index da43e37d4..c7f8da161 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -518,7 +518,14 @@ static const int SPRITE_BOOT_LEFT_OFFSET = 2; int setGloveSprite(Stat * myStats, Entity* ent, int spriteOffset); bool isLevitating(Stat * myStats); -bool isSwimming(Entity* entity); +/* entity.cpp + * @param entity - The Entity being checked if it is swimming or not + * @returns true - If the Entity is in a water tile, is not levitating, and is not wearing water walking boots + * @returns false - Any other case + * Returns whether or not the given Entity, @entity, is currently swimming. Calculated by if they are in a water tile, and are not levitating or water walking + * TODOR: This function should be replaced by a flag on Entities after a refactor + */ +bool IsSwimming(Entity* entity); int getWeaponSkill(Item* weapon); int getStatForProficiency(int skill); void setSpriteAttributes(Entity* entityToSet, Entity* entityToCopy, Entity* entityStatToCopy); diff --git a/src/magic/act_HandMagic.cpp b/src/magic/act_HandMagic.cpp index 49c6c9a86..439cf1a5d 100644 --- a/src/magic/act_HandMagic.cpp +++ b/src/magic/act_HandMagic.cpp @@ -273,7 +273,7 @@ void actLeftHandMagic(Entity* my) } // Check to make sure the Player is not swimming - if ( isSwimming(players[clientnum]->entity) == true ) + if ( IsSwimming(players[clientnum]->entity) ) { // The Player is swimming, cancel the cast spellcastingAnimationManager_deactivate(&cast_animation); diff --git a/src/magic/castSpell.cpp b/src/magic/castSpell.cpp index 66a77cbb4..69ebd5b76 100644 --- a/src/magic/castSpell.cpp +++ b/src/magic/castSpell.cpp @@ -111,7 +111,7 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) } // Check to make sure the Caster is not swimming - if ( isSwimming(caster) == true ) + if ( IsSwimming(caster) ) { // If the Caster is a Player, tell them they cannot cast while swimming if ( player >= 0 ) @@ -219,7 +219,7 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool // This check prevents situations where the Caster starts swimming after starting to cast if ( !trap ) { - if ( isSwimming(caster) == true ) + if ( IsSwimming(caster) ) { // If the Caster is a Player, tell them they cannot cast while swimming if ( player >= 0 )