Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using BattleCore.Events;
- using BattleCore;
- namespace Sentinel
- {
- class WeaponCalc
- {
- private ushort[] bombStart, position;
- private int[] bombVel, playerVel;
- private int bombForce, intercept;
- private double slope;
- private int delay = 9750;
- //begins at cos 90 degrees and goes counterclockwise - light
- private double[] xChange = new[] { 0.001, -0.156, -0.309, -0.454, -0.588, -0.707, -0.809, -0.891, -0.951, -0.988,
- -1, -0.988, -0.951, -0.891, -0.809, -0.707, -0.588, -0.454, -0.309, -0.156,
- 0.001, 0.156, 0.309, 0.454, 0.588, 0.707, 0.848, 0.891, 0.951, 0.988,
- 1, 0.988, 0.951, 0.891, 0.809, 0.707, 0.588, 0.454, 0.309, 0.156 };
- //begins at sin 90 degrees and goes counterclockwise - light
- private double[] yChange = new[] { 1, 0.988, 0.951, 0.891, 0.809, 0.707, 0.588, 0.454, 0.309, 0.156,
- 0.001, -0.156, -0.309, -0.454, -0.588, -0.707, -0.809, -0.891, -0.951, -0.988,
- -1, -0.988, -0.951, -0.891, -0.809, -0.707, -0.588, -0.454, -0.309, -0.156,
- 0.001, 0.156, 0.309, 0.454, 0.588, 0.707, 0.809, 0.891, 0.951, 0.988 };
- /// <summary>
- /// This will configure your weapon for storing.
- /// </summary>
- public string Configure(ushort[] Target, PlayerPositionEvent p)
- {
- position = Target;
- int bombXVel, bombYVel;
- int playerXVel, playerYVel;
- // If the player being tracked has fired a bomb
- // Save the spot where the bomb was fired
- bombStart = new ushort[2] { p.MapPositionX, p.MapPositionY };
- // Compute the velocity of the bomb
- bombXVel = (int)(-xChange[p.ShipRotation] * 2000);
- bombYVel = (int)(-yChange[p.ShipRotation] * 2000);
- // Convert the player's velocity out of ss format
- playerXVel = (int)(p.VelocityX);
- if (playerXVel > (ushort.MaxValue / 2))
- playerXVel = playerXVel - ushort.MaxValue;
- playerYVel = (int)(p.VelocityY);
- if (playerYVel > (ushort.MaxValue / 2))
- playerYVel = playerYVel - ushort.MaxValue;
- // Add the reformatted velocity to the bomb velocity
- bombXVel = bombXVel + playerXVel;
- if (bombXVel > (ushort.MaxValue / 2))
- bombXVel = bombXVel - ushort.MaxValue;
- bombYVel = bombYVel + playerYVel;
- if (bombYVel > (ushort.MaxValue / 2))
- bombYVel = bombYVel - ushort.MaxValue;
- bombForce = (int)(Math.Sqrt(bombXVel * bombXVel + bombYVel * bombYVel));
- bombVel = new int[2] { bombXVel, bombYVel };
- playerVel = new int[2] { playerXVel, playerYVel };
- string result = CalculateHit();
- if (result == "~miss")
- return result;
- else return result;
- }
- private string CalculateHit()
- {
- string impact = "~miss";
- bool checkhit = false;
- ushort bombXStart = bombStart[0];
- ushort bombYStart = bombStart[1];
- int bombXVel = bombVel[0];
- int bombYVel = bombVel[1];
- int playerXVel = playerVel[0];
- int playerYVel = playerVel[1];
- int x1 = position[0];
- int y1 = position[1];
- int x2 = position[2];
- int y2 = position[3];
- // Calculate the Y-intercept of the bomb's trajectory
- slope = (double)(bombYVel) / (double)(bombXVel);
- intercept = (int)(bombYStart - (slope * bombXStart));
- if (bombXVel == 0)
- {
- // Special consideration if the bomb's slope is technically infinity
- if ((bombXStart > x1) && (bombXStart < x2))
- checkhit = true;
- }
- else if (slope < 0)
- {
- if (((y1 - (slope * x1)) <= intercept) && (intercept <= (y2 - (slope * x2))))
- checkhit = true;
- }
- else
- {
- if (((y2 - (slope * x1)) >= intercept) && (intercept >= (y1 - (slope * x2))))
- checkhit = true;
- }
- if (checkhit)
- {
- bombStart = new ushort[2] { bombXStart, bombYStart };
- bombVel = new int[2] { bombXVel, bombYVel };
- playerVel = new int[2] { playerXVel, playerYVel };
- // Determine if the bomb is going the correct way to hit the box
- if (slope < 0)
- {
- if ((bombStart[1] >= position[1]) && (bombVel[1] < 0))
- {
- if (intercept <= (position[3] - (slope * position[0])))
- //Hit on the west wall
- impact = "x1";
- else
- // Hit on the south wall
- impact = "y2";
- }
- else if ((bombStart[1] <= position[3]) && (bombVel[1] > 0))
- {
- if (intercept <= (position[1] - (slope * position[2])))
- //Hit on the north wall
- impact = "y1";
- else
- //Hit on the east wall
- impact = "x2";
- }
- }
- else
- {
- if ((bombStart[0] <= position[2]) && (bombVel[0] > 0))
- {
- if (intercept >= (position[1] - (slope * position[0])))
- // Hit on the west wall
- impact = "x1";
- else
- // Hit on the north wall
- impact = "y1";
- }
- else if ((bombStart[0] >= position[0]) && (bombVel[0] < 0))
- {
- if (intercept >= (position[3] - (slope * position[2])))
- // Hit on the south wall
- impact = "y2";
- else
- // Hit on the east wall
- impact = "x2";
- }
- }
- }
- return impact;
- }
- /// <summary>
- /// Calculate time until weapon impact.
- /// </summary>
- /// <param name="CHresult"></param>
- /// Send whatever was sent from Calculate Hit only if it is not "~miss" (Make sure to check)
- /// <returns>Time it will take for a weapon to hit.</returns>
- public double timeHit(string CHresult)
- {
- int coord, distance = 0;
- // Calculate the other half of the coordinate on the target needed to figure out the distance between
- // the player and the point of impact
- if (CHresult == "x1")
- {
- coord = (int)(slope * position[0]) + intercept;
- distance = (int)(Math.Sqrt((bombStart[1] - coord) * (bombStart[1] - coord) + (bombStart[0] - position[0]) * (bombStart[0] - position[0])));
- }
- else if (CHresult == "x2")
- {
- coord = (int)(slope * position[2]) + intercept;
- distance = (int)(Math.Sqrt((bombStart[1] - coord) * (bombStart[1] - coord) + (bombStart[0] - position[2]) * (bombStart[0] - position[2])));
- }
- else if (CHresult == "y1")
- {
- coord = (int)((position[1] - intercept) / slope);
- distance = (int)(Math.Sqrt((bombStart[1] - position[1]) * (bombStart[1] - position[1]) + (bombStart[0] - coord) * (bombStart[0] - coord)));
- }
- else if (CHresult == "y2")
- {
- coord = (int)((position[3] - intercept) / slope);
- distance = (int)(Math.Sqrt((bombStart[1] - position[3]) * (bombStart[1] - position[3]) + (bombStart[0] - coord) * (bombStart[0] - coord)));
- }
- // Estimate the time until impact
- double time = ((double)(distance) / (double)(bombForce));
- if (bombForce > 3500)
- if (distance < 350)
- // Reduce the delay a substantial amount for close range and high velocity
- time = time * (delay - 1000);
- else
- // Reduce the delay a fair bit for high velocity
- time = time * (delay - 500);
- else if (bombForce > 2000)
- if (distance < 350)
- // Reduce the delay a fair bit for close and medium velocity
- time = time * (delay - 500);
- else
- // Reduce the delay somewhat for just medium velocity
- time = time * (delay - 250);
- else
- if (distance < 350)
- // Reduce the delay a bit for close range low speed
- time = time * (delay - 250);
- else
- time = time * delay;
- return time;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment