Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- /// Whip's Fixed Weapon Drone Mod - rev 3.0 - 9/21/15 ///
- */
- double range = 400; //range in meters
- double degree_tolerance = 5;
- string message;
- string range_m = "0";
- string angle_m = "0";
- string shoot_m = "null";
- List<IMyTerminalBlock> remotes = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> weapons = new List<IMyTerminalBlock>();
- List<IMyTerminalBlock> antennas = new List<IMyTerminalBlock>();
- void Main()
- {
- IMyTimerBlock frontRefrence = GridTerminalSystem.GetBlockWithName("Timer - Drone Front") as IMyTimerBlock;
- if (frontRefrence == null)
- {
- message = "ERROR: No front refrence set";
- Echo("ERROR: No front refrence set");
- return;
- }
- else
- {
- Echo("WMI Drone Systems Online");
- }
- GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(blocks);
- for (int i=0 ; i < blocks.Count ; i++)
- {
- if(blocks[i] is IMyLargeTurretBase) continue; //ignore turrets
- if(!(blocks[i] is IMyUserControllableGun)) continue; //ignore everything not a weapon
- weapons.Add(blocks[i] as IMyUserControllableGun); //add weapons to list
- }
- GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(remotes);
- if (remotes.Count > 0)
- {
- var remote = remotes[0] as IMyRemoteControl;
- remote.ClearWaypoints();
- //making empty vector for us to populate
- Vector3D playerPosition = new Vector3D(0, 0, 0);
- Vector3D currentPosition = new Vector3D(0, 0, 0);
- Vector3D currentFront = new Vector3D(0, 0, 0);
- Vector3D shipVector = new Vector3D(0, 0, 0);
- Vector3D playerVector = new Vector3D(0, 0, 0);
- Vector3D difference = new Vector3D(0, 0, 0);
- bool success = remote.GetNearestPlayer(out playerPosition);
- remote.ApplyAction("CollisionAvoidance_On");
- if (success)
- {
- remote.AddWaypoint(playerPosition, "Player"); //follow player
- remote.SetAutoPilotEnabled(true); //enable autopilot
- //populating our vectors
- currentPosition = remote.GetPosition(); //position vector of ship
- currentFront = frontRefrence.GetPosition(); //position vector of front of ship
- shipVector = Vector3D.Subtract(currentFront, currentPosition); //direction vector of ship
- playerVector = Vector3D.Subtract(playerPosition, currentPosition); //direction vector of player
- //some gross vector math
- double dist = Vector3D.Distance(currentPosition, playerPosition);
- range_m = dist.ToString(); //gives us distance between player and ship
- double dotProduct;
- Vector3D.Dot(ref shipVector, ref playerVector, out dotProduct);
- double x = dotProduct / shipVector.Length() / playerVector.Length();
- double theta_deg = Math.Acos(x) * 180f / Math.PI; //angle between ship and player
- angle_m = theta_deg.ToString(); //debug
- //in range
- if (dist < range && theta_deg < degree_tolerance)
- {
- for (int i=0 ; i < weapons.Count ; i++)
- {
- var weaponToShoot = weapons[i] as IMyUserControllableGun;
- weaponToShoot.ApplyAction("Shoot_On");
- shoot_m = "In Range";
- }
- }
- //not in range
- else
- {
- for (int i=0 ; i < weapons.Count ; i++)
- {
- var weaponToShoot = weapons[i] as IMyUserControllableGun;
- weaponToShoot.ApplyAction("Shoot_Off");
- shoot_m = "Out of Range";
- }
- }
- }
- //for debugging since we can't access the ship once it is owned
- GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(antennas);
- var antenna = antennas[0] as IMyRadioAntenna;
- message = "Antenna\nRange: " + range_m
- + "\nAngle: " + angle_m
- + "\nStatus: " + shoot_m;
- antenna.SetCustomName(message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement