Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Turret API

Discussion in 'Programming (In-game)' started by joeblack616, Mar 5, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi, we added following new methods into Sandbox.ModAPI.Ingame.IMyLargeTurretBase

    void TrackTarget(IMyEntity entity);
    void TrackTarget(Vector3D pos, Vector3 velocity);
    void SetTarget(IMyEntity Entity);
    void SetTarget(Vector3D pos);

    float Elevation { get; set; }
    void SyncElevation();
    float Azimuth { get; set; }
    void SyncAzimuth();
    bool EnableIdleRotation { get; set; }

    void SyncEnableIdleRotation();
    bool AIEnabled { get; }
    void ResetTargetingToDefault();

    also ShootOnce and Shoot actions can be triggered on turrets.
     
  2. hellokeith Apprentice Engineer

    Messages:
    335
    These exposed to scripts? Or just mods?
     
  3. joeblack616 Apprentice Engineer

    Messages:
    225
    Sandbox.ModAPI.Ingame.IMyLargeTurretBase ;) (yes, it is for programmable block also)
     
  4. ScriptyNoob Apprentice Engineer

    Messages:
    133
    wow :eek Thanks!
     
  5. indigodarkwolf Apprentice Engineer

    Messages:
    115
    Hopefully someone uses this to make a laser-light show for their world, using the targeting lasers on the turrets. :3
     
  6. SigmaStrain Trainee Engineer

    Messages:
    27
    I noticed with the track target and set target functions, they pass IMyEntity as a parameter. How are we to make use of this? As far as I can tell, no functions exist that return an IMyEntity from another ship.
     
  7. spacecadet Trainee Engineer

    Messages:
    89
    @indigodarkwolf green argon laser rave \m/

    @SigmaStrain Sensor can return IMyEntity from LastDetectedEntity...my guess is a Laser Antenna would do similar.
     
    Last edited by a moderator: Mar 6, 2015
  8. teclab85 Trainee Engineer

    Messages:
    21
    I was using Sensor blocks to track positions of enemies.. It had to be within 50 m of the sensor. If you think really hard about what I just wrote I think you will realize that turrets have an 800m range... hehe fun for the whole fleet!
     
  9. Phoera Senior Engineer

    Messages:
    1,713
    joeblack616, why still ignoring code i have sent to fix switches?
     
  10. Burillo Junior Engineer

    Messages:
    648
    can this be used to target meteors?
     
  11. ScriptyNoob Apprentice Engineer

    Messages:
    133
    phoenixcorp13

    Old known bugs in PB not fixed now, maybe later devs fix, who know...
    IMHO aren't against that some bugs are not fixed, I get a lot of fun to using some bugs. :)

    Example: http://forums.keenswh.com/post/nuclear-missile-prototype-7323714
     
    Last edited by a moderator: Mar 6, 2015
  12. RA2lover Trainee Engineer

    Messages:
    96
    What happens when an out-of-sync turret is fired?
     
  13. SigmaStrain Trainee Engineer

    Messages:
    27
    I'd also like to know this. What is the purpose of turret syncing?
     
  14. ScriptyNoob Apprentice Engineer

    Messages:
    133
    Turret API Sample

    http://steamcommunity.com/sharedfiles/filedetails/?id=401966136

    I'm try to load, but game: this world can not be loaded. It has been created in newer version of game etc.

    That version? I use 1.72.008 :(

    Hm, I found

    Code:
    <AppVersion>1073001</AppVersion>
     
    Last edited by a moderator: Mar 6, 2015
  15. Lynnux Junior Engineer

    Messages:
    881
    Is there a description for this API somewhere ?

    Specifics:
    1) How to set the velocity ?
    Is it like "Target.GetPosition() - Target1SecondBefore.GetPosition()" ?
    Currently when I use TrackTarget(TargetPos, velocity), the game will crash

    2) What is the purpose of turret syncing? What are SyncElevation() and SyncAzimuth() doing ?
     
    Last edited by a moderator: Mar 7, 2015
  16. Lynnux Junior Engineer

    Messages:
    881
    Except for tricks with sensor and previously connected ships (declared as bug by KSH) this is only possible in mods.
    But we have - I almost don't dare to write this again - radar. You can set the position of the target found by radar. I just didn't succeed to set the velocity yet, game crashes everytime...

    means SetTarget(Vector3D) works, TrackTarget(Vector3D, Vector3) crashes.
     
    Last edited by a moderator: Mar 8, 2015
  17. Lynnux Junior Engineer

    Messages:
    881
    TrackTarget(Vector3D, Vector3) implementation is bugged, bug report created.
     
  18. Dawnkeeper Apprentice Engineer

    Messages:
    260
    We have radar? What ? How?
     
    Last edited by a moderator: Mar 10, 2015
  19. Phoera Senior Engineer

    Messages:
    1,713
    radar is mod.
     
  20. gchristopher Apprentice Engineer

    Messages:
    132
    Well, this looks great, and the information in Documentation.chm matches what was posted here, but I'm having a hard time validating any of it in game.

    I'm in creative mode, version 01_073_009 64-bit Build 2015-03-12 04:30, on a station with a single turret named "Gatling Turret Test" and a Text Panel named "Debug Panel"

    Here's the code I'm running to look for the properties:

    Code:
    void debug(string s, bool reset = false) {
      IMyTextPanel debug_panel = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("Debug Panel");
      if(reset) debug_panel.WritePublicText("", false);
      string curr_text = debug_panel.GetPublicText();
      debug_panel.WritePublicText(curr_text + "\n" + s, false);
    }
    void Main() {
      debug("IMyLargeTurretBase test script", true);
      // Get the test turret.
      IMyLargeTurretBase target_gun = (IMyLargeTurretBase)GridTerminalSystem.GetBlockWithName("Gatling Turret Test");
      // Make sure we've actually got the selected turret by switching it on so we can see the laser activate.
      target_gun.GetActionWithName("OnOff_On").Apply(target_gun); 
      
      // Display the list of properties for the turret.
      List<ITerminalProperty> result = new List<ITerminalProperty>(); 
      target_gun.GetProperties(result); 
      debug("Prop count: " + result.Count);
      for(int ii = 0; ii < result.Count; ii++) {
        debug(result[ii].Id);
      }
      
      debug(target_gun.DetailedInfo);
    }
    
    What shows up on the LCD is:
    How do I find the other properties? Is it possible to set Azimuth and Elevation?
     
  21. gchristopher Apprentice Engineer

    Messages:
    132
    Though, SetTarget(Vector3) should be able to accomplish any Azimuth and Elevation you want, if you calculate the relative positions, so I guess that's not a problem!
     
  22. hellokeith Apprentice Engineer

    Messages:
    335
    Keen could prolly do with a better naming schema, but anyways there are properties and methods, and then there are terminal properties and terminal actions. IMyLargeTurretBase has the properties and methods you mention, and IMyUserControllableGun has terminal properties / terminal actions. There are also terminal property extensions, so you could just do target_gun.ApplyAction("OnOff_On").
     
  23. Lynnux Junior Engineer

    Messages:
    881
    I've entered the properties and actions for some blocks found by the GetProperties and GetAction interfaces in the Wiki. Of course, I didn't find more than you.
    The other you'll find in the Documentation.chm or better if you install Visual Studio and take a look at the DLLs themselves.
    You can e.g. set Turret.Azimuth=0 and Turret.Elevation=0.
    If the turret is not moving into the idle position call Turret.SyncAzimuth() and Turret.SyncElevation() afterwards and see whats happening. I'm not sure what these interfaces are doing exactly, though but the turret was moving into the idle position for a short time while being controlled.
    Simulated to point the turret camera of Darth Biomech at a target this way while controlling it (and therefore looking through it) but it moved back to a different angle immediately.
     
    Last edited by a moderator: Mar 14, 2015
  24. gchristopher Apprentice Engineer

    Messages:
    132
    I'm still trying to reliably set a turret to an orientation relative to the ship. I'm testing on a dedicated server.

    SetTarget seems to work as advertised, and the turret tracks the selected location.

    One thing I noticed is that if a Turret has ever had a SetTarget call, it will ignore subsequent attempts to set Elevation or Azimuth. The AI continues to track the target and immediately overrides any set orientation. Resetting the server fixes this, but that's not very helpful.

    More frustrating, I still haven't found a combination of setting elevation and azimuth along with the synch commands that actually works.

    Here's the code I'm trying right now. (This snippet excludes the initialization and debug, etc, the only unproven code is the section below relating to the selected turret.)

    Code:
      IMyLargeTurretBase left_gun = (IMyLargeTurretBase)GridTerminalSystem.GetBlockWithName("Gatling Turret Top Left");
      debug("idle Enabled " + left_gun.EnableIdleRotation); 
      debug("AI Enabled " + left_gun.AIEnabled); 
      debug("elevation " + left_gun.Elevation);
      debug("Azimuth " + left_gun.Azimuth);
      left_gun.Elevation = (float)0.1234f;
      left_gun.SyncElevation();
      left_gun.Azimuth = (float)0.3456;
      left_gun.SyncAzimuth();
      debug("elevation " + left_gun.Elevation);
      debug("Azimuth " + left_gun.Azimuth);
    
    If I start by manually pointing the turret away, run this code, and watch the how the turret moves, I see the Elevation immediately change in response, but the Azimuth does not change.
    Here's what the debug panel looks like immediately after running the code once:

    [​IMG]
    The debug output is exactly as you'd expect, with the Elevation and Azimuth changed to the values specified by the script, except that the turret only elevates and does not rotate.

    When the script is run again, the turret does not move at all, but the debug output is very confusing:

    [​IMG]
    The value for Elevation appears to have been set to the value for the Azimuth somehow. Maybe there is a bug with SynchAzimuth?

    I'm not sure what else is required to orient a turret. Has anyone else tried?
     
  25. gchristopher Apprentice Engineer

    Messages:
    132
    One acceptable workaround for being unable to set Azimuth and Elevation directly was to set a programming block on a timer, and repeatedly calculate the point in space relative to the ship, then set the turret target to that point.

    The goal was to get all the gatling turrets on a large ship to focus their fire on the same target, and it worked great for accurately disabling NPC turrets from outside detection range, using a zoomed in camera to aim! (Detail rendering of the target is acceptable, though not great, at around 1000m. You can see the turret bases even if the turret heads aren't rendered.)
     
    Last edited by a moderator: Mar 23, 2015
  26. Lynnux Junior Engineer

    Messages:
    881
    So you tried to control more turrets than one via azimuth and elevation ? Did you try one turret ?
    Because SetTarget() is setting all turrets currently controlled by this interface to target that coordinate. If the same bug exists for azimuth and elevation...
     
  27. gchristopher Apprentice Engineer

    Messages:
    132
    I was trying to control only one turret.

    The two potential bugs I observed (in a DS, using the Synch... commands) were:

    - The turret moves in response to setting elevation, but not azimuth
    - Setting or synching causes azimuth to override elevation, maybe? (I'm not as sure of what behavior is happening here.)

    So either the code I posted above is wrong, (examples, anyone?) or setting elevation and azimuth doesn't work yet, for my installation at least.
     
  28. mexmer Senior Engineer

    Messages:
    1,977
    if you don't want turret to autoaim, after you set target, you need to disable AI.
    either you enable AI, or you manually set azimuth and elevation, but you cannot have both.
     
  29. gchristopher Apprentice Engineer

    Messages:
    132
    Yes, I tried that and was unable to change the value of AIEnabled, as part of earlier testing. But that was a few weeks ago. I can try again.

    Did you get it working reliably? I'd love to see sample code from anyone that has.
     
    Last edited: Apr 24, 2015
  30. evil.unicorn1 Trainee Engineer

    Messages:
    49
    Is there a possibility to make turrets just to aim, but not to shoot?
     
Thread Status:
This last post in this thread was made more than 31 days old.