Skip to content

Commit

Permalink
Replaced the raw weapon breakable type numbers with an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Apr 14, 2024
1 parent 2f85d0e commit 83dfe13
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/smw/GSGameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ void LoadMapObjects(bool fPreview)
g_map->blockdata[x][y] = new B_ThrowBlock(&rm->spr_throwblock, x << 5, y << 5, 4, 10, 1);
noncolcontainer.add(g_map->blockdata[x][y]);
} else if (iType >= 20 && iType <= 29) {
g_map->blockdata[x][y] = new B_WeaponBreakableBlock(&rm->spr_weaponbreakableblock, x << 5, y << 5, iType - 20);
g_map->blockdata[x][y] = new B_WeaponBreakableBlock(&rm->spr_weaponbreakableblock, x << 5, y << 5, static_cast<WeaponDamageType>(iType - 20));
noncolcontainer.add(g_map->blockdata[x][y]);
} else {
g_map->blockdata[x][y] = NULL;
Expand Down
33 changes: 16 additions & 17 deletions src/smw/objects/blocks/WeaponBreakableBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ extern CResourceManager* rm;
extern CGameValues game_values;
extern CEyecandyContainer eyecandy[3];

B_WeaponBreakableBlock::B_WeaponBreakableBlock(gfxSprite *nspr, short x, short y, short type) :
IO_Block(nspr, x, y)
B_WeaponBreakableBlock::B_WeaponBreakableBlock(gfxSprite *nspr, short x, short y, WeaponDamageType type)
: IO_Block(nspr, x, y)
, iType(type)
, iDrawOffsetX(static_cast<short>(type) * 32)
{
iType = type;
iw = TILESIZE;
ih = TILESIZE;

iDrawOffsetX = type << 5;
}

void B_WeaponBreakableBlock::draw()
Expand Down Expand Up @@ -66,10 +65,10 @@ bool B_WeaponBreakableBlock::hittop(CPlayer * player, bool useBehavior)
player->vely = GRAVITATION;

//Save this for when we create a super stomp destroyable block
if (iType == 6 && player->IsSuperStomping() && state == 0) {
if (iType == WeaponDamageType::KuriboShoe && player->IsSuperStomping() && state == 0) {
triggerBehavior(player->globalID, player->teamID);
return false;
} else if (iType == 8 && player->isInvincible()) {
} else if (iType == WeaponDamageType::Star && player->isInvincible()) {
triggerBehavior(player->globalID, player->teamID);
return false;
}
Expand All @@ -83,11 +82,11 @@ bool B_WeaponBreakableBlock::hitbottom(CPlayer * player, bool useBehavior)
if (useBehavior && state == 0) {
//If the player has a cape and they used it for a feather destroyable block, then kill it
bool fTriggerBlock = false;
if (iType == 1 && player->powerup == 3 && player->extrajumps > 0) {
if (iType == WeaponDamageType::Feather && player->powerup == 3 && player->extrajumps > 0) {
fTriggerBlock = true;
} else if (iType == 7 && player->powerup == 8 && player->flying) {
} else if (iType == WeaponDamageType::PWings && player->powerup == 8 && player->flying) {
fTriggerBlock = true;
} else if (iType == 8 && player->isInvincible()) {
} else if (iType == WeaponDamageType::Star && player->isInvincible()) {
fTriggerBlock = true;
}

Expand All @@ -103,7 +102,7 @@ bool B_WeaponBreakableBlock::hitbottom(CPlayer * player, bool useBehavior)
bool B_WeaponBreakableBlock::hitleft(CPlayer * player, bool useBehavior)
{
if (useBehavior && state == 0) {
if (iType == 8 && player->isInvincible())
if (iType == WeaponDamageType::Star && player->isInvincible())
triggerBehavior(player->globalID, player->teamID);

return IO_Block::hitleft(player, useBehavior);
Expand All @@ -115,7 +114,7 @@ bool B_WeaponBreakableBlock::hitleft(CPlayer * player, bool useBehavior)
bool B_WeaponBreakableBlock::hitright(CPlayer * player, bool useBehavior)
{
if (useBehavior && state == 0) {
if (iType == 8 && player->isInvincible())
if (iType == WeaponDamageType::Star && player->isInvincible())
triggerBehavior(player->globalID, player->teamID);

return IO_Block::hitright(player, useBehavior);
Expand All @@ -138,7 +137,7 @@ bool B_WeaponBreakableBlock::hittop(IO_MovingObject * object)

MovingObjectType type = object->getMovingObjectType();

if (iType == 0 && type == movingobject_fireball) {
if (iType == WeaponDamageType::Fireball && type == movingobject_fireball) {
triggerBehavior(object->iPlayerID, object->iTeamID);
removeifprojectile(object, false, true);
return false;
Expand All @@ -156,7 +155,7 @@ bool B_WeaponBreakableBlock::hitbottom(IO_MovingObject * object)

MovingObjectType type = object->getMovingObjectType();

if (iType == 0 && type == movingobject_fireball) {
if (iType == WeaponDamageType::Fireball && type == movingobject_fireball) {
triggerBehavior(object->iPlayerID, object->iTeamID);
removeifprojectile(object, false, true);
return false;
Expand Down Expand Up @@ -205,7 +204,7 @@ bool B_WeaponBreakableBlock::objecthitside(IO_MovingObject * object)
{
MovingObjectType type = object->getMovingObjectType();

if (iType == 2 && ((type == movingobject_shell && object->state == 1) || type == movingobject_throwblock || (type == movingobject_throwbox && !((CO_ThrowBox*)object)->HasKillVelocity()))) {
if (iType == WeaponDamageType::Shell && ((type == movingobject_shell && object->state == 1) || type == movingobject_throwblock || (type == movingobject_throwbox && !((CO_ThrowBox*)object)->HasKillVelocity()))) {
short iPlayerID = -1;
short iTeamID = -1;
if (type == movingobject_shell) {
Expand All @@ -224,15 +223,15 @@ bool B_WeaponBreakableBlock::objecthitside(IO_MovingObject * object)

triggerBehavior(iPlayerID, iTeamID);
return false;
} else if (iType == 0 && type == movingobject_fireball) {
} else if (iType == WeaponDamageType::Fireball && type == movingobject_fireball) {
MO_Fireball * fireball = (MO_Fireball*)object;
triggerBehavior(fireball->iPlayerID, fireball->iTeamID);
removeifprojectile(object, false, true);
return false;
} else if (type == movingobject_attackzone) {
MO_AttackZone * zone = (MO_AttackZone*)object;

if ((zone->iStyle == KillStyle::Leaf && iType == 9) || (zone->iStyle == KillStyle::Feather && iType == 1)) {
if ((zone->iStyle == KillStyle::Leaf && iType == WeaponDamageType::Leaf) || (zone->iStyle == KillStyle::Feather && iType == WeaponDamageType::Feather)) {
triggerBehavior(zone->iPlayerID, zone->iTeamID);
zone->Die();
return false;
Expand Down
52 changes: 32 additions & 20 deletions src/smw/objects/blocks/WeaponBreakableBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,49 @@

#include "IO_Block.h"


enum class WeaponDamageType : unsigned char {
Fireball,
Feather,
Shell,
Bomb,
Boomerang,
Hammer,
KuriboShoe,
PWings,
Star,
Leaf,
};


class B_WeaponBreakableBlock : public IO_Block {
public:
B_WeaponBreakableBlock(gfxSprite *nspr, short x, short y, short type);
~B_WeaponBreakableBlock(){};
B_WeaponBreakableBlock(gfxSprite *nspr, short x, short y, WeaponDamageType type);

BlockType getBlockType() const override {
return BlockType::WeaponBreakable;
}

void draw() override;
void update() override;
void draw() override;
void update() override;

bool hittop(CPlayer * player, bool useBehavior) override;
bool hitbottom(CPlayer * player, bool useBehavior) override;
bool hitleft(CPlayer * player, bool useBehavior) override;
bool hitright(CPlayer * player, bool useBehavior) override;
bool hittop(CPlayer* player, bool useBehavior) override;
bool hitbottom(CPlayer* player, bool useBehavior) override;
bool hitleft(CPlayer* player, bool useBehavior) override;
bool hitright(CPlayer* player, bool useBehavior) override;

bool hittop(IO_MovingObject * object) override;
bool hitbottom(IO_MovingObject * object) override;
bool hitright(IO_MovingObject * object) override;
bool hitleft(IO_MovingObject * object) override;
bool hittop(IO_MovingObject* object) override;
bool hitbottom(IO_MovingObject* object) override;
bool hitright(IO_MovingObject* object) override;
bool hitleft(IO_MovingObject* object) override;

void triggerBehavior(short iPlayerID, short iTeamID);
void triggerBehavior(short iPlayerID, short iTeamID);

private:
bool objecthitside(IO_MovingObject * object);
WeaponDamageType type() const { return iType; }

short iType;
short iDrawOffsetX;
private:
bool objecthitside(IO_MovingObject * object);

friend class MO_Hammer;
friend class MO_Boomerang;
friend class MO_Explosion;
const WeaponDamageType iType;
const short iDrawOffsetX;
};
2 changes: 1 addition & 1 deletion src/smw/objects/moving/MO_Boomerang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void MO_Boomerang::update()
for (short iBlock = 0; iBlock < 4; iBlock++) {
if (blocks[iBlock] && blocks[iBlock]->getBlockType() == BlockType::WeaponBreakable) {
B_WeaponBreakableBlock* weaponbreakableblock = (B_WeaponBreakableBlock*)blocks[iBlock];
if (weaponbreakableblock->iType == 4) {
if (weaponbreakableblock->type() == WeaponDamageType::Boomerang) {
weaponbreakableblock->triggerBehavior(iPlayerID, iTeamID);
forcedead();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/smw/objects/moving/MO_Explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void MO_Explosion::update()
IO_Block* block = g_map->block(iTestX / TILESIZE, iTestRow);
if (block && block->getBlockType() == BlockType::WeaponBreakable) {
B_WeaponBreakableBlock* weaponbreakableblock = (B_WeaponBreakableBlock*)block;
if (weaponbreakableblock->iType == 3) {
if (weaponbreakableblock->type() == WeaponDamageType::Bomb) {
weaponbreakableblock->triggerBehavior(iPlayerID, iTeamID);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/smw/objects/moving/MO_Hammer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void MO_Hammer::update()
for (short iBlock = 0; iBlock < 4; iBlock++) {
if (blocks[iBlock] && blocks[iBlock]->getBlockType() == BlockType::WeaponBreakable) {
B_WeaponBreakableBlock* weaponbreakableblock = (B_WeaponBreakableBlock*)blocks[iBlock];
if (weaponbreakableblock->iType == 5) {
if (weaponbreakableblock->type() == WeaponDamageType::Hammer) {
weaponbreakableblock->triggerBehavior(iPlayerID, iTeamID);
removeifprojectile(this, false, false);
return;
Expand Down

0 comments on commit 83dfe13

Please sign in to comment.