Skip to content

Instantly share code, notes, and snippets.

@MrStonedOne
Forked from C-F-K/TRIGGER.NTSL
Created April 16, 2016 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrStonedOne/fa759b3ff7804ee4595d4f494358f9e2 to your computer and use it in GitHub Desktop.
Save MrStonedOne/fa759b3ff7804ee4595d4f494358f9e2 to your computer and use it in GitHub Desktop.
trigonometry automator for telescience on /tg/station13
// TRIGGER.NTSL - trigonometry automator for telescience on /tg/station13
// this isn't accurate enough to steal DAT FUKKEN DISK exactly
// but that's the price you pay for automation.
// it is PLENTY accurate - enough to, say, teleport an EMP grenade into the cap's office
// to take out cameras, then have an accomplice teleport you in to grab the disk yourself.
// and of course with a halfway competent toxins lab it's WAY precise enough for bombs.
// use your imagination.
// iterator function
def findMinimumPower ($x, $off) {
$powerSettings = vector(5,10,20,25,30,40,50,80,100);
$iter = 1;
$power = 0;
while ($iter < (length($powerSettings) + 1)) {
$tryPower = at($powerSettings, $iter);
if ((($tryPower-$off) ^ 2) > ($x * 10)) {
$power = $tryPower;
$iter = length($powerSettings) + 1;
} else {
$iter = $iter + 1;
}
}
return $power;
}
// variable defs
$origX = 0;
$origY = 0;
$offsetPower = 0;
$offsetBearing = 0;
$allowedCmds = vector(
"set-origin",
"calibrate",
"calc"
);
// get content
$contentVec = explode($content, " ");
// do some initialization
if (mem("originSaved") == 1) {
$origX = mem("origX");
$origY = mem("origY");
}
if (mem("calibrated") == 1) {
$offsetPower = mem("offsetPower");
$offsetBearing = mem("offsetBearing");
}
// check if trig command
if (at($contentVec, 1) == "/trig") {
$pass = false;
if (mem("originSaved") != 1 && at($contentVec,2) != "set-origin") {
broadcast("WARNING:\nUnknown teleport origin.\nDo '/trig set-origin X Y' and retry.",1351,"TRIGGER");
} else {
// check if command is allowed
$cmd = at($contentVec, 2);
if (!find($allowedCmds, $cmd)) {
broadcast("WARNING:\nInvalid command.",1351,"TRIGGER");
} else {
// get args
$arglen = length($contentVec) + 1;
$args = copy($contentVec, 3, $arglen);
// handle command
if ($cmd == "set-origin") {
$origX = at($args,1);
$origY = at($args,2);
$origX = tonum($origX);
$origY = tonum($origY);
mem("origX", $origX);
mem("origY", $origY);
mem("originSaved", 1);
broadcast("INFORMATION:\nTeleport origin set to (" + $origX + "," + $origY + ",1).",1351,"TRIGGER");
} elseif ($cmd == "calibrate") {
$destX = at($args,1);
$destY = at($args,2);
$destX = tonum($destX);
$destY = tonum($destY);
// how far did it go?
$distX = abs($origX - $destX);
$distY = abs($origY - $destY);
$distSquared = ($distX ^ 2) + ($distY ^ 2);
$distRaw = sqrt($distSquared);
// invert the destination equation to solve for bearing offset
$offsetBearing = asin(($destX - $origX) / $distRaw);
//$offsetBearing = round($offsetBearing);
mem("offsetBearing", $offsetBearing);
// invert distance equation to solve for power offset
$offsetPower = 20 - ((sqrt(10)) * ($distSquared ^ 0.25));
//$offsetPower = round($offsetPower);
mem("offsetPower", $offsetPower);
$bOffStr = tostring($offsetBearing);
$pOffStr = tostring($offsetPower);
broadcast("INFORMATION:\nOffsets calculated.\nPower offset is -" + $pOffStr + ".\nBearing offset is " + $bOffStr + ".",1351,"TRIGGER");
mem("calibrated",1);
} elseif ($cmd == "calc") {
if (mem("calibrated") != 1) {
broadcast("WARNING:\nYou do not appear to have entered calibration data yet.\nTeleport a GPS with settings: bearing 0, elevation 45, power 20.\nThen, do '/trig calibrate X Y' where X and Y are the destination coordinates, and retry.",1351,"TRIGGER");
} else {
$targX = at($args,1);
$targY = at($args,2);
$targX = tonum($targX);
$targY = tonum($targY);
// calculate distance
$tDistX = abs($origX - $targX);
$tDistY = abs($origY - $targY);
$tDistSquared = ($tDistX ^ 2) + ($tDistY ^ 2);
$tDist = sqrt($tDistSquared);
// invert and solve for bearing
$bearing = asin(($targX - $origX) / $tDist) - $offsetBearing;
$bearing = abs($bearing);
if ($targX > $origX) { // going east
if ($targY > $origY) { // going north
// do nothing;
} elseif ($targY < $origY) { // going south
$bearing = $bearing + 90;
} else { // not moving on Y axis
// not sure honestly
// but probably shouldn't fuck with it here
}
} elseif ($targX < $origX) { // going west
if ($targY > $origY) { // going north
$bearing = $bearing * -1;
} elseif ($targY < $origY) { // going south
$bearing = ($bearing + 90) * -1;
} else { // no delta Y
// ditto
}
} else { // no delta X
// same
}
$bearing = round($bearing);
// iterate over power settings for the lowest that still exceeds tDist*10 when squared, will return 0 if distance is craycray and throw an error
$testPower = findMinimumPower($tDist, $offsetPower);
if ($testPower) {
$elevation = asin((10 * $tDist) / (($testPower - $offsetPower) ^ 2)) / 2;
$elevation = round($elevation);
// VITAMINS DONE
$xStr = tostring($targX);
$yStr = tostring($targY);
$bearStr = tostring($bearing);
$elevStr = tostring($elevation);
$powrStr = tostring($testPower);
broadcast("INFORMATION:\nCalculations complete.\nDestination coordinates: (" + $xStr + "," + $yStr + ")\nBearing: " + $bearStr + "\nElevation: " + $elevStr + "\nPower: " + $powrStr + "",1351,"TRIGGER");
} else {
broadcast("WARNING:\nYour destination is out of range.",1351,"TRIGGER");
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment