Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #library "ORBITER"
- #include "zcommon.acs"
- function int sqrtx(int param) {
- int slider = 0.0;
- int range = 128.0;
- while (range > 0.0) {
- slider += range;
- if (FixedMul(slider, slider) > param) {
- slider -= range;
- }
- range >>= 1;
- }
- return slider;
- }
- #define ORBIT_RANDOMSCALE 0
- #define ORBIT_ORBITERCLASS 1
- #define ORBIT_ORBITERDEATHCLASS 2
- #define ORBIT_STOPTRIGGER 3
- #define ORBIT_RADIUSMIN 4
- #define ORBIT_RADIUSMAX 5
- #define ORBIT_ELLIPSISMIN 6
- #define ORBIT_TORQUE 7
- #define ORBIT_DEATHSPEEDMUL 8
- #define ORBIT_DEATHANGLEFIX 9
- #define ORBIT_ALL 10
- //100.0 - Random radius (bigger - better quality, but risk of blowing up)
- //Circler - What orbits around actor
- //Rocket - What object spawns during death, anything beginning with $ will not spawn
- //IAmGonnaDie - Death trigger
- //70.0, 90.0 - Random for radius
- //0.7 - if it's 1.0, then we get circle, otherwise it's ellipsis (random)
- //0.03 - orbiting speed
- //1st 0.25 - Object spawn speed when it stops orbiting
- //2nd 0.25 - Angle control after orbiting ends
- //only active if orbiterdeathclass doesn't start with "$"
- int ScriptConfig[2][ORBIT_ALL] = {
- {160.0, "DreadballOrbiter", "$DreadballOrbiter", "DreadballDetonate",
- 140.0, 120.1, 0.999, 0.03, 0.01, 0.25},
- {160.0, "CoreDreadballOrbiter", "$CoreDreadballOrbiter", "DreadballDetonate",
- 140.0, 120.1, 0.999, 0.03, 0.01, 0.25}
- };
- script "Orbit Dat Shite" (int liczba) {
- int randomium = ScriptConfig[liczba][ORBIT_RANDOMSCALE];
- int orbiterclass = ScriptConfig[liczba][ORBIT_ORBITERCLASS];
- int orbiterdeathclass = ScriptConfig[liczba][ORBIT_ORBITERDEATHCLASS];
- int stoptrigger = ScriptConfig[liczba][ORBIT_STOPTRIGGER];
- int radiusmin = ScriptConfig[liczba][ORBIT_RADIUSMIN];
- int radiusmax = ScriptConfig[liczba][ORBIT_RADIUSMAX];
- int ellipsismin = ScriptConfig[liczba][ORBIT_ELLIPSISMIN];
- int torque = ScriptConfig[liczba][ORBIT_TORQUE];
- int deathspeedmul = ScriptConfig[liczba][ORBIT_DEATHSPEEDMUL];
- int deathanglefix = ScriptConfig[liczba][ORBIT_DEATHANGLEFIX];
- //BEGIN: Generate two random perpendicular vectors
- int vx = Random(-randomium, randomium);
- int vy = Random(-randomium, randomium);
- int vz = Random(-randomium, randomium);
- int wx = Random(-randomium, randomium);
- int wy = Random(-randomium, randomium);
- int wz = Random(-randomium, randomium);
- int dotwv_presquish = FixedMul(wx, vx) + FixedMul(wy, vy) + FixedMul(wz, vz);
- int dotvv = FixedMul(vx, vx) + FixedMul(vy, vy) + FixedMul(vz, vz);
- int ratio = FixedDiv(dotwv_presquish, dotvv);
- wx -= FixedMul(vx, ratio);
- wy -= FixedMul(vy, ratio);
- wz -= FixedMul(vz, ratio);
- int dotww = FixedMul(wx, wx) + FixedMul(wy, wy) + FixedMul(wz, wz);
- //END: v and w are perpendicular vectors, 99,9% of the time, that is unless they were initially parallel
- //BEGIN: resize v and w according to specs
- int radius = random(radiusmin, radiusmax);
- int vratio = FixedDiv(radius, sqrtx(dotvv)); //the latter is vlen
- vx = FixedMul(vx, vratio);
- vy = FixedMul(vy, vratio);
- vz = FixedMul(vz, vratio);
- int ellipsisfactor = random(ellipsismin, 1.0);
- int wratio = FixedDiv(FixedMul(ellipsismin, radius), sqrt(dotww)); //the latter is wlen
- wx = FixedMul(wx, wratio);
- wy = FixedMul(wy, wratio);
- wz = FixedMul(wz, wratio);
- //END: v, w resized
- int i, fx, fy, fz;
- //DEBUG
- for (i = 0; i <= 1.0; i += 0.125) {
- fx = GetActorX(0) + FixedMul(i, vx);
- fy = GetActorY(0) + FixedMul(i, vy);
- fz = GetActorZ(0) + FixedMul(i, vz);
- Spawn("DebugGhost", fx, fy, fz);
- }
- //SPAWN
- int TID = UniqueTID();
- fx = GetActorX(0) + vx;
- fy = GetActorY(0) + vy;
- fz = GetActorZ(0) + vz;
- int angle = 0.0;
- if (!Spawn(orbiterclass, fx, fy, fz, TID)) {
- log(s:"ORBITER COULD NOT SPAWN");
- delay(35); restart;
- }
- SetActorVelocity(TID, 0.0, 0.0, 0.0, 0, 0);
- delay(1);
- while (CheckInventory(stoptrigger) == 0) {
- if (!IsTIDUsed(TID)) {
- Restart;
- }
- angle = (angle + torque) % 1.0;
- fx = GetActorX(0) + FixedMul(cos(angle), vx) + FixedMul(sin(angle), wx);
- fy = GetActorY(0) + FixedMul(cos(angle), vy) + FixedMul(sin(angle), wy);
- fz = GetActorZ(0) + FixedMul(cos(angle), vz) + FixedMul(sin(angle), wz);
- if (!SetActorPosition(TID, fx, fy, fz, 0)) {
- if (SetActorState(TID, "DieDieDie2") == 0
- && SetActorState(TID, "DieDieDie") == 0) {
- SetActorState(TID, "Death");
- }
- for (i = 0; i < 8; i++) {
- delay(1);
- if (CheckInventory(stoptrigger) > 0) {
- Terminate;
- }
- }
- Restart;
- }
- delay(1);
- }
- if (SetActorState(TID, "DieDieDie") == 0
- && SetActorState(TID, "DieDieDie2") == 0) {
- SetActorState(TID, "Death");
- }
- //optional post-death spawn-something option
- if (GetChar(orbiterdeathclass, 0) == '$') terminate;
- while (!IsTIDUsed(TID)) {
- delay(1);
- }
- angle = (angle + deathanglefix) % 1.0;
- Spawn(orbiterdeathclass, fx, fy, fz, TID);
- fx = FixedMul(deathspeedmul, FixedMul(cos(angle), vx) + FixedMul(sin(angle), wx));
- fy = FixedMul(deathspeedmul, FixedMul(cos(angle), vy) + FixedMul(sin(angle), wy));
- fz = FixedMul(deathspeedmul, FixedMul(cos(angle), vz) + FixedMul(sin(angle), wz));
- SetActorVelocity(TID, fx, fy, fz, 0, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement