From 29dd25a23a96744090caa309df76b2fae770e031 Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Mon, 22 Aug 2022 22:11:45 +0100 Subject: [PATCH] Cleaned up the effects reduction code and moved it to a separate method --- data/widgets/options.json | 2 +- src/battle/effects.c | 169 +++++++++----------------------------- 2 files changed, 40 insertions(+), 131 deletions(-) diff --git a/data/widgets/options.json b/data/widgets/options.json index ebca147..a62ef3d 100644 --- a/data/widgets/options.json +++ b/data/widgets/options.json @@ -15,7 +15,7 @@ "group" : "options", "type" : "WT_SELECT", "text" : "Effects Reduction", - "options" : "0;1;2", + "options" : "0;1;2;3", "x" : -1, "y" : 225, "w" : 400, diff --git a/src/battle/effects.c b/src/battle/effects.c index 7d2c38f..053210a 100644 --- a/src/battle/effects.c +++ b/src/battle/effects.c @@ -24,6 +24,7 @@ static void setRandomFlameHue(Effect *e); static void setRandomShieldHue(Effect *e); static void resizeDrawList(void); static int pointOnScreen(float x, float y); +static float calculateEffectsValue(unsigned int); static AtlasImage *explosionTexture; static AtlasImage *shieldHitTexture; @@ -202,11 +203,7 @@ void addBulletHitEffect(int x, int y, int r, int g, int b) e->type = EFFECT_TEXTURE; e->texture = explosionTexture; - e->size = 16; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(16); e->x = x; e->y = y; @@ -219,11 +216,7 @@ void addBulletHitEffect(int x, int y, int r, int g, int b) e->g = g; e->b = b; e->a = 64; - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); } } @@ -241,20 +234,12 @@ void addSmallFighterExplosion(void) e->x = self->x + (rand() % 16 - rand() % 16); e->y = self->y + (rand() % 16 - rand() % 16); e->texture = explosionTexture; - e->size = 32; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(32); setRandomFlameHue(e); e->a = 128 + (rand() % 128); - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -274,20 +259,12 @@ void addDebrisFire(int x, int y) e->x = x + (rand() % 8 - rand() % 8); e->y = y + (rand() % 8 - rand() % 8); e->texture = explosionTexture; - e->size = 4 + rand() % 12; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(4 + rand() % 12); setRandomFlameHue(e); e->a = rand() % 256; - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -314,21 +291,13 @@ void addSmallExplosion(void) e->dy = (rand() % 25) - (rand() % 25); e->dy *= 0.025; e->texture = explosionTexture; - e->size = 32 + (rand() % 64); - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(32 + (rand() % 64)); e->r = 255; setRandomFlameHue(e); e->a = 128 + (rand() % 128); - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -350,11 +319,7 @@ void addSmallExplosion(void) e->dy *= 0.1; e->a = 128; - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); setRandomFlameHue(e); } @@ -377,21 +342,13 @@ void addMineExplosion(void) e->x = self->x + rand() % 64 - rand() % 64; e->y = self->y + rand() % 64 - rand() % 64; e->texture = explosionTexture; - e->size = 64 + (rand() % 64); - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(64 + (rand() % 64)); e->r = 255; setRandomFlameHue(e); e->a = 32 + (rand() % 192); - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -406,11 +363,7 @@ void addMineExplosion(void) e->type = EFFECT_HALO; e->x = self->x; e->y = self->y; - e->size = 64; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(64); e->scaleAmount = 6; e->texture = haloTexture; @@ -419,11 +372,7 @@ void addMineExplosion(void) e->b = 255; e->a = 128; - e->health = 128; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(128); } void addLargeExplosion(void) @@ -447,21 +396,13 @@ void addLargeExplosion(void) e->dy = (rand() % 25) - (rand() % 25); e->dy *= 0.01; e->texture = explosionTexture; - e->size = 128 + (rand() % 512); - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(128 + (rand() % 512)); e->r = 255; setRandomFlameHue(e); e->a = 128 + (rand() % 128); - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -476,11 +417,7 @@ void addLargeExplosion(void) e->type = EFFECT_HALO; e->x = self->x; e->y = self->y; - e->size = 256; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(256); e->scaleAmount = 4; e->texture = haloTexture; @@ -489,11 +426,7 @@ void addLargeExplosion(void) e->b = 255; e->a = 255; - e->health = 255; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(255); } void addMissileExplosion(Bullet *b) @@ -517,21 +450,13 @@ void addMissileExplosion(Bullet *b) e->dy = (rand() % 25) - (rand() % 25); e->dy *= 0.025; e->texture = explosionTexture; - e->size = 32 + (rand() % 64); - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(32 + (rand() % 64)); e->r = 255; setRandomFlameHue(e); e->a = 128 + (rand() % 128); - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -553,11 +478,7 @@ void addMissileExplosion(Bullet *b) e->dy *= 0.1; e->a = 128; - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); setRandomFlameHue(e); } @@ -587,21 +508,13 @@ void addEngineEffect(void) e->x += rand() % 4 - rand() % 4; e->texture = explosionTexture; - e->size = 16; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(16); e->r = 128; e->g = 128; e->b = 255; e->a = 64; - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -628,21 +541,13 @@ void addLargeEngineEffect(void) e->x -= rand() % 4; e->texture = explosionTexture; - e->size = 64; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(64); e->r = 128; e->g = 128; e->b = 255; e->a = 64; - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -669,19 +574,11 @@ void addMissileEngineEffect(Bullet *b) e->x -= rand() % 4; e->texture = explosionTexture; - e->size = 12; - if (app.effects > 0) - { - e->size = e->size / (app.effects * 2); - } + e->size = calculateEffectsValue(12); setRandomFlameHue(e); e->a = 128; - e->health = e->a; - if (app.effects > 0) - { - e->health = e->health / (app.effects * 2); - } + e->health = calculateEffectsValue(e->a); e->x -= e->size / 2; e->y -= e->size / 2; @@ -800,3 +697,15 @@ void destroyEffects(void) effectsToDraw = NULL; } +static float calculateEffectsValue(unsigned int val) +{ + #if defined(__amigaos4__) + if (app.effects) + { + return val>>(app.effects<<1); + } + #endif + + return (float)val; +} +