From e81dba2ea99aea281eb81bc35e0b4160dafd0220 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 5 Sep 2022 00:04:29 +0200 Subject: [PATCH] - random angle cleanup --- source/games/sw/src/actor.cpp | 6 ++--- source/games/sw/src/ai.h | 47 --------------------------------- source/games/sw/src/bunny.cpp | 12 ++++----- source/games/sw/src/game.h | 11 ++++++-- source/games/sw/src/jweapon.cpp | 20 +++++++------- source/games/sw/src/morph.cpp | 4 +-- source/games/sw/src/player.cpp | 6 ++--- source/games/sw/src/ripper.cpp | 4 +-- source/games/sw/src/ripper2.cpp | 2 +- source/games/sw/src/sector.cpp | 2 +- source/games/sw/src/track.cpp | 4 +-- source/games/sw/src/weapon.cpp | 14 +++++----- source/games/sw/src/zombie.cpp | 4 +-- 13 files changed, 48 insertions(+), 88 deletions(-) diff --git a/source/games/sw/src/actor.cpp b/source/games/sw/src/actor.cpp index b3e2928f5..0cd17b448 100644 --- a/source/games/sw/src/actor.cpp +++ b/source/games/sw/src/actor.cpp @@ -314,7 +314,7 @@ void DoDebrisCurrent(DSWActor* actor) // attempt to move away from wall if (ret.type != kHitNone) { - DAngle rang = RANDOM_ANGLE(); + DAngle rang = RandomAngle(); vect = (sectp->angle + rang).ToVector() * spd; @@ -447,7 +447,7 @@ int DoActorDebris(DSWActor* actor) if (!move_debris(actor, nvec)) { - actor->spr.angle = RANDOM_ANGLE(); + actor->spr.angle = RandomAngle(); } } @@ -802,7 +802,7 @@ int DoActorStopFall(DSWActor* actor) // don't stand on face or wall sprites - jump again if (actor->user.lowActor && !(actor->user.lowActor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_FLOOR)) { - actor->spr.angle += DAngle180 + DAngle::fromBuild(RANDOM_P2(512<<8)>>8); + actor->spr.angle += DAngle180 + RandomAngle(DAngle90); actor->user.jump_speed = -350; DoActorBeginJump(actor); diff --git a/source/games/sw/src/ai.h b/source/games/sw/src/ai.h index 8a6ba8fed..0534a3262 100644 --- a/source/games/sw/src/ai.h +++ b/source/games/sw/src/ai.h @@ -105,53 +105,6 @@ int InitActorReposition(DSWActor* actor); int DoActorReposition(DSWActor* actor); int InitActorPause(DSWActor* actor); int DoActorPause(DSWActor* actor); - -/* -ANIMATOR -InitActorDecide, -InitActorMoveCloser, -InitActorAttack, -InitActorRunAway, -InitActorEvade, -InitActorWanderAround, -InitActorFindPlayer, -InitActorReposition, -InitActorPause, -InitActorDuck, -InitActorAmbientNoise, -InitActorAlertNoise, -InitActorAttackNoise, -InitActorPainNoise, -InitActorDieNoise, -InitActorExtra1Noise, -InitActorExtra2Noise, -InitActorExtra3Noise, -InitActorExtra4Noise, -InitActorExtra5Noise, -InitActorExtra6Noise; - -ANIMATOR -DoActorDecide, -DoActorMoveCloser, -DoActorAttack, -DoActorRunAway, -DoActorWanderAround, -DoActorReposition, -DoActorPause, -DoActorDuck, -DoActorAmbientNoise, -DoActorAlertNoise, -DoActorAttackNoise, -DoActorPainNoise, -DoActorDieNoise, -DoActorExtra1Noise, -DoActorExtra2Noise, -DoActorExtra3Noise, -DoActorExtra4Noise, -DoActorExtra5Noise, -DoActorExtra6Noise; -*/ - void DoActorSetSpeed(DSWActor* actor, uint8_t speed); END_SW_NS diff --git a/source/games/sw/src/bunny.cpp b/source/games/sw/src/bunny.cpp index 7d97cf7b2..e1e90e777 100644 --- a/source/games/sw/src/bunny.cpp +++ b/source/games/sw/src/bunny.cpp @@ -855,7 +855,7 @@ int DoBunnyBeginJumpAttack(DSWActor* actor) Collision coll = move_sprite(actor, DVector3(tang.ToVector() * 8, 0), actor->user.ceiling_dist, actor->user.floor_dist, CLIPMASK_ACTOR, ACTORMOVETICS); - auto rndang = DAngle::fromBuild(RANDOM_NEG(256, 6) >> 6); + auto rndang = RandomAngle(DAngle45) - DAngle22_5; if (coll.type != kHitNone) actor->spr.angle += DAngle180 + rndang; else @@ -1152,7 +1152,7 @@ void BunnyHatch(DSWActor* actor) actorNew->spr.pos = actor->spr.pos; actorNew->spr.xrepeat = 30; // Baby size actorNew->spr.yrepeat = 24; - actorNew->spr.angle = RANDOM_ANGLE(); + actorNew->spr.angle = RandomAngle(); actorNew->spr.pal = 0; SetupBunny(actorNew); actorNew->spr.shade = actor->spr.shade; @@ -1213,7 +1213,7 @@ DSWActor* BunnyHatch2(DSWActor* actor) actorNew->spr.pos = actor->spr.pos; actorNew->spr.xrepeat = 30; // Baby size actorNew->spr.yrepeat = 24; - actorNew->spr.angle = RANDOM_ANGLE(); + actorNew->spr.angle = RandomAngle(); actorNew->spr.pal = 0; SetupBunny(actorNew); actorNew->spr.shade = actor->spr.shade; @@ -1240,9 +1240,9 @@ DSWActor* BunnyHatch2(DSWActor* actor) { PickJumpMaxSpeed(actorNew, -600-RandomRange(600)); actorNew->spr.xrepeat = actorNew->spr.yrepeat = 64; - actorNew->vel.X = (150 + RandomRange(1000)) * maptoworld; + actorNew->vel.X = 9.375 + RandomRangeF(62.5); actorNew->user.Health = 1; // Easy to pop. Like shootn' skeet. - actorNew->spr.angle += DAngle::fromBuild(RandomRange(128) - RandomRange(128)); + actorNew->spr.angle += RandomAngle(22.5) - RandomAngle(22.5); } else PickJumpMaxSpeed(actorNew, -600); @@ -1329,7 +1329,7 @@ int DoBunnyMove(DSWActor* actor) NewStateGroup(actor,sg_BunnyStand); break; default: - actor->spr.angle = DAngle::fromBuild(RandomRange(2048 << 6) >> 6); + actor->spr.angle = RandomAngle(); actor->user.jump_speed = -350; DoActorBeginJump(actor); actor->user.ActorActionFunc = DoActorMoveJump; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index b9900b6ff..afeb6323d 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -118,9 +118,17 @@ inline double RandomRangeF(double range) { return RANDOM() * range / 65536; } +inline DAngle RandomAngle(double range = 360.) +{ + return DAngle::fromDeg(RandomRangeF(range)); +} +inline DAngle RandomAngle(DAngle range) +{ + return DAngle::fromDeg(RandomRangeF(range.Degrees())); +} + int RANDOM_P2(int pwr_of_2) { return (RANDOM() & (pwr_of_2 - 1)); } double RANDOM_P2F(int pwr_of_2, int shift) { return (RANDOM() & ((pwr_of_2 << shift) - 1)) * (1./(1 << shift)); } -DAngle RANDOM_ANGLE(int range = 2048) { return DAngle::fromBuild(RANDOM_P2(range)); } // // Map directions/degrees @@ -190,7 +198,6 @@ inline int32_t FIXED(int32_t msw, int32_t lsw) constexpr int NORM_ANGLE(int ang) { return ((ang) & 2047); } -inline int RANDOM_NEG(int x, int y) { return ((RANDOM_P2(((x) << (y)) << 1) - (x)) << (y)); } int StdRandomRange(int range); diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index ec3427ef4..87b38b7ab 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -273,13 +273,13 @@ int DoWallBloodDrip(DSWActor* actor) } else { - actor->vel.Z = (((300+RandomRange(2300)) >> 1)) * maptoworld; + actor->vel.Z = 9.375 + RandomRangeF(71.875); actor->spr.pos.Z += actor->vel.Z; } } else { - actor->vel.Z = (((300+RandomRange(2300)) >> 1)) * maptoworld; + actor->vel.Z = 9.375 + RandomRangeF(71.875); actor->spr.pos.Z += actor->vel.Z; } @@ -1202,8 +1202,8 @@ int SpawnRadiationCloud(DSWActor* actor) //if (RANDOM_P2(1024) < 512) //actorNew->spr.cstat |= (CSTAT_SPRITE_YFLIP); - actorNew->spr.angle = RANDOM_ANGLE(); - actorNew->vel.X = (RANDOM_P2(32)) * maptoworld; + actorNew->spr.angle = RandomAngle(); + actorNew->vel.X = RandomRangeF(2); actorNew->user.Counter = 0; actorNew->user.Counter2 = 0; @@ -1212,12 +1212,12 @@ int SpawnRadiationCloud(DSWActor* actor) { actorNew->user.Radius = 2000; actorNew->user.change.XY() = actorNew->spr.angle.ToVector() * actorNew->vel.X * 0.25; - actorNew->vel.Z = 1 + (RANDOM_P2(Z(2))) * zmaptoworld; + actorNew->vel.Z = 1 + RandomRangeF(2); } else { UpdateChangeXY(actorNew); - actorNew->vel.Z = 4 + (RANDOM_P2(Z(4))) * zmaptoworld; + actorNew->vel.Z = 4 + RandomRangeF(4); actorNew->user.Radius = 4000; } @@ -1341,7 +1341,7 @@ int InitSpriteChemBomb(DSWActor* actor) actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER); actorNew->spr.cstat |= (CSTAT_SPRITE_BLOCK); - actorNew->vel.Z = (-RandomRange(100) * HORIZ_MULT) * zmaptoworld; + actorNew->vel.Z = -RandomRangeF(6.25 * HORIZ_MULT); actorNew->spr.clipdist = 80L >> 2; @@ -1382,7 +1382,7 @@ int InitChemBomb(DSWActor* actor) if (SpriteInUnderwaterArea(actorNew)) actorNew->user.Flags |= (SPR_UNDERWATER); - actorNew->vel.Z = (-RandomRange(100) * HORIZ_MULT) * zmaptoworld; + actorNew->vel.Z = -RandomRangeF(6.25 * HORIZ_MULT); actorNew->spr.clipdist = 0; if (actor->user.ID == MUSHROOM_CLOUD || actor->user.ID == 3121 || actor->user.ID == SUMO_RUN_R0) // 3121 == GRENADE_EXP @@ -1709,7 +1709,7 @@ int InitPhosphorus(DSWActor* actor) // Spawn a shot // Inserting and setting up variables auto actorNew = SpawnActor(STAT_SKIP4, FIREBALL1, s_Phosphorus, actor->sector(), - actor->spr.pos, RANDOM_ANGLE(), CHEMBOMB_VELOCITY/3); + actor->spr.pos, RandomAngle(), CHEMBOMB_VELOCITY/3); actorNew->spr.hitag = LUMINOUS; // Always full brightness actorNew->user.Flags |= (SPR_XFLIP_TOGGLE); @@ -1773,7 +1773,7 @@ int InitBloodSpray(DSWActor* actor, bool dogib, short velocity) if (dogib) ang = ang + DAngle90 + DAngle::fromBuild(RandomRange(200)); else - ang = ang + DAngle180 + DAngle45 - DAngle::fromBuild(RandomRange(256)); + ang = ang + DAngle180 + DAngle45 - RandomAngle(45); // Spawn a shot auto actorNew = SpawnActor(STAT_MISSILE, GOREDrip, s_BloodSprayChunk, actor->sector(), diff --git a/source/games/sw/src/morph.cpp b/source/games/sw/src/morph.cpp index 859246361..38d777218 100644 --- a/source/games/sw/src/morph.cpp +++ b/source/games/sw/src/morph.cpp @@ -326,7 +326,7 @@ void MorphTornado(SECTOR_OBJECT* sop) sop->morph_off = sop->pmid - mpos; if ((RANDOM_P2(1024<<4)>>4) < sop->morph_rand_freq) - sop->morph_ang = RANDOM_ANGLE(); + sop->morph_ang = RandomAngle(); // move it x,y dragpoint(sop->morph_wall_point, mpos); @@ -394,7 +394,7 @@ void MorphFloor(SECTOR_OBJECT* sop) } if ((RANDOM_P2(1024<<4)>>4) < sop->morph_rand_freq) - sop->morph_ang = RANDOM_ANGLE(); + sop->morph_ang = RandomAngle(); // move x,y point "just like in build" dragpoint(sop->morph_wall_point, mpos); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 95eeafff4..f8fc525d4 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -5704,7 +5704,7 @@ void DoPlayerDeathCheckKick(PLAYER* pp) pp->KillerActor = itActor; plActor->user.slide_ang = VecToAngle(plActor->spr.pos - itActor->spr.pos); - plActor->user.slide_ang += DAngle::fromBuild((RANDOM_P2(128<<5)>>5) - 64); + plActor->user.slide_ang += RandomAngle(22.5) - DAngle22_5 / 2; plActor->user.slide_vel = itActor->vel.X * 2; plActor->user.Flags &= ~(SPR_BOUNCE); @@ -5721,7 +5721,7 @@ void DoPlayerDeathCheckKick(PLAYER* pp) // sector stomper kick if (abs(pp->loz - pp->hiz) < ActorSizeZ(plActor) - 8) { - plActor->user.slide_ang = RANDOM_ANGLE(); + plActor->user.slide_ang = RandomAngle(); plActor->user.slide_vel = 62.5; plActor->user.Flags &= ~(SPR_BOUNCE); pp->jump_speed = -100; @@ -5884,7 +5884,7 @@ void DoPlayerDeathBounce(PLAYER* pp) plActor->user.Flags |= (SPR_BOUNCE); pp->jump_speed = -300; plActor->user.slide_vel *= 0.25; - plActor->user.slide_ang = DAngle::fromBuild((RANDOM_P2(64<<8)>>8) - 32); + plActor->user.slide_ang = RandomAngle(11.25) - DAngle22_5 / 4; pp->Flags |= (PF_JUMPING); SpawnShrap(pp->actor, nullptr); } diff --git a/source/games/sw/src/ripper.cpp b/source/games/sw/src/ripper.cpp index 4c952fe23..b0cdebec0 100644 --- a/source/games/sw/src/ripper.cpp +++ b/source/games/sw/src/ripper.cpp @@ -1031,9 +1031,9 @@ int DoRipperBeginJumpAttack(DSWActor* actor) Collision coll = move_sprite(actor, DVector3(vec, 0), actor->user.ceiling_dist, actor->user.floor_dist, CLIPMASK_ACTOR, ACTORMOVETICS); if (coll.type != kHitNone) - actor->spr.angle += DAngle180 + DAngle::fromBuild(RANDOM_NEG(256, 6) >> 6); + actor->spr.angle += RandomAngle(DAngle45) + DAngle180 - DAngle22_5; else - actor->spr.angle = VecToAngle(vec) + DAngle::fromBuild(RANDOM_NEG(256, 6) >> 6); + actor->spr.angle = VecToAngle(vec) + RandomAngle(DAngle45) - DAngle22_5; DoActorSetSpeed(actor, FAST_SPEED); diff --git a/source/games/sw/src/ripper2.cpp b/source/games/sw/src/ripper2.cpp index 0cf1f694a..2fef9a4b2 100644 --- a/source/games/sw/src/ripper2.cpp +++ b/source/games/sw/src/ripper2.cpp @@ -1057,7 +1057,7 @@ int DoRipper2BeginJumpAttack(DSWActor* actor) Collision coll = move_sprite(actor, DVector3(vec, 0), actor->user.ceiling_dist, actor->user.floor_dist, CLIPMASK_ACTOR, ACTORMOVETICS); if (coll.type != kHitNone) - actor->spr.angle += DAngle180 + DAngle::fromBuild(RANDOM_NEG(256, 6) >> 6); + actor->spr.angle += RandomAngle(DAngle45) + DAngle180 - DAngle22_5; else actor->spr.angle = VecToAngle(vec); diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 2c403e067..6da029038 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -847,7 +847,7 @@ void SectorExp(DSWActor* actor, sectortype* sectp, double zh) actor->spr.cstat &= ~(CSTAT_SPRITE_ALIGNMENT_WALL|CSTAT_SPRITE_ALIGNMENT_FLOOR); auto mid = SectorMidPoint(sectp); // randomize the explosions - actor->spr.angle = DAngle::fromBuild(RANDOM_P2(256) - 128); + actor->spr.angle = RandomAngle(45) + DAngle22_5; actor->spr.pos = { mid.X + RANDOM_P2F(16, 4) - 16, mid.Y + RANDOM_P2F(64, 4) - 64, zh }; // setup vars needed by SectorExp diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index 1c2c59284..4b39ed6bc 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -961,7 +961,7 @@ void SetupSectorObject(sectortype* sectp, short tag) sop->scale_x_mult = 256; sop->scale_y_mult = 256; - sop->morph_ang = RANDOM_ANGLE(); + sop->morph_ang = RandomAngle(); sop->morph_z_speed = 20; sop->morph_speed = 2; sop->morph_dist_max = 64; @@ -2638,7 +2638,7 @@ void DoTornadoObject(SECTOR_OBJECT* sop) if (coll.type != kHitNone) { - ang = ang + DAngle180 - DAngle45 + DAngle::fromBuild(RANDOM_P2(512)); + ang = ang + DAngle180 - DAngle45 + RandomAngle(90); } TornadoSpin(sop); diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 96fc56353..df0a43442 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -11252,7 +11252,7 @@ void InitVulcanBoulder(DSWActor* actor) } else { - nang = RANDOM_ANGLE(); + nang = RandomAngle(); } if (SP_TAG6(actor)) @@ -11604,7 +11604,7 @@ int InitSwordAttack(PLAYER* pp) { bubble->set_int_ang(pp->angle.ang.Buildang()); - auto random_amt = DAngle::fromBuild((RANDOM_P2(32<<8)>>8) - 16); + auto random_amt = RandomAngle(DAngle22_5 / 4) - DAngle22_5 / 8; // back it up a bit to get it out of your face auto vec = MOVExy((1024 + 256) * 3, bubble->spr.angle + dangs[i] + random_amt); @@ -11772,7 +11772,7 @@ int InitFistAttack(PLAYER* pp) { bubble->set_int_ang(pp->angle.ang.Buildang()); - auto random_amt = DAngle::fromBuild((RANDOM_P2(32<<8)>>8) - 16); + auto random_amt = RandomAngle(DAngle22_5 / 4) - DAngle22_5 / 8; // back it up a bit to get it out of your face auto vec = MOVExy((1024+256)*3, bubble->spr.angle + dangs[i] + random_amt); @@ -15692,7 +15692,7 @@ int InitEnemyUzi(DSWActor* actor) return 0; daz = 0; - daang = actor->spr.angle + DAngle::fromBuild((RANDOM_P2(128)) - 64); + daang = actor->spr.angle + RandomAngle(DAngle22_5) - DAngle22_5/2; } // todo: confirm the ToVector factor. @@ -16634,7 +16634,7 @@ int SpawnVehicleSmoke(DSWActor* actor) if (RANDOM_P2(1024) < 512) actorNew->spr.cstat |= (CSTAT_SPRITE_YFLIP); - actorNew->spr.angle = RANDOM_ANGLE(); + actorNew->spr.angle = RandomAngle(); actorNew->set_int_xvel(RANDOM_P2(32)); UpdateChangeXY(actorNew); actorNew->set_int_zvel(Z(4) + RANDOM_P2(Z(4))); @@ -16658,7 +16658,7 @@ int SpawnSmokePuff(DSWActor* actor) if (RANDOM_P2(1024) < 512) actorNew->spr.cstat |= (CSTAT_SPRITE_YFLIP); - actorNew->spr.angle = RANDOM_ANGLE(); + actorNew->spr.angle = RandomAngle(); actorNew->set_int_xvel(RANDOM_P2(32)); UpdateChangeXY(actorNew); actorNew->set_int_zvel(Z(1) + RANDOM_P2(Z(2))); @@ -16953,7 +16953,7 @@ int QueueFloorBlood(DSWActor* actor) spawnedActor->spr.clipdist = 0; spawnedActor->spr.xoffset = spawnedActor->spr.yoffset = 0; spawnedActor->spr.pos = actor->spr.pos.plusZ(1); - spawnedActor->spr.angle = RANDOM_ANGLE(); // Just make it any old angle + spawnedActor->spr.angle = RandomAngle(); // Just make it any old angle spawnedActor->spr.shade -= 5; // Brighten it up just a bit spawnedActor->spr.cstat |= (CSTAT_SPRITE_ALIGNMENT_FLOOR); diff --git a/source/games/sw/src/zombie.cpp b/source/games/sw/src/zombie.cpp index 6930250a3..9d88c2ce0 100644 --- a/source/games/sw/src/zombie.cpp +++ b/source/games/sw/src/zombie.cpp @@ -779,7 +779,7 @@ void SpawnZombie(PLAYER* pp, DSWActor* weaponActor) auto actorNew = SpawnActor(STAT_ENEMY, ZOMBIE_RUN_R0, s_ZombieRun[0], pp->cursector, pp->pos, pp->angle.ang, 0); SetOwner(actorNew, ownerActor); actorNew->spr.pal = actorNew->user.spal = ownerActor->user.spal; - actorNew->spr.angle = RANDOM_ANGLE(); + actorNew->spr.angle = RandomAngle(); SetupZombie(actorNew); actorNew->spr.shade = -10; actorNew->user.Flags2 |= (SPR2_DONT_TARGET_OWNER); @@ -826,7 +826,7 @@ void SpawnZombie2(DSWActor* actor) actorNew->user.Counter3 = 0; SetOwner(ownerActor, actorNew); actorNew->spr.pal = actorNew->user.spal = ownerActor->user.spal; - actorNew->spr.angle = RANDOM_ANGLE(); + actorNew->spr.angle = RandomAngle(); SetupZombie(actorNew); actorNew->spr.shade = -10; actorNew->user.Flags2 |= (SPR2_DONT_TARGET_OWNER);