From d10356c42cfd2b10f17d5eff9075b51d1a8177d8 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 5 Feb 2018 08:37:07 +0000 Subject: [PATCH] Added swapSelf() to handle current entity handling. --- src/combat/explosions.c | 4 ++++ src/combat/explosions.h | 3 +++ src/entities/bullets/bullet.c | 2 ++ src/entities/bullets/bullet.h | 1 + src/entities/bullets/grenade.c | 2 ++ src/entities/bullets/grenade.h | 1 + src/entities/bullets/laser.c | 2 ++ src/entities/bullets/laser.h | 1 + src/entities/traps/laserTrap.c | 4 ++++ src/entities/traps/laserTrap.h | 1 + src/world/entities.c | 16 ++++++++++++++++ 11 files changed, 37 insertions(+) diff --git a/src/combat/explosions.c b/src/combat/explosions.c index c3ea130..b4f5c95 100644 --- a/src/combat/explosions.c +++ b/src/combat/explosions.c @@ -55,11 +55,15 @@ void addExplosion(float x, float y, int radius, Entity *owner) { if (e->flags & EF_BOMB_SHIELD) { + swapSelf(e); e->applyDamage(2); + swapSelf(e); } else { + swapSelf(e); e->applyDamage((int) power); + swapSelf(e); } if (e->type == ET_BOB) diff --git a/src/combat/explosions.h b/src/combat/explosions.h index b0344f4..78dc3f1 100644 --- a/src/combat/explosions.h +++ b/src/combat/explosions.h @@ -26,3 +26,6 @@ extern void addExplosionEffect(int x, int y, int dx, int dy); extern void playSound(int snd, int ch); extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern int getDistance(int x1, int y1, int x2, int y2); +extern void swapSelf(Entity *e); + +extern Entity *self; diff --git a/src/entities/bullets/bullet.c b/src/entities/bullets/bullet.c index 56bc1b7..1adf93b 100644 --- a/src/entities/bullets/bullet.c +++ b/src/entities/bullets/bullet.c @@ -97,7 +97,9 @@ static void touch(Entity *other) } else if (other != b->owner && (!(other->flags & EF_IGNORE_BULLETS)) && b->owner->type != other->type) { + swapSelf(other); other->applyDamage(b->damage); + swapSelf(other); if (other->flags & EF_EXPLODES) { diff --git a/src/entities/bullets/bullet.h b/src/entities/bullets/bullet.h index 9987d0f..ba46c61 100644 --- a/src/entities/bullets/bullet.h +++ b/src/entities/bullets/bullet.h @@ -25,6 +25,7 @@ extern void initEntity(Entity *e); extern void addSmallFleshChunk(float x, float y); extern void addSparkParticles(float x, float y); extern Bullet *createBaseBullet(Unit *owner); +extern void swapSelf(Entity *e); extern Camera camera; extern Entity *self; diff --git a/src/entities/bullets/grenade.c b/src/entities/bullets/grenade.c index 0f07296..8244a7b 100644 --- a/src/entities/bullets/grenade.c +++ b/src/entities/bullets/grenade.c @@ -87,7 +87,9 @@ static void touch(Entity *other) if (!(other->flags & EF_BOMB_SHIELD)) { + swapSelf(other); other->applyDamage(25); + swapSelf(other); } explode(); diff --git a/src/entities/bullets/grenade.h b/src/entities/bullets/grenade.h index aa210b9..9ea87fa 100644 --- a/src/entities/bullets/grenade.h +++ b/src/entities/bullets/grenade.h @@ -26,6 +26,7 @@ extern void addSmallFleshChunk(float x, float y); extern void addSparkParticles(float x, float y); extern void addExplosion(float x, float y, int radius, Entity *owner); extern void addScorchDecal(int x, int y); +extern void swapSelf(Entity *e); extern Entity *self; extern Game game; diff --git a/src/entities/bullets/laser.c b/src/entities/bullets/laser.c index 594e51d..25d6846 100644 --- a/src/entities/bullets/laser.c +++ b/src/entities/bullets/laser.c @@ -68,7 +68,9 @@ static void touch(Entity *other) playSound(SND_FLESH_HIT, CH_ANY); } + swapSelf(other); other->applyDamage(2); + swapSelf(other); if (b->owner->type == world.bob->type) { diff --git a/src/entities/bullets/laser.h b/src/entities/bullets/laser.h index ec55d74..469b709 100644 --- a/src/entities/bullets/laser.h +++ b/src/entities/bullets/laser.h @@ -26,6 +26,7 @@ extern void initLaser(Bullet *b); extern void addSmallFleshChunk(float x, float y); extern void addSparkParticles(float x, float y); extern void stunBob(void); +extern void swapSelf(Entity *e); extern Entity *self; extern Game game; diff --git a/src/entities/traps/laserTrap.c b/src/entities/traps/laserTrap.c index 2b82177..8ae55d5 100644 --- a/src/entities/traps/laserTrap.c +++ b/src/entities/traps/laserTrap.c @@ -119,12 +119,16 @@ static void touch(Entity *other) if (t->offTime != 0) { + swapSelf(other); other->applyDamage((int) (other->healthMax / 4)); + swapSelf(other); } else { /* instant kill */ + swapSelf(other); other->applyDamage((int) other->health); + swapSelf(other); } } diff --git a/src/entities/traps/laserTrap.h b/src/entities/traps/laserTrap.h index 660d41b..3e6c2fb 100644 --- a/src/entities/traps/laserTrap.h +++ b/src/entities/traps/laserTrap.h @@ -29,6 +29,7 @@ extern int rrnd(int low, int high); extern void stunBob(void); extern void addSparkParticles(float x, float y); extern void addSmallFleshChunk(float x, float y); +extern void swapSelf(Entity *e); extern Entity *self; extern World world; diff --git a/src/world/entities.c b/src/world/entities.c index 8e6884c..660388b 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -982,3 +982,19 @@ static void addTouched(Entity *e) } } } + +void swapSelf(Entity *e) +{ + static Entity *oldSelf = NULL; + + if (!oldSelf) + { + oldSelf = self; + self = e; + } + else + { + self = oldSelf; + oldSelf = NULL; + } +}