Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "zcommon.acs"
- #library "ropeandrubber"
- #include "ropeConstants.h"
- #include "ropeFunctions.h"
- /* -- script ROPE_OPEN [OPEN script] --
- * Checks if grapple_version is equal to 1, and sets grapple_version to 1,
- * grapple_startwith to 1, and grapple_strength to 2 if it isn't.
- */
- script "rope_open" open
- {
- if (GetCVar("grapple_version") != 1)
- {
- ConsoleCommand("set grapple_version 1");
- ConsoleCommand("set grapple_startwith 1");
- ConsoleCommand("set grapple_strength 2");
- ConsoleCommand("archivecvar grapple_version");
- ConsoleCommand("archivecvar grapple_startwith");
- ConsoleCommand("archivecvar grapple_strength");
- }
- }
- /* -- script ROPE_ENTER [ENTER script] --
- * If grapple_startswith is 1, give you the grappling hook and grapple item.
- */
- script "rope_enter" enter
- {
- if (GetCVar("grapple_startwith") == 1)
- {
- GiveInventory("Grappling Hook", 1);
- }
- }
- /* ** ROPE_HOLD (int ropeTID, int length, float strength)
- *
- * * Assumes that the object being roped is the activator of the script, due to
- * * lack of parameters.
- *
- *
- */
- script "rope_hold" (int ropeTID, int length, int strength)
- {
- int myX; int myY; int myZ;
- int ropeX; int ropeY; int ropeZ;
- int velX; int velY; int velZ;
- int normX; int normY; int normZ;
- int pullX; int pullY; int pullZ;
- int opulX; int opulY; int opulZ;
- int centX; int centY; int centZ;
- int rPullX; int rPullY; int rPullZ;
- int rOpulX; int rOpulY; int rOpulZ;
- int mag; int cMag;
- int mass1 = GetActorProperty(0, APROP_Mass) << 16;
- int mass2 = GetActorProperty(ropeTID, APROP_Mass) << 16;
- int massTotal = mass1 + mass2;
- int massF1; int massF2;
- int pull1; int pull2;
- int strict;
- int cLen = length >> 1;
- int playerTID = ActivatorTID();
- if ((mass1 == 0) || (mass2 == -1.0))
- {
- massF1 = 1.0;
- massF2 = 0.0;
- }
- else if ((mass2 == 0) || (mass1 == -1.0))
- {
- massF1 = 0.0;
- massF2 = 1.0;
- }
- else
- {
- massF1 = FixedDiv(mass2, massTotal);
- massF2 = FixedDiv(mass1, massTotal);
- }
- Log(s:"mass1 is ", f:mass1, s:" ", d:mass1);
- Log(s:"mass2 is ", f:mass2, s:" ", d:mass2);
- Log(s:"massTotal is ", f:massTotal, s:" ", d:massTotal);
- Log(s:"massF1 is ", f:massF1, s:" ", d:massF1);
- Log(s:"massF2 is ", f:massF2, s:" ", d:massF2);
- int mode = (strength - 1) / 100;
- strength %= 100;
- strength <<= 16;
- strength /= 100;
- strength = FixedMul(strength, strength);
- Log(f:strength);
- if (length == -1)
- {
- myX = GetActorX(0); myY = GetActorY(0); myZ = GetActorZ(0);
- ropeX = GetActorX(ropeTID); ropeY = GetActorY(ropeTID); ropeZ = GetActorZ(ropeTID);
- velX = myX - ropeX; velY = myY - ropeY; velZ = myZ - ropeZ;
- length = magnitudeThree(velX >> 16, velY >> 16, velZ >> 16);
- }
- if ((playerTID != 0) || (ThingCount(0, playerTID) != 1))
- {
- playerTID = unusedTID(5000, -1);
- Thing_ChangeTID(0, playerTID);
- }
- while (ThingCount(0, ropeTID) == 1)
- {
- strict = 0;
- myX = GetActorX(0); myY = GetActorY(0); myZ = GetActorZ(0);
- ropeX = GetActorX(ropeTID); ropeY = GetActorY(ropeTID); ropeZ = GetActorZ(ropeTID);
- velX = myX - ropeX; velY = myY - ropeY; velZ = myZ - ropeZ;
- // this is where precision goes down the drain
- mag = magnitudeThree(velX >> 16, velY >> 16, velZ >> 16);
- if (mag != 0)
- {
- normX = velX / mag; normY = velY / mag; normZ = velZ / mag;
- }
- else
- {
- normX = 0; normY = 0; normZ = 0;
- }
- switch (mode)
- {
- case 2:
- strict = (mag != length);
- case 0:
- if ((mag > length) || strict)
- {
- pullX = -(velX - (normX * length));
- pullY = -(velY - (normY * length));
- pullZ = -(velZ - (normZ * length));
- pullX = FixedMul(pullX, strength);
- pullY = FixedMul(pullY, strength);
- pullZ = FixedMul(pullZ, strength);
- opulX = -FixedMul(pullX, massF2);
- opulY = -FixedMul(pullY, massF2);
- opulZ = -FixedMul(pullZ, massF2);
- pullX = FixedMul(pullX, massF1);
- pullY = FixedMul(pullY, massF1);
- pullZ = FixedMul(pullZ, massF1);
- SetActorVelocity(0, pullX, pullY, pullZ, 1, 0);
- SetActorVelocity(ropeTID, opulX, opulY, opulZ, 1, 0);
- }
- break;
- case 3:
- strict = (mag != length);
- case 1:
- if ((mag > length) || strict)
- {
- centX = ropeX + (velX >> 1);
- centY = ropeY + (velY >> 1);
- centZ = ropeZ + (velZ >> 1);
- cMag = mag >> 1;
- pull1 = cMag - cLen;
- pull2 = pull1 * massF2;
- pull1 = pull1 * massF1;
- pullX = -(velX - (centX * cLen));
- pullY = -(velY - (centY * cLen));
- pullZ = -(velZ - (centZ * cLen));
- }
- break;
- }
- ACS_ExecuteAlways(ROPE_DRAWLINE, 0, ropeTID, playerTID, 24);
- Delay(1);
- }
- if (ThingCount(0, ropeTID) > 1)
- {
- Log(s:"Error: more than one object with tid ", d:ropeTID, s:" (is used for rope)");
- }
- }
- script ROPE_REEL (int grappleTid, int strength, int firetype)
- {
- int nX; int nY; int nZ;
- int plX; int plY; int plZ;
- int vX; int vY; int vZ;
- int velX; int velY; int velZ;
- int breakLoop = false;
- int magnitude;
- int pln = PlayerNumber();
- int playerTid = ActivatorTID();
- if (playerTid == 0) // can we give him a TID without breaking anything?
- {
- playerTid = unusedTID(STARTTID, -1);
- Thing_ChangeTID(0, playerTid);
- }
- // if not, then okay, just use the one he has already
- int grX = GetActorX(grappleTid);
- int grY = GetActorY(grappleTid);
- int grZ = GetActorZ(grappleTid);
- while (!breakLoop)
- {
- if (ThingCount(0, grappleTID) != 1)
- {
- break;
- }
- plX = GetActorX(0); plY = GetActorY(0); plZ = GetActorZ(0);
- vX = grX - plX; vY = grY - plY; vZ = grZ - plZ;
- // NOTE: I had to drop precision here in exchange for not overflowing
- magnitude = magnitudeThree(vX >> 16, vY >> 16, vZ >> 16);
- if (magnitude != 0)
- {
- nX = vX / magnitude; nY = vY / magnitude; nZ = vZ / magnitude;
- ACS_ExecuteAlways(ROPE_DRAWLINE, 0, grappleTid, playerTid, 16);
- }
- else
- {
- nX = 0; nY = 0; nZ = 0;
- }
- SetActorVelocity(0, nX*strength, nY*strength, nZ*strength, true, true);
- switch (firetype)
- {
- case 0:
- if (!(GetPlayerInput(-1, MODINPUT_BUTTONS) & BT_ATTACK))
- {
- breakLoop = true;
- }
- break;
- case 1:
- if (!(GetPlayerInput(-1, MODINPUT_BUTTONS) & BT_ALTATTACK))
- {
- breakLoop = true;
- }
- break;
- case 2:
- if (!CheckInventory("GrappleFromInv"))
- {
- breakLoop = true;
- }
- break;
- }
- Delay(1);
- }
- Thing_Remove(grappleTid);
- }
- script ROPE_PLAYERHOLD (int ropeTID, int length, int strength)
- {
- int playerInput = GetPlayerInput(-1, INPUT_BUTTONS);
- int fireType = 0;
- if (playerInput & BT_ALTATTACK)
- {
- fireType = BT_ALTATTACK;
- }
- else if (playerInput & BT_ATTACK)
- {
- fireType = BT_ATTACK;
- }
- if (ThingCount(0, ropeTID == 1))
- {
- ACS_NamedExecuteAlways("rope_hold", 0, ropeTID, length, strength);
- }
- else
- {
- terminate;
- }
- while (GetPlayerInput(-1, INPUT_BUTTONS) & fireType)
- {
- Delay(1);
- }
- Thing_Remove(ropeTID);
- }
- script ROPE_SPAWNBARREL (int barTID)
- {
- int spawnAngle = GetActorAngle(0);
- int spawnPitch = GetActorPitch(0);
- int spawnX = GetActorX(0);
- int spawnY = GetActorY(0);
- int spawnZ = GetActorZ(0);
- int newSpawnX = FixedMul(64 * cos(spawnAngle), cos(spawnPitch));
- int newSpawnY = FixedMul(64 * sin(spawnAngle), cos(spawnPitch));
- int newSpawnZ = -sin(spawnPitch);
- newSpawnX = spawnX + newSpawnX;
- newSpawnY = spawnY + newSpawnY;
- newSpawnZ = spawnZ + newSpawnZ;
- Spawn("PushableBarrel", newSpawnX, newSpawnY, newSpawnZ, barTID, 0);
- }
- script ROPE_DRAWLINE (int grappleTid, int playerTid, int density)
- {
- int plX; int plY; int plZ;
- int grX; int grY; int grZ;
- int vX; int vY; int vZ;
- int nX; int nY; int nZ;
- int bX; int bY; int bZ;
- int magnitude;
- int pointCount;
- int pointOffset;
- if (ThingCount(0, grappleTid) != 1)
- {
- terminate;
- }
- if (ThingCount(0, playerTid) != 1)
- {
- terminate;
- }
- plX = GetActorX(playerTid); grX = GetActorX(grappleTid);
- plY = GetActorY(playerTid); grY = GetActorY(grappleTid);
- plZ = GetActorZ(playerTid); grZ = GetActorZ(grappleTid);
- vX = grX - plX; vY = grY - plY; vZ = grZ - plZ;
- // NOTE: More precision bullshit
- magnitude = magnitudeThree(vX >> 16, vY >> 16, vZ >> 16);
- pointCount = magnitude / density;
- pointOffset = magnitude - (pointCount * density);
- if (magnitude != 0)
- {
- nX = vX / magnitude; nY = vY / magnitude; nZ = vZ / magnitude;
- int i; int j;
- for (i = 0; i < pointCount; i++)
- {
- j = (i * density) + pointOffset;
- bX = (nX * j) + plX;
- bY = (nY * j) + plY;
- bZ = (nZ * j) + plZ;
- Spawn("LinePoint", bX, bY, bZ);
- }
- }
- }
- script ROPE_GETUNUSEDTID (int mode, int fromItem)
- {
- int newTID;
- int itemType = "GrappleTIDIndicator";
- if (fromItem)
- {
- itemType = "ItemGrappleTID";
- }
- switch (mode)
- {
- case 0:
- newTID = unusedTID(STARTTID, -1);
- GiveInventory(itemType, newTID);
- Thing_ChangeTID(0, newTID);
- break;
- case 1:
- SetResultValue(CheckInventory(itemType));
- break;
- case 2:
- newTID = unusedTID(STARTTID, -1);
- GiveInventory(itemType, newTID);
- Thing_ChangeTID(0, newTID);
- SetResultValue(newTID);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement